Daniel Kinzler has uploaded a new change for review.
https://gerrit.wikimedia.org/r/203189
Change subject: Fix language fallback in value formatters.
......................................................................
Fix language fallback in value formatters.
This causes ValueFormatters from WikibaseValueFormatterBuilders to
always apply language fallback. Previously, this was only the case
for formatters constructed via WikibaseSnakFormatterBuilders, causing
inconsistencies. In particular, the wbformatvalue API module did
not apply language fallback as expected.
Bug: 94563
Change-Id: I45bbe1585b8e3e449f2c2b88b994b9dc5d175446
---
M lib/includes/formatters/WikibaseValueFormatterBuilders.php
M lib/tests/phpunit/formatters/WikibaseValueFormatterBuildersTest.php
M repo/tests/phpunit/includes/api/FormatSnakValueTest.php
3 files changed, 23 insertions(+), 0 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase
refs/changes/89/203189/1
diff --git a/lib/includes/formatters/WikibaseValueFormatterBuilders.php
b/lib/includes/formatters/WikibaseValueFormatterBuilders.php
index d31f8cd..15c84ad 100644
--- a/lib/includes/formatters/WikibaseValueFormatterBuilders.php
+++ b/lib/includes/formatters/WikibaseValueFormatterBuilders.php
@@ -287,6 +287,8 @@
* @return DispatchingValueFormatter
*/
public function buildDispatchingValueFormatter(
OutputFormatValueFormatterFactory $factory, $format, FormatterOptions $options
) {
+ $this->applyLanguageDefaults( $options );
+
switch ( $format ) {
case SnakFormatter::FORMAT_PLAIN:
$formatters = $this->getPlainTextFormatters(
$options );
diff --git
a/lib/tests/phpunit/formatters/WikibaseValueFormatterBuildersTest.php
b/lib/tests/phpunit/formatters/WikibaseValueFormatterBuildersTest.php
index b4cb9a8..331dfc1 100644
--- a/lib/tests/phpunit/formatters/WikibaseValueFormatterBuildersTest.php
+++ b/lib/tests/phpunit/formatters/WikibaseValueFormatterBuildersTest.php
@@ -155,6 +155,12 @@
new EntityIdValue( new ItemId( 'Q5' ) ),
'@^Label for Q5$@' // compare mock object
created in newBuilders()
),
+ 'plain item label (with language fallback)' => array(
+ SnakFormatter::FORMAT_PLAIN,
+ $this->newFormatterOptions( 'de-ch' ), //
should fall back to 'de'
+ new EntityIdValue( new ItemId( 'Q5' ) ),
+ '@^Name für Q5$@' // compare mock object
created in newBuilders()
+ ),
'widget item link (with entity lookup)' => array(
SnakFormatter::FORMAT_HTML_WIDGET,
$this->newFormatterOptions(),
diff --git a/repo/tests/phpunit/includes/api/FormatSnakValueTest.php
b/repo/tests/phpunit/includes/api/FormatSnakValueTest.php
index ed1aeca..0909491 100644
--- a/repo/tests/phpunit/includes/api/FormatSnakValueTest.php
+++ b/repo/tests/phpunit/includes/api/FormatSnakValueTest.php
@@ -4,6 +4,7 @@
use ApiTestCase;
use DataValues\DataValue;
+use DataValues\QuantityValue;
use DataValues\StringValue;
use DataValues\TimeValue;
use ValueFormatters\TimeFormatter;
@@ -94,6 +95,20 @@
'@^http://acme\.test$@'
),
array(
+ QuantityValue::newFromNumber( '+12.33', '1' ),
+ 'quantity',
+ SnakFormatter::FORMAT_PLAIN,
+ array( 'lang' => 'de' ),
+ '@^12,33$@' // german decimal separator
+ ),
+ array(
+ QuantityValue::newFromNumber( '+12.33', '1' ),
+ 'quantity',
+ SnakFormatter::FORMAT_PLAIN,
+ array( 'lang' => 'de-ch' ), // fallback
+ '@^12,33$@' // german decimal separator
+ ),
+ array(
new StringValue( 'http://acme.test' ),
'url',
SnakFormatter::FORMAT_WIKI,
--
To view, visit https://gerrit.wikimedia.org/r/203189
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I45bbe1585b8e3e449f2c2b88b994b9dc5d175446
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Daniel Kinzler <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits