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', 'oojs-ui']).then( function {	var link = mw.util.addPortletLink( 'p-personal', '#',		'UserRights', 'pt-userrights', 'Edit local or interwiki user rights', null, '#pt-preferences' );	$(link).click(function{ //Make interface $('#bodyContent').replaceWith(' '); var userBox = new OO.ui.TextInputWidget({ value: mw.config.get('wgUserName'), id: 'ur-username' }); $('#ur-interface').append('Enter a username:'); $('#ur-interface').append(userBox.$element.css('margin', '1em 0')); var wikiSelect = new OO.ui.ComboBoxInputWidget({			value: mw.config.get('wgDBname'),			options: [				{ data: 'metawiki', label: 'meta' },				{ data: 'testwiki', label: 'test' },			],			id: 'ur-wiki',		}); $('#ur-interface').append('Select which wiki you want to modify rights on:'); $('#ur-interface').append(wikiSelect.$element.css('margin', '1em 0')); var rightsField = new OO.ui.FieldsetLayout({}); rightsField.addItems([			new OO.ui.FieldLayout( new OO.ui.CheckboxInputWidget({ id: 'ur-sysop' }), { label: 'Administrator', align: 'inline' } ),			new OO.ui.FieldLayout( new OO.ui.CheckboxInputWidget({ id: 'ur-bureaucrat' }), { label: 'Bureaucrat', align: 'inline' } ),			new OO.ui.FieldLayout( new OO.ui.CheckboxInputWidget({ id: 'ur-oversight' }), { label: 'Oversight', align: 'inline' } ),			new OO.ui.FieldLayout( new OO.ui.CheckboxInputWidget({ id: 'ur-checkuser' }), { label: 'CheckUser', align: 'inline' } ),			new OO.ui.FieldLayout( new OO.ui.CheckboxInputWidget({ id: 'ur-steward' }), { label: 'Steward', align: 'inline' } )		]); $('#ur-interface').append(rightsField.$element.css('margin', '1em 0')); 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'		}); $('#ur-interface').append('Enter a reason for changing usergroups:'); $('#ur-interface').append(summaryInput.$element.css('margin', '1em 0')); var addButton = new OO.ui.ButtonWidget({ label: 'Add groups', flags: ['progressive', 'primary'] }); var removeButton = new OO.ui.ButtonWidget({ label: 'Remove groups', flags: 'destructive'}); $('#ur-interface').append(addButton.$element.click(function{ submit(true); addButton.setDisabled(true); removeButton.setDisabled(true); })); $('#ur-interface').append(removeButton.$element.click(function{ submit(false); addButton.setDisabled(true); removeButton.setDisabled(true); })); });	function submit(adding) {		$.getJSON( 'https://meta.miraheze.org/w/api.php', {				format: 'json', action: 'query', meta: 'tokens', type: 'userrights' }		).success(function(data){ modify(adding, data.query.tokens.userrightstoken); })		.fail(function{ alert('Failed to fetch userrights token'); });	}	function modify(adding, token) {		var username = $('#ur-username')[0].childNodes[0].value;		var wiki = $('#ur-wiki')[0].childNodes[0].value;		var sysop = $('#ur-sysop')[0].childNodes[0].checked;		var crat = $('#ur-bureaucrat')[0].childNodes[0].checked;		var os = $('#ur-oversight')[0].childNodes[0].checked;		var cu = $('#ur-checkuser')[0].childNodes[0].checked;		var steward = $('#ur-steward')[0].childNodes[0].checked;		var summary = $('#ur-summary')[0].childNodes[0].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;		var query = {};		if(adding) {			query = {				format: 'json',				action: 'userrights',				user: username,				add: selectedGroups,				reason: summary,				token: token			};		} else {			query = {				format: 'json',				action: 'userrights',				user: username,				remove: selectedGroups,				reason: summary,				token: token			};		}		$.ajax({ url: 'https://meta.miraheze.org/w/api.php', type: 'POST', dataType: 'json', data: query }).success(function{ alert((adding ? 'Added ' : 'Removed ') + selectedGroups.replace(/\|/g, ', ') + (adding ? ' to ' : ' from ') + username); })		.fail(function{ alert('Could not modify groups of ' + username); });	} }); } //