jenkins-bot has submitted this change and it was merged.

Change subject: Allow mw.wikibase.label( ) to find labels written in variants
......................................................................


Allow mw.wikibase.label( ) to find labels written in variants

Some hacky way is used here...

Change-Id: Ib73d9090f2db481c5c3592f0eab17fa33d6cd1bc
---
M client/includes/WikibaseLibrary.php
1 file changed, 16 insertions(+), 0 deletions(-)

Approvals:
  Daniel Kinzler: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/client/includes/WikibaseLibrary.php 
b/client/includes/WikibaseLibrary.php
index 0869edb..dbda842 100644
--- a/client/includes/WikibaseLibrary.php
+++ b/client/includes/WikibaseLibrary.php
@@ -28,6 +28,8 @@
 use Wikibase\Client\WikibaseClient;
 use Wikibase\Lib\Serializers\EntitySerializationOptions;
 use Wikibase\Lib\Serializers\SerializerFactory;
+use Wikibase\LanguageFallbackChainFactory;
+use Wikibase\Utils;
 
 class Scribunto_LuaWikibaseLibrary extends Scribunto_LuaLibraryBase {
 
@@ -76,6 +78,20 @@
 
                $serializerFactory = new SerializerFactory();
                $opt = new EntitySerializationOptions( 
WikibaseClient::getDefaultInstance()->getEntityIdFormatter() );
+
+               // This is $wgContLang, not parser target language or anything 
else.
+               // See Scribunto_LuaLanguageLibrary::getContLangCode().
+               global $wgContLang;
+
+               // See mw.wikibase.lua. This is the only way to inject values 
into mw.wikibase.label( ),
+               // so any customized Lua modules can access labels of another 
entity written in another variant,
+               // unless we give them the ability to getEntity() any entity by 
specifying its ID, not just self.
+               $chain = 
WikibaseClient::getDefaultInstance()->getLanguageFallbackChainFactory()->newFromLanguage(
+                       $wgContLang, 
LanguageFallbackChainFactory::FALLBACK_SELF | 
LanguageFallbackChainFactory::FALLBACK_VARIANTS
+               );
+               // MultiLangSerializationOptions accepts mixed types of keys 
happily.
+               $opt->setLanguages( Utils::getLanguageCodes() + array( 
$wgContLang->getCode() => $chain ) );
+
                $serializer = $serializerFactory->newSerializerForObject( 
$entityObject, $opt );
 
                try {

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

Gerrit-MessageType: merged
Gerrit-Change-Id: Ib73d9090f2db481c5c3592f0eab17fa33d6cd1bc
Gerrit-PatchSet: 10
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Liangent <[email protected]>
Gerrit-Reviewer: Aude <[email protected]>
Gerrit-Reviewer: Daniel Kinzler <[email protected]>
Gerrit-Reviewer: Denny Vrandecic <[email protected]>
Gerrit-Reviewer: Jens Ohlig <[email protected]>
Gerrit-Reviewer: Liangent <[email protected]>
Gerrit-Reviewer: jenkins-bot

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

Reply via email to