User:Timotheus Canens/massblock.js: Difference between revisions
Appearance
Content deleted Content added
ahhh |
Amorymeltzer (talk | contribs) m Remove duplicate case: 'vector' I left in |
||
(14 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
//Tim's mass blocking tool |
|||
function doMassDelete() { |
|||
//Adapted from [[User:Animum/massdelete.js]] |
|||
document.getElementById("wpMassDeleteSubmit").disabled = true; |
|||
var articles = document.getElementById("wpMassDeletePages").value.split("\n"); |
|||
function doMassBlock() { |
|||
if(articles.length == 0) return; |
|||
document.getElementById("wpMassBlockSubmit").disabled = true; |
|||
var wpMassDeleteReasons = document.getElementById("wpMassDeleteReasons").value, wpMassDeleteReason = document.getElementById("wpMassDeleteReason").value, deleted = 0, failed = new Array(), error = new Array(); |
|||
var users = document.getElementById("wpMassBlockUsers").value.split("\n"); |
|||
for(i=0;i<articles.length;i++) { |
|||
if(users.length == 0) return; |
|||
var article = articles[i]; |
|||
var wpMassBlockReasons = document.getElementById("wpMassBlockReasons").value, wpMassBlockReason = document.getElementById("wpMassBlockReason").value, blocked = 0, talkpageedited = 0, userpageedited = 0, failed = new Array(), error = new Array(); |
|||
if(article.length > 0) { |
|||
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 req = sajax_init_object(); |
|||
var wpMassBlockMessage = document.getElementById("wpMassBlockMessage").value, wpMassBlockTag = document.getElementById("wpMassBlockTag").value, wpMassBlockExpiry = document.getElementById("wpMassBlockExpiry").value; |
|||
req.open("GET", wgScriptPath + "/api.php?format=json&action=query&prop=info&intoken=delete&titles=" + encodeURIComponent(article), false); |
|||
var wpMassBlockSummaryTalk = document.getElementById("wpMassBlockSummaryTalk").value, wpMassBlockSummaryUser = document.getElementById("wpMassBlockSummaryUser").value, wpMassBlockExpiry = document.getElementById("wpMassBlockExpiry").value; |
|||
var blocksettingstring = "&expiry=" + encodeURIComponent(wpMassBlockExpiry == ""? "indefinite" : wpMassBlockExpiry) + (wpMassBlockAnononly ? "&anononly=1" : "") + (wpMassBlockNocreate ? "&nocreate=1" : "") + (wpMassBlockAutoblock ? "&autoblock=1" : "") + (wpMassBlockEmail ? "&noemail=1" : "") + (wpMassBlockTalkpage ? "" : "&allowusertalk=1") + (wpMassBlockReblock ? "&reblock=1" : ""); |
|||
for(i=0;i<users.length;i++) { |
|||
var user = users[i]; |
|||
if(user.length > 0) { |
|||
var req = new XMLHttpRequest(); |
|||
req.open("GET", mw.config.get('wgScriptPath') + "/api.php?format=json&action=query&prop=info&meta=tokens&type=csrf&titles=User:" + encodeURIComponent(user), false); |
|||
req.send(null); |
req.send(null); |
||
var |
var query = eval("(" + req.responseText + ")").query; |
||
var blocktoken = query.tokens.csrftoken; |
|||
var response = query.pages; |
|||
for(var index in response) { |
for(var index in response) { |
||
var info = response[index]; |
var info = response[index]; |
||
var deletetoken = info.deletetoken; |
|||
var postdata = "format=json" |
var postdata = "format=json" |
||
+ "&action= |
+ "&action=block" |
||
+ "& |
+ "&user=" + encodeURIComponent(user) |
||
+ "&reason=" + encodeURIComponent( |
+ "&reason=" + encodeURIComponent(wpMassBlockReasons == "other" ? wpMassBlockReason : wpMassBlockReasons + (wpMassBlockReason ? ": " + wpMassBlockReason : "")) |
||
+ |
+ blocksettingstring |
||
+ "&token=" + encodeURIComponent(blocktoken); |
|||
req |
var req = new XMLHttpRequest(); |
||
req.open("POST", mw.config.get('wgScriptPath') + "/api.php", false); |
|||
req.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); |
req.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); |
||
req.setRequestHeader("Content-length", postdata.length); |
req.setRequestHeader("Content-length", postdata.length); |
||
req.send(postdata); |
req.send(postdata); |
||
if(eval("(" + req.responseText + ")")[' |
if(eval("(" + req.responseText + ")")['block']) { //If blockd, update the blockd count and the button. |
||
blocked++; |
|||
// now edit user and user talk. |
|||
document.getElementById("wpMassDeleteSubmit").value = "(" + deleted + ")"; |
|||
if(wpMassBlockMessage != "") { |
|||
} else { //If not deleted, add the title to the "failed" array and a description of the error to the "error" array. |
|||
var postdata = "format=json&action=edit&watchlist=nochange&title=User%20talk:" + encodeURIComponent(user) + "&summary=" + encodeURIComponent(wpMassBlockSummaryTalk) |
|||
failed.push(article); |
|||
+ "&appendtext=" + encodeURIComponent(wpMassBlockMessage) |
|||
+ "&token=" + encodeURIComponent(blocktoken); |
|||
var req = new XMLHttpRequest(); |
|||
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 + ")")['edit']) { talkpageedited ++; } |
|||
else { //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(eval("(" + req.responseText + ")").error.info); |
|||
} |
|||
} |
|||
if(wpMassBlockTag != "") { |
|||
var postdata = "format=json&action=edit&watchlist=nochange&title=User:" + encodeURIComponent(user) + "&summary=" + encodeURIComponent(wpMassBlockSummaryUser) |
|||
+ "&text=" + encodeURIComponent(wpMassBlockTag) |
|||
+ "&token=" + encodeURIComponent(blocktoken); |
|||
var req = new XMLHttpRequest(); |
|||
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 + ")")['edit']) { userpageedited ++; } |
|||
else { //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(eval("(" + req.responseText + ")").error.info); |
|||
} |
|||
} |
|||
document.getElementById("wpMassBlockSubmit").value = "(" + blocked + "/" + talkpageedited + "/" + userpageedited + ")"; |
|||
} else { //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(eval("(" + req.responseText + ")").error.info); |
error.push(eval("(" + req.responseText + ")").error.info); |
||
} |
} |
||
} |
} |
||
} |
} |
||
if(! |
if(!users[i+1]) { |
||
document.getElementById(" |
document.getElementById("wpMassBlockSubmit").value = "(" + blocked + "/" + talkpageedited + "/" + userpageedited + ")"; |
||
if(failed.length > 0) { |
if(failed.length > 0) { |
||
var linkedList = ""; |
var linkedList = ""; |
||
for(x=0; x<failed.length; x++) { |
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 |
linkedList += "<li><a href=\"" + mw.config.get('wgScript') + "?title=" + encodeURIComponent(failed[x]) + "\">" + failed[x] + "</a>: " + error[x] + "</li>"; //Links the titles in the "failed" array |
||
} |
} |
||
document.getElementById(" |
document.getElementById("wpMassBlockFailedContainer").innerHTML += '<br /><b>Failed actions:</b><ul>' + linkedList + '</ul>'; |
||
} |
} |
||
Line 47: | Line 87: | ||
} |
} |
||
function |
function massblockform() { |
||
var bodyContent |
var bodyContent; |
||
switch (mw.config.get('skin')) { |
|||
document.getElementsByTagName("h1")[0].textContent = "Animum's mass-deletion tool"; |
|||
case 'modern': |
|||
document.title = "Animum's mass-deletion tool - Wikipedia, the free encyclopedia"; |
|||
bodyContent = 'mw_contentholder'; |
|||
break; |
|||
case 'cologneblue': |
|||
bodyContent = 'article'; |
|||
break; |
|||
case 'monobook': |
|||
case 'vector': |
|||
default: |
|||
bodyContent = 'bodyContent'; |
|||
break; |
|||
} |
|||
document.getElementsByTagName("h1")[0].textContent = "Tim's mass-blocking tool"; |
|||
document.title = "Tim's mass-blocking tool - Wikipedia, the free encyclopedia"; |
|||
document.getElementById(bodyContent).innerHTML = '<h3 id="siteSub">From Wikipedia, the free encyclopedia</h3><br /><br />' |
document.getElementById(bodyContent).innerHTML = '<h3 id="siteSub">From Wikipedia, the free encyclopedia</h3><br /><br />' |
||
+ '<form id=" |
+ '<form id="wpMassBlock" name="wpMassBlock">' |
||
+ '<b>If you abuse this tool, it\'s <i>your</i> fault, not mine.</b>' |
+ '<b>If you abuse this tool, it\'s <i>your</i> fault, not mine.</b>' |
||
+ '<div id=" |
+ '<div id="wpMassBlockFailedContainer"></div>' |
||
+ '<br /><br />' |
+ '<br /><br />' |
||
+ ' |
+ 'Users to block (one on each line, please):<br />' |
||
+ '<textarea tabindex="1" accesskey="," name=" |
+ '<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">' |
+ '<br /><br /><table style="background-color:transparent">' |
||
+ '<tr><td>Common reasons:</td>' |
+ '<tr><td>Common reasons:</td>' |
||
+ '<td><select id=" |
+ '<td><select id="wpMassBlockReasons">' |
||
+ '<optgroup label="Other reason">' |
+ '<optgroup label="Other reason">' |
||
+ '<option value="other">Other reason</option>' |
+ '<option value="other">Other reason</option>' |
||
+ '</optgroup>' |
+ '</optgroup>' |
||
+ '<optgroup label=" |
+ '<optgroup label="Common reasons">' |
||
+ '< |
+ '<option value="[[WP:Vandalism|Vandalism]]">[[WP:Vandalism|Vandalism]]</option>' |
||
+ '<option value="[[WP:Vandalism-only account|Vandalism-only account]] ">[[WP:Vandalism-only account|Vandalism-only account]] </option>' |
|||
+ '<option value="Violations of the [[WP:BLP|Biographies of living persons policy]] ">Violations of the [[WP:BLP|Biographies of living persons policy]] </option>' |
|||
+ '<option value="Using Wikipedia for [[WP:Spam|spam]] or [[WP:Advertising|advertising]] purposes">Using Wikipedia for [[WP:Spam|spam]] or [[WP:Advertising|advertising]] purposes</option>' |
|||
+ '<option value="[[WP:Spam|Spam]] / [[WP:Advertising|advertising]]-only account">[[WP:Spam|Spam]] / [[WP:Advertising|advertising]]-only account</option>' |
|||
+ '<option value="Creating [[WP:Attack page|attack]], [[WP:Patent nonsense|nonsense]] or other inappropriate pages">Creating [[WP:Attack page|attack]], [[WP:Patent nonsense|nonsense]] or other inappropriate pages</option>' |
|||
+ '<option value="Creating [[WP:Copyright violations|copyright violations]]">Creating [[WP:Copyright violations|copyright violations]]</option>' |
|||
+ '<option value="Abusing [[WP:Sock puppetry|multiple accounts]]">Abusing [[WP:Sock puppetry|multiple accounts]]</option>' |
|||
+ '<option value="[[WP:Block#Evasion of blocks|Block evasion]]">[[WP:Block#Evasion of blocks|Block evasion]]</option>' |
|||
+ '<option value="[[WP:No personal attacks|Personal attacks]] or [[WP:Harassment|harassment]]">[[WP:No personal attacks|Personal attacks]] or [[WP:Harassment|harassment]]</option>' |
|||
+ '<option value="[[WP:Edit warring|Edit warring]]">[[WP:Edit warring|Edit warring]]</option>' |
|||
+ '<option value="Violation of the [[WP:Three-revert rule|three-revert rule]] ">Violation of the [[WP:Three-revert rule|three-revert rule]] </option>' |
|||
+ '</ |
+ '<option value="[[WP:Disruptive editing|Disruptive editing]]">[[WP:Disruptive editing|Disruptive editing]]</option>' |
||
+ '< |
+ '<option value="[[WP:Long-term abuse|Long-term abuse]]">[[WP:Long-term abuse|Long-term abuse]]</option>' |
||
+ '<option value="Making [[WP:No legal threats|legal threats]]">Making [[WP:No legal threats|legal threats]]</option>' |
|||
+ '<option value="[[WP:Arbitration enforcement|Arbitration enforcement]]">[[WP:Arbitration enforcement|Arbitration enforcement]]</option>' |
|||
+ '<option value="Deliberately triggering the [[WP:Edit filter|Edit filter]]">Deliberately triggering the [[WP:Edit filter|Edit filter]]</option>' |
|||
+ '<option value="Revoking talk page access: inappropriate use of user talk page while blocked">Revoking talk page access: inappropriate use of user talk page while blocked</option>' |
|||
+ '<option value="\{\{anonblock}}">\{\{anonblock}}</option>' |
|||
+ '<option value="\{\{schoolblock}}">\{\{schoolblock}}</option>' |
|||
+ '<option value="\{\{blocked proxy}}">\{\{blocked proxy}}</option>' |
|||
+ '<option value="\{\{usernameblock}}">\{\{usernameblock}}</option>' |
|||
+ '<option value="\{\{UsernameHardBlocked}}">\{\{UsernameHardBlocked}}</option>' |
|||
+ '</ |
+ '<option value="\{\{spamusernameblock}}">\{\{spamusernameblock}}</option>' |
||
+ '< |
+ '<option value="\{\{softerblock}}">\{\{softerblock}}</option>' |
||
+ '<option value="\{\{checkuserblock}}">\{\{checkuserblock}}</option>' |
|||
+ '<option value="\{\{checkuserblock-account}}">\{\{checkuserblock-account}}</option>' |
|||
+ '<option value="\{\{Tor}}">\{\{Tor}}</option>' |
|||
+ '</ |
+ '<option value="\{\{Vaublock}}">\{\{Vaublock}}</option>' |
||
+ '<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>' |
+ '</optgroup>' |
||
+ '</select></td></tr>' |
+ '</select></td></tr>' |
||
+ '<tr><td>Other/additional reason:</td>' |
+ '<tr><td>Other/additional reason:</td>' |
||
+ '<td><input type="text" id=" |
+ '<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>'; |
+ '</form>'; |
||
document.getElementById(" |
document.getElementById("wpMassBlockReasons").onchange = function() { |
||
var maxlength = (document.getElementById(" |
var maxlength = (document.getElementById("wpMassBlockReasons").value == "other" ? 255 : 253-document.getElementById("wpMassBlockReasons").value.length); //It's 25e because of the two characters (": ") in addition to the selected summary. |
||
document.getElementById(" |
document.getElementById("wpMassBlockReason").setAttribute("maxlength", maxlength); |
||
} |
} |
||
} |
} |
||
if(wgNamespaceNumber == -1 && ( |
if(mw.config.get("wgNamespaceNumber") == -1 && mw.config.get("wgTitle").toLowerCase() == "massblock" && /sysop/.test(mw.config.get("wgUserGroups"))) $(massblockform); |
Latest revision as of 11:38, 1 December 2021
//Tim's mass blocking tool
//Adapted from [[User:Animum/massdelete.js]]
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 = new Array(), error = new Array();
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, wpMassBlockExpiry = document.getElementById("wpMassBlockExpiry").value;
var blocksettingstring = "&expiry=" + encodeURIComponent(wpMassBlockExpiry == ""? "indefinite" : wpMassBlockExpiry) + (wpMassBlockAnononly ? "&anononly=1" : "") + (wpMassBlockNocreate ? "&nocreate=1" : "") + (wpMassBlockAutoblock ? "&autoblock=1" : "") + (wpMassBlockEmail ? "&noemail=1" : "") + (wpMassBlockTalkpage ? "" : "&allowusertalk=1") + (wpMassBlockReblock ? "&reblock=1" : "");
for(i=0;i<users.length;i++) {
var user = users[i];
if(user.length > 0) {
var req = new XMLHttpRequest();
req.open("GET", mw.config.get('wgScriptPath') + "/api.php?format=json&action=query&prop=info&meta=tokens&type=csrf&titles=User:" + encodeURIComponent(user), false);
req.send(null);
var query = eval("(" + req.responseText + ")").query;
var blocktoken = query.tokens.csrftoken;
var response = query.pages;
for(var index in response) {
var info = response[index];
var postdata = "format=json"
+ "&action=block"
+ "&user=" + encodeURIComponent(user)
+ "&reason=" + encodeURIComponent(wpMassBlockReasons == "other" ? wpMassBlockReason : wpMassBlockReasons + (wpMassBlockReason ? ": " + wpMassBlockReason : ""))
+ blocksettingstring
+ "&token=" + encodeURIComponent(blocktoken);
var req = new XMLHttpRequest();
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 + ")")['block']) { //If blockd, update the blockd count and the button.
blocked++;
// now edit user and user talk.
if(wpMassBlockMessage != "") {
var postdata = "format=json&action=edit&watchlist=nochange&title=User%20talk:" + encodeURIComponent(user) + "&summary=" + encodeURIComponent(wpMassBlockSummaryTalk)
+ "&appendtext=" + encodeURIComponent(wpMassBlockMessage)
+ "&token=" + encodeURIComponent(blocktoken);
var req = new XMLHttpRequest();
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 + ")")['edit']) { talkpageedited ++; }
else { //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(eval("(" + req.responseText + ")").error.info);
}
}
if(wpMassBlockTag != "") {
var postdata = "format=json&action=edit&watchlist=nochange&title=User:" + encodeURIComponent(user) + "&summary=" + encodeURIComponent(wpMassBlockSummaryUser)
+ "&text=" + encodeURIComponent(wpMassBlockTag)
+ "&token=" + encodeURIComponent(blocktoken);
var req = new XMLHttpRequest();
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 + ")")['edit']) { userpageedited ++; }
else { //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(eval("(" + req.responseText + ")").error.info);
}
}
document.getElementById("wpMassBlockSubmit").value = "(" + blocked + "/" + talkpageedited + "/" + userpageedited + ")";
} else { //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(eval("(" + req.responseText + ")").error.info);
}
}
}
if(!users[i+1]) {
document.getElementById("wpMassBlockSubmit").value = "(" + blocked + "/" + talkpageedited + "/" + userpageedited + ")";
if(failed.length > 0) {
var linkedList = "";
for(x=0; x<failed.length; x++) {
linkedList += "<li><a href=\"" + mw.config.get('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 massblockform() {
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 = "Tim's mass-blocking tool";
document.title = "Tim's mass-blocking tool - Wikipedia, the free encyclopedia";
document.getElementById(bodyContent).innerHTML = '<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">'
+ '<option value="[[WP:Vandalism|Vandalism]]">[[WP:Vandalism|Vandalism]]</option>'
+ '<option value="[[WP:Vandalism-only account|Vandalism-only account]] ">[[WP:Vandalism-only account|Vandalism-only account]] </option>'
+ '<option value="Violations of the [[WP:BLP|Biographies of living persons policy]] ">Violations of the [[WP:BLP|Biographies of living persons policy]] </option>'
+ '<option value="Using Wikipedia for [[WP:Spam|spam]] or [[WP:Advertising|advertising]] purposes">Using Wikipedia for [[WP:Spam|spam]] or [[WP:Advertising|advertising]] purposes</option>'
+ '<option value="[[WP:Spam|Spam]] / [[WP:Advertising|advertising]]-only account">[[WP:Spam|Spam]] / [[WP:Advertising|advertising]]-only account</option>'
+ '<option value="Creating [[WP:Attack page|attack]], [[WP:Patent nonsense|nonsense]] or other inappropriate pages">Creating [[WP:Attack page|attack]], [[WP:Patent nonsense|nonsense]] or other inappropriate pages</option>'
+ '<option value="Creating [[WP:Copyright violations|copyright violations]]">Creating [[WP:Copyright violations|copyright violations]]</option>'
+ '<option value="Abusing [[WP:Sock puppetry|multiple accounts]]">Abusing [[WP:Sock puppetry|multiple accounts]]</option>'
+ '<option value="[[WP:Block#Evasion of blocks|Block evasion]]">[[WP:Block#Evasion of blocks|Block evasion]]</option>'
+ '<option value="[[WP:No personal attacks|Personal attacks]] or [[WP:Harassment|harassment]]">[[WP:No personal attacks|Personal attacks]] or [[WP:Harassment|harassment]]</option>'
+ '<option value="[[WP:Edit warring|Edit warring]]">[[WP:Edit warring|Edit warring]]</option>'
+ '<option value="Violation of the [[WP:Three-revert rule|three-revert rule]] ">Violation of the [[WP:Three-revert rule|three-revert rule]] </option>'
+ '<option value="[[WP:Disruptive editing|Disruptive editing]]">[[WP:Disruptive editing|Disruptive editing]]</option>'
+ '<option value="[[WP:Long-term abuse|Long-term abuse]]">[[WP:Long-term abuse|Long-term abuse]]</option>'
+ '<option value="Making [[WP:No legal threats|legal threats]]">Making [[WP:No legal threats|legal threats]]</option>'
+ '<option value="[[WP:Arbitration enforcement|Arbitration enforcement]]">[[WP:Arbitration enforcement|Arbitration enforcement]]</option>'
+ '<option value="Deliberately triggering the [[WP:Edit filter|Edit filter]]">Deliberately triggering the [[WP:Edit filter|Edit filter]]</option>'
+ '<option value="Revoking talk page access: inappropriate use of user talk page while blocked">Revoking talk page access: inappropriate use of user talk page while blocked</option>'
+ '<option value="\{\{anonblock}}">\{\{anonblock}}</option>'
+ '<option value="\{\{schoolblock}}">\{\{schoolblock}}</option>'
+ '<option value="\{\{blocked proxy}}">\{\{blocked proxy}}</option>'
+ '<option value="\{\{usernameblock}}">\{\{usernameblock}}</option>'
+ '<option value="\{\{UsernameHardBlocked}}">\{\{UsernameHardBlocked}}</option>'
+ '<option value="\{\{spamusernameblock}}">\{\{spamusernameblock}}</option>'
+ '<option value="\{\{softerblock}}">\{\{softerblock}}</option>'
+ '<option value="\{\{checkuserblock}}">\{\{checkuserblock}}</option>'
+ '<option value="\{\{checkuserblock-account}}">\{\{checkuserblock-account}}</option>'
+ '<option value="\{\{Tor}}">\{\{Tor}}</option>'
+ '<option value="\{\{Vaublock}}">\{\{Vaublock}}</option>'
+ '</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("wpMassBlockReasons").onchange = function() {
var maxlength = (document.getElementById("wpMassBlockReasons").value == "other" ? 255 : 253-document.getElementById("wpMassBlockReasons").value.length); //It's 25e because of the two characters (": ") in addition to the selected summary.
document.getElementById("wpMassBlockReason").setAttribute("maxlength", maxlength);
}
}
if(mw.config.get("wgNamespaceNumber") == -1 && mw.config.get("wgTitle").toLowerCase() == "massblock" && /sysop/.test(mw.config.get("wgUserGroups"))) $(massblockform);