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' },				{ data: 'testwiki' },				{ data: 'loginwiki' },			],			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({}); 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' }); rightsField.addItems([			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' } )		]); $('#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')); $('#ur-interface').append(' '); 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); })); $('#ur-interface').append(removeButton.$element.click(function{ submit(false); })); function submit(adding) { link.remove; addButton.setDisabled(true); removeButton.setDisabled(true); var newlink = mw.util.addPortletLink(				'p-personal',				'#',				'UserRights',				'pt-userrights',				'Edit local or interwiki user rights',				null,				'#pt-preferences'			); $(newlink).click(function{ addButton.setDisabled(false); removeButton.setDisabled(false); newlink.remove; }); $.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 = 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; 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); }); }	}); }); } //