Page MenuHomePhabricator

Message class should use appropiate default language based on request context
Closed, ResolvedPublic

Description

For most typical MediaWiki contexts (e.g. index.php, page views) the default languages for messages is the user language.

The Message class currently determines this via $wgLang (created in Setup.php) -> StubUserLang -> RequestContext::getMain()->getLanguage() -> getUser()->getOption('language').

For ResourceLoader (designed to be cookieless) the user language is specified via lang= query parameter. Typically retrieved via ResourceLoaderContext->getLanguage(), which in turn received it from load.php/WebStart/$wgRequest.

Instead of it working nicely by default in index.php and requiring ResourceLoader code to manually specify inLanguage( $context->getLanguage() ) we should be able to have the Message class (indirectly) get the appropiate default user language for a given request.

Right now the pattern if inLanguage() isn't being used and load.php will end up indirectly unstubbing $wgUser via Message/wgLang/StubUserLang->getLanguage->getUser->getOption - which is possibly even the wrong language and causing cache pollution if a session is present as it ignores ResourceLoaderContext.

In practice requests from sessioned users tend to be in their own preferred user language (unless they manually generate a different url), but this still needs fixing.

Details

Related Gerrit Patches:

Event Timeline

Krinkle created this task.Feb 24 2016, 1:22 AM
Restricted Application added subscribers: StudiesWorld, Aklapper. · View Herald TranscriptFeb 24 2016, 1:22 AM
Anomie added a subscriber: Anomie.EditedFeb 24 2016, 2:04 PM

The solution, if we really do want to have the default behavior of Message vary based on the entry point, would be for the load.php entry point to redefine $wgLang after WebStart.php returns.

The solution, if we really do want to have the default behavior of Message vary based on the entry point, would be for the load.php entry point to redefine $wgLang after WebStart.php returns.

I'm inclined to agree, though I'd like us to try and find a way that involves something instead of $wgLang. Something effectively the same but not a global variable. Probably RequestContext?

We'd have load.php call setLanguage(), and Message.php call getLanguage(). StubUserLang ($wgLang) is just a proxy for RequestContext::getMain()->getLanguage() anyway. So non-load.php behaviour would be the same as now, except without $wgLang and without StubUserLang.

Thoughts?

Krinkle claimed this task.Mar 1 2016, 12:00 AM
Krinkle triaged this task as Medium priority.
Krinkle moved this task from Inbox to Assigned on the MediaWiki-ResourceLoader board.

Change 274025 had a related patch set uploaded (by Krinkle):
Message: Use RequestContext instead of $wgLang

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

We should probably have load.php or ResourceLoader::respond() set both the RequestContext and $wgLang anyway. Is https://gerrit.wikimedia.org/r/274025 actually necessary to solve this task, or would setting both RequestContext and $wgLang solve this task so T129185 doesn't have to block T127233?

Change 274025 merged by jenkins-bot:
Message: Use RequestContext instead of $wgLang

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

Krinkle renamed this task from Let Message class use appropiate user language based on entry point to Message class should use appropiate default language based on request context.Mar 23 2016, 4:49 AM
Krinkle closed this task as Resolved.

@Krinkle changed the title from "Let Message class use appropiate user language based on entry point" to "Message class should use appropiate default language based on request context".
@Krinkle closed this task as "Resolved".

Well, yes, if you retitle the bug that way then it's resolved. But that retitling loses sight of the reason this bug was opened in the first place: the load.php entry point still needs to actually set an appropriate language somewhere.

Change 279122 had a related patch set uploaded (by Anomie):
Have load.php use the RL language, not the user's preference language

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