Page MenuHomePhabricator

Avoid usage of global state in LanguageConverter
Closed, DuplicatePublic

Description

LanguageConverter makes frequent use of global variables, which can be problematic during initialization, especially for $wgUser (see T235360).

Configuration variables should be injected instead, via LanguageConverterFactory (T226833), using a ServiceOptions object:

  • $wgDisableLangConversion
  • $wgDisableTitleConversion
  • $wgLanguageConverterCacheType
  • $wgDisabledVariants
  • $wgDefaultLanguageVariant

Variables that depend on the request should be replaced by method parameters. For backwards compatibility, the parameters should initially be optional. Once all known callers have been updated, calling the respective methods without the new parameters should trigger a deprecation warning. In a later release, the parameters should become mandatory. This applies to:

  • $wgRequest in getURLVariant(), getHeaderVariant(), findVariantLink()
  • $wgUser in getPreferredVariant(), getUserVariant(),

TODO: consider whether the getXxxVariant() methods should be extracted into a separate service, along with getVariants(), getVariantFallback(), validateVariant(), and findVariantLink(). Seems tempting, but it's not immediately obvious whether it would be possible without introducing a cyclic dependency.

Event Timeline

Assuming this task is about MediaWiki-Language-converter, hence adding project tag so others can find this task when searching for tasks under that project.

Change 735676 had a related patch set uploaded (by Zabe; author: Zabe):

[mediawiki/core@master] Inject services into LanguageConverter

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

Change 735676 abandoned by Zabe:

[mediawiki/core@master] Inject services into LanguageConverter

Reason:

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