// <nowiki>// Some UI code adapted from [[User:Mr. Stradivarius/gadgets/Draftify.js]](function(){if(!/Wikipedia:Requests for permissions\//.test(document.title)){return;}varpermissionNames={'Account creator':'accountcreator','Autopatrolled':'autoreviewer','Confirmed':'confirmed','Event coordinator':'eventcoordinator','Extended confirmed':'extendedconfirmed','File mover':'filemover','Mass message sender':'massmessage-sender','New page reviewer':'patroller','Page mover':'extendedmover','Pending changes reviewer':'reviewer','Rollback':'rollbacker','Template editor':'templateeditor','Temporary account IP viewer':'temporary-account-viewer',};vartemplates={'Account creator':'Account creator granted','Autopatrolled':'Autopatrolledgiven','AutoWikiBrowser':'','Confirmed':'','Event coordinator':'Event coordinator granted','Extended confirmed':'','File mover':'Filemovergiven','Mass message sender':'Mass message sender granted','New page reviewer':'New Page Reviewer granted','Page mover':'Page mover granted','Pending changes reviewer':'Pending changes reviewer granted','Rollback':'Rollback granted 3','Template editor':'Template editor granted','Temporary account IP viewer':'Temporary account IP viewer granted',};varapi,permission=mw.config.get('wgTitle').split('/').slice(-1)[0],revisionId=mw.config.get('wgRevisionId'),tagLine=' (using [[User:MusikAnimal/userRightsManager|userRightsManager]])',permaLink,userName,dialog;mw.loader.using(['oojs-ui','mediawiki.api','mediawiki.widgets.DateInputWidget'],function(){api=newmw.Api();$('.perm-assign-permissions a').on('click',function(e){if(permission==='AutoWikiBrowser')returntrue;e.preventDefault();userName=$(this).parents('.plainlinks').find('a').eq(0).text();showDialog();});});functionshowDialog(){Dialog=function(config){Dialog.super.call(this,config);};OO.inheritClass(Dialog,OO.ui.ProcessDialog);Dialog.static.name='user-rights-manager';Dialog.static.title='Grant '+permission+' to '+userName;Dialog.static.actions=[{action:'submit',label:'Submit',flags:['primary','constructive']},{label:'Cancel',flags:'safe'}];Dialog.prototype.getApiManager=function(){returnthis.apiManager;};Dialog.prototype.getBodyHeight=function(){return208;};Dialog.prototype.initialize=function(){Dialog.super.prototype.initialize.call(this);this.editFieldset=newOO.ui.FieldsetLayout({classes:['container']});this.editPanel=newOO.ui.PanelLayout({expanded:false});this.editPanel.$element.append(this.editFieldset.$element);this.rightsChangeSummaryInput=newOO.ui.TextInputWidget({value:'Requested at [[WP:PERM]]'});this.expiryInput=newmw.widgets.DateInputWidget({$overlay:$('.oo-ui-window')});this.closingRemarksInput=newOO.ui.TextInputWidget({value:'{{done}} ~~~~'});this.watchTalkPageCheckbox=newOO.ui.CheckboxInputWidget({selected:false});varformElements=[newOO.ui.FieldLayout(this.rightsChangeSummaryInput,{label:'Summary'}),newOO.ui.FieldLayout(this.expiryInput,{label:'Expiry (optional)'}),newOO.ui.FieldLayout(this.closingRemarksInput,{label:'Closing remarks'})];if(!!templates[permission]){formElements.push(newOO.ui.FieldLayout(this.watchTalkPageCheckbox,{label:'Watch user talk page'}));}this.editFieldset.addItems(formElements);this.submitPanel=newOO.ui.PanelLayout({$:this.$,expanded:false});this.submitFieldset=newOO.ui.FieldsetLayout({classes:['container']});this.submitPanel.$element.append(this.submitFieldset.$element);this.changeRightsProgressLabel=newOO.ui.LabelWidget();this.changeRightsProgressField=newOO.ui.FieldLayout(this.changeRightsProgressLabel);this.markAsDoneProgressLabel=newOO.ui.LabelWidget();this.markAsDoneProgressField=newOO.ui.FieldLayout(this.markAsDoneProgressLabel);this.issueTemplateProgressLabel=newOO.ui.LabelWidget();this.issueTemplateProgressField=newOO.ui.FieldLayout(this.issueTemplateProgressLabel);this.stackLayout=newOO.ui.StackLayout({items:[this.editPanel,this.submitPanel],padded:true});this.$body.append(this.stackLayout.$element);$('.mw-widget-dateInputWidget').css('width','100%');};Dialog.prototype.onSubmit=function(){varself=this,promiseCount=!!templates[permission]?3:2;self.actions.setAbilities({submit:false});addPromise=function(field,promise){self.pushPending();promise.done(function(){field.$field.append($('<span>').text('Complete!').prop('style','position:relative; top:0.5em; color: #009000; font-weight: bold'));}).fail(function(obj){if(obj&&obj.error&&obj.error.info){field.$field.append($('<span>').text('Error: '+obj.error.info).prop('style','position:relative; top:0.5em; color: #cc0000; font-weight: bold'));}else{field.$field.append($('<span>').text('An unknown error occurred.').prop('style','position:relative; top:0.5em; color: #cc0000; font-weight: bold'));}}).always(function(){promiseCount--;// FIXME: maybe we could use a self.isPending() or somethingself.popPending();if(promiseCount===0){setTimeout(function(){location.reload(true);},1000);}});returnpromise;};self.markAsDoneProgressField.setLabel('Marking request as done...');self.submitFieldset.addItems([self.markAsDoneProgressField]);self.changeRightsProgressField.setLabel('Assigning rights...');self.submitFieldset.addItems([self.changeRightsProgressField]);if(!!templates[permission]){self.issueTemplateProgressField.setLabel('Issuing template...');self.submitFieldset.addItems([self.issueTemplateProgressField]);}addPromise(self.markAsDoneProgressField,markAsDone('\n:'+this.closingRemarksInput.getValue())).then(function(data){addPromise(self.changeRightsProgressField,assignPermission(this.rightsChangeSummaryInput.getValue(),data.edit.newrevid,this.expiryInput.getValue())).then(function(){// silently add user to MMS listif(permission==='New page reviewer'){addToMMSList();}elseif(permission==='Autopatrolled'){updateWhiteList();}if(!!templates[permission]){addPromise(self.issueTemplateProgressField,issueTemplate(this.watchTalkPageCheckbox.isSelected(),this.expiryInput.getValue()));}}.bind(this));}.bind(this));self.stackLayout.setItem(self.submitPanel);};Dialog.prototype.getActionProcess=function(action){returnDialog.super.prototype.getActionProcess.call(this,action).next(function(){if(action==='submit'){returnthis.onSubmit();}else{returnDialog.super.prototype.getActionProcess.call(this,action);}},this);};dialog=newDialog({size:'medium'});varwindowManager=newOO.ui.WindowManager();$('body').append(windowManager.$element);windowManager.addWindows([dialog]);windowManager.openWindow(dialog);}functionassignPermission(summary,revId,expiry){permaLink='[[Special:PermaLink/'+revId+'#User:'+userName+'|permalink]]';returnapi.postWithToken('userrights',{action:'userrights',format:'json',user:userName.replace(/ /g,'_'),add:permissionNames[permission],reason:'+'+permissionNames[permission]+'; '+summary+'; '+permaLink+tagLine,expiry:expiry===''?'infinity':expiry});}functionmarkAsDone(closingRemarks){varsectionNode=document.getElementById('User:'+userName.replace(/"/g,'.22').replace(/ /g,'_')),sectionNumber=$(sectionNode).siblings('.mw-editsection').find("a:not('.mw-editsection-visualeditor')").prop('href').match(/section=(\d+)/)[1];returnapi.postWithToken('edit',{format:'json',action:'edit',title:mw.config.get('wgPageName'),section:sectionNumber,summary:'/* User:'+userName+' */ done'+tagLine,appendtext:closingRemarks});}functionissueTemplate(watch,expiry){vartalkPage='User talk:'+userName.replace(/ /g,'_');returnapi.postWithToken('edit',{format:'json',action:'edit',title:talkPage,section:'new',summary:permission+' granted per '+permaLink+tagLine,text:'{{subst:'+templates[permission]+(expiry===''?'':'|expiry='+expiry)+'}}',sectiontitle:permission+' granted',watchlist:watch?'watch':'unwatch'});}functionaddToMMSList(){api.postWithToken('csrf',{format:'json',action:'editmassmessagelist',spamlist:'Wikipedia:New pages patrol/Reviewers/Newsletter list',add:'User talk:'+userName});}functionupdateWhiteList(){api.edit('Wikipedia:New pages patrol/Redirect autopatrol list',function(revision){varnewContent=revision.content.replace(newRegExp('\\*\\s*{{\\s*user2\\s*\\|\\s*'+userName+'\\s*}}\\n'),'');return{text:newContent,summary:'Removing '+userName+' who is now autopatrolled'+tagLine,minor:true};});}})();// </nowiki>