[MediaWiki-commits] [Gerrit] Add badges to page props - change (mediawiki...Wikibase)
Bene has uploaded a new change for review. https://gerrit.wikimedia.org/r/235043 Change subject: Add badges to page props .. Add badges to page props Bug: T72229 Change-Id: I6e4a86a9b009e8f17b4777c3437797599d4671e7 --- M client/includes/Hooks/ParserOutputUpdateHookHandlers.php M client/includes/ParserOutputDataUpdater.php M client/includes/WikibaseClient.php M client/tests/phpunit/includes/ParserOutputDataUpdaterTest.php 4 files changed, 64 insertions(+), 3 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase refs/changes/43/235043/1 diff --git a/client/includes/Hooks/ParserOutputUpdateHookHandlers.php b/client/includes/Hooks/ParserOutputUpdateHookHandlers.php index a9b0c7e..b70c8db 100644 --- a/client/includes/Hooks/ParserOutputUpdateHookHandlers.php +++ b/client/includes/Hooks/ParserOutputUpdateHookHandlers.php @@ -134,6 +134,7 @@ $this->parserOutputDataUpdater->updateItemIdProperty( $title, $parserOutput ); $this->parserOutputDataUpdater->updateOtherProjectsLinksData( $title, $parserOutput ); + $this->parserOutputDataUpdater->updateBadgesProperty( $title, $parserOutput ); if ( $useRepoLinks || $this->alwaysSort ) { $interwikiLinks = $parserOutput->getLanguageLinks(); diff --git a/client/includes/ParserOutputDataUpdater.php b/client/includes/ParserOutputDataUpdater.php index bf5bb99..da47ad0 100644 --- a/client/includes/ParserOutputDataUpdater.php +++ b/client/includes/ParserOutputDataUpdater.php @@ -7,7 +7,9 @@ use Title; use Wikibase\Client\Hooks\OtherProjectsSidebarGeneratorFactory; use Wikibase\Client\Usage\ParserOutputUsageAccumulator; +use Wikibase\DataModel\Entity\Item; use Wikibase\DataModel\Entity\ItemId; +use Wikibase\DataModel\Services\Lookup\EntityLookup; use Wikibase\Lib\Store\SiteLinkLookup; /** @@ -27,6 +29,11 @@ private $otherProjectsSidebarGeneratorFactory; /** +* @var EntityLookup +*/ + private $entityLookup; + + /** * @var SiteLinkLookup */ private $siteLinkLookup; @@ -40,11 +47,13 @@ * @param OtherProjectsSidebarGeneratorFactory $otherProjectsSidebarGeneratorFactory *Use the factory here to defer initialization of things like Site objects. * @param SiteLinkLookup $siteLinkLookup +* @param EntityLookup $entityLookup * @param string $siteId The global site ID for the local wiki */ public function __construct( OtherProjectsSidebarGeneratorFactory $otherProjectsSidebarGeneratorFactory, SiteLinkLookup $siteLinkLookup, + EntityLookup $entityLookup, $siteId ) { if ( !is_string( $siteId ) ) { @@ -52,6 +61,7 @@ } $this->otherProjectsSidebarGeneratorFactory = $otherProjectsSidebarGeneratorFactory; + $this->entityLookup = $entityLookup; $this->siteLinkLookup = $siteLinkLookup; $this->siteId = $siteId; } @@ -83,8 +93,8 @@ $itemId = $this->getItemIdForTitle( $title ); if ( $itemId ) { - $otherProjectsSidebarGenerator = $this->otherProjectsSidebarGeneratorFactory-> - getOtherProjectsSidebarGenerator(); + $otherProjectsSidebarGenerator = $this->otherProjectsSidebarGeneratorFactory + ->getOtherProjectsSidebarGenerator(); $otherProjects = $otherProjectsSidebarGenerator->buildProjectLinkSidebar( $title ); $out->setExtensionData( 'wikibase-otherprojects-sidebar', $otherProjects ); @@ -95,6 +105,31 @@ /** * @param Title $title +* @param ParserOutput $out +*/ + public function updateBadgesProperty( Title $title, ParserOutput $out ) { + $itemId = $this->getItemIdForTitle( $title ); + + // first reset all badges in case one got removed + foreach ( $out->getProperties() as $name => $property ) { + if ( strpos( $name, 'wikibase-badge-' ) === 0 ) { + $out->unsetProperty( $name ); + } + } + + if ( $itemId ) { + /** @var Item $item */ + $item = $this->entityLookup->getEntity( $itemId ); + $siteLink = $item->getSiteLinkList()->getBySiteId( $this->siteId ); + + foreach ( $siteLink->getBadges() as $badge ) { + $out->setProperty( 'wikibase-badge-' . $badge->getSerialization(), true ); + } + } + } + + /** +* @param Title $title *
[MediaWiki-commits] [Gerrit] Add badges to page props - change (mediawiki...Wikibase)
jenkins-bot has submitted this change and it was merged. Change subject: Add badges to page props .. Add badges to page props Bug: T72229 Change-Id: I6e4a86a9b009e8f17b4777c3437797599d4671e7 --- M client/includes/Hooks/ParserOutputUpdateHookHandlers.php M client/includes/ParserOutputDataUpdater.php M client/includes/WikibaseClient.php M client/tests/phpunit/includes/Hooks/ParserOutputUpdateHookHandlersTest.php M client/tests/phpunit/includes/ParserOutputDataUpdaterTest.php 5 files changed, 65 insertions(+), 3 deletions(-) Approvals: Daniel Kinzler: Looks good to me, approved jenkins-bot: Verified diff --git a/client/includes/Hooks/ParserOutputUpdateHookHandlers.php b/client/includes/Hooks/ParserOutputUpdateHookHandlers.php index a9b0c7e..b70c8db 100644 --- a/client/includes/Hooks/ParserOutputUpdateHookHandlers.php +++ b/client/includes/Hooks/ParserOutputUpdateHookHandlers.php @@ -134,6 +134,7 @@ $this->parserOutputDataUpdater->updateItemIdProperty( $title, $parserOutput ); $this->parserOutputDataUpdater->updateOtherProjectsLinksData( $title, $parserOutput ); + $this->parserOutputDataUpdater->updateBadgesProperty( $title, $parserOutput ); if ( $useRepoLinks || $this->alwaysSort ) { $interwikiLinks = $parserOutput->getLanguageLinks(); diff --git a/client/includes/ParserOutputDataUpdater.php b/client/includes/ParserOutputDataUpdater.php index bf5bb99..da47ad0 100644 --- a/client/includes/ParserOutputDataUpdater.php +++ b/client/includes/ParserOutputDataUpdater.php @@ -7,7 +7,9 @@ use Title; use Wikibase\Client\Hooks\OtherProjectsSidebarGeneratorFactory; use Wikibase\Client\Usage\ParserOutputUsageAccumulator; +use Wikibase\DataModel\Entity\Item; use Wikibase\DataModel\Entity\ItemId; +use Wikibase\DataModel\Services\Lookup\EntityLookup; use Wikibase\Lib\Store\SiteLinkLookup; /** @@ -27,6 +29,11 @@ private $otherProjectsSidebarGeneratorFactory; /** +* @var EntityLookup +*/ + private $entityLookup; + + /** * @var SiteLinkLookup */ private $siteLinkLookup; @@ -40,11 +47,13 @@ * @param OtherProjectsSidebarGeneratorFactory $otherProjectsSidebarGeneratorFactory *Use the factory here to defer initialization of things like Site objects. * @param SiteLinkLookup $siteLinkLookup +* @param EntityLookup $entityLookup * @param string $siteId The global site ID for the local wiki */ public function __construct( OtherProjectsSidebarGeneratorFactory $otherProjectsSidebarGeneratorFactory, SiteLinkLookup $siteLinkLookup, + EntityLookup $entityLookup, $siteId ) { if ( !is_string( $siteId ) ) { @@ -52,6 +61,7 @@ } $this->otherProjectsSidebarGeneratorFactory = $otherProjectsSidebarGeneratorFactory; + $this->entityLookup = $entityLookup; $this->siteLinkLookup = $siteLinkLookup; $this->siteId = $siteId; } @@ -83,8 +93,8 @@ $itemId = $this->getItemIdForTitle( $title ); if ( $itemId ) { - $otherProjectsSidebarGenerator = $this->otherProjectsSidebarGeneratorFactory-> - getOtherProjectsSidebarGenerator(); + $otherProjectsSidebarGenerator = $this->otherProjectsSidebarGeneratorFactory + ->getOtherProjectsSidebarGenerator(); $otherProjects = $otherProjectsSidebarGenerator->buildProjectLinkSidebar( $title ); $out->setExtensionData( 'wikibase-otherprojects-sidebar', $otherProjects ); @@ -95,6 +105,31 @@ /** * @param Title $title +* @param ParserOutput $out +*/ + public function updateBadgesProperty( Title $title, ParserOutput $out ) { + $itemId = $this->getItemIdForTitle( $title ); + + // first reset all badges in case one got removed + foreach ( $out->getProperties() as $name => $property ) { + if ( strpos( $name, 'wikibase-badge-' ) === 0 ) { + $out->unsetProperty( $name ); + } + } + + if ( $itemId ) { + /** @var Item $item */ + $item = $this->entityLookup->getEntity( $itemId ); + $siteLink = $item->getSiteLinkList()->getBySiteId( $this->siteId ); + + foreach ( $siteLink->getBadges() as $badge ) { + $out->setProperty( 'wikibase-badge-' . $badge->getSerialization(), true ); + } + } + } + + /** +*