Skip to content

Commit

Permalink
Fetch LanguageConverter status as part of wiki configuration.
Browse files Browse the repository at this point in the history
Bug: T153341
Change-Id: I7440a51727d24260689e0dc1c4972decea3a7a67
  • Loading branch information
cscott authored and arlolra committed Apr 25, 2017
1 parent 80bf30d commit 12f60b3
Show file tree
Hide file tree
Showing 4 changed files with 267 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/config/MWParserEnvironment.js
Original file line number Diff line number Diff line change
Expand Up @@ -796,6 +796,18 @@ MWParserEnvironment.prototype.getContentHandler = function(forceContentModel) {
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;
Expand Down
30 changes: 30 additions & 0 deletions lib/config/WikiConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,14 @@ function WikiConfig(parsoidConfig, resultConf, prefix) {
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) {
Expand Down Expand Up @@ -563,6 +571,28 @@ function WikiConfig(parsoidConfig, resultConf, prefix) {
// 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.
Expand Down
224 changes: 224 additions & 0 deletions lib/config/variants.json
Original file line number Diff line number Diff line change
@@ -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"
]
}
}
}
1 change: 1 addition & 0 deletions lib/mw/ApiRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -895,6 +895,7 @@ var ConfigRequest = function(uri, env, proxy) {
'general',
'interwikimap',
'languages',
'languagevariants', // T153341
'protocols',
'specialpagealiases',
'defaultoptions',
Expand Down

0 comments on commit 12f60b3

Please sign in to comment.