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 000..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"
+ ]
+ }
+ },
+