Page MenuHomePhabricator

Move WikibaseRepo UserLanguage to service container
Closed, ResolvedPublic

Description

The user interface language is not available in the service container, as far as I can tell, neither directly nor as part of some context source. I assume this is because service wiring is supposed to be independent of user configuration or individual request contexts. However, several other services in Wikibase Repository depend on the user language, so I don’t think we can make do without it yet. I suggest we add it to the service wiring file (based on $wgLang), but deprecate the accessor method in WikibaseRepo and create follow-up tasks to remove uses of this service.

Event Timeline

As far as I’m aware, the two main sources of the user language (assuming you don’t have access to an IContextSource where you can call getLanguage()) are global $wgLang and RequestContext::getMain()->getLanguage(). (Which ultimately amounts to the same thing – see StubUserLang::_newObject().) CirrusSearch’s SearchConfig.php puts it like this:

	/**
	 * Get user's language
	 * @return string User's language code
	 */
	public function getUserLanguage() {
		// I suppose using $wgLang would've been more evil than this, but
		// only marginally so. Find some real context to use here.
		return RequestContext::getMain()->getLanguage()->getCode();
	}

For our service wiring, I suggest we use $wgLang, which should be easier to mock in the unit test for this service wiring.

See also T218555: Provide access to WebRequest and associated information via a service object for some discussion of the user language (though it’s not the main focus of the discussion).

Change 676423 had a related patch set uploaded (by Itamar Givon; author: Itamar Givon):

[mediawiki/extensions/WikibaseCirrusSearch@master] Update calls to getUserLanguage

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

Change 676422 had a related patch set uploaded (by Itamar Givon; author: Itamar Givon):

[mediawiki/extensions/Wikibase@master] Move WikibaseRepo UserLanguage to service container

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

Change 676428 had a related patch set uploaded (by Itamar Givon; author: Itamar Givon):

[mediawiki/extensions/WikibaseLexeme@master] Update calls to getUserLanguage

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

Change 676432 had a related patch set uploaded (by Itamar Givon; author: Itamar Givon):

[mediawiki/extensions/WikibaseLexemeCirrusSearch@master] Update calls to getUserLanguage

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

Change 676433 had a related patch set uploaded (by Itamar Givon; author: Itamar Givon):

[mediawiki/extensions/WikibaseMediaInfo@master] Update calls to getUserLanguage

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

Change 676434 had a related patch set uploaded (by Itamar Givon; author: Itamar Givon):

[mediawiki/extensions/WikibaseQualityConstraints@master] Update calls to getUserLanguage

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

Change 677288 had a related patch set uploaded (by Itamar Givon; author: Itamar Givon):

[mediawiki/extensions/WikibaseLexeme@master] Pass down MediaWiki services

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

Change 676422 merged by jenkins-bot:

[mediawiki/extensions/Wikibase@master] Move WikibaseRepo UserLanguage to service container

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

Change 676428 merged by jenkins-bot:

[mediawiki/extensions/WikibaseLexeme@master] Update calls to getUserLanguage

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

Change 676423 merged by jenkins-bot:

[mediawiki/extensions/WikibaseCirrusSearch@master] Update calls to getUserLanguage

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

Change 676432 merged by jenkins-bot:

[mediawiki/extensions/WikibaseLexemeCirrusSearch@master] Update calls to getUserLanguage

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

Change 676434 merged by jenkins-bot:

[mediawiki/extensions/WikibaseQualityConstraints@master] Update calls to getUserLanguage

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

Change 677288 merged by jenkins-bot:

[mediawiki/extensions/WikibaseLexeme@master] Pass down MediaWiki services

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

Change 676433 merged by jenkins-bot:

[mediawiki/extensions/WikibaseMediaInfo@master] Update calls to getUserLanguage

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