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{	qlinterface; });

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");		qlinterface(user);	}); }

function qlinterface (user) { $('#bodyContent').replaceWith(' '); var userBox = new OO.ui.TextInputWidget({ value: user ? user : '', id: 'ql-username' }); $('#ql-interface').append('Enter a username:'); $('#ql-interface').append(userBox.$element.css('margin', '1em 0')); var summary = new OO.ui.TextInputWidget({ value: 'LTA', id: 'ql-summary' }); $('#ql-interface').append('Summary:'); $('#ql-interface').append(summary.$element.css('margin', '1em 0')); var lockB = new OO.ui.ButtonWidget({ label: 'Lock', flags: ['progressive', 'primary'] }); var blockB = new OO.ui.ButtonWidget({ label: 'Block & Lock', flags: 'destructive' }); $('#ql-interface').append( lockB.$element.click(function{lock;}) ); $('#ql-interface').append( blockB.$element.click(function{lock(true);}) ); function lock (block) { username = userBox.value; reason = summary.value; if(block) { $.ajax({				url: 'https://meta.miraheze.org/w/api.php',				type: 'POST',				dataType: 'json',				data: {					format: 'json',					action: 'block',					user: username,					expiry: 'infinite',					nocreate: 1,					autoblock: 1,					noemail: 1,					reblock: 1,					reason: reason,					token: mw.user.tokens.get( 'csrfToken' ),				}			}); }		$.getJSON(			'https://meta.miraheze.org/w/api.php',			{				format: 'json',				action: 'query',				meta: 'tokens',				token: 'setglobalaccountstatus',			}		).done(function(data){			$.ajax({ url: 'https://meta.miraheze.org/w/api.php', type: 'POST', dataType: 'json', data: { format: 'json', action: 'setglobalaccountstatus', user: username, locked: 'lock', reason: summary, token: data.query.tokens.setglobalaccountstatustoken, }			}).done(function{ $.getJSON(					'https://meta.miraheze.org/w/api.php',					{						format: 'json',						action: 'query',						list: 'globalallusers',						agufrom: username,						agulimit: 1,						aguinfo: 'lockinfo',					}				).done(function(data){					if(data.query.globalallusers[0].locked !== undefined) {						// Woo					} else {						alert( 'Could not lock account ' + username + '\nYou will now be sent to CentralAuth to do so manually' );						window.location = mw.util.getUrl( 'Special:CentralAuth/' + username );					}				}); });		});	} }

//