jenkins-bot has submitted this change and it was merged. Change subject: Drop ReferencedEntitiesFinder, use EntityParserOutputDataUpdater instead. ......................................................................
Drop ReferencedEntitiesFinder, use EntityParserOutputDataUpdater instead. Thus allows us to use the more flexible framework of EntityParserOutputDataUpdater for tracking snak values in secondary data tables. Bug: T114220 Change-Id: I7b03cc001d708ea18812d7c9a191d05362e150cc --- D lib/includes/ReferencedEntitiesFinder.php D lib/tests/phpunit/ReferencedEntitiesFinderTest.php M repo/includes/DataUpdates/EntityParserOutputDataUpdater.php M repo/includes/DataUpdates/ExternalLinksDataUpdate.php M repo/includes/DataUpdates/ImageLinksDataUpdate.php M repo/includes/DataUpdates/ReferencedEntitiesDataUpdate.php M repo/includes/EntityParserOutputGenerator.php M repo/includes/EntityParserOutputGeneratorFactory.php M repo/includes/WikibaseRepo.php M repo/tests/phpunit/includes/EntityParserOutputGeneratorTest.php 10 files changed, 116 insertions(+), 374 deletions(-) Approvals: Daniel Kinzler: Looks good to me, approved jenkins-bot: Verified Objections: Aude: There's a problem with this change, please improve diff --git a/lib/includes/ReferencedEntitiesFinder.php b/lib/includes/ReferencedEntitiesFinder.php deleted file mode 100644 index 39f8b8f..0000000 --- a/lib/includes/ReferencedEntitiesFinder.php +++ /dev/null @@ -1,97 +0,0 @@ -<?php - -namespace Wikibase; - -use DataValues\DataValue; -use DataValues\QuantityValue; -use Wikibase\DataModel\Entity\EntityId; -use Wikibase\DataModel\Entity\EntityIdValue; -use Wikibase\DataModel\Entity\EntityIdParser; -use Wikibase\DataModel\Entity\EntityIdParsingException; -use Wikibase\DataModel\Snak\PropertyValueSnak; -use Wikibase\DataModel\Snak\Snak; - -/** - * Finds linked entities given a list of entities or a list of claims. - * - * @since 0.4 - * - * @licence GNU GPL v2+ - * @author Jeroen De Dauw < [email protected] > - * @author Daniel Werner < [email protected] > - * @author Katie Filbert < [email protected] > - * @author Daniel Kinzler - * @author Bene* < [email protected] > - */ -class ReferencedEntitiesFinder { - - /** - * @var EntityIdParser - */ - private $externalEntityIdParser; - - /** - * @param EntityIdParser $externalEntityIdParser Parser for external entity IDs (usually URIs) - * into EntityIds. Such external entity IDs may be used for units in QuantityValues, for - * calendar models in TimeValue, and for the reference globe in GlobeCoordinateValues. - */ - public function __construct( EntityIdParser $externalEntityIdParser ) { - $this->externalEntityIdParser = $externalEntityIdParser; - } - - /** - * Finds linked entities within a set of snaks. - * - * @since 0.4 - * - * @param Snak[] $snaks - * - * @return EntityId[] Entity id strings pointing to EntityId objects. - */ - public function findSnakLinks( array $snaks ) { - $entityIds = array(); - - foreach ( $snaks as $snak ) { - $propertyId = $snak->getPropertyId(); - $entityIds[$propertyId->getSerialization()] = $propertyId; - - if ( $snak instanceof PropertyValueSnak ) { - $dataValue = $snak->getDataValue(); - $this->addEntityIdsFromValue( $dataValue, $entityIds ); - } - } - - return $entityIds; - } - - /** - * @param DataValue $dataValue - * @param EntityId[] $entityIds - */ - private function addEntityIdsFromValue( DataValue $dataValue, array &$entityIds ) { - if ( $dataValue instanceof EntityIdValue ) { - $entityId = $dataValue->getEntityId(); - $entityIds[$entityId->getSerialization()] = $entityId; - } elseif ( $dataValue instanceof QuantityValue ) { - $unitUri = $dataValue->getUnit(); - $this->addEntityIdsFromURI( $unitUri, $entityIds ); - } - - //TODO: EntityIds from GlobeCoordinateValue's globe URI (Wikidata, not local item URI!) - //TODO: EntityIds from TimeValue's calendar URI (Wikidata, not local item URI!) - } - - /** - * @param string $uri - * @param EntityId[] $entityIds - */ - private function addEntityIdsFromURI( $uri, array &$entityIds ) { - try { - $entityId = $this->externalEntityIdParser->parse( $uri ); - $entityIds[$entityId->getSerialization()] = $entityId; - } catch ( EntityIdParsingException $ex ) { - // noop - } - } - -} diff --git a/lib/tests/phpunit/ReferencedEntitiesFinderTest.php b/lib/tests/phpunit/ReferencedEntitiesFinderTest.php deleted file mode 100644 index 4209108..0000000 --- a/lib/tests/phpunit/ReferencedEntitiesFinderTest.php +++ /dev/null @@ -1,120 +0,0 @@ -<?php - -namespace Wikibase\Lib\Test; - -use DataValues\QuantityValue; -use DataValues\StringValue; -use Wikibase\DataModel\Entity\EntityId; -use Wikibase\DataModel\Entity\EntityIdValue; -use Wikibase\DataModel\Entity\ItemId; -use Wikibase\DataModel\Entity\PropertyId; -use Wikibase\DataModel\Entity\BasicEntityIdParser; -use Wikibase\DataModel\Services\EntityId\SuffixEntityIdParser; -use Wikibase\DataModel\Snak\PropertyNoValueSnak; -use Wikibase\DataModel\Snak\PropertySomeValueSnak; -use Wikibase\DataModel\Snak\PropertyValueSnak; -use Wikibase\DataModel\Snak\Snak; -use Wikibase\ReferencedEntitiesFinder; - -/** - * @covers Wikibase\ReferencedEntitiesFinder - * - * @group Wikibase - * @group WikibaseLib - * @group EntityLinkFinder - * - * @licence GNU GPL v2+ - * @author Jeroen De Dauw < [email protected] > - * @author Daniel Kinzler - */ -class ReferencedEntitiesFinderTest extends \PHPUnit_Framework_TestCase { - - public function snaksProvider() { - $argLists = array(); - - $p11 = new PropertyId( 'p11' ); - $p27 = new PropertyId( 'p27' ); - $p44 = new PropertyId( 'p44' ); - $q800 = new ItemId( 'Q800' ); - - $q23Value = new EntityIdValue( new ItemId( 'q23' ) ); - $q24Value = new EntityIdValue( new ItemId( 'q24' ) ); - $quantityValueUnitQ800 = QuantityValue::newFromNumber( 3, 'http://acme.test/entity/Q800' ); - - $argLists[] = array( - array(), - array(), - "empty" - ); - - $argLists[] = array( - array( new PropertyNoValueSnak( $p27 ) ), - array( $p27 ), - "Property" - ); - - $argLists[] = array( - array( new PropertySomeValueSnak( $p27 ) ), - array( $p27 ), - "PropertySomeValueSnak" - ); - - $argLists[] = array( - array( new PropertyValueSnak( $p27, new StringValue( 'onoez' ) ) ), - array( $p27 ), - "PropertyValueSnak with string value" - ); - - $argLists[] = array( - array( new PropertyValueSnak( $p27, $q23Value ) ), - array( $p27, $q23Value->getEntityId() ), - "PropertyValueSnak with EntityIdValue" - ); - - $argLists[] = array( - array( new PropertyValueSnak( $p27, $quantityValueUnitQ800 ) ), - array( $p27, $q800 ), - "PropertyValueSnak with unit URI in a QuantityValue" - ); - - $argLists[] = array( - array( - new PropertyValueSnak( $p11, $q23Value ), - new PropertyNoValueSnak( $p27 ), - new PropertySomeValueSnak( $p44 ), - new PropertyValueSnak( $p44, new StringValue( 'onoez' ) ), - new PropertyValueSnak( $p44, $q24Value ), - ), - array( $p11, $q23Value->getEntityId(), $p27, $p44, $q24Value->getEntityId() ), - "PropertyValueSnak with EntityId" - ); - - return $argLists; - } - - /** - * @dataProvider snaksProvider - * - * @param Snak[] $snaks - * @param EntityId[] $expected - * @param string $message - */ - public function testFindSnakLinks( array $snaks, array $expected, $message ) { - $linkFinder = new ReferencedEntitiesFinder( - new SuffixEntityIdParser( - 'http://acme.test/entity/', - new BasicEntityIdParser() - ) ); - - $actual = $linkFinder->findSnakLinks( $snaks ); - - $expected = array_values( $expected ); - $actual = array_values( $actual ); - - asort( $expected ); - asort( $actual ); - - $this->assertEquals( $expected, $actual, $message ); - } - -} diff --git a/repo/includes/DataUpdates/EntityParserOutputDataUpdater.php b/repo/includes/DataUpdates/EntityParserOutputDataUpdater.php index a4f2483..d03173f 100644 --- a/repo/includes/DataUpdates/EntityParserOutputDataUpdater.php +++ b/repo/includes/DataUpdates/EntityParserOutputDataUpdater.php @@ -8,6 +8,8 @@ use Wikibase\DataModel\Statement\StatementListProvider; /** + * @todo have ItemParserOutputDataUpdate, etc. instead. + * * @since 0.5 * * @license GNU GPL v2+ diff --git a/repo/includes/DataUpdates/ExternalLinksDataUpdate.php b/repo/includes/DataUpdates/ExternalLinksDataUpdate.php index 0cf6d71..cce6ee4 100644 --- a/repo/includes/DataUpdates/ExternalLinksDataUpdate.php +++ b/repo/includes/DataUpdates/ExternalLinksDataUpdate.php @@ -55,6 +55,8 @@ } /** + * Add DataValue to list of used urls, if Snak property has 'url' data type. + * * @param Statement $statement */ public function processStatement( Statement $statement ) { diff --git a/repo/includes/DataUpdates/ImageLinksDataUpdate.php b/repo/includes/DataUpdates/ImageLinksDataUpdate.php index c18a498..1331b93 100644 --- a/repo/includes/DataUpdates/ImageLinksDataUpdate.php +++ b/repo/includes/DataUpdates/ImageLinksDataUpdate.php @@ -55,6 +55,8 @@ } /** + * Add DataValue to list of used images if Snak property data type is commonsMedia. + * * @param Statement $statement */ public function processStatement( Statement $statement ) { diff --git a/repo/includes/DataUpdates/ReferencedEntitiesDataUpdate.php b/repo/includes/DataUpdates/ReferencedEntitiesDataUpdate.php index 9cdf943..635b16b 100644 --- a/repo/includes/DataUpdates/ReferencedEntitiesDataUpdate.php +++ b/repo/includes/DataUpdates/ReferencedEntitiesDataUpdate.php @@ -75,6 +75,8 @@ } /** + * Finds linked entities in a Statement. + * * @param Statement $statement */ public function processStatement( Statement $statement ) { @@ -134,6 +136,9 @@ * @param ParserOutput $parserOutput */ public function updateParserOutput( ParserOutput $parserOutput ) { + // needed and used in EntityParserOutputGenerator, for getEntityInfo, + // to allow this data to be accessed later in processing. + $parserOutput->setExtensionData( 'referenced-entities', $this->entityIds ); $this->addLinksToParserOutput( $parserOutput ); } diff --git a/repo/includes/EntityParserOutputGenerator.php b/repo/includes/EntityParserOutputGenerator.php index ddb3fc5..87d54e3 100644 --- a/repo/includes/EntityParserOutputGenerator.php +++ b/repo/includes/EntityParserOutputGenerator.php @@ -3,18 +3,14 @@ namespace Wikibase; use InvalidArgumentException; -use LinkBatch; use ParserOptions; use ParserOutput; use SpecialPage; -use Title; use Wikibase\DataModel\Entity\EntityDocument; use Wikibase\DataModel\Entity\EntityId; use Wikibase\DataModel\Entity\Item; -use Wikibase\DataModel\Services\DataValue\ValuesFinder; use Wikibase\DataModel\SiteLink; use Wikibase\DataModel\SiteLinkList; -use Wikibase\DataModel\Snak\Snak; use Wikibase\DataModel\Statement\StatementList; use Wikibase\DataModel\Statement\StatementListProvider; use Wikibase\DataModel\Term\FingerprintProvider; @@ -23,6 +19,7 @@ use Wikibase\Lib\Store\EntityInfoTermLookup; use Wikibase\Lib\Store\EntityTitleLookup; use Wikibase\Lib\Store\LanguageFallbackLabelDescriptionLookup; +use Wikibase\Repo\DataUpdates\EntityParserOutputDataUpdater; use Wikibase\Repo\DataUpdates\PageImagesDataUpdate; use Wikibase\Repo\LinkedData\EntityDataFormatProvider; use Wikibase\Repo\View\RepoSpecialPageLinker; @@ -62,11 +59,6 @@ private $entityTitleLookup; /** - * @var ValuesFinder - */ - private $valuesFinder; - - /** * @var EntityInfoBuilderFactory */ private $entityInfoBuilderFactory; @@ -75,16 +67,6 @@ * @var LanguageFallbackChain */ private $languageFallbackChain; - - /** - * @var string - */ - private $languageCode; - - /** - * @var ReferencedEntitiesFinder - */ - private $referencedEntitiesFinder; /** * @var TemplateFactory @@ -96,28 +78,37 @@ */ private $entityDataFormatProvider; + /** + * @var EntityParserOutputDataUpdater + */ + private $parserOutputDataUpdater; + + /** + * @var string + */ + private $languageCode; + public function __construct( EntityViewFactory $entityViewFactory, ParserOutputJsConfigBuilder $configBuilder, EntityTitleLookup $entityTitleLookup, - ValuesFinder $valuesFinder, EntityInfoBuilderFactory $entityInfoBuilderFactory, LanguageFallbackChain $languageFallbackChain, - $languageCode, - ReferencedEntitiesFinder $referencedEntitiesFinder, TemplateFactory $templateFactory, - EntityDataFormatProvider $entityDataFormatProvider + EntityDataFormatProvider $entityDataFormatProvider, + EntityParserOutputDataUpdater $parserOutputDataUpdater, + $languageCode ) { $this->entityViewFactory = $entityViewFactory; $this->configBuilder = $configBuilder; $this->entityTitleLookup = $entityTitleLookup; - $this->valuesFinder = $valuesFinder; $this->entityInfoBuilderFactory = $entityInfoBuilderFactory; $this->languageFallbackChain = $languageFallbackChain; $this->languageCode = $languageCode; - $this->referencedEntitiesFinder = $referencedEntitiesFinder; $this->templateFactory = $templateFactory; $this->entityDataFormatProvider = $entityDataFormatProvider; + $this->parserOutputDataUpdater = $parserOutputDataUpdater; + $this->languageCode = $languageCode; } /** @@ -154,30 +145,16 @@ $entity = $entityRevision->getEntity(); - if ( $entity instanceof StatementListProvider ) { - $snaks = $entity->getStatements()->getAllSnaks(); - } else { - $snaks = array(); - } - - $editable = $options->getEditSection(); - - $usedEntityIds = $this->referencedEntitiesFinder->findSnakLinks( $snaks ); - - // FIXME: Bad - if ( $entity instanceof Item ) { - foreach ( $entity->getSiteLinkList()->getIterator() as $sitelink ) { - $usedEntityIds = array_merge( $usedEntityIds, $sitelink->getBadges() ); - } - } - - $entityInfo = $this->getEntityInfo( $usedEntityIds ); + $this->parserOutputDataUpdater->processEntity( $entity ); + $this->parserOutputDataUpdater->updateParserOutput( $parserOutput ); $configVars = $this->configBuilder->build( $entity ); $parserOutput->addJsConfigVars( $configVars ); - $this->addBestImageToParserOutput( $parserOutput, $entity->getStatements() ); - $this->addLinksToParserOutput( $parserOutput, $usedEntityIds, $snaks ); + // FIXME: Rework this to use the visitor infrastructure above! + if ( $entity instanceof StatementListProvider ) { + $this->addBestImageToParserOutput( $parserOutput, $entity->getStatements() ); + } // FIXME: OCP violation - https://phabricator.wikimedia.org/T75495 if ( $entity instanceof Item ) { @@ -190,8 +167,8 @@ $this->addHtmlToParserOutput( $parserOutput, $entityRevision, - $entityInfo, - $editable + $this->getEntityInfo( $parserOutput ), + $options->getEditSection() ); } @@ -229,82 +206,22 @@ } /** - * @param ParserOutput $parserOutput - * @param EntityId[] $usedEntityIds - * @param Snak[] $snaks - */ - private function addLinksToParserOutput( ParserOutput $parserOutput, array $usedEntityIds, - array $snaks - ) { - $this->addEntityLinksToParserOutput( $parserOutput, $usedEntityIds ); - $this->addExternalLinksToParserOutput( $parserOutput, $snaks ); - $this->addImageLinksToParserOutput( $parserOutput, $snaks ); - } - - /** - * @param ParserOutput $parserOutput - * @param EntityId[] $entityIds - */ - private function addEntityLinksToParserOutput( ParserOutput $parserOutput, array $entityIds ) { - $linkBatch = new LinkBatch(); - - foreach ( $entityIds as $entityId ) { - $linkBatch->addObj( $this->entityTitleLookup->getTitleForId( $entityId ) ); - } - - $pages = $linkBatch->doQuery(); - - if ( $pages === false ) { - return; - } - - foreach ( $pages as $page ) { - $title = Title::makeTitle( $page->page_namespace, $page->page_title ); - $parserOutput->addLink( $title, $page->page_id ); - } - } - - /** - * @param ParserOutput $parserOutput - * @param Snak[] $snaks - */ - private function addExternalLinksToParserOutput( ParserOutput $parserOutput, array $snaks ) { - // treat URL values as external links ------ - $usedUrls = $this->valuesFinder->findFromSnaks( $snaks, 'url' ); - - foreach ( $usedUrls as $url ) { - $value = $url->getValue(); - if ( is_string( $value ) ) { - $parserOutput->addExternalLink( $value ); - } - } - } - - /** - * Treat CommonsMedia values as file transclusions - * - * @param ParserOutput $parserOutput - * @param array $snaks - */ - private function addImageLinksToParserOutput( ParserOutput $parserOutput, array $snaks ) { - $usedImages = $this->valuesFinder->findFromSnaks( $snaks, 'commonsMedia' ); - - foreach ( $usedImages as $image ) { - $value = $image->getValue(); - if ( is_string( $value ) ) { - $parserOutput->addImage( str_replace( ' ', '_', $value ) ); - } - } - } - - /** * Fetches some basic entity information from a set of entity IDs. * - * @param EntityId[] $entityIds + * @param ParserOutput $parserOutput * * @return EntityInfo */ - private function getEntityInfo( array $entityIds ) { + private function getEntityInfo( ParserOutput $parserOutput ) { + // set in ReferencedEntitiesDataUpdate + $entityIds = $parserOutput->getExtensionData( 'referenced-entities' ); + + if ( !is_array( $entityIds ) ) { + wfLogWarning( '$entityIds from ParserOutput "referenced-entities" extension data' + . ' expected to be an array' ); + $entityIds = array(); + } + $entityInfoBuilder = $this->entityInfoBuilderFactory->newEntityInfoBuilder( $entityIds ); $entityInfoBuilder->resolveRedirects(); @@ -373,7 +290,6 @@ EntityInfo $entityInfo, $editable = true ) { - $labelDescriptionLookup = new LanguageFallbackLabelDescriptionLookup( new EntityInfoTermLookup( $entityInfo ), $this->languageFallbackChain diff --git a/repo/includes/EntityParserOutputGeneratorFactory.php b/repo/includes/EntityParserOutputGeneratorFactory.php index 2ca11d3..e14f880 100644 --- a/repo/includes/EntityParserOutputGeneratorFactory.php +++ b/repo/includes/EntityParserOutputGeneratorFactory.php @@ -3,9 +3,15 @@ namespace Wikibase; use ParserOptions; -use Wikibase\DataModel\Services\DataValue\ValuesFinder; +use Wikibase\DataModel\Entity\EntityIdParser; +use Wikibase\DataModel\Services\Lookup\PropertyDataTypeLookup; use Wikibase\Lib\Store\EntityInfoBuilderFactory; use Wikibase\Lib\Store\EntityTitleLookup; +use Wikibase\Lib\Store\PropertyDataTypeMatcher; +use Wikibase\Repo\DataUpdates\EntityParserOutputDataUpdater; +use Wikibase\Repo\DataUpdates\ExternalLinksDataUpdate; +use Wikibase\Repo\DataUpdates\ImageLinksDataUpdate; +use Wikibase\Repo\DataUpdates\ReferencedEntitiesDataUpdate; use Wikibase\Repo\LinkedData\EntityDataFormatProvider; use Wikibase\View\EntityViewFactory; use Wikibase\View\Template\TemplateFactory; @@ -39,16 +45,6 @@ private $entityTitleLookup; /** - * @var ValuesFinder - */ - private $valuesFinder; - - /** - * @var ReferencedEntitiesFinder - */ - private $referencedEntitiesFinder; - - /** * @var LanguageFallbackChainFactory */ private $languageFallbackChainFactory; @@ -58,24 +54,34 @@ */ private $entityDataFormatProvider; + /** + * @var PropertyDataTypeLookup + */ + private $propertyDataTypeLookup; + + /** + * @var EntityIdParser + */ + private $externalEntityIdParser; + public function __construct( EntityViewFactory $entityViewFactory, EntityInfoBuilderFactory $entityInfoBuilderFactory, EntityTitleLookup $entityTitleLookup, - ValuesFinder $valuesFinder, LanguageFallbackChainFactory $languageFallbackChainFactory, - ReferencedEntitiesFinder $referencedEntitiesFinder, TemplateFactory $templateFactory, - EntityDataFormatProvider $entityDataFormatProvider + EntityDataFormatProvider $entityDataFormatProvider, + PropertyDataTypeLookup $propertyDataTypeLookup, + EntityIdParser $externalEntityIdParser ) { $this->entityViewFactory = $entityViewFactory; $this->entityInfoBuilderFactory = $entityInfoBuilderFactory; $this->entityTitleLookup = $entityTitleLookup; - $this->valuesFinder = $valuesFinder; $this->languageFallbackChainFactory = $languageFallbackChainFactory; - $this->referencedEntitiesFinder = $referencedEntitiesFinder; $this->templateFactory = $templateFactory; $this->entityDataFormatProvider = $entityDataFormatProvider; + $this->propertyDataTypeLookup = $propertyDataTypeLookup; + $this->externalEntityIdParser = $externalEntityIdParser; } /** @@ -92,13 +98,12 @@ $this->entityViewFactory, $this->newParserOutputJsConfigBuilder(), $this->entityTitleLookup, - $this->valuesFinder, $this->entityInfoBuilderFactory, $this->getLanguageFallbackChain( $languageCode ), - $languageCode, - $this->referencedEntitiesFinder, $this->templateFactory, - $this->entityDataFormatProvider + $this->entityDataFormatProvider, + new EntityParserOutputDataUpdater( $this->getDataUpdates() ), + $languageCode ); } @@ -122,4 +127,20 @@ ); } + /** + * @return ParserOutputDataUpdate[] + */ + private function getDataUpdates() { + $propertyDataTypeMatcher = new PropertyDataTypeMatcher( $this->propertyDataTypeLookup ); + + return array( + new ReferencedEntitiesDataUpdate( + $this->entityTitleLookup, + $this->externalEntityIdParser + ), + new ExternalLinksDataUpdate( $propertyDataTypeMatcher ), + new ImageLinksDataUpdate( $propertyDataTypeMatcher ) + ); + } + } diff --git a/repo/includes/WikibaseRepo.php b/repo/includes/WikibaseRepo.php index fc9c325..21097a9 100644 --- a/repo/includes/WikibaseRepo.php +++ b/repo/includes/WikibaseRepo.php @@ -23,7 +23,6 @@ use Wikibase\DataModel\DeserializerFactory; use Wikibase\DataModel\Entity\Item; use Wikibase\DataModel\Entity\Property; -use Wikibase\DataModel\Services\DataValue\ValuesFinder; use Wikibase\DataModel\Services\Diff\EntityDiffer; use Wikibase\DataModel\Entity\BasicEntityIdParser; use Wikibase\DataModel\Entity\DispatchingEntityIdParser; @@ -64,7 +63,6 @@ use Wikibase\Lib\WikibaseValueFormatterBuilders; use Wikibase\Lib\Interactors\TermIndexSearchInteractor; use Wikibase\PropertyInfoBuilder; -use Wikibase\ReferencedEntitiesFinder; use Wikibase\Repo\Api\ApiHelperFactory; use Wikibase\Repo\Content\EntityContentFactory; use Wikibase\Repo\Content\ItemHandler; @@ -1340,11 +1338,11 @@ $entityViewFactory, $this->getStore()->getEntityInfoBuilderFactory(), $this->getEntityContentFactory(), - new ValuesFinder( $this->getPropertyDataTypeLookup() ), $this->getLanguageFallbackChainFactory(), - new ReferencedEntitiesFinder( $this->getLocalEntityUriParser() ), $templateFactory, - $entityDataFormatProvider + $entityDataFormatProvider, + $this->getPropertyDataTypeLookup(), + $this->getLocalEntityUriParser() ); } diff --git a/repo/tests/phpunit/includes/EntityParserOutputGeneratorTest.php b/repo/tests/phpunit/includes/EntityParserOutputGeneratorTest.php index 698b62b..05b52c6 100644 --- a/repo/tests/phpunit/includes/EntityParserOutputGeneratorTest.php +++ b/repo/tests/phpunit/includes/EntityParserOutputGeneratorTest.php @@ -8,18 +8,21 @@ use ParserOptions; use SpecialPage; use Title; +use Wikibase\DataModel\Entity\BasicEntityIdParser; use Wikibase\DataModel\Entity\EntityId; use Wikibase\DataModel\Entity\Item; use Wikibase\DataModel\Entity\ItemId; use Wikibase\DataModel\Entity\PropertyId; -use Wikibase\DataModel\Services\DataValue\ValuesFinder; -use Wikibase\DataModel\Entity\BasicEntityIdParser; use Wikibase\DataModel\Services\Lookup\InMemoryDataTypeLookup; use Wikibase\DataModel\Snak\PropertyValueSnak; use Wikibase\EntityParserOutputGenerator; use Wikibase\EntityRevision; +use Wikibase\Lib\Store\PropertyDataTypeMatcher; use Wikibase\Lib\Store\Sql\SqlEntityInfoBuilderFactory; -use Wikibase\ReferencedEntitiesFinder; +use Wikibase\Repo\DataUpdates\EntityParserOutputDataUpdater; +use Wikibase\Repo\DataUpdates\ExternalLinksDataUpdate; +use Wikibase\Repo\DataUpdates\ImageLinksDataUpdate; +use Wikibase\Repo\DataUpdates\ReferencedEntitiesDataUpdate; use Wikibase\Repo\LinkedData\EntityDataFormatProvider; use Wikibase\View\Template\TemplateFactory; @@ -132,24 +135,34 @@ } private function newEntityParserOutputGenerator() { - $templateFactory = TemplateFactory::getDefaultInstance(); - $referencedEntitiesFinder = new ReferencedEntitiesFinder( new BasicEntityIdParser() ); $entityDataFormatProvider = new EntityDataFormatProvider(); $formats = array( 'json', 'ntriples' ); $entityDataFormatProvider->setFormatWhiteList( $formats ); + $entityTitleLookup = $this->getEntityTitleLookupMock(); + + $propertyDataTypeMatcher = new PropertyDataTypeMatcher( $this->getPropertyDataTypeLookup() ); + + $dataUpdates = array( + new ExternalLinksDataUpdate( $propertyDataTypeMatcher ), + new ImageLinksDataUpdate( $propertyDataTypeMatcher ), + new ReferencedEntitiesDataUpdate( + $entityTitleLookup, + new BasicEntityIdParser() + ) + ); + return new EntityParserOutputGenerator( $this->getEntityViewFactory(), $this->getConfigBuilderMock(), - $this->getEntityTitleLookupMock(), - $this->getValuesFinder(), + $entityTitleLookup, new SqlEntityInfoBuilderFactory(), $this->newLanguageFallbackChain(), - 'en', - $referencedEntitiesFinder, - $templateFactory, - $entityDataFormatProvider + TemplateFactory::getDefaultInstance(), + $entityDataFormatProvider, + new EntityParserOutputDataUpdater( $dataUpdates ), + 'en' ); } @@ -242,13 +255,13 @@ return $entityTitleLookup; } - private function getValuesFinder() { + private function getPropertyDataTypeLookup() { $dataTypeLookup = new InMemoryDataTypeLookup(); $dataTypeLookup->setDataTypeForProperty( new PropertyId( 'P42' ), 'url' ); $dataTypeLookup->setDataTypeForProperty( new PropertyId( 'P10' ), 'commonsMedia' ); - return new ValuesFinder( $dataTypeLookup ); + return $dataTypeLookup; } private function getParserOptions() { -- To view, visit https://gerrit.wikimedia.org/r/243613 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I7b03cc001d708ea18812d7c9a191d05362e150cc Gerrit-PatchSet: 18 Gerrit-Project: mediawiki/extensions/Wikibase Gerrit-Branch: master Gerrit-Owner: Aude <[email protected]> Gerrit-Reviewer: Aude <[email protected]> Gerrit-Reviewer: Bene <[email protected]> Gerrit-Reviewer: Daniel Kinzler <[email protected]> Gerrit-Reviewer: Hoo man <[email protected]> Gerrit-Reviewer: Thiemo Mättig (WMDE) <[email protected]> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list [email protected] https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
