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

Change subject: Make mw.wikibase.entity:getLabel/:getDescription obey 
allowDataAccessInUserLanguage
......................................................................


Make mw.wikibase.entity:getLabel/:getDescription obey 
allowDataAccessInUserLanguage

DEPLOY: post a heads-up about this to commons-l and commons village pump.

Bug: T143277
Change-Id: Idbbbf1cbfa1e10bdbc6c6bec1e27df19f30b2ab1
---
M client/includes/DataAccess/Scribunto/Scribunto_LuaWikibaseEntityLibrary.php
M client/includes/DataAccess/Scribunto/WikibaseLuaEntityBindings.php
M client/includes/DataAccess/Scribunto/mw.wikibase.entity.lua
M 
client/tests/phpunit/includes/DataAccess/Scribunto/Scribunto_LuaWikibaseEntityLibraryTest.php
M 
client/tests/phpunit/includes/DataAccess/Scribunto/WikibaseLuaEntityBindingsTest.php
M docs/lua.wiki
6 files changed, 77 insertions(+), 9 deletions(-)

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



diff --git 
a/client/includes/DataAccess/Scribunto/Scribunto_LuaWikibaseEntityLibrary.php 
b/client/includes/DataAccess/Scribunto/Scribunto_LuaWikibaseEntityLibrary.php
index c0c2bde..2fc0cfc 100644
--- 
a/client/includes/DataAccess/Scribunto/Scribunto_LuaWikibaseEntityLibrary.php
+++ 
b/client/includes/DataAccess/Scribunto/Scribunto_LuaWikibaseEntityLibrary.php
@@ -76,6 +76,7 @@
                        $plainTextTransclusionInteractor,
                        $richWikitextTransclusionInteractor,
                        $wikibaseClient->getEntityIdParser(),
+                       $lang,
                        $wikibaseClient->getSettings()->getSetting( 
'siteGlobalID' )
                );
        }
@@ -132,6 +133,7 @@
                // these can't be called from user code, unless explicitly 
exposed in Lua.
                $lib = [
                        'getGlobalSiteId' => [ $this, 'getGlobalSiteId' ],
+                       'getLanguageCode' => [ $this, 'getLanguageCode' ],
                        'formatStatements' => [ $this, 'formatStatements' ],
                        'formatPropertyValues' => [ $this, 
'formatPropertyValues' ],
                        'isFormatStatementsEnabled' => [ $this, 
'isFormatStatementsEnabled' ],
@@ -170,6 +172,17 @@
        }
 
        /**
+        * Wrapper for getLanguageCode in WikibaseLuaEntityBindings
+        *
+        * @since 0.5
+        *
+        * @return string[]
+        */
+       public function getLanguageCode() {
+               return [ $this->getImplementation()->getLanguageCode() ];
+       }
+
+       /**
         * Format the main Snaks belonging to a Statement (which is identified 
by a PropertyId
         * or the label of a Property) as escaped plain text.
         *
diff --git a/client/includes/DataAccess/Scribunto/WikibaseLuaEntityBindings.php 
b/client/includes/DataAccess/Scribunto/WikibaseLuaEntityBindings.php
index ee08478..fe97725 100644
--- a/client/includes/DataAccess/Scribunto/WikibaseLuaEntityBindings.php
+++ b/client/includes/DataAccess/Scribunto/WikibaseLuaEntityBindings.php
@@ -2,6 +2,7 @@
 
 namespace Wikibase\Client\DataAccess\Scribunto;
 
+use Language;
 use Wikibase\Client\DataAccess\StatementTransclusionInteractor;
 use Wikibase\DataModel\Entity\EntityIdParser;
 
@@ -31,6 +32,11 @@
        private $entityIdParser;
 
        /**
+        * @var Language
+        */
+       private $language;
+
+       /**
         * @var string
         */
        private $siteId;
@@ -39,17 +45,20 @@
         * @param StatementTransclusionInteractor 
$plainTextTransclusionInteractor
         * @param StatementTransclusionInteractor 
$richWikitextTransclusionInteractor
         * @param EntityIdParser $entityIdParser
+        * @param Language $language
         * @param string $siteId
         */
        public function __construct(
                StatementTransclusionInteractor 
$plainTextTransclusionInteractor,
                StatementTransclusionInteractor 
$richWikitextTransclusionInteractor,
                EntityIdParser $entityIdParser,
+               Language $language,
                $siteId
        ) {
                $this->plainTextTransclusionInteractor = 
$plainTextTransclusionInteractor;
                $this->richWikitextTransclusionInteractor = 
$richWikitextTransclusionInteractor;
                $this->entityIdParser = $entityIdParser;
+               $this->language = $language;
                $this->siteId = $siteId;
        }
 
@@ -110,4 +119,17 @@
                return $this->siteId;
        }
 
+       /**
+        * Get the language we are currently working with.
+        * @TODO: Once T114640 has been implemented, this should probably be
+        * generally exposed in Scribunto as parser target language.
+        *
+        * @since 0.5
+        *
+        * @return string
+        */
+       public function getLanguageCode() {
+               return $this->language->getCode();
+       }
+
 }
diff --git a/client/includes/DataAccess/Scribunto/mw.wikibase.entity.lua 
b/client/includes/DataAccess/Scribunto/mw.wikibase.entity.lua
index a13ed5d..4918335 100644
--- a/client/includes/DataAccess/Scribunto/mw.wikibase.entity.lua
+++ b/client/includes/DataAccess/Scribunto/mw.wikibase.entity.lua
@@ -44,14 +44,15 @@
        return entity
 end
 
--- Get a term of a given type for a given language code or the content 
language.
+-- Get a term of a given type for a given language code or the content 
language (on monolingual wikis)
+-- or the user's language (on multilingual wikis).
 -- Second return parameter is the language the term is in.
 --
 -- @param {table} entity
 -- @param {string} termType A valid key in the entity table (either labels, 
descriptions or aliases)
 -- @param {string|number} langCode
 local getTermAndLang = function( entity, termType, langCode )
-       langCode = langCode or mw.language.getContentLanguage():getCode()
+       langCode = langCode or php.getLanguageCode()
 
        if langCode == nil then
                return nil, nil
@@ -71,7 +72,8 @@
        return term.value, actualLang
 end
 
--- Get the label for a given language code or the content language
+-- Get the label for a given language code or the content language (on 
monolingual wikis)
+-- or the user's language (on multilingual wikis).
 --
 -- @param {string|number} [langCode]
 methodtable.getLabel = function( entity, langCode )
@@ -81,7 +83,8 @@
        return label
 end
 
--- Get the description for a given language code or the content language
+-- Get the description for a given language code or the content language (on 
monolingual wikis)
+-- or the user's language (on multilingual wikis).
 --
 -- @param {string|number} [langCode]
 methodtable.getDescription = function( entity, langCode )
@@ -91,7 +94,9 @@
        return description
 end
 
--- Get the label for a given language code or the content language
+-- Get the label for a given language code or the content language (on 
monolingual wikis)
+-- or the user's language (on multilingual wikis).
+-- Has the language the returned label is in as an additional second return 
parameter.
 --
 -- @param {string|number} [langCode]
 methodtable.getLabelWithLang = function( entity, langCode )
@@ -100,7 +105,9 @@
        return getTermAndLang( entity, 'labels', langCode )
 end
 
--- Get the description for a given language code or the content language
+-- Get the description for a given language code or the content language (on 
monolingual wikis)
+-- or the user's language (on multilingual wikis).
+-- Has the language the returned description is in as an additional second 
return parameter.
 --
 -- @param {string|number} [langCode]
 methodtable.getDescriptionWithLang = function( entity, langCode )
diff --git 
a/client/tests/phpunit/includes/DataAccess/Scribunto/Scribunto_LuaWikibaseEntityLibraryTest.php
 
b/client/tests/phpunit/includes/DataAccess/Scribunto/Scribunto_LuaWikibaseEntityLibraryTest.php
index 878b092..e85cfca 100644
--- 
a/client/tests/phpunit/includes/DataAccess/Scribunto/Scribunto_LuaWikibaseEntityLibraryTest.php
+++ 
b/client/tests/phpunit/includes/DataAccess/Scribunto/Scribunto_LuaWikibaseEntityLibraryTest.php
@@ -108,6 +108,23 @@
        /**
         * @dataProvider allowDataAccessInUserLanguageProvider
         */
+       public function testGetLanguageCode( $allowDataAccessInUserLanguage ) {
+               $this->setAllowDataAccessInUserLanguage( 
$allowDataAccessInUserLanguage );
+
+               $cacheSplit = false;
+               $lang = Language::factory( 'es' );
+               $luaWikibaseLibrary = $this->newScribuntoLuaWikibaseLibrary( 
$cacheSplit, $lang );
+
+               $this->assertSame(
+                       [ $allowDataAccessInUserLanguage ? 'es' : 'de' ],
+                       $luaWikibaseLibrary->getLanguageCode()
+               );
+               $this->assertSame( $allowDataAccessInUserLanguage, $cacheSplit 
);
+       }
+
+       /**
+        * @dataProvider allowDataAccessInUserLanguageProvider
+        */
        public function testFormatPropertyValues( 
$allowDataAccessInUserLanguage ) {
                $cacheSplit = false;
                $this->setAllowDataAccessInUserLanguage( 
$allowDataAccessInUserLanguage );
diff --git 
a/client/tests/phpunit/includes/DataAccess/Scribunto/WikibaseLuaEntityBindingsTest.php
 
b/client/tests/phpunit/includes/DataAccess/Scribunto/WikibaseLuaEntityBindingsTest.php
index 5f8042b..5903624 100644
--- 
a/client/tests/phpunit/includes/DataAccess/Scribunto/WikibaseLuaEntityBindingsTest.php
+++ 
b/client/tests/phpunit/includes/DataAccess/Scribunto/WikibaseLuaEntityBindingsTest.php
@@ -2,6 +2,8 @@
 
 namespace Wikibase\Client\Tests\DataAccess\Scribunto;
 
+use Language;
+use PHPUnit_Framework_TestCase;
 use Wikibase\Client\DataAccess\Scribunto\WikibaseLuaEntityBindings;
 use Wikibase\Client\DataAccess\StatementTransclusionInteractor;
 use Wikibase\DataModel\Entity\ItemId;
@@ -18,7 +20,7 @@
  * @license GPL-2.0+
  * @author Marius Hoch < h...@online.de >
  */
-class WikibaseLuaEntityBindingsTest extends \PHPUnit_Framework_TestCase {
+class WikibaseLuaEntityBindingsTest extends PHPUnit_Framework_TestCase {
 
        /**
         * @return WikibaseLuaEntityBindings
@@ -46,6 +48,7 @@
                        $plainTextTransclusionInteractor,
                        $richWikitextTransclusionInteractor,
                        new BasicEntityIdParser(),
+                       Language::factory( 'es' ),
                        'enwiki'
                );
        }
@@ -82,4 +85,10 @@
                $this->assertEquals( 'enwiki', 
$wikibaseLuaEntityBindings->getGlobalSiteId() );
        }
 
+       public function testGetLanguageCode() {
+               $wikibaseLuaEntityBindings = 
$this->getWikibaseLuaEntityBindings();
+
+               $this->assertEquals( 'es', 
$wikibaseLuaEntityBindings->getLanguageCode() );
+       }
+
 }
diff --git a/docs/lua.wiki b/docs/lua.wiki
index 7cdb875..44cab7d 100644
--- a/docs/lua.wiki
+++ b/docs/lua.wiki
@@ -154,7 +154,7 @@
 === mw.wikibase.entity:getLabel ===
 <code>entity:getLabel()</code><br>
 <code>entity:getLabel( langCode )</code><br>
-Returns the label of the entity in the language given as <code>langCode</code> 
or in the Wiki's content language. See also 
[[#mw.wikibase.entity:getLabelWithLang|<code>mw.wikibase.entity:getLabelWithLang</code>]].
+Returns the label of the entity in the language given as <code>langCode</code> 
or in the Wiki's content language (on monolingual wikis) or the user's language 
(on multilingual wikis). See also 
[[#mw.wikibase.entity:getLabelWithLang|<code>mw.wikibase.entity:getLabelWithLang</code>]].
 
 An example call might look like this:
 <source lang="lua">
@@ -164,7 +164,7 @@
 === mw.wikibase.entity:getDescription ===
 <code>entity:getDescription()</code><br>
 <code>entity:getDescription( langCode )</code><br>
-Returns the description of the entity in the language given as 
<code>langCode</code> or in the Wiki's content language. See also 
[[#mw.wikibase.entity:getDescriptionWithLang|<code>mw.wikibase.entity:getDescriptionWithLang</code>]].
+Returns the description of the entity in the language given as 
<code>langCode</code> or in the Wiki's content language (on monolingual wikis) 
or the user's language (on multilingual wikis). See also 
[[#mw.wikibase.entity:getDescriptionWithLang|<code>mw.wikibase.entity:getDescriptionWithLang</code>]].
 
 An example call might look like this:
 <source lang="lua">

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

Gerrit-MessageType: merged
Gerrit-Change-Id: Idbbbf1cbfa1e10bdbc6c6bec1e27df19f30b2ab1
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Hoo man <h...@online.de>
Gerrit-Reviewer: Addshore <addshorew...@gmail.com>
Gerrit-Reviewer: Aude <aude.w...@gmail.com>
Gerrit-Reviewer: Daniel Kinzler <daniel.kinz...@wikimedia.de>
Gerrit-Reviewer: Hoo man <h...@online.de>
Gerrit-Reviewer: Jackmcbarn <jackmcb...@gmail.com>
Gerrit-Reviewer: Jonas Kress (WMDE) <jonas.kr...@wikimedia.de>
Gerrit-Reviewer: Ladsgroup <ladsgr...@gmail.com>
Gerrit-Reviewer: Lucie Kaffee <lucie.kaf...@wikimedia.de>
Gerrit-Reviewer: Thiemo Mättig (WMDE) <thiemo.maet...@wikimedia.de>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to