// Script spostato a [[MediaWiki:Gadget-Massblock.js]]. Questa pagina esiste solo per la crono.
/**
* Tool for mass-blocking a list of IPs/users.
* Adapted from [[:en:User:Timotheus Canens/massblock.js]] to work a bit better
* with local config.
*/
function doMassBlock() {
document.getElementById("wpMassBlockSubmit").disabled = true;
var users = document.getElementById("wpMassBlockUsers").value.split("\n");
if (users.length === 0) {
return;
}
var wpMassBlockReasons = document.getElementById("wpMassBlockReasons").value,
wpMassBlockReason = document.getElementById("wpMassBlockReason").value,
blocked = 0,
talkpageedited = 0,
userpageedited = 0,
failed = [],
error = [];
var wpMassBlockAnononly = document.getElementById("wpMassBlockAnononly").checked,
wpMassBlockNocreate = document.getElementById("wpMassBlockNocreate").checked,
wpMassBlockEmail = document.getElementById("wpMassBlockEmail").checked,
wpMassBlockAutoblock = document.getElementById("wpMassBlockAutoblock").checked,
wpMassBlockTalkpage = document.getElementById("wpMassBlockTalkpage").checked,
wpMassBlockReblock = document.getElementById("wpMassBlockReblock").checked;
var wpMassBlockMessage = document.getElementById("wpMassBlockMessage").value,
wpMassBlockTag = document.getElementById("wpMassBlockTag").value,
wpMassBlockExpiry = document.getElementById("wpMassBlockExpiry").value;
var wpMassBlockSummaryTalk = document.getElementById("wpMassBlockSummaryTalk").value,
wpMassBlockSummaryUser = document.getElementById("wpMassBlockSummaryUser").value;
for (i = 0; i < users.length; i++) {
var user = users[i];
if (user.length > 0) {
var api = new mw.Api();
api.postWithToken("block", {
action: 'block',
allowusertalk: wpMassBlockTalkpage,
autoblock: wpMassBlockAutoblock,
nocreate: wpMassBlockNocreate,
expiry: wpMassBlockExpiry === "" ? "indefinite" : wpMassBlockExpiry,
anononly: wpMassBlockAnononly,
noemail: wpMassBlockEmail,
reblock: wpMassBlockReblock,
reason: wpMassBlockReasons === "other" ? wpMassBlockReason : wpMassBlockReasons + (wpMassBlockReason ? ": " + wpMassBlockReason : ""),
user: user
})
.then(
function(data) {
blocked++;
if (wpMassBlockMessage !== "") {
doEditTalk();
}
if (wpMassBlockTag !== "") {
doEditUserPage();
}
},
function(e) {
// If not blocked, add the title to the "failed" array and a description of the error to the "error" array.
failed.push("Special:Block/" + user);
error.push(e);
}
);
}
}
document.getElementById("wpMassBlockSubmit").value = "(" + blocked + "/" + talkpageedited + "/" + userpageedited + ")";
if (failed.length > 0) {
var linkedList = "";
for (x = 0; x < failed.length; x++) {
linkedList += "<li><a href=\"" + wgScript + "?title=" + encodeURIComponent(failed[x]) + "\">" + failed[x] + "</a>: " + error[x] + "</li>"; //Links the titles in the "failed" array
}
document.getElementById("wpMassBlockFailedContainer").innerHTML += '<br /><b>Failed actions:</b><ul>' + linkedList + '</ul>';
}
}
function doEditUserPage() {
new mw.Api().postWithEditToken({
action: 'edit',
title: 'User:' + user,
text: wpMassBlockTag,
summary: wpMassBlockSummaryUser,
watchlist: 'nochange'
}).done(function(data) {
userpageedited++;
}).fail(function(e) {
//If not edited, add the title to the "failed" array and a description of the error to the "error" array.
failed.push("User talk:" + user);
error.push(e);
});
}
function doEditTalk() {
new mw.Api().postWithEditToken({
action: 'edit',
title: 'User talk:' + user,
text: wpMassBlockMessage,
summary: wpMassBlockSummaryTalk,
watchlist: 'nochange'
}).done(function(data) {
talkpageedited++;
}).fail(function(e) {
//If not edited, add the title to the "failed" array and a description of the error to the "error" array.
failed.push("User talk:" + user);
error.push(e);
});
}
function massblockform() {
var bodyContent = (skin === "cologneblue" ? "article" : "bodyContent");
document.getElementsByTagName("h1")[0].textContent = "Tim's mass-blocking tool";
document.title = "Tim's mass-blocking tool - Wikipedia, the free encyclopedia";
var reasons = mw.mwg('Ipbreasons-dropdown').split('\*\*');
var content = '<h3 id="siteSub">From Wikipedia, the free encyclopedia</h3><br /><br />' +
'<form id="wpMassBlock" name="wpMassBlock">' +
'<b>If you abuse this tool, it\'s <i>your</i> fault, not mine.</b>' +
'<div id="wpMassBlockFailedContainer"></div>' +
'<br /><br />' +
'Users to block (one on each line, please):<br />' +
'<textarea tabindex="1" accesskey="," name="wpMassBlockUsers" id="wpMassBlockUsers" rows="10" cols="80"></textarea>' +
'Talk page message, if any (leave blank to leave no message):<br />' +
'<textarea tabindex="2" accesskey="," name="wpMassBlockMessage" id="wpMassBlockMessage" rows="10" cols="80"></textarea>' +
'Replace user page text with (leave blank for no change):<br />' +
'<textarea tabindex="3" accesskey="," name="wpMassBlockTag" id="wpMassBlockTag" rows="10" cols="80"></textarea>' +
'<br /><br /><table style="background-color:transparent">' +
'<tr><td>Common reasons:</td>' +
'<td><select id="wpMassBlockReasons">' +
'<optgroup label="Other reason">' +
'<option value="other">Other reason</option>' +
'</optgroup>' +
'<optgroup label="Common reasons">';
for (i = 1, j = reasons.length; i < j; i++) {
content += '<option value="' + reasons[i] + '">' + reasons[i] + '</option>';
}
content +=
'</optgroup>' +
'</select></td></tr>' +
'<tr><td>Other/additional reason:</td>' +
'<td><input type="text" id="wpMassBlockReason" name="wpMassBlockReason" maxlength="255" /></td></tr>' +
'<tr><td>Expiration time (blank for indefinite):</td>' +
'<td><input type="text" id="wpMassBlockExpiry" name="wpMassBlockExpiry" maxlength="255" /></td></tr>' +
'<tr><td>Edit summary for talk page edit:</td>' +
'<td><input type="text" id="wpMassBlockSummaryTalk" name="wpMassBlockSummaryTalk" maxlength="255" /></td></tr>' +
'<tr><td>Edit summary for user page edit:</td>' +
'<td><input type="text" id="wpMassBlockSummaryUser" name="wpMassBlockSummaryUser" maxlength="255" /></td></tr>' +
'<tr><td>Block anonymous users only (IPs only):</td><td><input type="checkbox" id="wpMassBlockAnononly" name="wpMassBlockAnononly" /></td></tr>' +
'<tr><td>Enable autoblock (accounts only):</td><td><input type="checkbox" id="wpMassBlockAutoblock" name="wpMassBlockAutoblock" checked="checked" /></td></tr>' +
'<tr><td>Block account creation:</td><td><input type="checkbox" id="wpMassBlockNocreate" name="wpMassBlockNocreate" checked="checked" /></td></tr>' +
'<tr><td>Block email:</td><td><input type="checkbox" id="wpMassBlockEmail" name="wpMassBlockEmail" /></td></tr>' +
'<tr><td>Remove talk page access:</td><td><input type="checkbox" id="wpMassBlockTalkpage" name="wpMassBlockTalkpage" /></td></tr>' +
'<tr><td>Override existing blocks:</td><td><input type="checkbox" id="wpMassBlockReblock" name="wpMassBlockReblock" checked="checked" /></td></tr>' +
'<tr><td><input type="button" id="wpMassBlockSubmit" name="wpMassBlockSubmit" value="Block" onclick="doMassBlock()" /></td></tr>' +
'</form>';
document.getElementById(bodyContent).innerHTML = content;
document.getElementById("wpMassBlockReasons").onchange = function() {
var maxlength = (document.getElementById("wpMassBlockReasons").value === "other" ? 255 : (255 - ': '.length) - document.getElementById("wpMassBlockReasons").value.length);
document.getElementById("wpMassBlockReason").setAttribute("maxlength", maxlength);
};
}
if (mw.config.get("wgNamespaceNumber") === -1 &&
(mw.config.get("wgTitle") == "Massblock" || mw.config.get("wgTitle") === "MassBlock") &&
/sysop/.test(mw.config.get("wgUserGroups"))
) {
$(massblockform);
}
|