User:Infinite0694/Mass blocking tool.js

/** * Copy from w:User:Timotheus Canens/massblock.js * https://en.wikipedia.org/wiki/User:Timotheus_Canens/massblock.js * w:Special:PermaLink/676016015 * @license * @author w:en:User:Timotheus Canens */ //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 0) { var req = new XMLHttpRequest; req.open("GET", wgScriptPath + "/api.php?format=json&action=query&prop=info&intoken=block&titles=User:" + encodeURIComponent(user), false); req.send(null); var response = eval("(" + req.responseText + ")").query.pages; for(var index in response) { var info = response[index]; var blocktoken = info.blocktoken; 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", 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", 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", 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[x] + ": " + error[x] + ""; //Links the titles in the "failed" array }               document.getElementById("wpMassBlockFailedContainer").innerHTML += ' Failed actions:' + linkedList + ''; }       }    } } 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"; document.getElementById(bodyContent).innerHTML = 'From Wikipedia, the free encyclopedia

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

'           + 'Users to block (one on each line, please): '               + ' ' + 'Talk page message, if any (leave blank to leave no message): '               + ' ' + 'Replace user page text with (leave blank for no change): '               + ' ' + '

'               + '  Common reasons: ' + ' ' + '' + ' Other reason ' + ' '                       + '' + 'Vandalism ' + '<option value="Vandalism-only account ">Vandalism-only account ' + '<option value="Violations of the Biographies of living persons policy ">Violations of the Biographies of living persons policy ' + '<option value="Using Wikipedia for spam or advertising purposes">Using Wikipedia for spam or advertising purposes ' + '<option value="Spam / advertising-only account">Spam / advertising-only account ' + '<option value="Creating attack, nonsense or other inappropriate pages">Creating attack, nonsense or other inappropriate pages ' + '<option value="Creating copyright violations">Creating copyright violations ' + '<option value="Abusing multiple accounts">Abusing multiple accounts ' + '<option value="Block evasion">Block evasion ' + '<option value="Personal attacks or harassment">Personal attacks or harassment ' + '<option value="Edit warring">Edit warring ' + '<option value="Violation of the three-revert rule ">Violation of the three-revert rule ' + '<option value="Disruptive editing">Disruptive editing ' + '<option value="Long-term abuse">Long-term abuse ' + '<option value="Making legal threats">Making legal threats ' + '<option value="Arbitration enforcement">Arbitration enforcement ' + '<option value="Deliberately triggering the Edit filter">Deliberately triggering the Edit filter ' + '<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 value="\{\{anonblock}}">\{\{anonblock}} ' + '<option value="\{\{schoolblock}}">\{\{schoolblock}} ' + '<option value="\{\{blocked proxy}}">\{\{blocked proxy}} ' + '<option value="\{\{usernameblock}}">\{\{usernameblock}} ' + '<option value="\{\{UsernameHardBlocked}}">\{\{UsernameHardBlocked}} ' + '<option value="\{\{spamusernameblock}}">\{\{spamusernameblock}} ' + '<option value="\{\{softerblock}}">\{\{softerblock}} ' + '<option value="\{\{checkuserblock}}">\{\{checkuserblock}} ' + '<option value="\{\{checkuserblock-account}}">\{\{checkuserblock-account}} ' + '<option value="\{\{Tor}}">\{\{Tor}} ' + '<option value="\{\{Vaublock}}">\{\{Vaublock}} ' + ' '                   + '  '            + '  Other/additional reason: ' + ' <input type="text" id="wpMassBlockReason" name="wpMassBlockReason" maxlength="255" /> ' + ' Expiration time (blank for indefinite): ' + ' <input type="text" id="wpMassBlockExpiry" name="wpMassBlockExpiry" maxlength="255" /> ' + ' Edit summary for talk page edit: ' + ' <input type="text" id="wpMassBlockSummaryTalk" name="wpMassBlockSummaryTalk" maxlength="255" /> ' + ' Edit summary for user page edit: ' + ' <input type="text" id="wpMassBlockSummaryUser" name="wpMassBlockSummaryUser" maxlength="255" /> ' + ' Block anonymous users only (IPs only):  <input type="checkbox" id="wpMassBlockAnononly" name="wpMassBlockAnononly" />  ' + ' Enable autoblock (accounts only):  <input type="checkbox" id="wpMassBlockAutoblock" name="wpMassBlockAutoblock" checked="checked" />  ' + ' Block account creation:  <input type="checkbox" id="wpMassBlockNocreate" name="wpMassBlockNocreate" checked="checked" />  ' + ' Block email:  <input type="checkbox" id="wpMassBlockEmail" name="wpMassBlockEmail" />  ' + ' Remove talk page access:  <input type="checkbox" id="wpMassBlockTalkpage" name="wpMassBlockTalkpage" />  ' + ' Override existing blocks:  <input type="checkbox" id="wpMassBlockReblock" name="wpMassBlockReblock" checked="checked" />  ' + ' <input type="button" id="wpMassBlockSubmit" name="wpMassBlockSubmit" value="Block" onclick="doMassBlock" />  ' + ' ';   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(wgNamespaceNumber == -1 && (wgPageName == "Special:Massblock" || wgPageName == "Special:MassBlock") && /autoconfirmed/.test(wgUserGroups)) addOnloadHook(massblockform);