User:Void/userRights.js

// // Script for changing userrights on meta, or other wikis // TODO: target user must be steward to recieve CU, OS, or Steward if( mw.config.get('wgGlobalGroups').includes('steward') ) { mw.loader.using( ['mediawiki.util', 'mediawiki.api', 'oojs-ui'] ).then( function {	var link = mw.util.addPortletLink( 'p-personal', '#',		'UserRights', 'pt-userrights', 'Edit local or interwiki user rights', null, '#pt-preferences' );

var api = new mw.Api;

var userBox = new OO.ui.TextInputWidget( {		value: mw.config.get('wgUserName'),		id: 'ur-username'	} );

var wikiSelect = new OO.ui.ComboBoxInputWidget( {		value: mw.config.get('wgDBname'),		options: [			{ data: 'metawiki' },			{ data: 'testwiki' },			{ data: 'loginwiki' },		],		id: 'ur-wiki'	} );

var sysopcb = new OO.ui.CheckboxInputWidget( { id: 'ur-sysop' } ); var cratcb = new OO.ui.CheckboxInputWidget( { id: 'ur-bureaucrat' } ); var oscb = new OO.ui.CheckboxInputWidget( { id: 'ur-oversight' } ); var cucb = new OO.ui.CheckboxInputWidget( { id: 'ur-checkuser' } ); var stewardcb = new OO.ui.CheckboxInputWidget( { id: 'ur-steward' } );

var summaryInput = new OO.ui.ComboBoxInputWidget( {		options: [			{ data: 'Redacting information' },			{ data: 'Investigating possible abuse' },			{ data: 'Revoking due to abuse' },			{ data: 'Assigning local permissions' },		],		id: 'ur-summary'	} );

var addButton = new OO.ui.ButtonOptionWidget( {		label: 'Add groups',		flags: 'progressive'	} );

var removeButton = new OO.ui.ButtonOptionWidget( {		label: 'Remove groups',		flags: 'destructive'	} );

var buttonSelection = new OO.ui.ButtonSelectWidget( {		items: [ removeButton, addButton ]	} ); buttonSelection.on( 'select', function ( items ) {		removeButton.setFlags( { destructive: true, primary: removeButton.isSelected } );		addButton.setFlags( { progressive: true, primary: addButton.isSelected } );	} );	buttonSelection.selectItem( addButton ); // Add by default

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

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

this.content = new OO.ui.FieldsetLayout( {			label: 'User rights options'			} ); this.content.addItems([			new OO.ui.FieldLayout( userBox, { label: 'Username:', align: 'inline' } ),			new OO.ui.FieldLayout( wikiSelect, { label: 'Wiki:', align: 'inline' } ),			new OO.ui.FieldLayout( sysopcb, { label: 'Administrator', align: 'inline' } ),			new OO.ui.FieldLayout( cratcb, { label: 'Bureaucrat', align: 'inline' } ),			new OO.ui.FieldLayout( oscb, { label: 'Oversight', align: 'inline' } ),			new OO.ui.FieldLayout( cucb, { label: 'CheckUser', align: 'inline' } ),			new OO.ui.FieldLayout( stewardcb, { label: 'Steward', align: 'inline' } ),			new OO.ui.FieldLayout( summaryInput, { label: 'Reason:', align: 'inline' } ),			new OO.ui.FieldLayout( buttonSelection )		]);		this.content.$element.css( 'padding', '1em' );

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

UserRightsProc.prototype.getActionProcess = function( action ) { var dialog = this; if( action ) { return new OO.ui.Process( function {				if( action == 'save' ) {					modify;				}

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

UserRightsProc.prototype.getBodyHeight = function { return this.content.$element.outerHeight( true ); };

var windowManager = new OO.ui.WindowManager; var userRightsProc = new UserRightsProc( {		size: 'medium'	} ); windowManager.addWindows( [ userRightsProc ] );

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

function modify { var adding = addButton.isSelected; var username = userBox.value; var wiki = wikiSelect.value; var sysop = sysopcb.isSelected; var crat = cratcb.isSelected; var os = oscb.isSelected; var cu = cucb.isSelected; var steward = stewardcb.isSelected; var summary = summaryInput.value;

if( wiki.lastIndexOf('wiki') !== wiki.length - 4 ) { wiki += 'wiki'; }

var selectedGroups = ''; if( sysop ) { selectedGroups += 'sysop'; }		if( crat ) { selectedGroups += (selectedGroups.length === 0 ? '' : '|') + 'bureaucrat'; }		if( os ) { selectedGroups += (selectedGroups.length === 0 ? '' : '|') + 'oversight'; }		if( cu ) { selectedGroups += (selectedGroups.length === 0 ? '' : '|') + 'checkuser'; }		if( steward ) { selectedGroups += (selectedGroups.length === 0 ? '' : '|') + 'steward'; }

if( wiki !== 'metawiki' ) { username += '@' + wiki; }

api.postWithToken( 'userrights', {			format: 'json',			action: 'userrights',			user: username,			add: adding ? selectedGroups : ,			remove: adding ?  : selectedGroups,			reason: summary		} ).done( function {			alert((adding ? 'Added ' : 'Removed ') + selectedGroups.replace(/\|/g, ', ') + (adding ? ' to ' : ' from ') + username);		} ).fail( function {			alert('Could not modify groups of ' + username);		} ); }

$( '#bodyContent' ).append( windowManager.$element ); } ); } //