Aude has uploaded a new change for review.

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

Change subject: Fix of property label formatting
......................................................................

Fix of property label formatting

EntityInfo now has labels in multiple labels, but
the code was just picking the first one which produced
inconsistent formatting.

On master, we already have Ia0be6bf which is a much
better solution but it is not trivial to backport.

Change-Id: I24581ef4b11caab7d765f82cff98dbda530c426f
---
M repo/includes/View/ClaimsView.php
M repo/includes/View/EntityViewFactory.php
M repo/includes/View/SnakHtmlGenerator.php
M repo/tests/phpunit/includes/View/SnakHtmlGeneratorTest.php
4 files changed, 23 insertions(+), 7 deletions(-)


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

diff --git a/repo/includes/View/ClaimsView.php 
b/repo/includes/View/ClaimsView.php
index c205d43..5f37733 100644
--- a/repo/includes/View/ClaimsView.php
+++ b/repo/includes/View/ClaimsView.php
@@ -127,8 +127,11 @@
                $key = $propertyId->getSerialization();
                $propertyLabel = $key;
                if ( isset( $entityInfo[$key] ) && !empty( 
$entityInfo[$key]['labels'] ) ) {
-                       $entityInfoLabel = reset( $entityInfo[$key]['labels'] );
-                       $propertyLabel = $entityInfoLabel['value'];
+                       $languageCode = $this->languageCode;
+
+                       if ( isset( $entityInfo[$key]['labels'][$languageCode] 
) ) {
+                               $propertyLabel = 
$entityInfo[$key]['labels'][$languageCode]['value'];
+                       }
                }
 
                $propertyLink = Linker::link(
diff --git a/repo/includes/View/EntityViewFactory.php 
b/repo/includes/View/EntityViewFactory.php
index f97697e..c1f0e8b 100644
--- a/repo/includes/View/EntityViewFactory.php
+++ b/repo/includes/View/EntityViewFactory.php
@@ -106,7 +106,8 @@
        ) {
                $snakHtmlGenerator = new SnakHtmlGenerator(
                        $this->getSnakFormatter( $languageCode, $fallbackChain, 
$labelLookup ),
-                       $this->entityTitleLookup
+                       $this->entityTitleLookup,
+                       $languageCode
                );
 
                $claimHtmlGenerator = new ClaimHtmlGenerator(
diff --git a/repo/includes/View/SnakHtmlGenerator.php 
b/repo/includes/View/SnakHtmlGenerator.php
index 99cad57..af8a491 100644
--- a/repo/includes/View/SnakHtmlGenerator.php
+++ b/repo/includes/View/SnakHtmlGenerator.php
@@ -36,14 +36,21 @@
        protected $entityTitleLookup;
 
        /**
+        * @var string
+        */
+       private $languageCode;
+
+       /**
         * @param SnakFormatter $snakFormatter
         * @param EntityTitleLookup $entityTitleLookup
+        * @param $languageCode $languageCode
         *
         * @throws InvalidArgumentException
         */
        public function __construct(
                SnakFormatter $snakFormatter,
-               EntityTitleLookup $entityTitleLookup
+               EntityTitleLookup $entityTitleLookup,
+               $languageCode
        ) {
                if ( $snakFormatter->getFormat() !== SnakFormatter::FORMAT_HTML
                                && $snakFormatter->getFormat() !== 
SnakFormatter::FORMAT_HTML_WIDGET ) {
@@ -53,6 +60,7 @@
 
                $this->snakFormatter = $snakFormatter;
                $this->entityTitleLookup = $entityTitleLookup;
+               $this->languageCode = $languageCode;
        }
 
        /**
@@ -98,8 +106,11 @@
                $key = $propertyId->getSerialization();
                $propertyLabel = $key;
                if ( isset( $entityInfo[$key] ) && !empty( 
$entityInfo[$key]['labels'] ) ) {
-                       $entityInfoLabel = reset( $entityInfo[$key]['labels'] );
-                       $propertyLabel = $entityInfoLabel['value'];
+                       $languageCode = $this->languageCode;
+
+                       if ( isset( $entityInfo[$key]['labels'][$languageCode] 
) ) {
+                               $propertyLabel = 
$entityInfo[$key]['labels'][$languageCode]['value'];
+                       }
                }
 
                // @todo use EntityIdHtmlLinkFormatter here
diff --git a/repo/tests/phpunit/includes/View/SnakHtmlGeneratorTest.php 
b/repo/tests/phpunit/includes/View/SnakHtmlGeneratorTest.php
index 426e322..a248578 100644
--- a/repo/tests/phpunit/includes/View/SnakHtmlGeneratorTest.php
+++ b/repo/tests/phpunit/includes/View/SnakHtmlGeneratorTest.php
@@ -35,7 +35,8 @@
        ) {
                $snakHtmlGenerator = new SnakHtmlGenerator(
                        $snakFormatter,
-                       $entityTitleLookup
+                       $entityTitleLookup,
+                       'en'
                );
 
                $html = $snakHtmlGenerator->getSnakHtml( $snak, $entityInfo );

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I24581ef4b11caab7d765f82cff98dbda530c426f
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: wmf/1.25wmf12c
Gerrit-Owner: Aude <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to