Daniel Kinzler has uploaded a new change for review. https://gerrit.wikimedia.org/r/237606
Change subject: Fix SiteLinkUsageLookup. ...................................................................... Fix SiteLinkUsageLookup. This fixes the fact that SiteLinkUsageLookup attempted to use the page id for looking up a sitelink in wb_items_per_site, which would always fail, because wb_items_per_site has page titles, not IDs. Change-Id: I9d7458816692935e2612f717cde1de7e760999bd --- M client/includes/Usage/SiteLinkUsageLookup.php M client/tests/phpunit/includes/Usage/SiteLinkUsageLookupTest.php 2 files changed, 26 insertions(+), 6 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase refs/changes/06/237606/1 diff --git a/client/includes/Usage/SiteLinkUsageLookup.php b/client/includes/Usage/SiteLinkUsageLookup.php index 0f7d012..0873d5d 100644 --- a/client/includes/Usage/SiteLinkUsageLookup.php +++ b/client/includes/Usage/SiteLinkUsageLookup.php @@ -65,7 +65,10 @@ public function getUsagesForPage( $pageId ) { $usages = array(); - $id = $this->siteLinkLookup->getItemIdForLink( $this->clientSiteId, $pageId ); + $titleFactory = $this->titleFactory; + $title = $titleFactory->newFromID( $pageId ); + + $id = $this->siteLinkLookup->getItemIdForLink( $this->clientSiteId, $title->getPrefixedText() ); if ( $id !== null ) { $usages[] = new EntityUsage( $id, EntityUsage::SITELINK_USAGE ); diff --git a/client/tests/phpunit/includes/Usage/SiteLinkUsageLookupTest.php b/client/tests/phpunit/includes/Usage/SiteLinkUsageLookupTest.php index 9753a53..cdaf1f8 100644 --- a/client/tests/phpunit/includes/Usage/SiteLinkUsageLookupTest.php +++ b/client/tests/phpunit/includes/Usage/SiteLinkUsageLookupTest.php @@ -33,13 +33,16 @@ * @return SiteLinkLookup */ private function getSiteLinkLookup( array $links ) { + $titleFactory = $this->getTitleFactory(); $siteLinkLookup = new HashSiteLinkStore(); - foreach ( $links as $name => $itemId ) { + foreach ( $links as $pageId => $itemId ) { + $title = $titleFactory->newFromID( $pageId ); + $item = new Item( $itemId ); - $item->getSiteLinkList()->addSiteLink( new SiteLink( 'testwiki', "$name" ) ); - $item->getSiteLinkList()->addSiteLink( new SiteLink( 'badwiki', "$name" ) ); - $item->getSiteLinkList()->addSiteLink( new SiteLink( 'sadwiki', "42" ) ); + $item->getSiteLinkList()->addSiteLink( new SiteLink( 'testwiki', $title->getPrefixedText() ) ); + $item->getSiteLinkList()->addSiteLink( new SiteLink( 'badwiki', $title->getPrefixedText() ) ); + $item->getSiteLinkList()->addSiteLink( new SiteLink( 'sadwiki', "Other stuff" ) ); $siteLinkLookup->saveLinksOfItem( $item ); } @@ -63,13 +66,27 @@ ); } + /** + * @return TitleFactory + */ private function getTitleFactory() { $titleFactory = $this->getMock( 'Wikibase\Client\Store\TitleFactory' ); $titleFactory->expects( $this->any() ) ->method( 'newFromText' ) ->will( $this->returnCallback( function ( $text ) { + if ( !preg_match( '/^Page number (\d+)$/', $text, $match ) ) { + throw new \InvalidArgumentException( 'Bad title text: ' . $text ); + } + $title = Title::newFromText( $text ); - $title->resetArticleID( $text ); + $title->resetArticleID( intval( $match[1] ) ); + return $title; + } ) ); + $titleFactory->expects( $this->any() ) + ->method( 'newFromID' ) + ->will( $this->returnCallback( function ( $id ) { + $title = Title::newFromText( "Page number $id" ); + $title->resetArticleID( $id ); return $title; } ) ); -- To view, visit https://gerrit.wikimedia.org/r/237606 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I9d7458816692935e2612f717cde1de7e760999bd Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/Wikibase Gerrit-Branch: master Gerrit-Owner: Daniel Kinzler <daniel.kinz...@wikimedia.de> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits