C. Scott Ananian has uploaded a new change for review. ( 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, 42 insertions(+), 0 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/parsoid refs/changes/98/348998/1 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 9fe20ea..f216798 100644 --- a/lib/config/WikiConfig.js +++ b/lib/config/WikiConfig.js @@ -557,6 +557,34 @@ // 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. + var languagevariants = resultConf.languagevariants; + if (languagevariants === undefined) { + // Hard-coded list of variants and fallbacks, for mediawiki + // releases before 1.29 without T153341 + languagevariants = require('./variants.json'); + } + 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..7ef417a --- /dev/null +++ b/lib/config/variants.json @@ -0,0 +1 @@ +{"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"]}}} diff --git a/lib/mw/ApiRequest.js b/lib/mw/ApiRequest.js index ac43bf9..0465517 100644 --- a/lib/mw/ApiRequest.js +++ b/lib/mw/ApiRequest.js @@ -895,6 +895,7 @@ 'general', 'interwikimap', 'languages', + 'languagevariants', // T153341 'protocols', 'specialpagealiases', ]; -- To view, visit https://gerrit.wikimedia.org/r/348998 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I7440a51727d24260689e0dc1c4972decea3a7a67 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/services/parsoid Gerrit-Branch: master Gerrit-Owner: C. Scott Ananian <canan...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits