From: Jack Phoenix Date: Sun, 23 Jul 2017 13:35:09 +0000 (+0300) Subject: Add a hook into LanguageConverter#getPreferredVariant() to allow extensions to pull... X-Git-Tag: 1.31.0-rc.0~815^2 X-Git-Url: http://git.cyclocoop.org/%24image?a=commitdiff_plain;h=43da7fb8844a6d517460aaf68b64092d1ced2068;p=lhc%2Fweb%2Fwiklou.git Add a hook into LanguageConverter#getPreferredVariant() to allow extensions to pull the desired variant from cookies (or other such source) Example implementation using this hook: wikiHow's ChineseVariantSelector extension, installed on zh.wikihow.com, which uses cookies to store the preferred language variant, allowing anonymous users to change the language variant without registering/logging in. Change-Id: I5295a26578b45a8d51f2b7550938088fec18404f --- diff --git a/docs/hooks.txt b/docs/hooks.txt index 3ff3365549..c21ce8a004 100644 --- a/docs/hooks.txt +++ b/docs/hooks.txt @@ -1662,6 +1662,13 @@ $query: query options passed to Title::getInternalURL() 'GetIP': modify the ip of the current user (called only once). &$ip: string holding the ip as determined so far +'GetLangPreferredVariant': Called in LanguageConverter#getPreferredVariant() to + allow fetching the language variant code from cookies or other such + alternative storage. +&$req: language variant from the URL (string) or boolean false if no variant + was specified in the URL; the value of this variable comes from + LanguageConverter#getURLVariant() + 'GetLinkColours': modify the CSS class of an array of page links. $linkcolour_ids: array of prefixed DB keys of the pages linked to, indexed by page_id. diff --git a/languages/LanguageConverter.php b/languages/LanguageConverter.php index 6d0368c7a1..d9e64b4611 100644 --- a/languages/LanguageConverter.php +++ b/languages/LanguageConverter.php @@ -160,6 +160,8 @@ class LanguageConverter { $req = $this->getURLVariant(); + Hooks::run( 'GetLangPreferredVariant', [ &$req ] ); + if ( $wgUser->isSafeToLoad() && $wgUser->isLoggedIn() && !$req ) { $req = $this->getUserVariant(); } elseif ( !$req ) {