Adrian Lang has uploaded a new change for review. https://gerrit.wikimedia.org/r/192787
Change subject: Use EntityIdFormatter in MessageParameterFormatter ...................................................................... Use EntityIdFormatter in MessageParameterFormatter Change-Id: Ia5c1a4d19c4c40ce668840700c032ce4f1302f9b --- M lib/includes/formatters/EntityIdLinkFormatter.php M lib/tests/phpunit/formatters/EntityIdLinkFormatterTest.php M repo/includes/Localizer/MessageParameterFormatter.php M repo/includes/WikibaseRepo.php M repo/tests/phpunit/includes/Localizer/MessageParameterFormatterTest.php 5 files changed, 21 insertions(+), 31 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase refs/changes/87/192787/1 diff --git a/lib/includes/formatters/EntityIdLinkFormatter.php b/lib/includes/formatters/EntityIdLinkFormatter.php index 60567f4..9a520aa 100644 --- a/lib/includes/formatters/EntityIdLinkFormatter.php +++ b/lib/includes/formatters/EntityIdLinkFormatter.php @@ -24,7 +24,7 @@ public function formatEntityId( EntityId $entityId ) { $title = parent::formatEntityId( $entityId ); - return "[[$title]]"; + return "[[$title|" . wfEscapeWikiText( $entityId->getSerialization() ) . "]]"; } } diff --git a/lib/tests/phpunit/formatters/EntityIdLinkFormatterTest.php b/lib/tests/phpunit/formatters/EntityIdLinkFormatterTest.php index 035a916..d7084b9 100644 --- a/lib/tests/phpunit/formatters/EntityIdLinkFormatterTest.php +++ b/lib/tests/phpunit/formatters/EntityIdLinkFormatterTest.php @@ -5,7 +5,6 @@ use LogicException; use PHPUnit_Framework_TestCase; use Title; -use ValueFormatters\FormatterOptions; use Wikibase\DataModel\Entity\EntityId; use Wikibase\DataModel\Entity\Item; use Wikibase\DataModel\Entity\ItemId; @@ -17,8 +16,6 @@ * @covers Wikibase\Lib\EntityIdLinkFormatter * * @group Wikibase - * @group ValueFormatters - * @group DataValueExtensions * @group WikibaseLib * @group EntityIdFormatterTest * @@ -31,11 +28,11 @@ return array( 'ItemId' => array( new ItemId( 'Q23' ), - '[[ITEM-TEST--Q23]]' + '[[ITEM-TEST--Q23|Q23]]' ), 'PropertyId' => array( new PropertyId( 'P23' ), - '[[PROPERTY-TEST--P23]]' + '[[PROPERTY-TEST--P23|P23]]' ), ); } @@ -61,8 +58,7 @@ } } - protected function newEntityIdLinkFormatter() { - $options = new FormatterOptions(); + private function newEntityIdLinkFormatter() { $titleLookup = $this->getMock( 'Wikibase\Lib\Store\EntityTitleLookup' ); $titleLookup->expects( $this->any() )->method( 'getTitleForId' ) ->will( $this->returnCallback( array( $this, 'getTitleForId' ) ) ); diff --git a/repo/includes/Localizer/MessageParameterFormatter.php b/repo/includes/Localizer/MessageParameterFormatter.php index 7d54deb..6cd3c75 100644 --- a/repo/includes/Localizer/MessageParameterFormatter.php +++ b/repo/includes/Localizer/MessageParameterFormatter.php @@ -10,8 +10,8 @@ use ValueFormatters\ValueFormatter; use Wikibase\DataModel\Entity\EntityId; use Wikibase\DataModel\SiteLink; +use Wikibase\Lib\EntityIdFormatter; use Wikibase\Lib\MediaWikiNumberLocalizer; -use Wikibase\Lib\Store\EntityTitleLookup; /** * ValueFormatter for formatting objects that may be encountered in @@ -28,9 +28,9 @@ private $dataValueFormatter; /** - * @var EntityTitleLookup + * @var EntityIdFormatter */ - private $entityTitleLookup; + private $entityIdFormatter; /** * @var SiteStore @@ -49,18 +49,18 @@ /** * @param ValueFormatter $dataValueFormatter A formatter for turning DataValues into wikitext. - * @param EntityTitleLookup $entityTitleLookup + * @param EntityIdFormatter $entityIdFormatter An entity id formatter returning wikitext. * @param SiteStore $sites * @param Language $language */ public function __construct( ValueFormatter $dataValueFormatter, - EntityTitleLookup $entityTitleLookup, + EntityIdFormatter $entityIdFormatter, SiteStore $sites, Language $language ) { $this->dataValueFormatter = $dataValueFormatter; - $this->entityTitleLookup = $entityTitleLookup; + $this->entityIdFormatter = $entityIdFormatter; $this->sites = $sites; $this->language = $language; @@ -129,13 +129,7 @@ * @return string The formatted ID (as a wikitext link). */ private function formatEntityId( EntityId $entityId ) { - // @todo: this should use TitleValue + MediaWikiPageLinkRenderer! - $title = $this->entityTitleLookup->getTitleForId( $entityId ); - - $target = $title->getFullText(); - $text = wfEscapeWikiText( $entityId->getSerialization() ); - - return "[[$target|$text]]"; + return $this->entityIdFormatter->formatEntityId( $entityId ); } /** diff --git a/repo/includes/WikibaseRepo.php b/repo/includes/WikibaseRepo.php index b83a7f8..399ef3d 100644 --- a/repo/includes/WikibaseRepo.php +++ b/repo/includes/WikibaseRepo.php @@ -760,7 +760,7 @@ return new MessageParameterFormatter( new DispatchingValueFormatter( $valueFormatters ), - $this->getEntityTitleLookup(), + new EntityIdLinkFormatter( $this->getEntityTitleLookup() ), $this->getSiteStore(), $wgLang ); diff --git a/repo/tests/phpunit/includes/Localizer/MessageParameterFormatterTest.php b/repo/tests/phpunit/includes/Localizer/MessageParameterFormatterTest.php index 08e4ada..b2d17c1 100644 --- a/repo/tests/phpunit/includes/Localizer/MessageParameterFormatterTest.php +++ b/repo/tests/phpunit/includes/Localizer/MessageParameterFormatterTest.php @@ -5,14 +5,14 @@ use DataValues\DataValue; use DataValues\DecimalValue; use Language; +use PHPUnit_Framework_TestCase; use Site; use SiteStore; -use Title; use ValueFormatters\ValueFormatter; use Wikibase\DataModel\Entity\EntityId; use Wikibase\DataModel\Entity\ItemId; use Wikibase\DataModel\SiteLink; -use Wikibase\Lib\Store\EntityTitleLookup; +use Wikibase\Lib\EntityIdFormatter; use Wikibase\Repo\Localizer\MessageParameterFormatter; /** @@ -25,7 +25,7 @@ * @licence GNU GPL v2+ * @author Daniel Kinzler */ -class MessageParameterFormatterTest extends \PHPUnit_Framework_TestCase { +class MessageParameterFormatterTest extends PHPUnit_Framework_TestCase { public function formatProvider() { $decimal = new DecimalValue( '+123.456' ); @@ -50,7 +50,7 @@ public function testFormat( $param, $lang, $expected ) { $formatter = new MessageParameterFormatter( $this->getMockValueFormatter(), - $this->getMockTitleLookup(), + $this->getMockIdFormatter(), $this->getMockSitesTable(), Language::factory( $lang ) ); @@ -79,15 +79,15 @@ } /** - * @return EntityTitleLookup + * @return EntityIdFormatter */ - private function getMockTitleLookup() { - $mock = $this->getMock( 'Wikibase\Lib\Store\EntityTitleLookup' ); + private function getMockIdFormatter() { + $mock = $this->getMock( 'Wikibase\Lib\EntityIdFormatter' ); $mock->expects( $this->any() ) - ->method( 'getTitleForId' ) + ->method( 'formatEntityId' ) ->will( $this->returnCallback( function ( EntityId $id ) { - return Title::makeTitle( NS_MAIN, $id->getSerialization() ); + return $id->getSerialization(); } ) ); -- To view, visit https://gerrit.wikimedia.org/r/192787 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ia5c1a4d19c4c40ce668840700c032ce4f1302f9b Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/Wikibase Gerrit-Branch: master Gerrit-Owner: Adrian Lang <adrian.he...@wikimedia.de> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits