User:Void/quickLock.js

// //This tool allows one to quickly block and lock a user account mw.loader.using( ['mediawiki.api', 'mediawiki.util', 'oojs-ui'] ).then( function {	var link = mw.util.addPortletLink( 'p-personal', '#',		'QuickLock', 'p-quicklock', 'Quickly lock an account', null, '#pt-preferences' );

var api = new mw.Api;

var user = mw.config.get( 'wgRelevantUserName' );

var userBox = new OO.ui.TextInputWidget({		value: mw.util.isIPAddress(user, true) ? '' : user,	});

var ipBox = new OO.ui.TextInputWidget({		value: mw.util.isIPAddress(user, true) ? user : '',	});

var summUser = new OO.ui.TextInputWidget({		value: 'LTA'	});

var summIP = new OO.ui.TextInputWidget({		value: 'LTA'	});

var blockC = new OO.ui.CheckboxInputWidget;

var lBlock = new OO.ui.CheckboxInputWidget({		selected: true,	});

var lockTab = new OO.ui.FieldsetLayout; lockTab.addItems([		new OO.ui.FieldLayout( userBox, { label: 'Username:', align: 'inline' } ),		new OO.ui.FieldLayout( blockC, { label: 'Block account locally', align: 'inline' } ),		new OO.ui.FieldLayout( summUser, { label: 'Reason:', align: 'inline' } ),	]);

var blockTab = new OO.ui.FieldsetLayout; blockTab.addItems([		new OO.ui.FieldLayout( ipBox, { label: 'IP Address:', align: 'inline' } ),		new OO.ui.FieldLayout( lBlock, { label: 'Block IP locally', align: 'inline' } ),		new OO.ui.FieldLayout( summIP, { label: 'Reason:', align: 'inline' } ),	]);

function TabUserLock( name, config ) { TabUserLock.super.call(this, name, config); this.$element.append(lockTab.$element); }	OO.inheritClass( TabUserLock, OO.ui.TabPanelLayout );

TabUserLock.prototype.setupTabItem = function { this.tabItem.setLabel( 'Lock User' ); };

function TabIPBlock( name, config ) { TabIPBlock.super.call(this, name, config); this.$element.append(blockTab.$element); }	OO.inheritClass( TabIPBlock, OO.ui.TabPanelLayout );

TabIPBlock.prototype.setupTabItem = function { this.tabItem.setLabel( 'Block IP' ); };

function LockProc( config ) { LockProc.super.call( this, config ); }	OO.inheritClass( LockProc, OO.ui.ProcessDialog ); LockProc.static.name = 'LockProc'; LockProc.static.title = 'Quick (B)lock'; LockProc.static.actions = [ {			action: 'save', label: 'Proceed', flags: [ 'primary', 'progressive' ] },		{			label: 'Cancel', flags: 'safe' }	];

LockProc.prototype.initialize = function { LockProc.super.prototype.initialize.apply( this, arguments );

this.content = new OO.ui.IndexLayout; this.content.addTabPanels([			new TabUserLock('lock'),			new TabIPBlock('block'),		]); if( mw.util.isIPAddress(user, true) ) { this.content.setTabPanel('block'); // Go to block page for IPs }		this.content.$element.css( 'padding', '1em' );

this.$body.append( this.content.$element ); };

LockProc.prototype.getActionProcess = function( action ) { var dialog = this; if( action ) { return new OO.ui.Process( function {				if( action == 'save' ) {					if( dialog.content.getCurrentTabPanelName == 'lock' && userBox.value != mw.config.get('wgUserName') ) {						api.postWithToken( 'setglobalaccountstatus', { format: 'json', action: 'setglobalaccountstatus', user: userBox.value, locked: 'lock', reason: summUser.value } );

if( blockC.isSelected ) { api.postWithToken( 'csrf', {								format: 'json',								action: 'block',								user: userBox.value,								expiry: 'infinite',								nocreate: 1,								autoblock: 1,								noemail: 1,								reblock: 1,								reason: summUser.value							} ); }					} else if( dialog.content.getCurrentTabPanelName == 'block' && mw.util.isIPAddress( ipBox.value ) ) { api.postWithToken( 'csrf', {							format: 'json',							action: 'globalblock',							target: ipBox.value,							expiry: '6 months',							reason: summIP.value,							anononly: 1,							modify: 1						} ); if( lBlock.isSelected ) { api.postWithToken( 'csrf', {								format: 'json',								action: 'block',								user: ipBox.value,								expiry: '6 months',								nocreate: 1,								anononly: 1,								reblock: 1,								reason: summIP.value							} ); }					}				}

dialog.close({					action: action				}); } );		}		return LockProc.super.prototype.getActionProcess.call( this, action );	};

LockProc.prototype.getBodyHeight = function { return this.content.getCurrentTabPanel.$element.outerHeight( true ) * 2 + lockTab.$element.outerHeight( true ) + blockTab.$element.outerHeight( true ); };

var windowManager = new OO.ui.WindowManager; var lockProc = new LockProc({		size: 'small'	}); windowManager.addWindows( [ lockProc ] );

$( link ).click( function {		windowManager.openWindow( lockProc );	} );

$( 'body' ).append( windowManager.$element ); } ); //