jenkins-bot has submitted this change and it was merged.
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/ClaimHtmlGeneratorTest.php
M repo/tests/phpunit/includes/View/SnakHtmlGeneratorTest.php
5 files changed, 25 insertions(+), 8 deletions(-)
Approvals:
Hoo man: Looks good to me, approved
jenkins-bot: Verified
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/ClaimHtmlGeneratorTest.php
b/repo/tests/phpunit/includes/View/ClaimHtmlGeneratorTest.php
index 37fea2f..f0839e4 100644
--- a/repo/tests/phpunit/includes/View/ClaimHtmlGeneratorTest.php
+++ b/repo/tests/phpunit/includes/View/ClaimHtmlGeneratorTest.php
@@ -85,7 +85,8 @@
) {
$snakHtmlGenerator = new SnakHtmlGenerator(
$snakFormatter,
- $entityTitleLookup
+ $entityTitleLookup,
+ 'en'
);
$claimHtmlGenerator = new ClaimHtmlGenerator(
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: merged
Gerrit-Change-Id: I24581ef4b11caab7d765f82cff98dbda530c426f
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: wmf/1.25wmf12c
Gerrit-Owner: Aude <[email protected]>
Gerrit-Reviewer: Aude <[email protected]>
Gerrit-Reviewer: Hoo man <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits