User:MusikAnimal/userRightsManager.js: Difference between revisions

Content deleted Content added
fix api init.
small fix to add a template that can be placed on a user's talk page when TAIV is granted (again should be relatively uncontroversial as a change, so actioning it on my own) -- folks (other intadmins or MusikAnimal) are welcomed to revert me if they disagree :)
 
(9 intermediate revisions by 2 users not shown)
Line 10:
'Autopatrolled': 'autoreviewer',
'Confirmed': 'confirmed',
'Event coordinator': 'eventcoordinator',
'Extended confirmed': 'extendedconfirmed',
'File mover': 'filemover',
Line 17 ⟶ 18:
'Pending changes reviewer': 'reviewer',
'Rollback': 'rollbacker',
'Template editor': 'templateeditor',
'Temporary account IP viewer': 'temporary-account-viewer',
};
 
Line 25 ⟶ 27:
'AutoWikiBrowser': '',
'Confirmed': '',
'Event coordinator': 'Event coordinator granted',
'Extended confirmed': '',
'File mover': 'Filemovergiven',
Line 31 ⟶ 34:
'Page mover': 'Page mover granted',
'Pending changes reviewer': 'Pending changes reviewer granted',
'Rollback': 'Rollbackgiven3Rollback granted 3',
'Template editor': 'Template editor granted',
'Temporary account IP viewer': 'Temporary account IP viewer granted',
};
 
Line 41 ⟶ 45:
permaLink, userName, dialog;
 
mw.loader.using(['oojs-ui', 'mediawiki.api', 'mediawiki.widgets.DateInputWidget'], function() {
api = new mw.Api();
$('.perm-assign-permissions a').on('click', function(e) {
Line 66 ⟶ 70:
};
Dialog.prototype.getBodyHeight = function() {
return 160208;
};
Dialog.prototype.initialize = function() {
Line 79 ⟶ 83:
this.rightsChangeSummaryInput = new OO.ui.TextInputWidget({
value: 'Requested at [[WP:PERM]]'
});
this.expiryInput = new mw.widgets.DateInputWidget({
$overlay: $('.oo-ui-window')
});
this.closingRemarksInput = new OO.ui.TextInputWidget({
Line 89 ⟶ 96:
new OO.ui.FieldLayout(this.rightsChangeSummaryInput, {
label: 'Summary'
}),
new OO.ui.FieldLayout(this.expiryInput, {
label: 'Expiry (optional)'
}),
new OO.ui.FieldLayout(this.closingRemarksInput, {
Line 121 ⟶ 131:
} );
this.$body.append( this.stackLayout.$element );
$( '.mw-widget-dateInputWidget' ).css( 'width', '100%' );
};
 
Line 173 ⟶ 184:
addPromise(
self.markAsDoneProgressField,
markAsDone('\n::' + this.closingRemarksInput.getValue())
).then(function(data) {
addPromise(
Line 179 ⟶ 190:
assignPermission(
this.rightsChangeSummaryInput.getValue(),
data.edit.newrevid,
this.expiryInput.getValue()
)
).then(function() {
// silently add user to MMS list
if (permission === 'New page reviewer') {
addToMMSList();
} else if (permission === 'Autopatrolled') {
updateWhiteList();
}
 
if (!!templates[permission]) {
addPromise(
self.issueTemplateProgressField,
issueTemplate(this.watchTalkPageCheckbox.isSelected(), this.expiryInput.getValue())
);
}
Line 217 ⟶ 233:
}
 
function assignPermission(summary, revId, expiry) {
permaLink = '[[Special:PermaLink/' + revId + '#User:' + userName + '|permalink]]';
return api.postWithToken( 'userrights', {
action: 'userrights',
Line 224 ⟶ 240:
user: userName.replace(/ /g, '_'),
add: permissionNames[permission],
reason: '+' + permissionNames[permission] + '; ' + summary + '; ' + permaLink + tagLine,
expiry: expiry === '' ? 'infinity' : expiry
});
}
Line 241 ⟶ 258:
}
 
function issueTemplate(watch, expiry) {
var talkPage = 'User talk:' + userName.replace(/ /g, '_');
return api.postWithToken( 'edit', {
Line 249 ⟶ 266:
section: 'new',
summary: permission + ' granted per ' + permaLink + tagLine,
text: '{{subst:' + templates[permission] + (expiry === '' ? '' : '|expiry=' + expiry) + '}}',
sectiontitle: permission + ' granted',
watchlist: watch ? 'watch' : 'unwatch'
Line 261 ⟶ 278:
spamlist: 'Wikipedia:New pages patrol/Reviewers/Newsletter list',
add: 'User talk:' + userName
});
}
function updateWhiteList() {
api.edit( 'Wikipedia:New pages patrol/Redirect autopatrol list', function (revision) {
var newContent = revision.content.replace(
new RegExp('\\*\\s*{{\\s*user2\\s*\\|\\s*' + userName + '\\s*}}\\n'),
''
);
return {
text: newContent,
summary: 'Removing ' + userName + ' who is now autopatrolled' + tagLine,
minor: true
};
});
}