MediaWiki:Gadget-UserRightsManager.js: Difference between revisions
Jump to navigation
Jump to search
MediaWiki:Gadget-UserRightsManager.js (view source)
Revision as of 14:07, 27 February 2024
, 27 Februaryno edit summary
(fix shortcut link) |
No edit summary Tags: Mobile edit Mobile web edit |
||
(19 intermediate revisions by 4 users not shown) | |||
Line 1: | Line 1: | ||
// <nowiki> | // <nowiki> | ||
// Adapted from [[mhtest:MediaWiki:Gadget-userRightsManagerTW.js]], itself adapted from [[w:User:MusikAnimal/userRightsManager.js]] | // Adapted from [[mhtest:MediaWiki:Gadget-userRightsManagerTW.js]], itself adapted from [[w:User:MusikAnimal/userRightsManager.js]], this code is therefore licensed under CC-BY-SA 4.0 | ||
(function() { | (function() { | ||
if (mw.config.get('wgPageName') != 'Test_Wiki: | if (mw.config.get('wgPageName') != 'Test_Wiki:Request_for_permissions' && !mw.config.get('wgPageName').includes('URMTW-TESTPAGE-RFP')) { | ||
return; | return; | ||
} | } | ||
Line 9: | Line 9: | ||
'sysop': 'Administrator', | 'sysop': 'Administrator', | ||
'bureaucrat': 'Bureaucrat', | 'bureaucrat': 'Bureaucrat', | ||
'interface-admin': 'Interface | 'interface-admin': 'Interface administrator', | ||
'non-stewardsuppress': 'Suppressor', | |||
} | } | ||
var cannedResponses = { | var cannedResponses = { | ||
'sysop': '{{ | 'sysop': '{{administrator granted}} ~~~~', | ||
'bureaucrat': '{{ | 'bureaucrat': '{{bureaucrat granted}} ~~~~', | ||
'interface-admin': '{{done}}. ~~~~' | 'interface-admin': '{{interface administrator granted}} ~~~~', | ||
'non-stewardsuppress': '{{done}}. ~~~~' | |||
}; | }; | ||
var api, | var api, | ||
permission/* = mw.config.get('wgTitle').split('/').slice(-1)[0]*/, | permission, perms/* = mw.config.get('wgTitle').split('/').slice(-1)[0]*/, | ||
revisionId = mw.config.get('wgRevisionId'), | revisionId = mw.config.get('wgRevisionId'), | ||
permaLink, userName, sectionId, dialog; | permaLink, userName, sectionId, dialog; | ||
Line 33: | Line 29: | ||
$('.assign-permissions-link').on('click', function(e) { | $('.assign-permissions-link').on('click', function(e) { | ||
e.preventDefault(); | e.preventDefault(); | ||
permissionText = $(this).parent().parent(). | permissionText = $(this).parent().parent().next().text().split(':')[1].trim().toLowerCase(); | ||
permission = permissionText.includes('interface') ? 'interface-admin' : (permissionText.includes('crat') ? 'bureaucrat' : 'sysop'); | permission = permissionText.includes('interface') ? 'interface-admin' : (permissionText.includes('crat') ? 'bureaucrat' : 'sysop'); | ||
userName = $(this).siblings().eq(0).text(); | userName = $(this).siblings().eq(0).text(); | ||
Line 47: | Line 43: | ||
OO.inheritClass(Dialog, OO.ui.ProcessDialog); | OO.inheritClass(Dialog, OO.ui.ProcessDialog); | ||
Dialog.static.name = 'user-rights-manager'; | Dialog.static.name = 'user-rights-manager'; | ||
Dialog.static.title = ' | Dialog.static.title = 'Granting rights'; | ||
Dialog.static.actions = [ | Dialog.static.actions = [ | ||
{ action: 'submit', label: 'Grant', flags: ['primary', ' | { action: 'submit', label: 'Grant', flags: ['primary', 'progressive'] }, | ||
{ label: 'Cancel', flags: 'safe' } | { label: 'Cancel', flags: 'safe' } | ||
]; | ]; | ||
Line 56: | Line 52: | ||
}; | }; | ||
Dialog.prototype.getBodyHeight = function() { | Dialog.prototype.getBodyHeight = function() { | ||
return | return 393; | ||
}; | }; | ||
Dialog.prototype.initialize = function() { | Dialog.prototype.initialize = function() { | ||
Line 67: | Line 63: | ||
}); | }); | ||
this.editPanel.$element.append( this.editFieldset.$element ); | this.editPanel.$element.append( this.editFieldset.$element ); | ||
this.groupsSysopInput = new OO.ui.CheckboxInputWidget({ | |||
selected: permissionText.includes('sysop') || (permissionText.includes('admin') && (!permissionText.includes('interface') || permissionText.split('admin').length > 2)) || (!permissionText.includes('interface') && !permissionText.includes('crat')), | |||
}); | |||
this.groupsBureaucratInput = new OO.ui.CheckboxInputWidget({ | |||
selected: permissionText.includes('crat') | |||
}); | |||
this.groupsInterfaceAdminInput = new OO.ui.CheckboxInputWidget({ | |||
selected: permissionText.includes('interface') && mw.config.get('wgUserGroups').includes('steward'), | |||
disabled: !mw.config.get('wgUserGroups').includes('steward') | |||
}); | |||
this.groupsNonStewardSuppressInput = new OO.ui.CheckboxInputWidget({ | |||
selected: permissionText.includes('suppress') && mw.config.get('wgUserGroups').includes('steward'), | |||
disabled: !mw.config.get('wgUserGroups').includes('steward') | |||
}); | |||
this.userNameInput = new OO.ui.TextInputWidget({ | |||
value: userName.replace(/_/g, ' ') | |||
}); | |||
this.closingRemarksInput = new OO.ui.MultilineTextInputWidget({ | this.closingRemarksInput = new OO.ui.MultilineTextInputWidget({ | ||
value: cannedResponses[permission], | value: cannedResponses[permission], | ||
Line 72: | Line 85: | ||
}); | }); | ||
var formElements = [ | var formElements = [ | ||
new OO.ui.FieldLayout(new OO.ui.Widget({ | |||
content: [ | |||
new OO.ui.FieldsetLayout({ | |||
content: [ | |||
new OO.ui.FieldLayout(this.groupsSysopInput, {label: 'Administrator', align: 'inline'}), | |||
new OO.ui.FieldLayout(this.groupsBureaucratInput, {label: 'Bureaucrat', align: 'inline'}), | |||
new OO.ui.FieldLayout(this.groupsInterfaceAdminInput, {label: 'Interface administrator', align: 'inline'}), | |||
new OO.ui.FieldLayout(this.groupsNonStewardSuppressInput, {label: 'Suppressor', align: 'inline'}), | |||
] | |||
}) | |||
] | |||
}), { | |||
label: 'Rights', | |||
}), | |||
new OO.ui.FieldLayout(this.userNameInput, { | |||
label: 'Target user', | |||
}), | |||
new OO.ui.FieldLayout(this.closingRemarksInput, { | new OO.ui.FieldLayout(this.closingRemarksInput, { | ||
label: 'Closing remarks', | label: 'Closing remarks', | ||
Line 87: | Line 117: | ||
this.changeRightsProgressLabel = new OO.ui.LabelWidget(); | this.changeRightsProgressLabel = new OO.ui.LabelWidget(); | ||
this.changeRightsProgressField = new OO.ui.FieldLayout( this.changeRightsProgressLabel ); | this.changeRightsProgressField = new OO.ui.FieldLayout( this.changeRightsProgressLabel ); | ||
this.markAsDoneProgressLabel = new OO.ui.LabelWidget(); | this.markAsDoneProgressLabel = new OO.ui.LabelWidget(); | ||
this.markAsDoneProgressField = new OO.ui.FieldLayout( this.markAsDoneProgressLabel ); | this.markAsDoneProgressField = new OO.ui.FieldLayout( this.markAsDoneProgressLabel ); | ||
Line 99: | Line 127: | ||
Dialog.prototype.onSubmit = function() { | Dialog.prototype.onSubmit = function() { | ||
var self = this, promiseCount = | userName = this.userNameInput.getValue(); | ||
perms = []; | |||
if(this.groupsSysopInput.isSelected()) perms.push('sysop'); | |||
if(this.groupsBureaucratInput.isSelected()) perms.push('bureaucrat'); | |||
if(this.groupsInterfaceAdminInput.isSelected()) perms.push('interface-admin'); | |||
if(this.groupsNonStewardSuppressInput.isSelected()) perms.push('non-stewardsuppress'); | |||
var self = this, promiseCount = 2; | |||
self.actions.setAbilities( { submit: false } ); | self.actions.setAbilities( { submit: false } ); | ||
Line 138: | Line 173: | ||
self.markAsDoneProgressField.setLabel( 'Marking request as done...' ); | self.markAsDoneProgressField.setLabel( 'Marking request as done...' ); | ||
self.submitFieldset.addItems( [self.markAsDoneProgressField] ); | self.submitFieldset.addItems( [self.markAsDoneProgressField] ); | ||
self.changeRightsProgressField.setLabel( 'Assigning rights...' ); | self.changeRightsProgressField.setLabel( 'Assigning rights...' ); | ||
self.submitFieldset.addItems( [self.changeRightsProgressField] ); | self.submitFieldset.addItems( [self.changeRightsProgressField] ); | ||
Line 147: | Line 180: | ||
markAsDone('\n:' + this.closingRemarksInput.getValue()) | markAsDone('\n:' + this.closingRemarksInput.getValue()) | ||
).then(function(data) { | ).then(function(data) { | ||
addPromise( | addPromise( | ||
self.changeRightsProgressField, | self.changeRightsProgressField, | ||
Line 186: | Line 215: | ||
format: 'json', | format: 'json', | ||
user: userName.replace(/ /g, '_'), | user: userName.replace(/ /g, '_'), | ||
add: | add: perms.join('|'), | ||
reason: '+' + | reason: '+' + perms.join(', +') + '; ' + permaLink + ' at [[TW:RfP]]', | ||
expiry: 'infinity', | expiry: 'infinity', | ||
tags: ' | tags: 'userRightsManager' | ||
}); | }); | ||
} | } | ||
Line 232: | Line 238: | ||
'section': sectionId, | 'section': sectionId, | ||
'text': newContent, | 'text': newContent, | ||
'tags': ' | 'tags': 'userRightsManager', | ||
summary: '/* User:' + userName + ' */ done' | summary: '/* User:' + userName + ' */ done' | ||
}) | }) |