Aude has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/199586

Change subject: Revert "Use EntityIdFormatter in MessageParameterFormatter"
......................................................................

Revert "Use EntityIdFormatter in MessageParameterFormatter"

will be just for the branch for now, since it causes T93804.

we can investigate more proper fix for master, as using
EntityIdFormatter here is a good idea.

This reverts commit fb60de9acf5ffa5347fc0f57656073154e170c97.
Bug: T93804

Change-Id: I330d4761a47bb244f4fde4d7b549e24aa4410c79
---
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, 32 insertions(+), 22 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase 
refs/changes/86/199586/1

diff --git a/lib/includes/formatters/EntityIdLinkFormatter.php 
b/lib/includes/formatters/EntityIdLinkFormatter.php
index 9a520aa..60567f4 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|" . wfEscapeWikiText( 
$entityId->getSerialization() ) . "]]";
+               return "[[$title]]";
        }
 
 }
diff --git a/lib/tests/phpunit/formatters/EntityIdLinkFormatterTest.php 
b/lib/tests/phpunit/formatters/EntityIdLinkFormatterTest.php
index d7084b9..035a916 100644
--- a/lib/tests/phpunit/formatters/EntityIdLinkFormatterTest.php
+++ b/lib/tests/phpunit/formatters/EntityIdLinkFormatterTest.php
@@ -5,6 +5,7 @@
 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;
@@ -16,6 +17,8 @@
  * @covers Wikibase\Lib\EntityIdLinkFormatter
  *
  * @group Wikibase
+ * @group ValueFormatters
+ * @group DataValueExtensions
  * @group WikibaseLib
  * @group EntityIdFormatterTest
  *
@@ -28,11 +31,11 @@
                return array(
                        'ItemId' => array(
                                new ItemId( 'Q23' ),
-                               '[[ITEM-TEST--Q23|Q23]]'
+                               '[[ITEM-TEST--Q23]]'
                        ),
                        'PropertyId' => array(
                                new PropertyId( 'P23' ),
-                               '[[PROPERTY-TEST--P23|P23]]'
+                               '[[PROPERTY-TEST--P23]]'
                        ),
                );
        }
@@ -58,7 +61,8 @@
                }
        }
 
-       private function newEntityIdLinkFormatter() {
+       protected function newEntityIdLinkFormatter() {
+               $options = new FormatterOptions();
                $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 6cd3c75..7d54deb 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 EntityIdFormatter
+        * @var EntityTitleLookup
         */
-       private $entityIdFormatter;
+       private $entityTitleLookup;
 
        /**
         * @var SiteStore
@@ -49,18 +49,18 @@
 
        /**
         * @param ValueFormatter $dataValueFormatter A formatter for turning 
DataValues into wikitext.
-        * @param EntityIdFormatter $entityIdFormatter An entity id formatter 
returning wikitext.
+        * @param EntityTitleLookup $entityTitleLookup
         * @param SiteStore $sites
         * @param Language $language
         */
        public function __construct(
                ValueFormatter $dataValueFormatter,
-               EntityIdFormatter $entityIdFormatter,
+               EntityTitleLookup $entityTitleLookup,
                SiteStore $sites,
                Language $language
        ) {
                $this->dataValueFormatter = $dataValueFormatter;
-               $this->entityIdFormatter = $entityIdFormatter;
+               $this->entityTitleLookup = $entityTitleLookup;
                $this->sites = $sites;
                $this->language = $language;
 
@@ -129,7 +129,13 @@
         * @return string The formatted ID (as a wikitext link).
         */
        private function formatEntityId( EntityId $entityId ) {
-               return $this->entityIdFormatter->formatEntityId( $entityId );
+               // @todo: this should use TitleValue + 
MediaWikiPageLinkRenderer!
+               $title = $this->entityTitleLookup->getTitleForId( $entityId );
+
+               $target = $title->getFullText();
+               $text = wfEscapeWikiText( $entityId->getSerialization() );
+
+               return "[[$target|$text]]";
        }
 
        /**
diff --git a/repo/includes/WikibaseRepo.php b/repo/includes/WikibaseRepo.php
index 683db98..9f4bacd 100644
--- a/repo/includes/WikibaseRepo.php
+++ b/repo/includes/WikibaseRepo.php
@@ -761,7 +761,7 @@
 
                return new MessageParameterFormatter(
                        new DispatchingValueFormatter( $valueFormatters ),
-                       new EntityIdLinkFormatter( 
$this->getEntityTitleLookup() ),
+                       $this->getEntityTitleLookup(),
                        $this->getSiteStore(),
                        $wgLang
                );
diff --git 
a/repo/tests/phpunit/includes/Localizer/MessageParameterFormatterTest.php 
b/repo/tests/phpunit/includes/Localizer/MessageParameterFormatterTest.php
index a3bb80a..08e4ada 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\EntityIdFormatter;
+use Wikibase\Lib\Store\EntityTitleLookup;
 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', '[[ENTITYID]]' ),
+                       'EntityId' => array( $entityId, 'en', '[[Q123|Q123]]' ),
                        '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->getMockIdFormatter(),
+                       $this->getMockTitleLookup(),
                        $this->getMockSitesTable(),
                        Language::factory( $lang )
                );
@@ -79,15 +79,15 @@
        }
 
        /**
-        * @return EntityIdFormatter
+        * @return EntityTitleLookup
         */
-       private function getMockIdFormatter() {
-               $mock = $this->getMock( 'Wikibase\Lib\EntityIdFormatter' );
+       private function getMockTitleLookup() {
+               $mock = $this->getMock( 'Wikibase\Lib\Store\EntityTitleLookup' 
);
                $mock->expects( $this->any() )
-                       ->method( 'formatEntityId' )
+                       ->method( 'getTitleForId' )
                        ->will( $this->returnCallback(
                                function ( EntityId $id ) {
-                                       return '[[ENTITYID]]';
+                                       return Title::makeTitle( NS_MAIN, 
$id->getSerialization() );
                                }
                        ) );
 

-- 
To view, visit https://gerrit.wikimedia.org/r/199586
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I330d4761a47bb244f4fde4d7b549e24aa4410c79
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Aude <aude.w...@gmail.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to