Page MenuHomePhabricator

Data access in user language doesn't obey the uselang get parameter
Closed, ResolvedPublic

Description

There is a problem that we had not noticed before: T140792.

mw.wikibase.label() takes into account the user's default language, and does not change language when ?uselang=xx is added to the URL. This is
I see two possible solutions:

  1. change the behavior of mw.wikibase.label() so that it takes into account ?uselang
  2. provide a Lua function that retrieves the user's language using the same criteria as mw.wikibase.label() so that we can adapt Lua modules to fix the ?uselang= issue locally.

Apparently ParserOptions::getUser()->getOption( 'language' ) doesn't provide the right language here, only ParserOptions::getUserLang() does. We use the former as an optimization in Scribunto_LuaWikibaseLibrary::getLanguage and Scribunto_LuaWikibaseEntityLibrary::getLanguage to only split the parser cache when actually needed.

As far as I see, we only call getLanguage when a Lua function is called anyway, so this hack probably doesn't save us much, so I suggest dropping it.

Event Timeline

hoo added subscribers: Raymond, Geagea, Jarekt, Zppix.

Merged the other task into this one, as this has more technical details.

Change 305439 had a related patch set uploaded (by Hoo man):
Don't abuse ParserOptions::getUser()->getOption( 'language' ) to get the user lang

https://gerrit.wikimedia.org/r/305439

Change 305439 merged by jenkins-bot:
Don't abuse ParserOptions::getUser()->getOption( 'language' ) to get the user lang

https://gerrit.wikimedia.org/r/305439

hoo moved this task from Review to Done on the Wikidata-Sprint-2016-08-16 board.
hoo removed a project: Patch-For-Review.

It is still not working right. I just set my preferred language to Polish and executed lua code with

  • mw.message.new( "lang" ):plain()
  • mw.message.getDefaultLanguage():getCode()

both returned "en" instead of "pl". At the same time call to message "{{int:lang}}" without LUA returns correctly "pl".

It is still not working right. I just set my preferred language to Polish and executed lua code with

  • mw.message.new( "lang" ):plain()
  • mw.message.getDefaultLanguage():getCode()

both returned "en" instead of "pl". At the same time call to message "{{int:lang}}" without LUA returns correctly "pl".

mw.message.* is not part of Wikibase, thus not affected by this. The changes mentioned here only affect the functionality to access data from the Wikibase repository (Wikidata) (mw.wikibase.*).