User:MohandesWiki/common.js

function doMassDelete { document.getElementById("wpMassDeleteSubmit").disabled = true; var articles = document.getElementById("wpMassDeletePages").value.split("\n"); if(articles.length == 0) return; var wpMassDeleteReasons = document.getElementById("wpMassDeleteReasons").value, wpMassDeleteReason = document.getElementById("wpMassDeleteReason").value, deleted = 0, failed = [], error = []; for(i=0;i 0) { // FIXME: Sajax is deprecated, use jQuery.ajax or mediawiki.api instead. var req = sajax_init_object; req.open("GET", mw.config.get('wgScriptPath') + "/api.php?format=json&action=query&prop=info&intoken=delete&titles=" + encodeURIComponent(article), false); req.send(null); var response = eval("(" + req.responseText + ")").query.pages; for(var index in response) { var info = response[index]; var deletetoken = info.deletetoken; var postdata = "format=json" + "&action=delete" + "&title=" + encodeURIComponent(article) + "&reason=" + encodeURIComponent(wpMassDeleteReasons == "other" ? wpMassDeleteReason : wpMassDeleteReasons + (wpMassDeleteReason ? " (" + wpMassDeleteReason + ")" : "")) + "&token=" + encodeURIComponent(deletetoken); // FIXME: Sajax is deprecated, use jQuery.ajax or mediawiki.api instead. var req = sajax_init_object; req.open("POST", mw.config.get('wgScriptPath') + "/api.php", false); req.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); req.setRequestHeader("Content-length", postdata.length); req.send(postdata); if(eval("(" + req.responseText + ")")['delete']) { //If deleted, update the deleted count and the button. deleted++; document.getElementById("wpMassDeleteSubmit").value = "(" + deleted + ")"; } else { //If not deleted, add the title to the "failed" array and a description of the error to the "error" array. failed.push(article); error.push(eval("(" + req.responseText + ")").error.info); }           }        }        if(!articles[i+1]) { document.getElementById("wpMassDeleteSubmit").value = "Done (" + deleted + ")"; if(failed.length > 0) { var linkedList = ""; for(x=0; x" + failed[x] + ": " + error[x] + ""; //Links the titles in the "failed" array }               document.getElementById("wpMassDeleteFailedContainer").innerHTML += ' Failed deletions:' + linkedList + ''; }       }    } } function massdeleteform { var bodyContent = (mw.config.get('skin') == "cologneblue" ? "article" : "bodyContent"); document.getElementsByTagName("h1")[0].textContent = "Mass delete pages"; document.title = "Mass delete pages"; document.getElementById(bodyContent).innerHTML = 'From Wikimedia Incubator '       + '' + 'Welcome to the mass deletion form, the page which you can use to mass delete a couple of pages. If you are deleting multiple pages that were created by one user, please use Special:Nuke! If you are deleting more than 10 pages, please flag yourself as a bot first to avoid flooding Special:RecentChanges, thank you! Please add the list of pages you would like to delete in the text box below, listing one page in one line. Thank you for using this tool!' + ' '       + ' '            + 'Pages to delete (one on each line, please): '               + ' ' + ' '               + '  Common reasons: ' + ' <select id="wpMassDeleteReasons">' + '<optgroup label="Other reason">' + ' Other reason ' + ' '                       + '<optgroup label="Criteria for speedy deletion">' + '<optgroup label="Common delete reasons">' + '<option value="Redirect to non-existing page">Redirect to non-existing page ' + '<option value="Author request">Author request ' + '<option value="Vandalism">Vandalism ' + '<option value="Copyright violation">Copyright violation ' + '<option value="Talkpage of a deleted page">Talkpage of a deleted page ' + '<option value="Unneeded redirect">Unneeded redirect ' + ' '                           + '<optgroup label="Maintenance">' + '<option value="Process deletion">Process deletion ' + '<option value="Invalid ISO 639 code">Invalid ISO 639 code ' + '<option value="Redirect to a correctly prefixed page">Redirect to a correctly prefixed page ' + '<option value="Correctly prefixed page exists">Correctly prefixed page exists ' + ' '                       + ' '                    + '  '            + '  Other/additional reason: ' + ' <input type="text" id="wpMassDeleteReason" name="wpMassDeleteReason" maxlength="255" /> ' + ' <input type="button" id="wpMassDeleteSubmit" name="wpMassDeleteSubmit" value="Delete" onclick="doMassDelete" /> ' + ' ';   document.getElementById("wpMassDeleteReasons").onchange = function { var maxlength = (document.getElementById("wpMassDeleteReasons").value == "other" ? 255 : 252-document.getElementById("wpMassDeleteReasons").value.length); //It's 252 because of the three characters (" ") in addition to the selected summary. document.getElementById("wpMassDeleteReason").setAttribute("maxlength", maxlength); } } if(mw.config.get('wgNamespaceNumber') == -1 &&	$.inArray(mw.config.get('wgPageName'), ["Special:Massdelete", "Special:MassDelete"]) !== -1 &&	$.inArray('sysop', mw.config.get("wgUserGroups")) !== -1 ) { $(massdeleteform); }