Benutzer:Yomomo/ massdelete.js
Erscheinungsbild
Hinweis: Leere nach dem Veröffentlichen den Browser-Cache, um die Änderungen sehen zu können.
- Firefox/Safari: Umschalttaste drücken und gleichzeitig Aktualisieren anklicken oder entweder Strg+F5 oder Strg+R (⌘+R auf dem Mac) drücken
- Google Chrome: Umschalttaste+Strg+R (⌘+Umschalttaste+R auf dem Mac) drücken
- Edge: Strg+F5 drücken oder Strg drücken und gleichzeitig Aktualisieren anklicken
// Copy of https://en.wikipedia.org/wiki/User:Animum/massdelete.js modified to be able to undelete
mw.loader.using(['mediawiki.api', 'mediawiki.Title'], function () {
"use strict";
// Configuration setup for namespace and user groups
var config = mw.config.get(['wgNamespaceNumber', 'wgTitle', 'wgUserGroups', 'skin']);
/**
* Remove blank lines from a list of strings.
* @param {Array<string>} arr List of strings.
* @return {Array<string>} List without blank lines.
*/
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;
}
/**
* Executes the mass delete or undelete action on a list of pages.
*/
function doMassAction() { // Renamed from doMassDelete to doMassAction
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,
actionType = document.getElementById("wpMassDeleteAction").value, // New action type selector
actionLabel = actionType === "delete" ? "Deleted" : "Undeleted", // Label change for delete/undelete
processed = 0,
failed = [],
error = [],
reason = wpMassDeleteReasons == "other" ?
wpMassDeleteReason :
wpMassDeleteReasons + (wpMassDeleteReason ? " (" + wpMassDeleteReason + ")" : ""),
onSuccess = function () {
processed++;
document.getElementById("wpMassDeleteSubmit").value = "(" + actionLabel + ": " + processed + ")";
};
/**
* Creates a deferred function to delete or undelete an article.
* @param {string} article Article to delete or undelete.
* @return {Function} Deferred delete/undelete function.
*/
function makeActionFunc(article) {
return function () {
return $.Deferred(function (deferred) {
var apiParams = {
format: 'json',
action: actionType, // Dynamic action based on selector
title: article,
reason: reason
};
var promise = api.postWithToken('csrf', apiParams);
promise.done(onSuccess);
promise.fail(function (code, obj) {
failed.push(article);
error.push(obj.error.info);
});
promise.always(function () {
deferred.resolve();
});
});
};
}
// Chain deferred objects to execute actions sequentially
var deferred = makeActionFunc(articles[0])();
for (var i = 1, len = articles.length; i < len; i++) {
deferred = deferred.then(makeActionFunc(articles[i]));
}
// Show results and clean up after all actions are done
$.when(deferred).then(function () {
document.getElementById("wpMassDeleteSubmit").value = "Done (" + actionLabel + ": " + processed + ")";
if (failed.length) {
var $failedList = $('<ul>');
for (var x = 0; x < failed.length; x++) {
var failedTitle = mw.Title.newFromText(failed[x]);
var $failedItem = $('<li>');
if (failedTitle) {
$failedItem.append($('<a>')
.attr('href', failedTitle.getUrl())
.text(failed[x])
);
} else {
$failedItem.text(failed[x]);
}
$failedItem.append(document.createTextNode(': ' + error[x]));
$failedList.append($failedItem);
}
$('#wpMassDeleteFailedContainer')
.append($('<br />'))
.append($('<b>')
.text('Failed actions:')
)
.append($failedList);
}
});
}
/**
* Creates the mass delete or undelete form in the content area.
*/
function massDeleteForm() { // Keeping the name as per request
var bodyContent;
switch (mw.config.get('skin')) {
case 'modern':
bodyContent = 'mw_contentholder';
break;
case 'cologneblue':
bodyContent = 'article';
break;
case 'monobook':
case 'vector':
default:
bodyContent = 'bodyContent';
break;
}
document.getElementsByTagName("h1")[0].textContent = "Animum's mass-action tool (edited to undelete too)";
document.title = "Animum's mass-action 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 or undelete (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>Action:</td>' + // New Action selector for delete/undelete
'<td><select id="wpMassDeleteAction">' +
'<option value="delete">Delete</option>' +
'<option value="undelete">Undelete</option>' +
'</select></td></tr>' +
'<tr><td>Common reasons:</td>' +
'<td><select id="wpMassDeleteReasons">' +
'<optgroup label="Other reason">' +
'<option value="other">Anderer Grund</option>' +
'</optgroup>' +
'<optgroup label="Criteria for speedy deletion">' +
'<optgroup label="General criteria">' +
'<option value="[[WP:CSD#G1|G1]]: [[WP:PN|Patent nonsense]], meaningless, or incomprehensible">G1: Patent nonsense</option>' +
'<option value="[[WP:CSD#G2|G2]]: Test page">G2: Test page</option>' +
'<option value="[[WP:CSD#G3|G3]]: [[WP:Vandalism|Vandalism]]">G3: Vandalism</option>' +
'<option value="[[WP:CSD#G3|G3]]: Blatant [[WP:Do not create hoaxes|hoax]]">G3: Hoax</option>' +
'<option value="[[WP:CSD#G4|G4]]: Recreation of a page that was [[WP:DEL|deleted]] per a [[WP:XFD|deletion discussion]]">G4: Repost</option>' +
'<option value="[[WP:CSD#G5|G5]]: Creation by a [[WP:BLOCK|blocked]] or [[WP:BAN|banned]] user in violation of block or ban">G5: Banned</option>' +
'<option value="[[WP:CSD#G6|G6]]: Housekeeping and routine (non-controversial) cleanup">G6: Maintenance</option>' +
'<option value="[[WP:CSD#G7|G7]]: One author who has requested deletion or blanked the page">G7: Author</option>' +
'<option value="[[WP:CSD#G8|G8]]: Page dependent on a deleted or nonexistent page">G8: Orphaned talk page</option>' +
'<option value="[[WP:CSD#G10|G10]]: [[WP:ATP|Attack page]] or negative unsourced [[WP:BLP|BLP]]">G10: Attack page</option>' +
'<option value="[[WP:CSD#G11|G11]]: Unambiguous [[WP:NOTADVERTISING|advertising]] or promotion">G11: Advertising</option>' +
'<option value="[[WP:CSD#G12|G12]]: Unambiguous [[WP:CV|copyright infringement]]">G12: Copyvio</option>' +
'<option value="[[WP:CSD#G13|G13]]: Abandoned draft or [[WP:AFC|Articles for Creation]] submission – to retrieve it, see [[WP:REFUND/G13]]">G13: Abandoned draft</option>' +
'</optgroup>' +
'<optgroup label="Articles">' +
'<option value="[[WP:CSD#A1|A1]]: Short article without enough context to identify the subject">A1: No context</option>' +
'<option value="[[WP:CSD#A2|A2]]: Article in a foreign language that exists on another project">A2: Foreign</option>' +
'<option value="[[WP:CSD#A3|A3]]: Article that has no meaningful, substantive content">A3: No content</option>' +
'<option value="[[WP:CSD#A7|A7]]: No credible indication of importance (individuals, animals, organizations, web content, events)">A7: Non-notable individual, animal, organization, web content, or event</option>' +
'<option value="[[WP:CSD#A9|A9]]: Music recording by redlinked artist and no indication of importance or significance">A9: Non-notable recording by redlinked artist</option>' +
'<option value="[[WP:CSD#A10|A10]]: Recently created article that duplicates an existing topic">A10: Recently created article that duplicates an existing topic</option>' +
'<option value="[[WP:CSD#A11|A11]]: [[Wikipedia:Wikipedia is not for things made up one day|Made up]] by article creator or an associate, and no indication of importance/significance">A11: Made up</option>' +
'</optgroup>' +
'<optgroup label="Redirects">' +
'<option value="[[WP:CSD#R2|R2]]: Cross-[[WP:NS|namespace]] [[WP:R|redirect]] from mainspace">R2: Cross-namespace</option>' +
'<option value="[[WP:CSD#R3|R3]]: Recently created, implausible [[WP:R|redirect]]">R3: Implausible redirect</option>' +
'</optgroup>' +
'<optgroup label="Images and other media">' +
'<option value="[[WP:CSD#F1|F1]]: File redundant to another on Wikipedia">F1: Redundant</option>' +
'<option value="[[WP:CSD#F2|F2]]: Corrupt or empty file, or a file description page for a file on Commons">F2: Corrupt, empty. or Commons</option>' +
'<option value="[[WP:CSD#F3|F3]]: File with improper license">F3: File with improper license</option>' +
'<option value="[[WP:CSD#F4|F4]]: Lack of licensing information">F4: Lack of licensing information</option>' +
'<option value="[[WP:CSD#F5|F5]]: Unused non-free media">F5: Unfree and unused</option>' +
'<option value="[[WP:CSD#F6|F6]]: Non-free file without [[WP:RAT|fair-use rationale]]">F6: No rationale</option>' +
'<option value="[[WP:CSD#F7|F7]]: [[WP:NFCC|Invalid]] fair-use claim">F7: Bad fair use rationale</option>' +
'<option value="[[WP:CSD#F8|F8]]: Media file available on Commons">F8: On Commons</option>' +
'<option value="[[WP:CSD#F9|F9]]: File [[WP:COPYVIO|copyright violation]]">F9: File copyvio</option>' +
'<option value="[[WP:CSD#F11|F11]]: No evidence of permission">F11: No permission</option>' +
'</optgroup>' +
'<optgroup label="Categories">' +
'<option value="[[WP:CSD#C1|C1]]: Empty category">C1: Empty</option>' +
'<option value="[[WP:CSD#C2|C2]]: Speedy renaming">C2: Speedy rename</option>' +
'<option value="[[WP:CSD#G8|G8]]: Populated by deleted or retargeted template">G8: Populated by deleted or retargeted template</option>' +
'</optgroup>' +
'<optgroup label="User namespace">' +
'<option value="[[WP:CSD#U1|U1]]: User request to delete page in own userspace">U1: User requests deletion</option>' +
'<option value="[[WP:CSD#U2|U2]]: Userpage or subpage of a nonexistent user">U2: Non-existent user</option>' +
'<option value="[[WP:CSD#U5|U5]]: [[WP:NOTWEBHOST|Misuse of Wikipedia as a web host]]">U5: Misuse as webhost</option>' +
'</optgroup>' +
'<optgroup label="Templates">' +
'<option value="[[WP:CSD#G8|G8]]: Component or documentation of a deleted template">G8: component of deleted template</option>' +
'</optgroup>' +
'<optgroup label="Other">' +
'<option value="[[WP:PROD]]: Nominated for seven days with no objection">PRODded for more than 7 days without objection</option>' +
'<option value="[[WP:BLPPROD]]: Nominated for seven days with no reliable sources present in the article">BLPPRODded for more than seven days without a source</option>' +
'<option value="Listed at [[Wikipedia:Copyright problems]] for over seven days">Listed at Copyright problems for over seven days</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/undelete" /></td>' +
'</form>';
document.getElementById("wpMassDeleteReasons").onchange = function() {
var maxlength = (document.getElementById("wpMassDeleteReasons").value == "other" ? 255 : 252 - document.getElementById("wpMassDeleteReasons").value.length);
document.getElementById("wpMassDeleteReason").setAttribute("maxlength", maxlength);
};
document.getElementById("wpMassDeleteSubmit").addEventListener("click", function (e) {
doMassAction(); // Call updated function to perform delete/undelete
});
}
if (config.wgNamespaceNumber == -1 &&
config.wgTitle.toLowerCase() == "massdelete" &&
/sysop/.test(config.wgUserGroups)
) {
massDeleteForm();
}
});