MediaWiki:Gadget-userRightsManager.js: Difference between revisions

From Test Wiki
update the gadget to allow selecting which rights to grant + changing the target user
(fix right detection)
(update the gadget to allow selecting which rights to grant + changing the target user)
Line 25: Line 25:


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 47: Line 47:
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 = 'Grant ' + names[permission] + ' to ' + userName;
Dialog.static.title = 'Granting rights';
Dialog.static.actions = [
Dialog.static.actions = [
{ action: 'submit', label: 'Grant', flags: ['primary', 'constructive'] },
{ action: 'submit', label: 'Grant', flags: ['primary', 'progressive'] },
{ label: 'Cancel', flags: 'safe' }
{ label: 'Cancel', flags: 'safe' }
];
];
Line 56: Line 56:
};
};
Dialog.prototype.getBodyHeight = function() {
Dialog.prototype.getBodyHeight = function() {
return 208;
return 393;
};
};
Dialog.prototype.initialize = function() {
Dialog.prototype.initialize = function() {
Line 67: Line 67:
});
});
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.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'}),
]
})
]
}), {
label: 'Rights',
}),
new OO.ui.FieldLayout(this.closingRemarksInput, {
new OO.ui.FieldLayout(this.closingRemarksInput, {
label: 'Closing remarks',
label: 'Closing remarks',
Line 99: Line 125:


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 = 3;
var self = this, promiseCount = 3;


Line 186: Line 218:
format: 'json',
format: 'json',
user: userName.replace(/ /g, '_'),
user: userName.replace(/ /g, '_'),
add: permission,
add: perms.join('|'),
reason: '+' + permission + '; ' + permaLink + ' at [[TW:RFP]]',
reason: '+' + perms.join(', +') + '; ' + permaLink + ' at [[TW:RFP]]',
expiry: 'infinity',
expiry: 'infinity',
tags: 'userRightsManagerTW'
tags: 'userRightsManagerTW'
Line 203: Line 235:
}).then(function(data){
}).then(function(data){
var newContent = JSON.parse(data['query']['pages'][Object.keys(data['query']['pages'])[0]]['revisions'][0]['slots']['main']['*']);
var newContent = JSON.parse(data['query']['pages'][Object.keys(data['query']['pages'])[0]]['revisions'][0]['slots']['main']['*']);
newContent['userSet'][listKeys[permission]].push(userName.replace(/_/g, ' '))
for(perm in perms){
newContent['userSet'][listKeys[permission]].sort()
if(!newContent['userSet'][listKeys[perm]].includes(userName.replace(/_/g, ' '))){
newContent['userSet'][listKeys[perm]].push(userName.replace(/_/g, ' '))
}
newContent['userSet'][listKeys[perm]].sort()
}
newContent = JSON.stringify(newContent, null, 4)
newContent = JSON.stringify(newContent, null, 4)
return api.postWithToken( 'edit', {
return api.postWithToken( 'edit', {
78

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.