MediaWiki:Gadget-userRightsManagerTW.js: Difference between revisions
Content added Content deleted
(fix section id detection) |
(update the gadget to allow selecting which rights to grant + changing the target user) |
||
Line 19: | Line 19: | ||
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 41: | Line 41: | ||
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 50: | Line 50: | ||
}; |
}; |
||
Dialog.prototype.getBodyHeight = function() { |
Dialog.prototype.getBodyHeight = function() { |
||
return |
return 393; |
||
}; |
}; |
||
Dialog.prototype.initialize = function() { |
Dialog.prototype.initialize = function() { |
||
Line 61: | Line 61: | ||
}); |
}); |
||
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('consul'), |
|||
disabled: !mw.config.get('wgUserGroups').includes('consul') |
|||
}); |
|||
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 66: | Line 79: | ||
}); |
}); |
||
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'}), |
|||
] |
|||
}) |
|||
] |
|||
}), { |
|||
label: 'Rights', |
|||
}), |
|||
new OO.ui.FieldLayout(this.closingRemarksInput, { |
new OO.ui.FieldLayout(this.closingRemarksInput, { |
||
label: 'Closing remarks', |
label: 'Closing remarks', |
||
Line 91: | Line 117: | ||
Dialog.prototype.onSubmit = function() { |
Dialog.prototype.onSubmit = function() { |
||
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'); |
|||
var self = this, promiseCount = 2; |
var self = this, promiseCount = 2; |
||
Line 172: | Line 204: | ||
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: 'userRightsManagerTW' |
tags: 'userRightsManagerTW' |
||
Line 197: | Line 229: | ||
'tags': 'userRightsManagerTW', |
'tags': 'userRightsManagerTW', |
||
summary: '/* User:' + userName + ' */ done' |
summary: '/* User:' + userName + ' */ done' |
||
}) |
}); |
||
}); |
}); |
||
} |
} |