User:Ale jrb/Scripts/csdcheck.js: Difference between revisions

Content deleted Content added
Ale jrb (talk | contribs)
m ..
Ale jrb (talk | contribs)
m .
Line 3:
// CSD thing
if ((wgAction == 'delete') && (csdCheckEnable == true)) {
(function runCsd() {
var list = document.getElementById('wpDeleteReasonList');
var td = document.createElement('td');
td.setAttribute('id', 'csdCheck');
document.getElementById('wpReason').parentNode.appendChild(td);
document.getElementById('csdCheck').innerHTML = 'Checking for CSD tags...';
ajaxPageContent(wgPageName);
function ajaxDone(content) {
// reasons_regex taken from existing sysop script, because it works well. :)
var reasons_regex = {
'G10': // copied from [[User:Ilmari Karonen]]'s script, covers more bases than the others since it's more important (this script should blank the summary in _all_ cases where the other script does
/\{\{\s*(msg:\s*)?(template:\s*)?(db-a(p|tk)?|((csd|db)[-:])?(a6|attack(pages?|template)?|g10))\s*[|}]/i,
// other regexes are simpler and cover probably 99% of actual tags.
'G1': /\{\{\s*(db-|csd[-:])?(nonsense|ns|g1)\s*\}\}/i,
'G2': /\{\{\s*(db-|csd[-:])?(test|g2)\s*\}\}/i,
'G3': /\{\{\s*(db-|csd[-:])?(vandalism|vandal|vand|g3)\s*\}\}/i,
'G4': /\{\{\s*((db-|csd[-:])?(repost|g4)|deleteagain)\s*\}\}/i,
'G5': /\{\{\s*(db-|csd[-:])?(banned|ban|g5)\s*\}\}/i,
'G6': /\{\{\s*(db-|csd[-:])?(maintenance|move|histmerge|g6)\s*\}\}/i, // db-move and db-histmerge should be covered elsewhere if possible
'G7': /\{\{\s*(db-|csd[-:])?(author|blanked|g7)\s*\}\}/i,
'G8': /\{\{\s*(db-|csd[-:])?(talk|g8|redirnone|r1)\s*\}\}/i,
// G9 is for office, there is no tag.
// G10 is covered above
'G11': /\{\{\s*(db-|csd[-:])?(spam|ad|advert|g11)\s*\}\}/i,
'G12': /\{\{\s*(db-|csd[-:])?(copyvio|cv|cvio|g12|a8)\s*(\}\}|\|)/i,
'A1': /\{\{\s*(db-|csd[-:])?((no)?context|a1)\s*\}\}/i,
'A2': /\{\{\s*(db-|csd[-:])?(foreign|a2)\s*\}\}/i,
'A3': /\{\{\s*(db-|csd[-:])?((no)?content|a3|contact|a4)\s*\}\}/i,
// A4 = A3
'A5': /\{\{\s*(db-|csd[-:])?(transwiki|a5)\s*\}\}/i,
// A6 = G10
'A7 (bio)': /\{\{\s*(nn-|db-|csd[-:])?(a7|notability|bio|person)\s*\}\}/i,
'A7 (web)': /\{\{\s*(nn-|db-|csd[-:])?(web(site)?|inter(net|tubes))\s*\}\}/i,
'A7 (group)': /\{\{\s*(db-|csd[-:]|nn-)?(band|club|music|inc|corp|comp(any)?)\s*\}\}/i,
// TODO separate for music/band?
// A8 = G12
'A9': /\{\{\s*(db-|csd[-:]|nn-)?(a9|album)\s*\}\}/i,
'C1': /(\{\{\s*(db-|csd[-:])?(catempty|emptycat|c1)\s*\}\}|empty category)/i,
'U1': /\{\{\s*(db-|csd[-:])?(userreq|u1|user)\s*\}\}/i,
'I2': /\{\{\s*(db-|csd[-:])?(noimage|i2)\s*\}\}/i,
// no point in including the other image categories here, this will only work
// when deleting a description page with no image
// R1 = G8
'R2': /\{\{\s*(db-|csd[-:])?(rediruser|r2)\s*\}\}/i,
'R3': /\{\{\s*(db-|csd[-:])?(redirtypo|r3)\s*\}\}/i,
'dummy': /this will never be reached, it is there to allow every entry above to end in a comma/
}
for (var category in reasons_regex) {
if (reasons_regex[category].test(content)) {
var option = findCSD(category);
list.selectedIndex = option.index;
break;
}
}
ajaxPageContent(wgPageName);
document.getElementById('csdCheck').parentNode.removeChild(document.getElementById('csdCheck'));
function findCSD(s) { // s e.g. "U1", "G10"
for(var i=0;i<list.options.length;i++) {
var o=list.options[i];
if (o.text.indexOf("CSD "+s+":") == 0) return o;
if (o.text.indexOf(s+":") == 0) return o;
//TODO fine-tuning for A7 and G6
}
}
 
}
function ajaxPageContent(page) {
var page_request = false;
if (window.XMLHttpRequest)
function ajaxDone(content) {
page_request = new XMLHttpRequest();
// reasons_regex taken from existing sysop script, because it works well. :)
else if (window.ActiveXObject){
tryvar reasons_regex = {
'G10': // copied from [[User:Ilmari Karonen]]'s script, covers more bases than the others since it's more important (this script should blank the summary in _all_ cases where the other script does
page_request = new ActiveXObject("Msxml2.XMLHTTP");
/\{\{\s*(msg:\s*)?(template:\s*)?(db-a(p|tk)?|((csd|db)[-:])?(a6|attack(pages?|template)?|g10))\s*[|}]/i,
}
// other regexes are simpler and cover probably 99% of actual tags.
catch (e){
'G1': /\{\{\s*(db-|csd[-:])?(nonsense|ns|g1)\s*\}\}/i,
try{
'G2': /\{\{\s*(db-|csd[-:])?(test|g2)\s*\}\}/i,
page_request = new ActiveXObject("Microsoft.XMLHTTP");
'G3': /\{\{\s*(db-|csd[-:])?(vandalism|vandal|vand|g3)\s*\}\}/i,
'G4': /\{\{\s*((db-|csd[-:])?(repost|g4)|deleteagain)\s*\}\}/i,
'G5': /\{\{\s*(db-|csd[-:])?(banned|ban|g5)\s*\}\}/i,
'G6': /\{\{\s*(db-|csd[-:])?(maintenance|move|histmerge|g6)\s*\}\}/i, // db-move and db-histmerge should be covered elsewhere if possible
'G7': /\{\{\s*(db-|csd[-:])?(author|blanked|g7)\s*\}\}/i,
'G8': /\{\{\s*(db-|csd[-:])?(talk|g8|redirnone|r1)\s*\}\}/i,
// G9 is for office, there is no tag.
// G10 is covered above
'G11': /\{\{\s*(db-|csd[-:])?(spam|ad|advert|g11)\s*\}\}/i,
'G12': /\{\{\s*(db-|csd[-:])?(copyvio|cv|cvio|g12|a8)\s*(\}\}|\|)/i,
'A1': /\{\{\s*(db-|csd[-:])?((no)?context|a1)\s*\}\}/i,
'A2': /\{\{\s*(db-|csd[-:])?(foreign|a2)\s*\}\}/i,
'A3': /\{\{\s*(db-|csd[-:])?((no)?content|a3|contact|a4)\s*\}\}/i,
// A4 = A3
'A5': /\{\{\s*(db-|csd[-:])?(transwiki|a5)\s*\}\}/i,
// A6 = G10
'A7 (bio)': /\{\{\s*(nn-|db-|csd[-:])?(a7|notability|bio|person)\s*\}\}/i,
'A7 (web)': /\{\{\s*(nn-|db-|csd[-:])?(web(site)?|inter(net|tubes))\s*\}\}/i,
'A7 (group)': /\{\{\s*(db-|csd[-:]|nn-)?(band|club|music|inc|corp|comp(any)?)\s*\}\}/i,
// TODO separate for music/band?
// A8 = G12
'A9': /\{\{\s*(db-|csd[-:]|nn-)?(a9|album)\s*\}\}/i,
'C1': /(\{\{\s*(db-|csd[-:])?(catempty|emptycat|c1)\s*\}\}|empty category)/i,
'U1': /\{\{\s*(db-|csd[-:])?(userreq|u1|user)\s*\}\}/i,
'I2': /\{\{\s*(db-|csd[-:])?(noimage|i2)\s*\}\}/i,
// no point in including the other image categories here, this will only work
// when deleting a description page with no image
// R1 = G8
'R2': /\{\{\s*(db-|csd[-:])?(rediruser|r2)\s*\}\}/i,
'R3': /\{\{\s*(db-|csd[-:])?(redirtypo|r3)\s*\}\}/i,
'dummy': /this will never be reached, it is there to allow every entry above to end in a comma/
}
for (var category in reasons_regex) {
if (reasons_regex[category].test(content)) {
var option = findCSD(category);
list.selectedIndex = option.index;
break;
}
catch (e){}
}
}
document.getElementById('csdCheck').parentNode.removeChild(document.getElementById('csdCheck'));
else
{
function findCSD(s) { // s e.g. "U1", "G10"
return false;
for(var i=0;i<list.options.length;i++) {
var o=list.options[i];
if (o.text.indexOf("CSD "+s+":") == 0) return o;
if (o.text.indexOf(s+":") == 0) return o;
//TODO fine-tuning for A7 and G6
}
}
}
function ajaxPageContent(page) {
var url = wgServer + '/w/api.php';
var page_request = false;
url = url + '?action=query&prop=revisions&titles='+page+'&rvlimit=1&rvprop=content&format=txtfm'
if (window.XMLHttpRequest)
page_request.onreadystatechange = function() {
if ( page_request.readyState == 4new XMLHttpRequest() {;
else if (page_requestwindow.status == 200ActiveXObject){ {
try {
var page_content = page_request.responseText;
page_request = new ActiveXObject("Msxml2.XMLHTTP");
var pos = page_content.indexOf('[*] =&gt;');
}
page_content = page_content.substr(pos, 250);
catch (e){
try{
ajaxDone(page_content);
page_request = new ActiveXObject("Microsoft.XMLHTTP");
} else {
}
document.getElementById('csdCheck').innerHTML = 'AJAX request failed.';
returncatch false;(e){}
}
}
else
{
return false;
}
var url = wgServer + '/w/api.php';
url = url + '?action=query&prop=revisions&titles='+page+'&rvlimit=1&rvprop=content&format=txtfm'
page_request.onreadystatechange = function() {
if (page_request.readyState == 4) {
if (page_request.status == 200) {
var page_content = page_request.responseText;
var pos = page_content.indexOf('[*] =&gt;');
page_content = page_content.substr(pos, 250);
ajaxDone(page_content);
} else {
document.getElementById('csdCheck').innerHTML = 'AJAX request failed.';
return false;
}
}
}
//page_request.overrideMimeType('text/xml');
page_request.open('GET', url, true);
page_request.send(null);
}
});
//page_request.overrideMimeType('text/xml');
page_request.open('GET', url, true);
page_request.send(null);
}
}
hookEvent('load', runCsd);
}