User:Enterprisey/massblock.js
Appearance
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
Documentation for this user script can be added at User:Enterprisey/massblock. |
//<nowiki>
if( mw.config.get( "wgPageName" ) === "Special:BlankPage/mass-block" ) {
$( "#mw-content-text" ).empty()
.append( "Usernames (one per line):" )
.append( $( "<textarea>", { "rows":"8", "cols":"100", "id":"mass-block-users" } ) )
.append( "<br />" )
.append( "Reason (will also be used for edit summary on talk page): " )
.append( $( "<input>", { "type":"text", "length":"256", "id":"mass-block-reason" } ) )
.append( "<br />" )
.append( "Talk page section name: " )
.append( $( "<input>", { "type":"text", "length":"256", "id":"mass-block-talk-header" } ) )
.append( "<br />" )
.append( "Talk page message: " )
.append( $( "<textarea>", { "rows":"8", "cols":"100", "id":"mass-block-talk" } ) )
.append( "<br />" )
.append( $( "<button>" ).text( "Block all" ).click( function () {
mw.loader.using( [ "mediawiki.api" ], function () {
var api = new mw.Api();
var reason = $( "#mass-block-reason" ).val();
var users = $( "#mass-block-users" ).val().split( '\n' );
var talkHeader = $( "#mass-block-talk-header" ).val();
var talkMessage = $( "#mass-block-talk" ).val();
users.forEach( function ( username ) {
api.postWithToken( "csrf", {
action: "block",
user: username,
expiry: "indefinite",
reason: reason,
anononly: true, // just because twinkle has it on
nocreate: false,
autoblock: false,
noemail: false,
allowusertalk: true
} ).then( function () {
console.log("Blocked " + username);
return api.postWithToken( "csrf", {
action: "edit",
title: "User talk:" + username,
section: "new",
sectiontitle: talkHeader,
text: talkMessage,
summary: reason,
} ).then( function(){console.log("Notified " + username);} )
.catch( function ( e ) { console.error( e ); } );
}.bind( this ) ).catch( function ( e ) { console.error( e ); } );
} ) // end forEach callback
} ); // end mw.loader.using
} ) ); // end button click handler
}
// </nowiki>