function escapeRegEx(string) {
return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // $& means the whole matched string
}
whitelist = ['a+', 'AI ', 'a.k.a.', 'a^', 'aka', 'BBC', 'BTS group', 'c.', 'cDNA', 'dBase', 'dsDNA', 'DVD', 'e^', 'eLearning', 'gTLD', 'iMac ', 'iOS', 'iPad', 'iPhone', 'iTunes', 'macOS', 'mRNA', 'microRNA', 'OECD', 'pH-dependent', 'pH ', 'rRNA', 'tRNA', 'TV', 'x86', 'xBase', 'β']
sdchar = oldText.replace(/[\s\S]*\{\{ *[Ss]hort description *\| *(?:1\=)?(.)[\s\S]*/, '$1') // Get first letter of SD
sdcharUpper = sdchar.toUpperCase()
shortdesc = oldText.replace(/[\s\S]*\{\{ *[Ss]hort description *\| *(?:1\=)?([^\}]+)[\s\S]*/, '$1') // Get SD
if (shortdesc == 'none' || sdcharUpper == sdchar || oldText.match(/\{\{ *[Ss]hort description *\|/) === null) {
return {text: false} // skip if none, no change, or no SD
}
var whitelistLength = whitelist.length;
for (var i = 0; i < whitelistLength; i++) {
if (shortdesc.match(new RegExp('^'+escapeRegEx(whitelist[i]), 'i')) != null) {
return {text: false} // skip if begins with whitelisted word
}
}
if (shortdesc == 'wikimedia list article' || shortdesc == 'wikipedia list article' || shortdesc == 'list' || shortdesc == 'list article' ) { // Bad SD, so convert to none
oldText = oldText.replace(new RegExp('([\\s\\S]*?)(\\n*)\\{\\{ *[Ss]hort description *\\| *'+escapeRegEx(shortdesc)+' *\\}\\}\\n*'), '{{Short description|None}}\n$1\n') // None SD, move SD to top
oldText = oldText.replace(/([\s\S]*?\n*\{\{ *[Ss]hort description *\|None\}\})\n*/, '$1\n') // fix newline issue
summ = 'Changing short description "'+shortdesc+'" to "None" per [[WP:SDNONE]] (via [[de:Benutzer:Schnark/js/bandersnatch|Bandersnatch]])'
return {text: oldText, bot: true, summary: summ};
}
shortdescUpper = shortdesc.replace(new RegExp(sdchar), sdcharUpper)
oldText = oldText.replace(new RegExp('([\\s\\S]*?)(\\n*)\\{\\{ *[Ss]hort description *\\| *'+escapeRegEx(shortdesc)+' *\\}\\}\\n*'), '{{Short description|'+shortdescUpper+'}}\n$1\n') // Upper SD, move SD to top
oldText = oldText.replace(new RegExp('([\\s\\S]*?\\n*\\{\\{ *short description *\\| *'+escapeRegEx(shortdesc)+' *\\}\\})\\n{2,}', 'i'), '$1\n') // Fix multiple newlines after SD issue
summ = 'Capitalising short description "'+shortdesc+'" per [[WP:SDFORMAT]] (via [[de:Benutzer:Schnark/js/bandersnatch|Bandersnatch]])'
return {text: oldText, bot: true, summary: summ};