Aude has uploaded a new change for review.
https://gerrit.wikimedia.org/r/180069
Change subject: Apply LanguageFallback (variants) for getLabel in lua
......................................................................
Apply LanguageFallback (variants) for getLabel in lua
we had this before we changed to use the label lookup.
maybe we also want a method to request labels without
resolving fallback or something else? regardless of
whatever / however else we want, i think we should
keep getLabel behavior consistent with what it was before.
also add test case to check that language fallback is
applied for lua entity serialization for variant languages.
Change-Id: I07e698b9fec99c612f0d52fc337396360b765b66
---
M client/includes/scribunto/Scribunto_LuaWikibaseLibrary.php
M client/tests/phpunit/includes/scribunto/Scribunto_LuaWikibaseLibraryTest.php
M
client/tests/phpunit/includes/scribunto/WikibaseLuaIntegrationTestItemSetUpHelper.php
3 files changed, 46 insertions(+), 3 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase
refs/changes/69/180069/1
diff --git a/client/includes/scribunto/Scribunto_LuaWikibaseLibrary.php
b/client/includes/scribunto/Scribunto_LuaWikibaseLibrary.php
index 5a9fac5..be82b52 100644
--- a/client/includes/scribunto/Scribunto_LuaWikibaseLibrary.php
+++ b/client/includes/scribunto/Scribunto_LuaWikibaseLibrary.php
@@ -4,8 +4,9 @@
use Wikibase\Client\Usage\ParserOutputUsageAccumulator;
use Wikibase\Client\WikibaseClient;
use Wikibase\DataModel\Entity\EntityIdParsingException;
+use Wikibase\LanguageFallbackChainFactory;
use Wikibase\Lib\Store\EntityRetrievingTermLookup;
-use Wikibase\Lib\Store\LanguageLabelLookup;
+use Wikibase\Lib\Store\LanguageFallbackLabelLookup;
use Wikibase\Utils;
/**
@@ -40,9 +41,15 @@
$wikibaseClient = WikibaseClient::getDefaultInstance();
$entityLookup = $wikibaseClient->getStore()->getEntityLookup();
- $labelLookup = new LanguageLabelLookup(
+
+ $fallbackChain =
$wikibaseClient->getLanguageFallbackChainFactory()->newFromLanguage(
+ $language,
+ LanguageFallbackChainFactory::FALLBACK_SELF |
LanguageFallbackChainFactory::FALLBACK_VARIANTS
+ );
+
+ $labelLookup = new LanguageFallbackLabelLookup(
new EntityRetrievingTermLookup( $entityLookup ),
- $wgContLang->getCode()
+ $fallbackChain
);
return new WikibaseLuaBindings(
diff --git
a/client/tests/phpunit/includes/scribunto/Scribunto_LuaWikibaseLibraryTest.php
b/client/tests/phpunit/includes/scribunto/Scribunto_LuaWikibaseLibraryTest.php
index 7393ffe..d4ecc3a 100644
---
a/client/tests/phpunit/includes/scribunto/Scribunto_LuaWikibaseLibraryTest.php
+++
b/client/tests/phpunit/includes/scribunto/Scribunto_LuaWikibaseLibraryTest.php
@@ -2,6 +2,7 @@
namespace Wikibase\Client\Tests\Scribunto;
+use Language;
use Parser;
use ParserOptions;
use Scribunto;
@@ -55,6 +56,39 @@
$this->assertEquals( array( null ), $entity );
}
+ public function testGetEntity_hasLanguageFallback() {
+ $this->setMwGlobals( array(
+ 'wgContLang' => Language::factory( 'ku-arab' )
+ ) );
+
+ $luaWikibaseLibrary = $this->newScribuntoLuaWikibaseLibrary();
+ $entityArray = $luaWikibaseLibrary->getEntity( 'Q885588', false
);
+
+ $expected = array(
+ array(
+ 'id' => 'Q885588',
+ 'type' => 'item',
+ 'labels' => array(
+ 'ku-latn' => array(
+ 'language' => 'ku-latn',
+ 'value' => 'Pisîk'
+ ),
+ 'ku-arab' => array (
+ 'language' => 'ku-arab',
+ 'value' => 'پسیک',
+ 'source-language' => 'ku-latn',
+ )
+ ),
+ 'schemaVersion' => 2,
+ )
+ );
+
+ $this->assertEquals( $expected, $entityArray, 'getEntity' );
+
+ $label = $luaWikibaseLibrary->getLabel( 'Q885588' );
+ $this->assertEquals( array( 'پسیک' ), $label, 'getLabel' );
+ }
+
public function testGetEntityInvalidIdType() {
$this->setExpectedException( 'ScribuntoException' );
$luaWikibaseLibrary = $this->newScribuntoLuaWikibaseLibrary();
diff --git
a/client/tests/phpunit/includes/scribunto/WikibaseLuaIntegrationTestItemSetUpHelper.php
b/client/tests/phpunit/includes/scribunto/WikibaseLuaIntegrationTestItemSetUpHelper.php
index 180292e..f28d385 100644
---
a/client/tests/phpunit/includes/scribunto/WikibaseLuaIntegrationTestItemSetUpHelper.php
+++
b/client/tests/phpunit/includes/scribunto/WikibaseLuaIntegrationTestItemSetUpHelper.php
@@ -87,6 +87,8 @@
// Create another test item to test arbitrary access
$this->createTestItem( new ItemId( 'Q199024' ), array( 'de' =>
'Arbitrary access \o/' ) );
+
+ $this->createTestItem( new ItemId( 'Q885588'), array( 'ku-latn'
=> 'Pisîk' ) );
}
/**
--
To view, visit https://gerrit.wikimedia.org/r/180069
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I07e698b9fec99c612f0d52fc337396360b765b66
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