User:Void/quickLock.js

// //This tool adds two different ways to quickly block and lock a user account mw.util.addPortletLink(	'p-personal',	'#',	'QuickLock',	'p-quicklock',	'Quickly lock an account',	null,	'#pt-preferences' );

$("#p-quicklock").click(function{	var user = prompt("Enter a username:");	if( user !== mw.config.get("wgUserName") ) {		var summary = prompt("Enter a reason for locking the account:");		lock(user, summary);	} });

if( mw.config.get("wgRelevantUserName") && mw.config.get("wgRelevantUserName") !== mw.config.get("wgUserName") ) { mw.util.addPortletLink(		'p-cactions',		'#',		'QuickLock',		'p-lockacc',		'Quickly lock ' + mw.config.get("wgRelevantUserName")	); $("#p-lockacc").click(function{		var user = mw.config.get("wgRelevantUserName");		if(confirm("Lock account " + user + "?")) {			var summary = '';			do {summary = prompt("Enter a reason for locking the account:", "LTA");}			while (summary.trim.length === 0);			lock(user, summary);		}	}); }

function lock( username, summary ) { $.ajax( {       url: mw.util.wikiScript( 'api' ),        type: 'POST',        dataType: 'json',        data: {            format: 'json',            action: 'block',            user: username,            expiry: "infinite",            nocreate: 1,            autoblock: 1,            noemail: 1,            reblock: 1,            reason: summary,            token: mw.user.tokens.get( 'csrfToken' ),        }    } ).done(console.log( "Blocked user: " + username )    ).fail( function ( e, data ) {    	console.log( e.message );    	console.log( JSON.stringify( data ) );    }); $.getJSON(	//Get setglobalaccountstatus token   mw.util.wikiScript('api'),    {        format: 'json',        action: 'query',        meta: 'tokens',        type: 'setglobalaccountstatus'    }).done( function ( data ) {    	try {    		var Token = data.query.tokens.setglobalaccountstatustoken;    		//Lock account    		$.ajax( { url: mw.util.wikiScript( 'api' ), type: 'POST', dataType: 'json', data: { format: 'json', action: 'setglobalaccountstatus', user: username, locked: 'lock', reason: summary, token: Token, }	   	} ).done(console.log( "Locked account: " + username ) ).fail( function ( e, data ){ console.log( e.message ); console.log( JSON.stringify( data ) ); });   	}    	catch ( e ) {        	console.log( "Content request error: " + e.message );        	console.log( "Content request response: " + JSON.stringify( data ) );    	}	} ).fail( function  {	    console.log( "While getting the token, there was an AJAX error." );	} ); }

//