User:Animum/massdelete.js
Appearance
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
![]() | Documentation for this user script can be added at User:Animum/massdelete. |
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 = new Array(), error = new Array();
for(i=0;i<articles.length;i++) {
var article = articles[i];
if(article.length > 0) {
var req = sajax_init_object();
req.open("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);
var req = sajax_init_object();
req.open("POST", 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.length; x++) {
linkedList += "<li><a href=\"/wiki/" + encodeURIComponent(failed[x]).replace("%2F", "/") + "\">" + failed[x] + "</a>: " + error[x] + "</li>"; //Links the titles in the "failed" array
}
document.getElementById("wpMassDeleteFailedContainer").innerHTML += '<br /><b>Failed deletions:</b> <ul>' + linkedList + '</ul>';
}
}
}
}
function massdeleteform() {
var bodyContent = (skin == "cologneblue" ? "article" : "bodyContent");
document.getElementsByTagName("h1")[0].textContent = "Animum's mass-deletion tool";
document.title = "Animum's mass-deletion tool - Wikipedia, the free encyclopedia";
document.getElementById(bodyContent).innerHTML = '<h3 id="siteSub">From Wikipedia, the free encyclopedia</h3><br /><br />'
+ '<form id="wpMassDelete" name="wpMassDelete">'
+ '<b>If you abuse this tool, it\'s <i>your</i> fault, not mine.</b>'
+ '<div id="wpMassDeleteFailedContainer"></div>'
+ '<br /><br />'
+ 'Pages to delete (one on each line, please):<br />'
+ '<textarea tabindex="1" accesskey="," name="wpMassDeletePages" id="wpMassDeletePages" rows="10" cols="80"></textarea>'
+ '<br /><br /><table style="background-color:transparent">'
+ '<tr><td>Common reasons:</td>'
+ '<td><select id="wpMassDeleteReasons">'
+ '<optgroup label="Other reason">'
+ '<option value="other">Other reason</option>'
+ '</optgroup>'
+ '<optgroup label="Criteria for speedy deletion">'
+ '<optgroup label="General criteria">'
+ '<option value="[[Wikipedia:Criteria for speedy deletion#G1|G1]]: [[Wikipedia:Patent nonsense|Patent nonsense]]">G1: Patent nonsense</option>'
+ '<option value="[[Wikipedia:Criteria for speedy deletion#G2|G2]]: Test page">G2: Test page</option>'
+ '<option value="[[Wikipedia:Criteria for speedy deletion#G3|G3]]: Pure [[Wikipedia:Vandalism|vandalism]], including the redirects created from the cleanup of page-move vandalism">G3: Vandalism</option>'
+ '<option value="[[Wikipedia:Criteria for speedy deletion#G4|G4]]: Recreation of material previously deleted pursuant to an XfD">G4: Repost</option>'
+ '<option value="[[Wikipedia:Criteria for speedy deletion#G5|G5]]: Page created by a [[Wikipedia:List of banned users|banned user]]">G5: Banned</option>'
+ '<option value="[[Wikipedia:Criteria for speedy deletion#G6|G6]]: Non-controversial maintenance, including deleting a page to merge histories or making way for an uncontroversial move">G6: Maintenance</option>'
+ '<option value="[[Wikipedia:Criteria for speedy deletion#G7|G7]]: Only one editor has made significant edits to this page, and he or she has blanked it or requested its deletion.">G7: Author</option>'
+ '<option value="[[Wikipedia:Criteria for speedy deletion#G8|G8]]: Talk page whose corresponding article does not exist">G8: Orphaned talk page</option>'
+ '<option value="[[Wikipedia:Criteria for speedy deletion#G10|G10]]: [[Wikipedia:Attack page|Attack page]]">G10: Attack page</option>'
+ '<option value="[[Wikipedia:Criteria for speedy deletion#G11|G11]]: [[Wikipedia:Spam|Blatant advertising]]">G11: Advertising</option>'
+ '<option value="[[Wikipedia:Criteria for speedy deletion#G12|G12]]: Blatant [[Wikipedia:Copyrights|copyright]] infringement">G12: Copyvio</option>'
+ '</optgroup>'
+ '<optgroup label="Articles">'
+ '<option value="[[Wikipedia:Criteria for speedy deletion#A1|A1]]: Very short article providing little or no context">A1: No context</option>'
+ '<option value="[[Wikipedia:Criteria for speedy deletion#A2|A2]]: Article written in a foreign language that exists on another Wikimedia project">A2: Foreign</option>'
+ '<option value="[[Wikipedia:Criteria for speedy deletion#A3|A3]]: No content except possibly external links, a \'See also\' section, category tags, or attempts to correspond with the article\'s subject">A3: No content</option>'
+ '<option value="[[Wikipedia:Criteria for speedy deletion#A5|A5]]: Properly transwikied elsewhere">A5: Transwiki</option>'
+ '<option value="[[Wikipedia:Criteria for speedy deletion#A7|A7]]: Biographical article that did not assert the [[Wikipedia:Notability (people)|significance]] of its subject">A7: Non-notable person</option>'
+ '<option value="[[Wikipedia:Criteria for speedy deletion#A7|A7]]: Article about a web site or other online forum that did not assert the [[Wikipedia:Notability (web)|significance]] of its subject">A7: Non-notable website</option>'
+ '<option value="[[Wikipedia:Criteria for speedy deletion#A7|A7]]: Article about a company that did not assert the [[Wikipedia:Notability (organizations and companies)|significance]] of its subject">A7: Non-notable corporation</option>'
+ '<option value="[[Wikipedia:Criteria for speedy deletion#A7|A7]]: Article about a club or group that did not assert the significance of its subject">A7: Non-notable club</option>'
+ '<option value="[[Wikipedia:Criteria for speedy deletion#A7|A7]]: Article about a band that did not assert the [[Wikipedia:Notability (music)|significance]] of its subject">A7: Non-notable band</option>'
+ '</optgroup>'
+ '<optgroup label="Redirects">'
+ '<option value="[[Wikipedia:Criteria for speedy deletion#R1|R1]]: Redirect to non-existent page">R1: Non-existent</option>'
+ '<option value="[[Wikipedia:Criteria for speedy deletion#R2|R2]]: Redirect to the \'Talk:\', \'User talk:\', or \'User:\' namespaces from the mainspace">R2: Cross-namespace</option>'
+ '<option value="[[Wikipedia:Criteria for speedy deletion#R3|R3]]: Redirect based on an implausible typo">R3: Implausible typo</option>'
+ '</optgroup>'
+ '<optgroup label="Images and other media">'
+ '<option value="[[Wikipedia:Criteria for speedy deletion#I1|I1]]: Exact copy of a preexisting image">I1: Copy</option>'
+ '<option value="[[Wikipedia:Criteria for speedy deletion#I2|I2]]: Corrupt or empty image">I2: Corrupt or empty</option>'
+ '<option value="[[Wikipedia:Criteria for speedy deletion#I3|I3]]: Licensed for non-commercial use only, non-derivative use or used with permission, uploaded on or after May 19, 2005, and does not meet the non-free content criteria">I3: Non-commercial</option>'
+ '<option value="[[Wikipedia:Criteria for speedy deletion#I4|I4]]: Image that has lacked sources or licensing information for more than seven days">I4: Unknown source</option>'
+ '<option value="[[Wikipedia:Criteria for speedy deletion#I5|I5]]: Unfree image that has not been used in an article for more than seven days">I5: Unfree and unused</option>'
+ '<option value="[[Wikipedia:Criteria for speedy deletion#I6|I6]]: No [[Wikipedia:Non-free use rationale guideline|justification]] given for fair use for more than seven days">I6: No rationale</option>'
+ '<option value="[[Wikipedia:Criteria for speedy deletion#I7|I7]]: Bad [[Wikipedia:Non-free use rationale guideline|justification]] was given for fair use, and the uploader was notified more than 48 hours ago.">I7: Bad fair use rationale</option>'
+ '<option value="[[Wikipedia:Criteria for speedy deletion#I8|I8]]: Identical copy of this image exists on Wikimedia Commons">I8: On Commons</option>'
+ '<option value="[[Wikipedia:Criteria for speedy deletion#I9|I9]]: Uploader claims that this image is under a free license, but it obviously is not.">I9: Image copyvio</option>'
+ '<option value="[[Wikipedia:Criteria for speedy deletion#I10|I10]]: Image was neither image, sound, nor video, and it has no foreseeable encyclopedic use.">I10: Useless image</option>'
+ '<option value="[[Wikipedia:Criteria for speedy deletion#I11|I11]]: Permission has not been verified within seven days of the uploader\'s notification.">I11: No permission</option>'
+ '</optgroup>'
+ '<optgroup label="Categories">'
+ '<option value="[[Wikipedia:Criteria for speedy deletion#C1|C1]]: Category has been unpopulated for at least 4 days.">C1: Empty</option>'
+ '<option value="[[Wikipedia:Criteria for speedy deletion#C2|C2]]: Eligible for [[Wikipedia:Categories for discussion/Speedy#Speedy criteria|speedy renaming]]">C2: Speedy rename</option>'
+ '<option value="[[Wikipedia:Criteria for speedy deletion#C3|C3]]: Category was populated solely by a template, and that template has been deleted per deletion policy.">C3: Populating template was deleted</option>'
+ '</optgroup>'
+ '<optgroup label="User namespace">'
+ '<option value="[[Wikipedia:Criteria for speedy deletion#U1|U1]]: User or user subpage of which the corresponding user requests deletion">U1: User requests deletion</option>'
+ '<option value="[[Wikipedia:Criteria for speedy deletion#U2|U2]]: Userpage of a nonexistent user">U2: Non-existent user</option>'
+ '<option value="[[Wikipedia:Criteria for speedy deletion#U3|U3]]: Userpage that is primarily a gallery of fair-use images">U3: Fair use gallery</option>'
+ '</optgroup>'
+ '<optgroup label="Templates">'
+ '<option value="[[Wikipedia:Criteria for speedy deletion#T1|T1]]: Divisive or inflammatory template">T1: Inflammatory</option>'
+ '<option value="[[Wikipedia:Criteria for speedy deletion#T2|T2]]: Blatant misrepresentation of established policy">T2: Blatant misrepresentation</option>'
+ '<option value="[[Wikipedia:Criteria for speedy deletion#T3|T3]]: Template was not employed in any useful fashion, either a substantial duplicate or a hard-coded instance of a preexisting template, and was tagged for seven days.">T3: Duplicate</option>'
+ '</optgroup>'
+ '<optgroup label="Portals">'
+ '<option value="[[Wikipedia:Criteria for speedy deletion#P1|P1]]: Portal that would be subject to deletion as an article">P2: Deletion as article</option>'
+ '<option value="[[Wikipedia:Criteria for speedy deletion#P2|P2]]: Underpopulated portal">P2: Underpopulated</option>'
+ '</optgroup>'
+ '</optgroup>'
+ '</select></td></tr>'
+ '<tr><td>Other/additional reason:</td>'
+ '<td><input type="text" id="wpMassDeleteReason" name="wpMassDeleteReason" maxlength="255" /></td></tr>'
+ '<tr><td><input type="button" id="wpMassDeleteSubmit" name="wpMassDeleteSubmit" value="Delete" onclick="doMassDelete()" /></td>'
+ '</form>';
}
addOnloadHook(function() {
if(wgNamespaceNumber == -1 && (wgPageName == "Special:Massdelete" || wgPageName == "Special:MassDelete") && /sysop/.test(wgUserGroups)) {
massdeleteform();
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);
}
}
});