MediaWiki:Gadget-libExtraUtil.js: Difference between revisions

Content deleted Content added
Version 2.1.1: parseTemplates: fix test for recursive templates
Drop polyfills per request
 
(4 intermediate revisions by 2 users not shown)
Line 5:
* | Please discuss changes on the talk page or on [[WT:Gadget]] before editing. |
* |_____________________________________________________________________________|
*
* ###############################################################################
* # #
* # This script has unit tests on its /testcases.js subpage. Please install #
* # the WikiUnit script [[User:Evad37/WikiUnit]] and run tests before saving. #
* # #
* ###############################################################################
*
* Imported from version 924857650 as of 14 November 2019 from [[User:Evad37/extra.js]]
Line 17 ⟶ 24:
// <nowiki>
 
window.extraJs = { version: '2.23.10' };
 
/* ========== Polyfills to support IE11 and Edge<14 ============================================= */
// Array.prototype.includes polyfill
if (!Array.prototype.includes) {
Array.prototype.includes = function(searchElement /*, fromIndex*/) {
return this.indexOf(searchElement) !== -1;
};
}
// String.prototype.includes polyfill, per https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/includes#Polyfill
if (!String.prototype.includes) {
String.prototype.includes = function(search, start) {
'use strict';
if (typeof start !== 'number') {
start = 0;
}
 
if (start + search.length > this.length) {
return false;
} else {
return this.indexOf(search, start) !== -1;
}
};
}
/* ============================================================================================== */
 
/**
Line 51 ⟶ 34:
*
* @param {string} code
* First paramaterparameter passed to failure callback function.
* @param {jQuery.jqXHR} jqxhr
* Second paramaterparameter passed to failure callback function.
* @return {string} Error message details, with in a format like
* "(API|HTTP) error: details"
Line 398 ⟶ 381:
var numUnclosed = 0;
 
// are we inside a comment, or between nowiki tags, or in a {{{parameter}}}?
var inComment = false;
var inNowiki = false;
var inParameter = false;
 
var startIdx, endIdx;
Line 406 ⟶ 390:
for (var i=0; i<n; i++) {
if ( !inComment && !inNowiki && !inParameter ) {
if (wikitext[i] === '{' && wikitext[i+1] === '{' && wikitext[i+2] === '{' && wikitext[i+3] !== '{') {
inParameter = true;
i += 2;
} else if (wikitext[i] === '{' && wikitext[i+1] === '{') {
if (numUnclosed === 0) {
startIdx = i+2;
Line 432 ⟶ 419:
}
 
} else { // we are in a comment or nowiki or {{{parameter}}}
if (wikitext[i] === '|') {
// swap out pipes with \1 character
Line 442 ⟶ 429:
inNowiki = false;
i += 8;
} else if (wikitext[i] === '}' && wikitext[i+1] === '}' && wikitext[i+2] === '}') {
inParameter = false;
i += 2;
}
}
Line 752 ⟶ 742:
}
// Mark any other list items with backlinks for manual review, using {{subst:void}}
var manual_review_regex = new RegExp(
'^(\\*+.*)(?:' + simple_regex_str + '|' +
simple_regex_str.replace(/([^\\])\(([^?])/g, "$1(?:$2") + // replace capturing groups with non-capturing groups
named_regex_str + ').*$', 'gm' );
'|' +
wikitext = wikitext.replace(manual_review_regex, '{{subst:void}}$&');
named_regex_str.replace(/([^\\])\(([^?])/g, "$1(?:$2") + // replace capturing groups with non-capturing groups
named_regex_str + ')(.*)$', 'gm' );
wikitext = wikitext.replace(manual_review_regex, '{{subst:void}}$&1{{subst:^|<strong>}}$2{{subst:^|</strong>}}$3');
 
// For all other links, replace with unlinked text