User:Infinite0694/Mass Delete tool.js

mw.loader.using(['mediawiki.api.edit', 'mediawiki.Title'], function {	"use strict";

var config = mw.config.get(['wgNamespaceNumber', 'wgTitle', 'wgUserGroups', 'skin']);

function removeBlanks(arr) { var ret = []; var i, len; for (i = 0, len = arr.length; i < len; i++) { var s = arr[i]; s = s.trim; if (s) { ret.push(s); }		}		return ret; }

function doMassDelete { document.getElementById("wpMassDeleteSubmit").disabled = true; var articles = document.getElementById("wpMassDeletePages").value.split("\n"); articles = removeBlanks(articles); if (!articles.length) { return; }		var api = new mw.Api, wpMassDeleteReasons = document.getElementById("wpMassDeleteReasons").value, wpMassDeleteReason = document.getElementById("wpMassDeleteReason").value, deleted = 0, failed = [], error = [], deferreds = [], reason = wpMassDeleteReasons == "other" ? wpMassDeleteReason : wpMassDeleteReasons + (wpMassDeleteReason ? " (" + wpMassDeleteReason + ")" : ""), onSuccess = function { deleted++; document.getElementById("wpMassDeleteSubmit").value = "(" + deleted + ")"; };

function makeDeleteFunc(article) { return function { return $.Deferred(function (deferred) {					var promise = api.postWithToken('delete', { format: 'json', action: 'delete', title: article, reason: reason });					promise.done(onSuccess);					promise.fail(function (code, obj) { failed.push(article); error.push(obj.error.info); });					promise.always(function { deferred.resolve; });				});			};		}

// Make a chain of deferred objects. We chain them rather than execute them in		// parallel so that we don't make 1000 simultaneous delete requests and bring the // site down. We use deferred objects rather than the promise objects returned // from the API request so that the chain continues even if some articles gave // errors. var deferred = makeDeleteFunc(articles[0]); for (var i = 1, len = articles.length; i < len; i++) { deferred = deferred.then(makeDeleteFunc(articles[i])); }

// Show the output and do cleanup once all the requests are done. $.when(deferred).then(function {			document.getElementById("wpMassDeleteSubmit").value = "Done (" + deleted + ")";			if (failed.length) {				var $failedList = $('');				for(var x = 0; x < failed.length; x++) {					// Link the titles in the "failed" array					var failedTitle = mw.Title.newFromText(failed[x]);					var $failedItem = $('');					if (failedTitle) {						$failedItem.append( $('') .attr('href', failedTitle.getUrl) .text(failed[x]) );					} else {						$failedItem.text(failed[x]);					}					$failedItem.append(document.createTextNode(': ' + error[x]));					$failedList.append($failedItem);				}				$('#wpMassDeleteFailedContainer')					.append($(' '))					.append($('') .text('Failed deletions:') )					.append($failedList);			}		}); }	function massdeleteform { var bodyContent = (config.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 = 'From Wikipedia, the free encyclopedia

' +			'' + 'If you abuse this tool, it\'s your fault, not mine.' + ' ' +			'

' +				'Pages to delete (one on each line, please): ' +					' ' + '

' +					' Common reasons: ' + ' ' + '' + ' Other reason ' + ' ' +							'' + '' + 'G1: Patent nonsense ' + 'G2: Test page ' + 'G3: Vandalism ' + 'G4: Repost ' + 'G5: Banned ' + '<option value="G6: Housekeeping and routine (non-controversial) cleanup">G6: Maintenance ' + '<option value="G7: One author who has requested deletion or blanked the page">G7: Author ' + '<option value="G8: Page dependent on a deleted or nonexistent page">G8: Orphaned talk page ' + '<option value="G10: Attack page or negative unsourced BLP">G10: Attack page ' + '<option value="G11: Unambiguous advertising or promotion">G11: Advertising ' + '<option value="G12: Unambiguous copyright infringement">G12: Copyvio ' + ' ' +								'<optgroup label="Articles">' + '<option value="A1: Not enough context to identify article\'s subject">A1: No context ' + '<option value="A2: Article in a foreign language that exists on another project">A2: Foreign ' + '<option value="A3: Article that has no meaningful, substantive content">A3: No content ' + '<option value="A5: Article that has been transwikied to another project">A5: Transwiki ' + '<option value="A7: No explanation of the subject\'s significance (real person, animal, organization, or web content)">A7: Non-notable real person, animal, organization, or web content ' + '<option value="A9: Music recording by redlinked artist and no indication of importance or significance">A9: Non-notable recording by redlinked artist ' + '<option value="A10: Recently created article that duplicates an existing topic">A10: Recently created article that duplicates an existing topic ' + ' ' +								'<optgroup label="Redirects">' + '<option value="R2: Cross-namespace redirect from mainspace">R2: Cross-namespace ' + '<option value="R3: Recently created, implausible redirect">R3: Implausible redirect ' + ' ' +								'<optgroup label="Images and other media">' + '<option value="F1: File redundant to another on Wikipedia">F1: Redundant ' + '<option value="F2: Corrupt or empty file, or a file description page for a file on Commons">F2: Corrupt, empty. or Commons ' + '<option value="F3: File with improper license">F3: File with improper license ' + '<option value="F4: Lack of licensing information">F4: Lack of licensing information ' + '<option value="F5: Unused non-free media">F5: Unfree and unused ' + '<option value="F6: Non-free file without fair-use rationale">F6: No rationale ' + '<option value="F7: Invalid fair-use claim">F7: Bad fair use rationale ' + '<option value="F8: Media file available on Commons">F8: On Commons ' + '<option value="F9: File copyright violation">F9: File copyvio ' + '<option value="F10: Useless media file">F10: Useless media file ' + '<option value="F11: No evidence of permission">F11: No permission ' + ' ' +								'<optgroup label="Categories">' + '<option value="C1: Empty category">C1: Empty ' + '<option value="C2: Speedy renaming">C2: Speedy rename ' + '<option value="G8: Populated by deleted or retargeted template">G8: Populated by deleted or retargeted template ' + ' ' +								'<optgroup label="User namespace">' + '<option value="U1: User request to delete page in own userspace">U1: User requests deletion ' + '<option value="U2: Userpage or subpage of a nonexistent user">U2: Non-existent user ' + '<option value="U3: Non-free gallery">U3: Fair use gallery ' + ' ' +								'<optgroup label="Templates">' + '<option value="T2: Template that unambiguously misrepresents established policy">T2: Blatant misrepresentation ' + '<option value="T3: Unused, redundant template">T3: Redundant and unused ' + '<option value="G8: Component or documentation of a deleted template">G8: component of deleted template ' + ' ' +								'<optgroup label="Portals">' + '<option value="P1: Portal page that would be subject to speedy deletion as an article">P1: Deletion as article ' + '<option value="P2: Portal without a substantial topic base">P2: Underpopulated ' + ' ' +								'<optgroup label="Other">' + '<option value="WP:PROD: Nominated for seven days with no objection">PRODded for more than 7 days without objection ' + '<option value="WP:BLPPROD: Nominated for ten days with no sources present in the article">BLPPRODded for more than 10 days without a source ' + '<option value="Listed at Copyright problems for over seven days">Listed at Copyright problems for over seven days ' + ' ' +							' ' +						' ' +				'  Other/additional reason: ' + ' <input type="text" id="wpMassDeleteReason" name="wpMassDeleteReason" maxlength="255" /> ' + ' <input type="button" id="wpMassDeleteSubmit" name="wpMassDeleteSubmit" value="Delete" /> ' + ' ';		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); };		document.getElementById("wpMassDeleteSubmit").addEventListener("click", function (e) {			doMassDelete;		}); }	if (config.wgNamespaceNumber == -1 &&		config.wgTitle.toLowerCase == "massdelete" &&		/user/.test(config.wgUserGroups)	) { massdeleteform; }

});