jenkins-bot has submitted this change and it was merged. Change subject: Tidy up infomation flow in SpecialListProperties ......................................................................
Tidy up infomation flow in SpecialListProperties Change-Id: Iec9c3ad35133e14ae04c3b168e6f7492c8d71ceb --- M repo/includes/specials/SpecialListProperties.php M repo/tests/phpunit/includes/specials/SpecialListPropertiesTest.php 2 files changed, 44 insertions(+), 67 deletions(-) Approvals: Daniel Kinzler: Looks good to me, approved jenkins-bot: Verified diff --git a/repo/includes/specials/SpecialListProperties.php b/repo/includes/specials/SpecialListProperties.php index 34009eb..d6c5513 100644 --- a/repo/includes/specials/SpecialListProperties.php +++ b/repo/includes/specials/SpecialListProperties.php @@ -9,12 +9,14 @@ use Wikibase\DataModel\Entity\EntityId; use Wikibase\DataModel\Entity\PropertyId; use Wikibase\DataModel\Services\EntityId\EntityIdFormatter; +use Wikibase\DataModel\Services\Lookup\LabelDescriptionLookup; use Wikibase\DataTypeSelector; +use Wikibase\LanguageFallbackChainFactory; use Wikibase\Lib\Store\EntityTitleLookup; use Wikibase\Lib\Store\LanguageFallbackLabelDescriptionLookup; use Wikibase\PropertyInfoStore; -use Wikibase\Lib\Store\LanguageFallbackLabelDescriptionLookupFactory; use Wikibase\Repo\WikibaseRepo; +use Wikibase\Store\BufferingTermLookup; use Wikibase\View\EntityIdFormatterFactory; /** @@ -45,16 +47,6 @@ private $propertyInfoStore; /** - * @var EntityIdFormatterFactory - */ - private $entityIdFormatterFactory; - - /** - * @var LanguageFallbackLabelDescriptionLookupFactory - */ - private $labelDescriptionLookupFactory; - - /** * @var LanguageFallbackLabelDescriptionLookup */ private $labelDescriptionLookup; @@ -63,11 +55,6 @@ * @var string */ private $dataType; - - /** - * @var PropertyId[] - */ - private $propertyIds = array(); /** * @var EntityIdFormatter @@ -79,6 +66,11 @@ */ private $titleLookup; + /** + * @var BufferingTermLookup + */ + private $bufferingTermLookup; + public function __construct() { parent::__construct( 'ListProperties' ); @@ -88,8 +80,9 @@ $wikibaseRepo->getDataTypeFactory(), $wikibaseRepo->getStore()->getPropertyInfoStore(), $wikibaseRepo->getEntityIdHtmlLinkFormatterFactory(), - $wikibaseRepo->getLanguageFallbackLabelDescriptionLookupFactory(), - $wikibaseRepo->getEntityTitleLookup() + $wikibaseRepo->getLanguageFallbackChainFactory(), + $wikibaseRepo->getEntityTitleLookup(), + $wikibaseRepo->getBufferingTermLookup() ); } @@ -101,14 +94,27 @@ DataTypeFactory $dataTypeFactory, PropertyInfoStore $propertyInfoStore, EntityIdFormatterFactory $entityIdFormatterFactory, - LanguageFallbackLabelDescriptionLookupFactory $labelDescriptionLookupFactory, - EntityTitleLookup $titleLookup + LanguageFallbackChainFactory $languageFallbackChainFactory, + EntityTitleLookup $titleLookup, + BufferingTermLookup $bufferingTermLookup ) { + $this->labelDescriptionLookup = new LanguageFallbackLabelDescriptionLookup( + $bufferingTermLookup, + $languageFallbackChainFactory->newFromLanguage( + $this->getLanguage(), + LanguageFallbackChainFactory::FALLBACK_SELF + | LanguageFallbackChainFactory::FALLBACK_VARIANTS + | LanguageFallbackChainFactory::FALLBACK_OTHERS + ) + ); + $this->dataTypeFactory = $dataTypeFactory; $this->propertyInfoStore = $propertyInfoStore; - $this->entityIdFormatterFactory = $entityIdFormatterFactory; - $this->labelDescriptionLookupFactory = $labelDescriptionLookupFactory; + $this->entityIdFormatter = $entityIdFormatterFactory->getEntityIdFormater( + $this->labelDescriptionLookup + ); $this->titleLookup = $titleLookup; + $this->bufferingTermLookup = $bufferingTermLookup; } /** @@ -211,16 +217,14 @@ * @return string */ protected function formatRow( $propertyId ) { - $labelDescriptionLookup = $this->getLabelDescriptionLookup(); - $title = $this->titleLookup->getTitleForId( $propertyId ); if ( !$title->exists() ) { - return $this->getEntityIdFormater()->formatEntityId( $propertyId ); + return $this->entityIdFormatter->formatEntityId( $propertyId ); } $row = $this->getIdHtml( $propertyId, $title ); try { - $label = $labelDescriptionLookup->getLabel( $propertyId )->getText(); + $label = $this->labelDescriptionLookup->getLabel( $propertyId )->getText(); $row .= wfMessage( 'colon-separator' )->escaped() . $label; } catch ( OutOfBoundsException $e ) { // If there is no label do not add it @@ -251,25 +255,6 @@ return $idElement; } - private function getLabelDescriptionLookup() { - if ( !isset( $this->labelDescriptionLookup ) ) { - $this->labelDescriptionLookup = $this->labelDescriptionLookupFactory->newLabelDescriptionLookup( - $this->getLanguage(), - $this->propertyIds - ); - } - return $this->labelDescriptionLookup; - } - - private function getEntityIdFormater() { - if ( !isset( $this->entityIdFormatter ) ) { - $this->entityIdFormatter = $this->entityIdFormatterFactory->getEntityIdFormater( - $this->getLabelDescriptionLookup() - ); - } - return $this->entityIdFormatter; - } - /** * @param integer $offset Start to include at number of entries from the start title * @param integer $limit Stop at number of entries after start of inclusion @@ -285,7 +270,7 @@ $propertyIds[] = PropertyId::newFromNumber( $numericId ); } - $this->propertyIds = $propertyIds; + $this->bufferingTermLookup->prefetchTerms( $propertyIds ); return $propertyIds; } diff --git a/repo/tests/phpunit/includes/specials/SpecialListPropertiesTest.php b/repo/tests/phpunit/includes/specials/SpecialListPropertiesTest.php index f7cc47f..c769b06 100644 --- a/repo/tests/phpunit/includes/specials/SpecialListPropertiesTest.php +++ b/repo/tests/phpunit/includes/specials/SpecialListPropertiesTest.php @@ -14,8 +14,8 @@ use Wikibase\Lib\Store\EntityTitleLookup; use Wikibase\PropertyInfoStore; use Wikibase\Repo\EntityIdHtmlLinkFormatterFactory; -use Wikibase\Lib\Store\LanguageFallbackLabelDescriptionLookupFactory; use Wikibase\Repo\Specials\SpecialListProperties; +use Wikibase\Store\BufferingTermLookup; /** * @covers Wikibase\Repo\Specials\SpecialListProperties @@ -71,25 +71,20 @@ } /** - * @return TermLookup + * @return BufferingTermLookup */ - private function getTermLookup() { - $termLookup = $this->getMock( 'Wikibase\DataModel\Services\Lookup\TermLookup' ); - $termLookup->expects( $this->any() ) + private function getBufferingTermLookup() { + $lookup = $this->getMockBuilder( 'Wikibase\Store\BufferingTermLookup' ) + ->disableOriginalConstructor() + ->getMock(); + $lookup->expects( $this->any() ) + ->method( 'prefetchTerms' ); + $lookup->expects( $this->any() ) ->method( 'getLabels' ) ->will( $this->returnCallback( function( PropertyId $propertyId ) { return array( 'en' => 'Property with label ' . $propertyId->getSerialization() ); } ) ); - - return $termLookup; - } - - private function getTermBuffer() { - $termBuffer = $this->getMock( 'Wikibase\Store\TermBuffer' ); - $termBuffer->expects( $this->any() ) - ->method( 'prefetchTerms' ); - - return $termBuffer; + return $lookup; } /** @@ -115,12 +110,9 @@ $this->getDataTypeFactory(), $this->getPropertyInfoStore(), new EntityIdHtmlLinkFormatterFactory( $this->getEntityTitleLookup(), new LanguageNameLookup() ), - new LanguageFallbackLabelDescriptionLookupFactory( - new LanguageFallbackChainFactory(), - $this->getTermLookup(), - $this->getTermBuffer() - ), - $this->getEntityTitleLookup() + new LanguageFallbackChainFactory(), + $this->getEntityTitleLookup(), + $this->getBufferingTermLookup() ); return $specialPage; -- To view, visit https://gerrit.wikimedia.org/r/234247 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: Iec9c3ad35133e14ae04c3b168e6f7492c8d71ceb Gerrit-PatchSet: 3 Gerrit-Project: mediawiki/extensions/Wikibase Gerrit-Branch: master Gerrit-Owner: Addshore <addshorew...@gmail.com> Gerrit-Reviewer: Addshore <addshorew...@gmail.com> Gerrit-Reviewer: Bene <benestar.wikime...@gmail.com> Gerrit-Reviewer: Daniel Kinzler <daniel.kinz...@wikimedia.de> Gerrit-Reviewer: Jonas Kress (WMDE) <jonas.kr...@wikimedia.de> Gerrit-Reviewer: Thiemo Mättig (WMDE) <thiemo.maet...@wikimedia.de> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits