Thiemo Mättig (WMDE) has uploaded a new change for review. https://gerrit.wikimedia.org/r/172275
Change subject: Narrow EntityParserOutputGeneratorFactory interface ...................................................................... Narrow EntityParserOutputGeneratorFactory interface ... to not require an EntityRevision object any more. ... and optimize imports. Please merge this after Aude's patches to not cause unnecesarry merge conflicts. Change-Id: I3bc3a356c63c33bc82cf960b27eab77e1f86a03a --- M repo/includes/ChangeOp/ChangeOpClaimRemove.php M repo/includes/Diff/ClaimDifferenceVisualizer.php M repo/includes/EntityParserOutputGenerator.php M repo/includes/EntityParserOutputGeneratorFactory.php M repo/includes/Interactors/RedirectCreationInteractor.php M repo/includes/LinkedData/EntityDataSerializationService.php M repo/includes/ParserOutputJsConfigBuilder.php M repo/includes/UpdateRepo/UpdateRepoOnMoveJob.php M repo/includes/View/SnakHtmlGenerator.php M repo/includes/WikibaseRepo.php M repo/includes/api/ApiHelperFactory.php M repo/includes/api/ApiWikibase.php M repo/includes/api/ClaimModificationHelper.php M repo/includes/content/EntityContent.php M repo/includes/content/EntityHandler.php M repo/includes/content/ItemContent.php M repo/includes/content/PropertyContent.php M repo/includes/store/sql/SqlStore.php M repo/tests/phpunit/includes/EntityParserOutputGeneratorFactoryTest.php 19 files changed, 38 insertions(+), 77 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase refs/changes/75/172275/1 diff --git a/repo/includes/ChangeOp/ChangeOpClaimRemove.php b/repo/includes/ChangeOp/ChangeOpClaimRemove.php index ddc2d53..0e6c727 100644 --- a/repo/includes/ChangeOp/ChangeOpClaimRemove.php +++ b/repo/includes/ChangeOp/ChangeOpClaimRemove.php @@ -8,7 +8,6 @@ use Wikibase\DataModel\Entity\Entity; use Wikibase\DataModel\Entity\Item; use Wikibase\DataModel\Entity\Property; -use Wikibase\DataModel\Entity\PropertyId; use Wikibase\DataModel\Snak\Snak; use Wikibase\DataModel\Statement\StatementList; use Wikibase\Summary; diff --git a/repo/includes/Diff/ClaimDifferenceVisualizer.php b/repo/includes/Diff/ClaimDifferenceVisualizer.php index 808dc24..2a34f46 100644 --- a/repo/includes/Diff/ClaimDifferenceVisualizer.php +++ b/repo/includes/Diff/ClaimDifferenceVisualizer.php @@ -2,11 +2,11 @@ namespace Wikibase\Repo\Diff; +use Diff\Differ\ListDiffer; use Diff\DiffOp\Diff\Diff; use Diff\DiffOp\DiffOpAdd; use Diff\DiffOp\DiffOpChange; use Diff\DiffOp\DiffOpRemove; -use Diff\Differ\ListDiffer; use Exception; use InvalidArgumentException; use Message; diff --git a/repo/includes/EntityParserOutputGenerator.php b/repo/includes/EntityParserOutputGenerator.php index 447484b..be239ae 100644 --- a/repo/includes/EntityParserOutputGenerator.php +++ b/repo/includes/EntityParserOutputGenerator.php @@ -3,9 +3,10 @@ namespace Wikibase; use ParserOutput; -use Wikibase\DataModel\Entity\Entity; +use Wikibase\DataModel\Entity\EntityId; use Wikibase\DataModel\Entity\Item; use Wikibase\DataModel\Entity\PropertyDataTypeLookup; +use Wikibase\DataModel\SiteLink; use Wikibase\DataModel\SiteLinkList; use Wikibase\Lib\Serializers\SerializationOptions; use Wikibase\Lib\Store\EntityInfoBuilderFactory; @@ -170,7 +171,7 @@ * @since 0.4 * * @param EntityId[] $entityIds - * @return array obtained from EntityInfoBuilder::getEntityInfo + * @return array[] obtained from EntityInfoBuilder::getEntityInfo */ private function getEntityInfo( array $entityIds ) { wfProfileIn( __METHOD__ ); @@ -196,6 +197,7 @@ } private function addBadgesToParserOutput( ParserOutput $pout, SiteLinkList $siteLinkList ) { + /** @var SiteLink $siteLink */ foreach ( $siteLinkList as $siteLink ) { foreach ( $siteLink->getBadges() as $badge ) { $pout->addLink( $this->entityTitleLookup->getTitleForId( $badge ) ); @@ -203,13 +205,13 @@ } } - private function addHtmlToParserOutput( ParserOutput $pout, EntityRevision $entityRevision, $editable ) { + private function addHtmlToParserOutput( ParserOutput $pout, EntityRevision $entityRevision, $editable = true ) { $html = $this->entityView->getHtml( $entityRevision, $editable ); $pout->setText( $html ); $pout->setExtensionData( 'wikibase-view-chunks', $this->entityView->getPlaceholders() ); } - private function addModules( ParserOutput $pout, $editable ) { + private function addModules( ParserOutput $pout, $editable = true ) { // make css available for JavaScript-less browsers $pout->addModuleStyles( array( 'wikibase.common', diff --git a/repo/includes/EntityParserOutputGeneratorFactory.php b/repo/includes/EntityParserOutputGeneratorFactory.php index 5d4d797..3e4b77b3 100644 --- a/repo/includes/EntityParserOutputGeneratorFactory.php +++ b/repo/includes/EntityParserOutputGeneratorFactory.php @@ -2,18 +2,14 @@ namespace Wikibase; +use InvalidArgumentException; use Language; use ParserOptions; -use ParserOutput; use RequestContext; -use User; use ValueFormatters\FormatterOptions; use ValueFormatters\ValueFormatter; -use Wikibase\DataModel\Entity\Entity; -use Wikibase\DataModel\Entity\EntityId; use Wikibase\DataModel\Entity\EntityIdParser; use Wikibase\DataModel\Entity\PropertyDataTypeLookup; -use Wikibase\LanguageFallbackChainFactory; use Wikibase\Lib\OutputFormatSnakFormatterFactory; use Wikibase\Lib\Serializers\SerializationOptions; use Wikibase\Lib\SnakFormatter; @@ -23,7 +19,6 @@ use Wikibase\Repo\View\FingerprintView; use Wikibase\Repo\View\SectionEditLinkGenerator; use Wikibase\Repo\View\SnakHtmlGenerator; -use Wikibase\Repo\WikibaseRepo; /** * @since 0.5 @@ -95,19 +90,16 @@ /** * Creates an EntityParserOutputGenerator to create the ParserOutput for the entity * - * @param EntityRevision $entityRevision + * @param string $entityType * @param ParserOptions|null $options * * @return EntityParserOutputGenerator */ - public function getEntityParserOutputGenerator( - EntityRevision $entityRevision, - ParserOptions $options = null - ) { + public function getEntityParserOutputGenerator( $entityType, ParserOptions $options = null ) { $languageCode = $this->getLanguageCode( $options ); return new EntityParserOutputGenerator( - $this->newEntityView( $entityRevision, $languageCode ), + $this->newEntityView( $entityType, $languageCode ), $this->newParserOutputJsConfigBuilder( $languageCode ), $this->makeSerializationOptions( $languageCode ), $this->entityTitleLookup, @@ -155,16 +147,13 @@ * @return string */ private function getLanguageCode( ParserOptions $options = null ) { - $context = RequestContext::getMain(); - // NOTE: Parser Options language overrides context language! if ( $options !== null ) { - $languageCode = $options->getUserLang(); - } else { - $languageCode = $context->getLanguage()->getCode(); + return $options->getUserLang(); } - return $languageCode; + $context = RequestContext::getMain(); + return $context->getLanguage()->getCode(); } /** @@ -209,24 +198,25 @@ /** * Creates an EntityView suitable for rendering the entity. * - * @param EntityRevision $entityRevision + * @param string $entityType * @param string $languageCode * + * @throws \InvalidArgumentException * @return EntityView */ - private function newEntityView( EntityRevision $entityRevision, $languageCode ) { + private function newEntityView( $entityType, $languageCode ) { $fingerprintView = $this->newFingerprintView( $languageCode ); $claimsView = $this->newClaimsView( $languageCode ); - $entityType = $entityRevision->getEntity()->getType(); // @fixme all that seems needed in EntityView is language code and dir. $language = Language::factory( $languageCode ); // @fixme support more entity types - if ( $entityType === 'item' ) { - return new ItemView( $fingerprintView, $claimsView, $language ); - } elseif ( $entityType === 'property' ) { - return new PropertyView( $fingerprintView, $claimsView, $language ); + switch ( $entityType ) { + case 'item': + return new ItemView( $fingerprintView, $claimsView, $language ); + case 'property': + return new PropertyView( $fingerprintView, $claimsView, $language ); } throw new InvalidArgumentException( 'No EntityView for entity type: ' . $entityType ); diff --git a/repo/includes/Interactors/RedirectCreationInteractor.php b/repo/includes/Interactors/RedirectCreationInteractor.php index 1d3cbfa..2f8abb8 100644 --- a/repo/includes/Interactors/RedirectCreationInteractor.php +++ b/repo/includes/Interactors/RedirectCreationInteractor.php @@ -2,7 +2,6 @@ namespace Wikibase\Repo\Interactors; -use Status; use User; use Wikibase\DataModel\Entity\EntityId; use Wikibase\Lib\Store\EntityRedirect; diff --git a/repo/includes/LinkedData/EntityDataSerializationService.php b/repo/includes/LinkedData/EntityDataSerializationService.php index 557ba15..ce8059b 100644 --- a/repo/includes/LinkedData/EntityDataSerializationService.php +++ b/repo/includes/LinkedData/EntityDataSerializationService.php @@ -13,10 +13,10 @@ use RequestContext; use SiteList; use Wikibase\Api\ResultBuilder; -use Wikibase\Lib\Store\EntityLookup; use Wikibase\EntityRevision; use Wikibase\Lib\Serializers\SerializationOptions; use Wikibase\Lib\Serializers\SerializerFactory; +use Wikibase\Lib\Store\EntityLookup; use Wikibase\Lib\Store\EntityTitleLookup; use Wikibase\RdfSerializer; diff --git a/repo/includes/ParserOutputJsConfigBuilder.php b/repo/includes/ParserOutputJsConfigBuilder.php index b7d8f3b..aae67a7 100644 --- a/repo/includes/ParserOutputJsConfigBuilder.php +++ b/repo/includes/ParserOutputJsConfigBuilder.php @@ -8,7 +8,6 @@ use Wikibase\Lib\Serializers\EntitySerializer; use Wikibase\Lib\Serializers\SerializationOptions; use Wikibase\Lib\Serializers\SerializerFactory; -use Wikibase\Lib\Store\EntityInfoBuilderFactory; use Wikibase\Lib\Store\EntityTitleLookup; /** diff --git a/repo/includes/UpdateRepo/UpdateRepoOnMoveJob.php b/repo/includes/UpdateRepo/UpdateRepoOnMoveJob.php index 4ce820c..2db6d5f 100644 --- a/repo/includes/UpdateRepo/UpdateRepoOnMoveJob.php +++ b/repo/includes/UpdateRepo/UpdateRepoOnMoveJob.php @@ -7,17 +7,17 @@ use SiteStore; use Title; use User; -use Wikibase\Summary; -use Wikibase\SummaryFormatter; use Wikibase\DataModel\Entity\ItemId; use Wikibase\DataModel\SiteLink; +use Wikibase\EditEntity; use Wikibase\Lib\Store\EntityRevisionLookup; use Wikibase\Lib\Store\EntityStore; use Wikibase\Lib\Store\EntityTitleLookup; use Wikibase\Lib\Store\StorageException; use Wikibase\Repo\Store\EntityPermissionChecker; use Wikibase\Repo\WikibaseRepo; -use Wikibase\EditEntity; +use Wikibase\Summary; +use Wikibase\SummaryFormatter; /** * Job for updating the repo after a page on the client has been moved. diff --git a/repo/includes/View/SnakHtmlGenerator.php b/repo/includes/View/SnakHtmlGenerator.php index 99cad57..8e1ecc6 100644 --- a/repo/includes/View/SnakHtmlGenerator.php +++ b/repo/includes/View/SnakHtmlGenerator.php @@ -4,8 +4,8 @@ use InvalidArgumentException; use ValueFormatters\FormattingException; -use Wikibase\DataModel\Snak\Snak; use Wikibase\DataModel\Entity\PropertyNotFoundException; +use Wikibase\DataModel\Snak\Snak; use Wikibase\Lib\SnakFormatter; use Wikibase\Lib\Store\EntityTitleLookup; diff --git a/repo/includes/WikibaseRepo.php b/repo/includes/WikibaseRepo.php index 654eee5..7b05392 100644 --- a/repo/includes/WikibaseRepo.php +++ b/repo/includes/WikibaseRepo.php @@ -22,6 +22,7 @@ use Wikibase\DataModel\Entity\EntityIdParser; use Wikibase\DataModel\Entity\Item; use Wikibase\DataModel\Entity\Property; +use Wikibase\DataModel\Entity\PropertyDataTypeLookup; use Wikibase\EntityFactory; use Wikibase\EntityParserOutputGeneratorFactory; use Wikibase\InternalSerialization\DeserializerFactory; @@ -41,7 +42,6 @@ use Wikibase\Lib\Localizer\ParseExceptionLocalizer; use Wikibase\Lib\OutputFormatSnakFormatterFactory; use Wikibase\Lib\OutputFormatValueFormatterFactory; -use Wikibase\DataModel\Entity\PropertyDataTypeLookup; use Wikibase\Lib\PropertyInfoDataTypeLookup; use Wikibase\Lib\SnakConstructionService; use Wikibase\Lib\SnakFormatter; @@ -55,7 +55,6 @@ use Wikibase\Repo\Content\EntityContentFactory; use Wikibase\Repo\Content\ItemHandler; use Wikibase\Repo\Content\PropertyHandler; -use Wikibase\Repo\EntityNamespaceLookup; use Wikibase\Repo\Localizer\ChangeOpValidationExceptionLocalizer; use Wikibase\Repo\Localizer\MessageParameterFormatter; use Wikibase\Repo\Notifications\ChangeNotifier; diff --git a/repo/includes/api/ApiHelperFactory.php b/repo/includes/api/ApiHelperFactory.php index 0e6bd61..3db43d7 100644 --- a/repo/includes/api/ApiHelperFactory.php +++ b/repo/includes/api/ApiHelperFactory.php @@ -3,9 +3,9 @@ namespace Wikibase\Api; use ApiBase; +use Wikibase\DataModel\Entity\PropertyDataTypeLookup; use Wikibase\EntityFactory; use Wikibase\Lib\Localizer\ExceptionLocalizer; -use Wikibase\DataModel\Entity\PropertyDataTypeLookup; use Wikibase\Lib\Serializers\SerializationOptions; use Wikibase\Lib\Serializers\SerializerFactory; use Wikibase\Lib\Store\EntityTitleLookup; diff --git a/repo/includes/api/ApiWikibase.php b/repo/includes/api/ApiWikibase.php index 29d3394..33965fa 100644 --- a/repo/includes/api/ApiWikibase.php +++ b/repo/includes/api/ApiWikibase.php @@ -12,10 +12,10 @@ use Wikibase\DataModel\Entity\Entity; use Wikibase\DataModel\Entity\EntityId; use Wikibase\DataModel\Entity\EntityIdParser; +use Wikibase\DataModel\Entity\PropertyDataTypeLookup; use Wikibase\EditEntity; use Wikibase\EntityRevision; use Wikibase\Lib\Localizer\ExceptionLocalizer; -use Wikibase\DataModel\Entity\PropertyDataTypeLookup; use Wikibase\Lib\Store\BadRevisionException; use Wikibase\Lib\Store\EntityRevisionLookup; use Wikibase\Lib\Store\EntityStore; diff --git a/repo/includes/api/ClaimModificationHelper.php b/repo/includes/api/ClaimModificationHelper.php index c7a108c..2d55f80 100644 --- a/repo/includes/api/ClaimModificationHelper.php +++ b/repo/includes/api/ClaimModificationHelper.php @@ -19,9 +19,9 @@ use Wikibase\DataModel\Entity\EntityIdParser; use Wikibase\DataModel\Entity\EntityIdParsingException; use Wikibase\DataModel\Entity\PropertyId; +use Wikibase\DataModel\Entity\PropertyNotFoundException; use Wikibase\DataModel\Snak\Snak; use Wikibase\Lib\ClaimGuidValidator; -use Wikibase\DataModel\Entity\PropertyNotFoundException; use Wikibase\Lib\SnakConstructionService; use Wikibase\Summary; diff --git a/repo/includes/content/EntityContent.php b/repo/includes/content/EntityContent.php index 80e7741..2ce3a57 100644 --- a/repo/includes/content/EntityContent.php +++ b/repo/includes/content/EntityContent.php @@ -10,13 +10,11 @@ use Diff\DiffOp\Diff\Diff; use Diff\Patcher\MapPatcher; use Diff\Patcher\PatcherException; -use IContextSource; use Language; use LogicException; use MWException; use ParserOptions; use ParserOutput; -use RequestContext; use RuntimeException; use Status; use Title; @@ -26,18 +24,10 @@ use ValueValidators\Result; use Wikibase\DataModel\Entity\Entity; use Wikibase\DataModel\Entity\EntityId; -use Wikibase\Lib\Serializers\SerializationOptions; -use Wikibase\Lib\SnakFormatter; -use Wikibase\Lib\Store\EntityInfoBuilderFactory; use Wikibase\Lib\Store\EntityRedirect; -use Wikibase\Lib\Store\EntityTitleLookup; use Wikibase\Repo\Content\EntityContentDiff; use Wikibase\Repo\Content\EntityHandler; use Wikibase\Repo\EntitySearchTextGenerator; -use Wikibase\Repo\View\ClaimsView; -use Wikibase\Repo\View\FingerprintView; -use Wikibase\Repo\View\SectionEditLinkGenerator; -use Wikibase\Repo\View\SnakHtmlGenerator; use Wikibase\Repo\WikibaseRepo; use Wikibase\Validators\EntityValidator; use WikiPage; @@ -270,15 +260,15 @@ ) { $wikibaseRepo = WikibaseRepo::getDefaultInstance(); $entityParserOutputGeneratorFactory = $wikibaseRepo->getEntityParserOutputGeneratorFactory(); - - $entityRevision = $this->getEntityRevision( $title, $revId ); + $entityType = $this->getEntity()->getType(); $outputGenerator = $entityParserOutputGeneratorFactory->getEntityParserOutputGenerator( - $entityRevision, + $entityType, $options ); - $editable = !$options ? true : $options->getEditSection(); + $entityRevision = $this->getEntityRevision( $title, $revId ); + $editable = $options ? $options->getEditSection() : true; $output = $outputGenerator->getParserOutput( $entityRevision, diff --git a/repo/includes/content/EntityHandler.php b/repo/includes/content/EntityHandler.php index 6189dff..08d2ed9 100644 --- a/repo/includes/content/EntityHandler.php +++ b/repo/includes/content/EntityHandler.php @@ -14,7 +14,6 @@ use ParserOptions; use RequestContext; use Revision; -use Status; use Title; use User; use ValueValidators\Result; @@ -24,7 +23,6 @@ use Wikibase\EntityContent; use Wikibase\Lib\Store\EntityContentDataCodec; use Wikibase\Lib\Store\EntityRedirect; -use Wikibase\Repo\EntityNamespaceLookup; use Wikibase\Repo\Store\EntityPerPage; use Wikibase\Repo\WikibaseRepo; use Wikibase\TermIndex; diff --git a/repo/includes/content/ItemContent.php b/repo/includes/content/ItemContent.php index 46cd222..4f59b97 100644 --- a/repo/includes/content/ItemContent.php +++ b/repo/includes/content/ItemContent.php @@ -3,15 +3,12 @@ namespace Wikibase; use InvalidArgumentException; -use Language; use LogicException; use MWException; use Title; use Wikibase\DataModel\Entity\Item; use Wikibase\Lib\Store\EntityRedirect; use Wikibase\Repo\ItemSearchTextGenerator; -use Wikibase\Repo\View\ClaimsView; -use Wikibase\Repo\View\FingerprintView; /** * Content object for articles representing Wikibase items. diff --git a/repo/includes/content/PropertyContent.php b/repo/includes/content/PropertyContent.php index 78b094c..d36b79e 100644 --- a/repo/includes/content/PropertyContent.php +++ b/repo/includes/content/PropertyContent.php @@ -2,10 +2,7 @@ namespace Wikibase; -use Language; use Wikibase\DataModel\Entity\Property; -use Wikibase\Repo\View\ClaimsView; -use Wikibase\Repo\View\FingerprintView; /** * Content object for articles representing Wikibase properties. diff --git a/repo/includes/store/sql/SqlStore.php b/repo/includes/store/sql/SqlStore.php index f33d637..5c8410d 100644 --- a/repo/includes/store/sql/SqlStore.php +++ b/repo/includes/store/sql/SqlStore.php @@ -26,8 +26,8 @@ use Wikibase\Lib\Store\WikiPageEntityRevisionLookup; use Wikibase\Repo\Store\DispatchingEntityStoreWatcher; use Wikibase\Repo\Store\EntityPerPage; -use Wikibase\Repo\Store\WikiPageEntityStore; use Wikibase\Repo\Store\SQL\EntityPerPageTable; +use Wikibase\Repo\Store\WikiPageEntityStore; use Wikibase\Repo\WikibaseRepo; use WikiPage; diff --git a/repo/tests/phpunit/includes/EntityParserOutputGeneratorFactoryTest.php b/repo/tests/phpunit/includes/EntityParserOutputGeneratorFactoryTest.php index 38ea93d..9cf22b1 100644 --- a/repo/tests/phpunit/includes/EntityParserOutputGeneratorFactoryTest.php +++ b/repo/tests/phpunit/includes/EntityParserOutputGeneratorFactoryTest.php @@ -4,9 +4,6 @@ use Language; use ParserOptions; -use TestUser; -use Wikibase\DataModel\Entity\Item; -use Wikibase\DataModel\Entity\ItemId; use Wikibase\Repo\WikibaseRepo; /** @@ -21,18 +18,12 @@ $wikibaseRepo = WikibaseRepo::getDefaultInstance(); $parserOutputGeneratorFactory = $wikibaseRepo->getEntityParserOutputGeneratorFactory(); - $item = Item::newEmpty(); - $item->setId( new ItemId( 'Q777' ) ); - $item->setLabel( 'en', 'elephant' ); - - $entityRevision = new EntityRevision( $item, 7777 ); - - $testUser = new TestUser( 'Wikibase User' ); + $testUser = new \TestUser( 'Wikibase User' ); $language = Language::factory( 'en' ); $parserOptions = new ParserOptions( $testUser->getUser(), $language ); $parserOutputGenerator = $parserOutputGeneratorFactory->getEntityParserOutputGenerator( - $entityRevision, + 'item', $parserOptions ); -- To view, visit https://gerrit.wikimedia.org/r/172275 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I3bc3a356c63c33bc82cf960b27eab77e1f86a03a Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/Wikibase Gerrit-Branch: master Gerrit-Owner: Thiemo Mättig (WMDE) <thiemo.maet...@wikimedia.de> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits