User:HelloAnnyong/cumassblock.js

/** * HelloAnnyong's shamelessly pilfered mass blocking tool * Nearly identical to User:Timotheus Canens/massblock.js, only it parses the users differently. * Access by going to Special:CUMassBlock * Basically you can just copypaste a bunch of list items into the users box (e.g. * HelloAnnyong (talk+) ...) and it'll work. * 2010.12.04 */ function doCUMassBlock { document.getElementById("wpMassBlockSubmit").disabled = true; var userstring = document.getElementById("wpMassBlockUsers").value.split("\n"); var users = []; for(i=0;i<userstring.length;i++) { var oneline = userstring[i]; if(oneline.trim != "") { var usr = oneline.trim; // check for the checkuser line var loc = usr.search(/\(talk\+/);           if(loc != -1) {                usr = usr.substring(0,loc);            }            usr = removeChars(usr);            usr = usr.trim;            if(usr != undefined && usr != "") {                users.push(usr);            }        }    }    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 = sajax_init_object; req.open("GET", mw.config.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 = sajax_init_object; 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 = sajax_init_object; 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 = sajax_init_object; 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[x] + ": " + error[x] + ""; //Links the titles in the "failed" array }               document.getElementById("wpMassBlockFailedContainer").innerHTML += ' Failed actions:' + linkedList + ''; }       }    } }

function removeChars(charstr) { var firstpos = charstr[0]; while(charstr.length > 1 && charstr != "" && (firstpos == "#" || firstpos == "*" || firstpos == "+")) { charstr = charstr.substring(1,charstr.length-1); firstpos = charstr[0]; }	charstr = ((charstr == "#" || charstr == "*" || charstr == "+") ? '' : charstr); return charstr; } function cumassblockform { var bodyContent = (skin == "cologneblue" ? "article" : "bodyContent"); document.getElementsByTagName("h1")[0].textContent = "HA's mass-blocking tool"; document.title = "HA'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 (you can just copy/paste a bunch of lines that use the checkuser template): '               + ' ' + '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="\{\{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="doCUMassBlock" />  ' + ' ';   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('wgPageName') == "Special:CUMassblock" || mw.config.get('wgPageName') == "Special:CUMassBlock") && /sysop/.test(mw.config.get('wgUserGroups'))) addOnloadHook(cumassblockform);