jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/348998 )
Change subject: Fetch LanguageConverter status as part of wiki configuration. ...................................................................... Fetch LanguageConverter status as part of wiki configuration. Bug: T153341 Change-Id: I7440a51727d24260689e0dc1c4972decea3a7a67 --- M lib/config/MWParserEnvironment.js M lib/config/WikiConfig.js A lib/config/variants.json M lib/mw/ApiRequest.js 4 files changed, 267 insertions(+), 0 deletions(-) Approvals: jenkins-bot: Verified Arlolra: Looks good to me, approved diff --git a/lib/config/MWParserEnvironment.js b/lib/config/MWParserEnvironment.js index a8d15af..9b6286e 100644 --- a/lib/config/MWParserEnvironment.js +++ b/lib/config/MWParserEnvironment.js @@ -796,6 +796,18 @@ return this.conf.wiki.extContentModel.get(contentmodel); }; +/** + * @method + * + * Determine if LanguageConverter markup should be parsed on this page, + * based on the wiki configuration and the current page language. + * + * @return {Boolean} + */ +MWParserEnvironment.prototype.langConverterEnabled = function() { + var lang = this.page.pagelanguage || this.conf.wiki.lang || 'en'; + return this.conf.wiki.langConverterEnabled.has(lang); +}; if (typeof module === "object") { module.exports.MWParserEnvironment = MWParserEnvironment; diff --git a/lib/config/WikiConfig.js b/lib/config/WikiConfig.js index 58d76cb..559bb52 100644 --- a/lib/config/WikiConfig.js +++ b/lib/config/WikiConfig.js @@ -74,6 +74,14 @@ this.siteInfo.general.legaltitlechars = baseConfig.general.legaltitlechars; } + // Introduced in T153341 (core 1824778e, wmf/1.29.0-wmf.15) + var languagevariants = resultConf.languagevariants; + if (languagevariants === undefined) { + // Hard-coded list of variants and fallbacks, for mediawiki + // releases before 1.29 + languagevariants = require('./variants.json'); + } + // Was introduced in T46449 (core 1b64ddf0) var protocols = resultConf.protocols; if (protocols === undefined && mwApiVersion.compare('1.21.0') < 0) { @@ -563,6 +571,28 @@ // Function hooks on this wiki, indexed by their normalized form this.functionHooks = new Set(resultConf.functionhooks || []); + // Somewhat annoyingly, although LanguageConversion is turned on by + // default for all WMF wikis (ie, $wgDisableLangConversion = false, as + // reported by `general.langconversion` in siteinfo), but the + // -{ }- syntax is only parsed when the current *page language* + // has variants. We can't use the "UI language" (in siteinfo + // `general.lang`) and "UI variants" (in `general.fallback` and + // `general.variants`), because the *page language* could be quite + // different. Use the mechanism introduced in T153341 instead. + this.variants = new Map(); + this.langConverterEnabled = new Set(); + Object.keys(languagevariants).forEach(function(code) { + if (general.langconversion !== undefined) { + this.langConverterEnabled.add(code); + } + Object.keys(languagevariants[code]).forEach(function(v) { + this.variants.set(v, { + base: code, + fallbacks: languagevariants[code][v].fallbacks, + }); + }.bind(this)); + }.bind(this)); + // Match a wikitext line containing just whitespace, comments, and // sol transparent links and behavior switches. // Redirects should not contain any preceding non-whitespace chars. diff --git a/lib/config/variants.json b/lib/config/variants.json new file mode 100644 index 0000000..62973e4 --- /dev/null +++ b/lib/config/variants.json @@ -0,0 +1,224 @@ +{ + "gan": { + "gan": { + "fallbacks": [ + "gan-hans", + "gan-hant" + ] + }, + "gan-hans": { + "fallbacks": [ + "gan" + ] + }, + "gan-hant": { + "fallbacks": [ + "gan" + ] + } + }, + "iu": { + "ike-cans": { + "fallbacks": [ + "iu" + ] + }, + "ike-latn": { + "fallbacks": [ + "iu" + ] + }, + "iu": { + "fallbacks": [ + "ike-cans" + ] + } + }, + "kk": { + "kk": { + "fallbacks": [ + "kk-cyrl" + ] + }, + "kk-arab": { + "fallbacks": [ + "kk" + ] + }, + "kk-cn": { + "fallbacks": [ + "kk-arab" + ] + }, + "kk-cyrl": { + "fallbacks": [ + "kk" + ] + }, + "kk-kz": { + "fallbacks": [ + "kk-cyrl" + ] + }, + "kk-latn": { + "fallbacks": [ + "kk" + ] + }, + "kk-tr": { + "fallbacks": [ + "kk-latn" + ] + } + }, + "ku": { + "ku": { + "fallbacks": [ + "ku-latn" + ] + }, + "ku-arab": { + "fallbacks": [ + "ku-latn" + ] + }, + "ku-latn": { + "fallbacks": [ + "ku-arab" + ] + } + }, + "shi": { + "shi": { + "fallbacks": [ + "shi-tfng" + ] + }, + "shi-latn": { + "fallbacks": [ + "shi" + ] + }, + "shi-tfng": { + "fallbacks": [ + "shi" + ] + } + }, + "sr": { + "sr": { + "fallbacks": [ + "sr-ec" + ] + }, + "sr-ec": { + "fallbacks": [ + "sr" + ] + }, + "sr-el": { + "fallbacks": [ + "sr" + ] + } + }, + "tg": { + "tg": { + "fallbacks": [ + "tg" + ] + }, + "tg-latn": { + "fallbacks": [ + "tg" + ] + } + }, + "uz": { + "uz": { + "fallbacks": [ + "uz-latn" + ] + }, + "uz-cyrl": { + "fallbacks": [ + "uz" + ] + }, + "uz-latn": { + "fallbacks": [ + "uz" + ] + } + }, + "zh": { + "zh": { + "fallbacks": [ + "zh-hans", + "zh-hant", + "zh-cn", + "zh-tw", + "zh-hk", + "zh-sg", + "zh-mo", + "zh-my" + ] + }, + "zh-cn": { + "fallbacks": [ + "zh-hans", + "zh-sg", + "zh-my" + ] + }, + "zh-hans": { + "fallbacks": [ + "zh-cn", + "zh-sg", + "zh-my" + ] + }, + "zh-hant": { + "fallbacks": [ + "zh-tw", + "zh-hk", + "zh-mo" + ] + }, + "zh-hk": { + "fallbacks": [ + "zh-hant", + "zh-mo", + "zh-tw" + ] + }, + "zh-mo": { + "fallbacks": [ + "zh-hant", + "zh-hk", + "zh-tw" + ] + }, + "zh-my": { + "fallbacks": [ + "zh-hans", + "zh-sg", + "zh-cn" + ] + }, + "zh-sg": { + "fallbacks": [ + "zh-hans", + "zh-cn", + "zh-my" + ] + }, + "zh-tw": { + "fallbacks": [ + "zh-hant", + "zh-hk", + "zh-mo" + ] + } + } +} \ No newline at end of file diff --git a/lib/mw/ApiRequest.js b/lib/mw/ApiRequest.js index f0481ee..420b28b 100644 --- a/lib/mw/ApiRequest.js +++ b/lib/mw/ApiRequest.js @@ -895,6 +895,7 @@ 'general', 'interwikimap', 'languages', + 'languagevariants', // T153341 'protocols', 'specialpagealiases', 'defaultoptions', -- To view, visit https://gerrit.wikimedia.org/r/348998 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I7440a51727d24260689e0dc1c4972decea3a7a67 Gerrit-PatchSet: 6 Gerrit-Project: mediawiki/services/parsoid Gerrit-Branch: master Gerrit-Owner: C. Scott Ananian <canan...@wikimedia.org> Gerrit-Reviewer: Arlolra <abrea...@wikimedia.org> Gerrit-Reviewer: C. Scott Ananian <canan...@wikimedia.org> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits