jenkins-bot has submitted this change and it was merged.
Change subject: Use EntityIdFormatter in MessageParameterFormatter
......................................................................
Use EntityIdFormatter in MessageParameterFormatter
MessageParameterFormatter currently does [[TITLE|ENTITYID]]. This change makes
it use a EntityIdLinkFormatter, which used to do [[ENTITYID]]. This change also
makes it do [[TITLE|ENTITYID]] instead. EntityIdLinkFormatter is currently only
used in the SummaryFormatter.
Put together, the only change in behaviour this change introduces is the
trimming of the namespace in links to entities in summaries.
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, 22 insertions(+), 32 deletions(-)
Approvals:
Daniel Kinzler: Looks good to me, approved
jenkins-bot: Verified
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 9f4bacd..683db98 100644
--- a/repo/includes/WikibaseRepo.php
+++ b/repo/includes/WikibaseRepo.php
@@ -761,7 +761,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..a3bb80a 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' );
@@ -38,7 +38,7 @@
'float en' => array( 123.456, 'en', '123.456' ),
'float de' => array( 123.456, 'de', '123,456' ),
'DecimalValue en' => array( $decimal, 'en',
'DataValues\DecimalValue:+123.456' ),
- 'EntityId' => array( $entityId, 'en', '[[Q123|Q123]]' ),
+ 'EntityId' => array( $entityId, 'en', '[[ENTITYID]]' ),
'SiteLink' => array( $siteLink, 'en',
'[http://acme.com/Foo acme:Foo]' ),
'list of floats' => array( array( 1.2, 0.5 ), 'en',
'1.2, 0.5' ),
);
@@ -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 '[[ENTITYID]]';
}
) );
--
To view, visit https://gerrit.wikimedia.org/r/192787
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ia5c1a4d19c4c40ce668840700c032ce4f1302f9b
Gerrit-PatchSet: 4
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Adrian Lang <[email protected]>
Gerrit-Reviewer: Adrian Lang <[email protected]>
Gerrit-Reviewer: Daniel Kinzler <[email protected]>
Gerrit-Reviewer: JanZerebecki <[email protected]>
Gerrit-Reviewer: Jeroen De Dauw <[email protected]>
Gerrit-Reviewer: Thiemo Mättig (WMDE) <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits