More actions
m
keep options in obj instead of vars
(undo last changes - you can use [https://url text] for links (parse() isn't meant to have full wikitext support, just basics)) |
m (keep options in obj instead of vars) |
||
Line 680: | Line 680: | ||
* @param name The name of the script the messages are for. | * @param name The name of the script the messages are for. | ||
* @param res The JSON string. | * @param res The JSON string. | ||
* @param | * @param options Options set by the loading script. | ||
* | * | ||
* @return The resulting i18n object. | * @return The resulting i18n object. | ||
*/ | */ | ||
function parseMessagesToObject(name, res, | function parseMessagesToObject(name, res, options) { | ||
var json = {}, | var json = {}, | ||
obj, | obj, | ||
Line 708: | Line 708: | ||
cache[name] = obj; | cache[name] = obj; | ||
if (typeof cacheVersion === 'number') { | if (typeof options.cacheVersion === 'number') { | ||
saveToCache(name, json, cacheVersion); | saveToCache(name, json, options.cacheVersion); | ||
} | } | ||
Line 743: | Line 743: | ||
* used to get messages from | * used to get messages from | ||
* https://dev.fandom.com/wiki/MediaWiki:Custom-name/i18n.json. | * https://dev.fandom.com/wiki/MediaWiki:Custom-name/i18n.json. | ||
* @param options Options | * @param options Options set by the loading script: | ||
* cacheVersion: Minimum cache version requested by the loading script. | * cacheVersion: Minimum cache version requested by the loading script. | ||
* noCache: Never load i18n from cache (not recommended for general use). | * noCache: Never load i18n from cache (not recommended for general use). | ||
Line 750: | Line 750: | ||
*/ | */ | ||
function loadMessages(name, options) { | function loadMessages(name, options) { | ||
var deferred = $.Deferred(), | var deferred = $.Deferred(), | ||
customSource = name.match(/^u:(?:([a-z-]+)\.)?([a-z0-9-]+):/), | customSource = name.match(/^u:(?:([a-z-]+)\.)?([a-z0-9-]+):/), | ||
apiEndpoint = 'https://dev.fandom.com/api.php', | apiEndpoint = 'https://dev.fandom.com/api.php', | ||
page = 'MediaWiki:Custom-' + name + '/i18n.json', | page = 'MediaWiki:Custom-' + name + '/i18n.json', | ||
params; | params; | ||
options = options || {}; | |||
options.cacheVersion = Number(options.cacheVersion) || 0; | |||
options.useCache = (options.noCache || conf.debug) !== true; | |||
// if using the special 'qqx' language code, there's no need to load | // if using the special 'qqx' language code, there's no need to load | ||
Line 766: | Line 766: | ||
} | } | ||
if (useCache) { | if (options.useCache) { | ||
loadFromCache(name, cacheVersion); | loadFromCache(name, options.cacheVersion); | ||
if (cache[name]) { | if (cache[name]) { | ||
Line 814: | Line 814: | ||
} | } | ||
deferred.resolve(parseMessagesToObject(name, res, | deferred.resolve(parseMessagesToObject(name, res, options)); | ||
}); | }); | ||
}); | }); |