php Wikibase-Repo-WikibaseRepo类(方法)实例源码

下面列出了php Wikibase-Repo-WikibaseRepo 类(方法)源码代码实例,从而了解它的用法。

作者:Benesta    项目:mediawiki-extensions-Wikibas   
/**
  * @see SpecialWikibasePage::__construct
  */
 public function __construct()
 {
     parent::__construct('GoToLinkedPage', '', true);
     $wikibaseRepo = WikibaseRepo::getDefaultInstance();
     $this->initServices($wikibaseRepo->getSiteStore(), $wikibaseRepo->getStore()->newSiteLinkStore(), $wikibaseRepo->getStore()->getEntityRedirectLookup(), $wikibaseRepo->getEntityIdParser(), $wikibaseRepo->getStore()->getEntityLookup());
     $this->errorMessageKey = null;
 }

作者:TU-Berli    项目:WikidataMat   
/**
  * @param ApiMain $mainModule
  * @param string $moduleName
  * @param string $modulePrefix
  *
  * @see ApiBase::__construct
  */
 public function __construct(ApiMain $mainModule, $moduleName, $modulePrefix = '')
 {
     parent::__construct($mainModule, $moduleName, $modulePrefix);
     $wikibaseRepo = WikibaseRepo::getDefaultInstance();
     $apiHelperFactory = $wikibaseRepo->getApiHelperFactory($this->getContext());
     $this->setServices($wikibaseRepo->getEntityIdParser(), $apiHelperFactory->getErrorReporter($this), $apiHelperFactory->getResultBuilder($this), new ItemMergeInteractor($wikibaseRepo->getChangeOpFactoryProvider()->getMergeChangeOpFactory(), $wikibaseRepo->getEntityRevisionLookup('uncached'), $wikibaseRepo->getEntityStore(), $wikibaseRepo->getEntityPermissionChecker(), $wikibaseRepo->getSummaryFormatter(), $this->getUser(), $wikibaseRepo->newRedirectCreationInteractor($this->getUser(), $this->getContext())));
 }

作者:Benesta    项目:mediawiki-extensions-Wikibas   
protected function setUp()
 {
     parent::setUp();
     $sitesTable = WikibaseRepo::getDefaultInstance()->getSiteStore();
     $sitesTable->clear();
     $sitesTable->saveSites(TestSites::getSites());
 }

作者:Benesta    项目:mediawiki-extensions-Wikibas   
/**
  * Tests @see WikibaseItem::getIdForSiteLink
  */
 public function testMovePrevention()
 {
     $wikibaseRepo = WikibaseRepo::getDefaultInstance();
     $titleLookup = $wikibaseRepo->getEntityTitleLookup();
     // Moving a regular page into data NS onto an existing item
     $title = $this->itemTitle;
     $this->assertInstanceOf('Title', $title);
     // sanity check
     $this->assertFalse($this->page->getTitle()->moveTo($title) === true);
     $entityNamespaceLookup = $wikibaseRepo->getEntityNamespaceLookup();
     $itemNamespace = $entityNamespaceLookup->getEntityNamespace(CONTENT_MODEL_WIKIBASE_ITEM);
     // Moving a regular page into data NS to an invalid location
     // @todo: test other types of entities too!
     $title = Title::newFromText($this->page->getTitle()->getText(), $itemNamespace);
     $this->assertFalse($this->page->getTitle()->moveTo($title) === true);
     // Moving a regular page into data NS to an empty (but valid) location
     $title = $titleLookup->getTitleForId(new ItemId('Q42'));
     $this->assertFalse($this->page->getTitle()->moveTo($title) === true);
     // Moving item page out of data NS onto an existing page
     $title = $this->page->getTitle();
     $this->assertFalse($this->itemTitle->moveTo($title) === true);
     // Moving item page out of data NS onto a non-existing page
     $title = Title::newFromText('wbmovetestitem');
     $this->assertFalse($this->itemTitle->moveTo($title) === true);
     // Moving item to an invalid location in the data NS
     $title = Title::newFromText($this->page->getTitle()->getText(), $itemNamespace);
     $this->assertFalse($this->itemTitle->moveTo($title) === true);
     // Moving item to an valid location in the data NS
     $title = $titleLookup->getTitleForId(new ItemId('Q42'));
     $this->assertFalse($this->itemTitle->moveTo($title) === true);
 }

作者:TU-Berli    项目:WikidataMat   
/**
  * Get the language fallback chain for current context.
  *
  * @since 0.4
  *
  * @return LanguageFallbackChain
  */
 public function getLanguageFallbackChain()
 {
     if ($this->languageFallbackChain === null) {
         $this->languageFallbackChain = WikibaseRepo::getDefaultInstance()->getLanguageFallbackChainFactory()->newFromContext($this->getContext());
     }
     return $this->languageFallbackChain;
 }

作者:Benesta    项目:mediawiki-extensions-Wikibas   
/**
  * @since 0.4
  *
  * @param string $title The title of the special page
  * @param string $restriction The required user right, 'edit' per default.
  */
 public function __construct($title, $restriction = 'edit')
 {
     parent::__construct($title, $restriction);
     $settings = WikibaseRepo::getDefaultInstance()->getSettings();
     $this->rightsUrl = $settings->getSetting('dataRightsUrl');
     $this->rightsText = $settings->getSetting('dataRightsText');
 }

作者:Benesta    项目:mediawiki-extensions-Wikibas   
/**
  * @param ApiMain $mainModule
  * @param string $moduleName
  * @param string $modulePrefix
  *
  * @see ApiBase::__construct
  */
 public function __construct(ApiMain $mainModule, $moduleName, $modulePrefix = '')
 {
     parent::__construct($mainModule, $moduleName, $modulePrefix);
     $wikibaseRepo = WikibaseRepo::getDefaultInstance();
     $apiHelperFactory = $wikibaseRepo->getApiHelperFactory($this->getContext());
     $this->setServices($wikibaseRepo->getDataTypeFactory(), $wikibaseRepo->getValueParserFactory(), $wikibaseRepo->getDataTypeValidatorFactory(), $wikibaseRepo->getExceptionLocalizer(), $wikibaseRepo->getValidatorErrorLocalizer(), $apiHelperFactory->getErrorReporter($this));
 }

作者:TU-Berli    项目:WikidataMat   
public function testScript()
 {
     $dumpScript = new DumpRdf();
     $mockRepo = new MockRepository();
     $mockEntityPerPage = new MockEntityPerPage();
     $snakList = new SnakList();
     $snakList->addSnak(new PropertySomeValueSnak(new PropertyId('P12')));
     $snakList->addSnak(new PropertyValueSnak(new PropertyId('P12'), new StringValue('stringVal')));
     /** @var Entity[] $testEntities */
     $testEntities = array(new Item(new ItemId('Q1')), new Property(new PropertyId('P1'), null, 'string'), new Property(new PropertyId('P12'), null, 'string', new StatementList(array(new Statement(new PropertySomeValueSnak(new PropertyId('P999')), null, null, 'GUID1')))), new Item(new ItemId('Q2'), new Fingerprint(new TermList(array(new Term('en', 'en-label'), new Term('de', 'de-label'))), new TermList(array(new Term('fr', 'en-desc'), new Term('de', 'de-desc'))), new AliasGroupList(array(new AliasGroup('en', array('ali1', 'ali2')), new AliasGroup('dv', array('ali11', 'ali22'))))), new SiteLinkList(array(new SiteLink('enwiki', 'Berlin'), new SiteLink('dewiki', 'England', array(new ItemId('Q1'))))), new StatementList(array(new Statement(new PropertySomeValueSnak(new PropertyId('P12')), null, null, 'GUID1'), new Statement(new PropertySomeValueSnak(new PropertyId('P12')), $snakList, new ReferenceList(array(new Reference(array(new PropertyValueSnak(new PropertyId('P12'), new StringValue('refSnakVal')), new PropertyNoValueSnak(new PropertyId('P12')))))), 'GUID2')))));
     foreach ($testEntities as $key => $testEntity) {
         $mockRepo->putEntity($testEntity, $key, '20000101000000');
         $mockEntityPerPage->addEntityPage($testEntity->getId(), $key);
     }
     // Note: We are testing with the actual RDF bindings, so we can check for actual RDF output.
     $rdfBuilder = WikibaseRepo::getDefaultInstance()->getValueSnakRdfBuilderFactory();
     $dumpScript->setServices($mockEntityPerPage, new NullEntityPrefetcher(), MockSiteStore::newFromTestSites(), $this->getMockPropertyDataTypeLookup(), $rdfBuilder, $mockRepo, 'fooUri');
     $logFileName = tempnam(sys_get_temp_dir(), "Wikibase-DumpRdfTest");
     $outFileName = tempnam(sys_get_temp_dir(), "Wikibase-DumpRdfTest");
     $dumpScript->loadParamsAndArgs(null, array('log' => $logFileName, 'output' => $outFileName, 'format' => 'n-triples'));
     $dumpScript->execute();
     $expectedLog = file_get_contents(__DIR__ . '/../data/maintenance/dumpRdf-log.txt');
     $expectedOut = file_get_contents(__DIR__ . '/../data/maintenance/dumpRdf-out.txt');
     $actualOut = file_get_contents($outFileName);
     $actualOut = preg_replace('/<http:\\/\\/wikiba.se\\/ontology-beta#Dump> <http:\\/\\/schema.org\\/dateModified> "[^"]+"/', "<http://wikiba.se/ontology-beta#Dump> <http://schema.org/dateModified> \"2015-01-01T00:00:00Z\"", $actualOut);
     $this->assertEquals($this->fixLineEndings($expectedLog), $this->fixLineEndings(file_get_contents($logFileName)));
     $this->assertEquals($this->fixLineEndings($expectedOut), $this->fixLineEndings($actualOut));
 }

作者:Benesta    项目:mediawiki-extensions-Wikibas   
private function getChangeNotifier($expectNotifications = 1)
 {
     $changeTransmitter = $this->getMock('Wikibase\\Repo\\Notifications\\ChangeTransmitter');
     $changeTransmitter->expects($this->exactly($expectNotifications))->method('transmitChange');
     $notifier = new ChangeNotifier(WikibaseRepo::getDefaultInstance()->getEntityChangeFactory(), array($changeTransmitter));
     return $notifier;
 }

作者:Benesta    项目:mediawiki-extensions-Wikibas   
/**
  * @param ItemId $itemId
  * @param ItemId $targetId
  *
  * @return ItemContent
  */
 private function newRedirect(ItemId $itemId, ItemId $targetId)
 {
     // FIXME: Use the respective EntityHandler instead of going via the global title lookup!
     $titleLookup = WikibaseRepo::getDefaultInstance()->getEntityTitleLookup();
     $title = $titleLookup->getTitleForId($targetId);
     return ItemContent::newFromRedirect(new EntityRedirect($itemId, $targetId), $title);
 }

作者:Benesta    项目:mediawiki-extensions-Wikibas   
/**
  * @dataProvider termProvider
  */
 public function testRebuildSearchKey($languageCode, $termText, $searchText, $matches)
 {
     /* @var TermSqlIndex $termCache */
     $termCache = WikibaseRepo::getDefaultInstance()->getStore()->getTermIndex();
     // make term in item
     $item = new Item(new ItemId('Q42'));
     $item->setLabel($languageCode, $termText);
     // save term
     $termCache->clear();
     $termCache->saveTermsOfEntity($item);
     // remove search key
     $dbw = wfGetDB(DB_MASTER);
     $dbw->update($termCache->getTableName(), array('term_search_key' => ''), array(), __METHOD__);
     // rebuild search key
     $builder = new TermSearchKeyBuilder($termCache);
     $builder->setRebuildAll(true);
     $builder->rebuildSearchKey();
     // remove search key
     $term = new TermIndexEntry();
     $term->setLanguage($languageCode);
     $term->setText($searchText);
     $options = array('caseSensitive' => false);
     $obtainedTerms = $termCache->getMatchingTerms(array($term), TermIndexEntry::TYPE_LABEL, Item::ENTITY_TYPE, $options);
     $this->assertEquals($matches ? 1 : 0, count($obtainedTerms));
     if ($matches) {
         $obtainedTerm = array_shift($obtainedTerms);
         $this->assertEquals($termText, $obtainedTerm->getText());
     }
 }

作者:Benesta    项目:mediawiki-extensions-Wikibas   
/**
  * @see ApiBase::execute
  *
  * @since 0.5
  */
 public function execute()
 {
     $badgeItems = WikibaseRepo::getDefaultInstance()->getSettings()->getSetting('badgeItems');
     $idStrings = array_keys($badgeItems);
     ApiResult::setIndexedTagName($idStrings, 'badge');
     $this->getResult()->addValue(null, 'badges', $idStrings);
 }

作者:Benesta    项目:mediawiki-extensions-Wikibas   
/**
  * @param EntityDocument $entity
  */
 private function save(EntityDocument $entity)
 {
     $flags = $entity->getId() ? EDIT_UPDATE : EDIT_NEW;
     $store = WikibaseRepo::getDefaultInstance()->getEntityStore();
     $rev = $store->saveEntity($entity, '', $GLOBALS['wgUser'], $flags);
     $entity->setId($rev->getEntity()->getId());
 }

作者:TU-Berli    项目:WikidataMat   
public function __construct()
 {
     parent::__construct('SetLabelDescriptionAliases', 'edit');
     $wikibaseRepo = WikibaseRepo::getDefaultInstance();
     $this->changeOpFactory = $wikibaseRepo->getChangeOpFactoryProvider()->getFingerprintChangeOpFactory();
     $this->termsLanguages = $wikibaseRepo->getTermsLanguages();
 }

作者:TU-Berli    项目:WikidataMat   
public function setup()
 {
     parent::setup();
     if (!isset(self::$hasSetup)) {
         $wikibaseRepo = WikibaseRepo::getDefaultInstance();
         $store = $wikibaseRepo->getEntityStore();
         $prop = Property::newFromType('string');
         $store->saveEntity($prop, 'EditEntityTestP56', $GLOBALS['wgUser'], EDIT_NEW);
         self::$idMap['%P56%'] = $prop->getId()->getSerialization();
         self::$idMap['%StringProp%'] = $prop->getId()->getSerialization();
         $prop = Property::newFromType('string');
         $store->saveEntity($prop, 'EditEntityTestP72', $GLOBALS['wgUser'], EDIT_NEW);
         self::$idMap['%P72%'] = $prop->getId()->getSerialization();
         $this->initTestEntities(array('Berlin'), self::$idMap);
         self::$idMap['%Berlin%'] = EntityTestHelper::getId('Berlin');
         $p56 = self::$idMap['%P56%'];
         $berlinData = EntityTestHelper::getEntityOutput('Berlin');
         self::$idMap['%BerlinP56%'] = $berlinData['claims'][$p56][0]['id'];
         $badge = new Item();
         $store->saveEntity($badge, 'EditEntityTestQ42', $GLOBALS['wgUser'], EDIT_NEW);
         self::$idMap['%Q42%'] = $badge->getId()->getSerialization();
         $badge = new Item();
         $store->saveEntity($badge, 'EditEntityTestQ149', $GLOBALS['wgUser'], EDIT_NEW);
         self::$idMap['%Q149%'] = $badge->getId()->getSerialization();
         $badge = new Item();
         $store->saveEntity($badge, 'EditEntityTestQ32', $GLOBALS['wgUser'], EDIT_NEW);
         self::$idMap['%Q32%'] = $badge->getId()->getSerialization();
         $wikibaseRepo->getSettings()->setSetting('badgeItems', array(self::$idMap['%Q42%'] => '', self::$idMap['%Q149%'] => '', 'Q99999' => ''));
     }
     self::$hasSetup = true;
 }

作者:TU-Berli    项目:WikidataMat   
/**
  * @return OutputPageBeforeHTMLHookHandler
  */
 public static function newFromGlobalState()
 {
     $wikibaseRepo = WikibaseRepo::getDefaultInstance();
     $entityIdParser = $wikibaseRepo->getEntityIdParser();
     $entityContentFactory = $wikibaseRepo->getEntityContentFactory();
     return new self(TemplateFactory::getDefaultInstance(), new BabelUserLanguageLookup(), $wikibaseRepo->getTermsLanguages(), $entityIdParser, $wikibaseRepo->getEntityRevisionLookup(), new LanguageNameLookup(), $entityContentFactory);
 }

作者:Benesta    项目:mediawiki-extensions-Wikibas   
/**
  * @param Entity $entity
  * @param string|null $expectedEntityType
  * @param EntityId|null $expectedEntityId
  *
  * @return EntityHolder
  */
 private function newHolder(Entity $entity, $expectedEntityType = null, EntityId $expectedEntityId = null)
 {
     $wikibaseRepo = WikibaseRepo::getDefaultInstance();
     $codec = new EntityContentDataCodec(new BasicEntityIdParser(), $wikibaseRepo->getInternalEntitySerializer(), $wikibaseRepo->getInternalEntityDeserializer());
     $blob = $codec->encodeEntity($entity, CONTENT_FORMAT_JSON);
     return new DeferredDecodingEntityHolder($codec, $blob, CONTENT_FORMAT_JSON, $expectedEntityType ?: $entity->getType(), $expectedEntityId);
 }

作者:Benesta    项目:mediawiki-extensions-Wikibas   
private function setUpEntities()
 {
     global $wgUser;
     static $setup = false;
     if ($setup) {
         return;
     }
     $setup = true;
     $store = WikibaseRepo::getDefaultInstance()->getStore()->getEntityStore();
     // remove entities we care about
     $idsToDelete = array(new ItemId('Q404'), new ItemId('Q23'), new PropertyId('P404'));
     foreach ($idsToDelete as $id) {
         try {
             $store->deleteEntity($id, 'test', $wgUser);
         } catch (StorageException $ex) {
             // ignore
         }
     }
     // Set up Q23
     $item = new Item(new ItemId('Q23'));
     $item->getFingerprint()->setLabel('en', 'George Washington');
     // Set up P42
     $property = new Property(new PropertyId('P42'), null, 'string');
     $store->saveEntity($item, 'testing', $wgUser, EDIT_NEW);
     $store->saveEntity($property, 'testing', $wgUser, EDIT_NEW);
 }

作者:TU-Berli    项目:WikidataMat   
/**
  * @param int $flavor Bitmap for the output flavor, use RdfProducer::PRODUCE_XXX constants.
  * @param EntityId[] &$mentioned Receives any entity IDs being mentioned.
  * @param DedupeBag $dedupe A bag of reference hashes that should be considered "already seen".
  *
  * @return FullStatementRdfBuilder
  */
 private function newBuilder($flavor, array &$mentioned = array(), DedupeBag $dedupe = null)
 {
     $vocabulary = $this->getTestData()->getVocabulary();
     $writer = $this->getTestData()->getNTriplesWriter();
     $mentionTracker = $this->getMock('Wikibase\\Rdf\\EntityMentionListener');
     $mentionTracker->expects($this->any())->method('propertyMentioned')->will($this->returnCallback(function (EntityId $id) use(&$mentioned) {
         $key = $id->getSerialization();
         $mentioned[$key] = $id;
     }));
     // Note: using the actual factory here makes this an integration test!
     $valueBuilderFactory = WikibaseRepo::getDefaultInstance()->getValueSnakRdfBuilderFactory();
     if ($flavor & RdfProducer::PRODUCE_FULL_VALUES) {
         $valueWriter = $writer->sub();
         $statementValueBuilder = $valueBuilderFactory->getComplexValueSnakRdfBuilder($this->getTestData()->getVocabulary(), $valueWriter, $mentionTracker, new HashDedupeBag());
     } else {
         $statementValueBuilder = $valueBuilderFactory->getSimpleValueSnakRdfBuilder($this->getTestData()->getVocabulary(), $writer, $mentionTracker, new HashDedupeBag());
     }
     $snakRdfBuilder = new SnakRdfBuilder($vocabulary, $statementValueBuilder, $this->getTestData()->getMockRepository());
     $statementBuilder = new FullStatementRdfBuilder($vocabulary, $writer, $snakRdfBuilder);
     $statementBuilder->setDedupeBag($dedupe ?: new NullDedupeBag());
     if ($flavor & RdfProducer::PRODUCE_PROPERTIES) {
         $snakRdfBuilder->setEntityMentionListener($mentionTracker);
     }
     $statementBuilder->setProduceQualifiers($flavor & RdfProducer::PRODUCE_QUALIFIERS);
     $statementBuilder->setProduceReferences($flavor & RdfProducer::PRODUCE_REFERENCES);
     // HACK: stick the writer into a public field, for use by getDataFromBuilder()
     $statementBuilder->test_writer = $writer;
     return $statementBuilder;
 }

作者:filbertk    项目:WikibaseSystemTest   
private function getEntityContentDataCodec()
 {
     if (!isset($this->codec)) {
         $this->codec = WikibaseRepo::getDefaultInstance()->getEntityContentDataCodec();
     }
     return $this->codec;
 }


问题


面经


文章

微信
公众号

扫码关注公众号