Content deleted Content added
No edit summary |
m Fix requested on WP:IANB |
||
(8 intermediate revisions by 2 users not shown) | |||
Line 1:
// <nowiki>
/**
* Returns an array of objects representing the
*
* |parameter=value pairs. *
* Piped links, nested templates, nowiki tags and even HTML comments in parameter
* values are adequately accounted for.
*
*
* templates would also be found. But since the API call needed to achieve this
* makes the function asynchronous, you need to provide a callback function to
* execute upon completion. The function takes the result array as the argument.
*
* Usage: Can be executed from the browser console or within another script.
*
* @param {string} wikitext
*
* @param {(string[]|string)}
▲ * @param {boolean} [resolveRedirects] Also check for transclusions of redirects to the specified `template`?
* template page names. Need not necessarily be pages in template namespace,
* @param {function} callback Callback function to execute after processing of the redirect▼
* any page can be used. If no namespace is provided, it is assumed as Template:.
* templates. The result array is passed as a parameter to it. Compulsory if `resolveRedirects` is set true.▼
*
* @returns {Object[]} Returns only if `resolveRedirects` is set false▼
* @param {boolean} [resolveRedirects=false] Also check for transclusions of
* redirects of the specified `templates`?
*
▲ *
*
*
* @throws if (i) API call is unsuccessful (resolveRedirects mode only)
* (ii) The end of template is not found in the wikitext
* (iii) resolveRedirects is set true but no callback is provided
*
* ISSUES:
* 1. It is possible that a template usage found be entirely within a comment or
* nowiki tags. * 2.
* inside a comment, or vice-versa, will cause problems.
*
* Found any other bug? Report at [[User talk:SD0001]] or via email.
Line 104 ⟶ 125:
}
}
}
if (numUnclosed !== 0) {
console.error('
}
Line 117 ⟶ 137:
// swap out pipe in links with \1 control character
text = text.replace(/(\[\[[^\]]*?)\|(.*?\]\])/g, '$1\1$2');
var chunks = text.split('|');
Line 146 ⟶ 164:
if(resolveRedirects && callback === undefined) {
console.error('[parseTemplate] No callback function provided to execute after resolving of redirects');
}
templates.forEach(function (template, idx) {
if (template.indexOf(':') === -1) {
template = "Template:" + template;
Line 163 ⟶ 181:
"lhshow": "redirect",
"lhlimit": "max"
}
$(response).find('lh').each(function(idx,tag) {
var template_redir = $(tag).attr('title');
Line 174 ⟶ 192:
callback(result);
}
}).fail(function (response) {
console.error('[parseTemplate] API call for getting redirects to {{'
+ template + '}} failed');
});
}
Line 185 ⟶ 206:
window.parseTemplate = parseTemplate;
// </nowiki>
|