User:Synoman Barris/common.js: Difference between revisions
Content added Content deleted
(Undid revision 41024 by Synoman Barris (talk)for now) Tag: Undo |
No edit summary |
||
Line 1: | Line 1: | ||
// <nowiki> |
|||
// Adapted from [[w:User:MusikAnimal/userRightsManager.js]] |
|||
(function() { |
|||
if (mw.config.get('wgPageName') != 'TestWiki:Request_permissions' && !mw.config.get('wgPageName').includes('URMTW-TESTPAGE-RFP')) { |
|||
return; |
|||
} |
|||
var names = { |
|||
'sysop': 'Administrator', |
|||
'bureaucrat': 'Bureaucrat', |
|||
'interface-admin': 'Interface Administrator', |
|||
} |
|||
var cannedResponses = { |
|||
'sysop': '{{done}} Please ensure you follow our [[TestWiki:Policies|policies]], especially [[TestWiki:Testing policy]] and [[TestWiki:Main policy]], reverting every test administrative action in the reverse order performed. As a best practice, test blocks should be done on [[User:Example]] or yourself. ~~~~', |
|||
'bureaucrat': '{{done}} Please continue to make sure you are following all [[TestWiki:Policies|policies]] and know that [[TestWiki:Bureaucrats|bureaucrat]] is, ultimately, a more senior, trusted testing permission. Ultimately, [[TestWiki:Consuls|Consuls]] are the de facto non-test administrators on TestWiki and they, together with the community at [[TestWiki:Community portal]], guide this wiki. If granting permissions, please try and link to the [[Special:Diff|diff]] page of the given user\'s request when granting rights, and only grant rights upon request. ~~~~', |
|||
'interface-admin': '{{done}} per the clear purpose articulated in your reason for requesting the permission, on an indefinite or time-limited basis. Where it is on a time-limited basis, please refer to a follow-up comment from the actioning [[TestWiki:Consuls|Consul]]. Thank you. ~~~~', |
|||
}; |
|||
View source for User:Lightdarkness/aiv.js |
|||
var api, |
|||
← User:Lightdarkness/aiv.js |
|||
permission/* = mw.config.get('wgTitle').split('/').slice(-1)[0]*/, |
|||
Jump to navigationJump to search |
|||
revisionId = mw.config.get('wgRevisionId'), |
|||
You do not have permission to edit this page, for the following reasons: |
|||
permaLink, userName, sectionId, dialog; |
|||
mw.loader.using(['oojs-ui', 'mediawiki.api'], function() { |
|||
api = new mw.Api(); |
|||
$('.assign-permissions-link').on('click', function(e) { |
|||
e.preventDefault(); |
|||
permissionText = $(this).parent().parent().siblings().eq(1).text().split(':')[1].trim().toLowerCase(); |
|||
permission = permissionText.includes('interface') ? 'interface-admin' : (permissionText.includes('crat') ? 'bureaucrat' : 'sysop'); |
|||
userName = $(this).siblings().eq(0).text(); |
|||
sectionId = $(this).parent().parent().parent().prev().find(".mw-editsection a:not('.mw-editsection-visualeditor')").prop('href').match(/section=(\d+)/)[1]; |
|||
showDialog(); |
|||
}); |
|||
}); |
|||
function showDialog() { |
|||
Dialog = function(config) { |
|||
Dialog.super.call(this, config); |
|||
}; |
|||
OO.inheritClass(Dialog, OO.ui.ProcessDialog); |
|||
Dialog.static.name = 'user-rights-manager'; |
|||
Dialog.static.title = 'Grant ' + names[permission] + ' to ' + userName; |
|||
Dialog.static.actions = [ |
|||
{ action: 'submit', label: 'Grant', flags: ['primary', 'constructive'] }, |
|||
{ label: 'Cancel', flags: 'safe' } |
|||
]; |
|||
Dialog.prototype.getApiManager = function() { |
|||
return this.apiManager; |
|||
}; |
|||
Dialog.prototype.getBodyHeight = function() { |
|||
return 208; |
|||
}; |
|||
Dialog.prototype.initialize = function() { |
|||
Dialog.super.prototype.initialize.call( this ); |
|||
this.editFieldset = new OO.ui.FieldsetLayout( { |
|||
classes: ['container'] |
|||
}); |
|||
this.editPanel = new OO.ui.PanelLayout({ |
|||
expanded: false |
|||
}); |
|||
this.editPanel.$element.append( this.editFieldset.$element ); |
|||
this.closingRemarksInput = new OO.ui.MultilineTextInputWidget({ |
|||
value: cannedResponses[permission], |
|||
rows: 9 |
|||
}); |
|||
var formElements = [ |
|||
new OO.ui.FieldLayout(this.closingRemarksInput, { |
|||
label: 'Closing remarks', |
|||
}) |
|||
]; |
|||
this.editFieldset.addItems(formElements); |
|||
this.submitPanel = new OO.ui.PanelLayout( { |
|||
$: this.$, |
|||
expanded: false |
|||
} ); |
|||
this.submitFieldset = new OO.ui.FieldsetLayout( { |
|||
classes: ['container'] |
|||
} ); |
|||
this.submitPanel.$element.append( this.submitFieldset.$element ); |
|||
this.changeRightsProgressLabel = new OO.ui.LabelWidget(); |
|||
this.changeRightsProgressField = new OO.ui.FieldLayout( this.changeRightsProgressLabel ); |
|||
this.markAsDoneProgressLabel = new OO.ui.LabelWidget(); |
|||
this.markAsDoneProgressField = new OO.ui.FieldLayout( this.markAsDoneProgressLabel ); |
|||
this.stackLayout = new OO.ui.StackLayout( { |
|||
items: [this.editPanel, this.submitPanel], |
|||
padded: true |
|||
} ); |
|||
this.$body.append( this.stackLayout.$element ); |
|||
}; |
|||
Dialog.prototype.onSubmit = function() { |
|||
var self = this, promiseCount = 2; |
|||
$(document).ready(AIV); |
|||
self.actions.setAbilities( { submit: false } ); |
|||
var AIVpageName = 'Wikipedia:Administrator_intervention_against_vandalism'; |
|||
addPromise = function( field, promise ) { |
|||
var section = '1'; |
|||
self.pushPending(); |
|||
var vandal; |
|||
promise.done(function() { |
|||
var reason; |
|||
field.$field.append( $( '<span>' ) |
|||
var username; |
|||
.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 something |
|||
self.popPending(); |
|||
function addlilinkAIV(url, name, id){ |
|||
if (promiseCount === 0) { |
|||
mw.util.addPortletLink( 'p-cactions', url, name, id, null, null ); |
|||
setTimeout(function() { |
|||
} |
|||
location.reload(true); |
|||
}, 1000); |
|||
} |
|||
}); |
|||
function AIV(){ |
|||
return promise; |
|||
if (document.title.indexOf("User talk:") != -1){ |
|||
}; |
|||
username = encodeURIComponent( mw.config.get('wgTitle') ); |
|||
var test = username.split('.'); |
|||
if(test[3]) { |
|||
addlilinkAIV('javascript:AIVandal("' + username + '")', 'Report IP', 'td-report'); |
|||
} |
|||
else { |
|||
addlilinkAIV('javascript:AIVandal("' + username + '")', 'Report', 'td-report'); |
|||
} |
|||
} |
|||
if (document.title.indexOf("User contributions") != -1){ |
|||
username = location.href.split('/')[5]; |
|||
if(username == undefined || username == ""){ |
|||
//if this is the case, then something is up |
|||
if(location.href.indexOf("&target=")){ |
|||
//it looks like we came here from a target link, lets just take the username from that |
|||
username = location.href.split('=')[2]; |
|||
} |
|||
} |
|||
addlilinkAIV('javascript:AIVandal("' + username + '")', 'Report', 'td-report'); |
|||
} |
|||
} |
|||
function AIVandal(vandalU){ |
|||
self.markAsDoneProgressField.setLabel( 'Marking request as done...' ); |
|||
vandal = vandalU; |
|||
self.submitFieldset.addItems( [self.markAsDoneProgressField] ); |
|||
if(vandal == document.getElementById('pt-userpage').getElementsByTagName('a')[0].innerHTML){ |
|||
self.changeRightsProgressField.setLabel( 'Assigning rights...' ); |
|||
alert('You don\'t want to report yourself, do you?'); |
|||
self.submitFieldset.addItems( [self.changeRightsProgressField] ); |
|||
return; |
|||
} |
|||
reason = prompt('Reason?:'); |
|||
if(!reason) |
|||
return; |
|||
document.getElementById('bodyContent').innerHTML = 'Please wait' + '...'; |
|||
document.getElementById('bodyContent').innerHTML += '<br />Grabbing page...'; |
|||
$.ajax({ |
|||
addPromise( |
|||
type: 'GET', |
|||
self.markAsDoneProgressField, |
|||
url: mw.config.get('wgServer') + mw.config.get('wgScriptPath') + '/api.php?action=query&prop=info|revisions&format=xml&intoken=edit&rvprop=content&titles=' + AIVpageName + '&rvsection=' + section, |
|||
markAsDone('\n:' + this.closingRemarksInput.getValue()) |
|||
dataType: "xml", |
|||
).then(function(data) { |
|||
success: function(xml){ |
|||
addPromise( |
|||
var pagetext = $(xml).find('rev').text(); |
|||
self.changeRightsProgressField, |
|||
var edittoken = $(xml).find('page').attr('edittoken'); |
|||
assignPermission(data.edit.newrevid) |
|||
PageReady(pagetext, edittoken); |
|||
); |
|||
}, |
|||
}.bind(this)); |
|||
error: function(){ |
|||
document.getElementById('bodyContent').innerHTML += '<br />Error reading page: ' + AIVpageName; |
|||
} |
|||
}); |
|||
} |
|||
function PageReady(pagetext, edittoken){ |
|||
self.stackLayout.setItem( self.submitPanel ); |
|||
}; |
|||
var x; |
|||
Dialog.prototype.getActionProcess = function( action ) { |
|||
var myArray = pagetext.split(" "); |
|||
return Dialog.super.prototype.getActionProcess.call( this, action ).next( function() { |
|||
var add = true; |
|||
if ( action === 'submit' ) { |
|||
document.getElementById('bodyContent').innerHTML += '<br />Searching for existing report...'; |
|||
return this.onSubmit(); |
|||
for (x=0; x < myArray.length; x++) |
|||
} else { |
|||
{ |
|||
return Dialog.super.prototype.getActionProcess.call( this, action ); |
|||
var myArray2 = myArray[x].split(/\n/); |
|||
} |
|||
var y; |
|||
}, this ); |
|||
for (y=0; y < myArray2.length; y++ ){ |
|||
}; |
|||
if(myArray2[y] == '{{IPvandal|' + vandal + '}}' || |
|||
myArray2[y] == '*{{IPvandal|' + vandal + '}}' || |
|||
myArray2[y] == '{{vandal|' + vandal + '}}' || |
|||
myArray2[y] == '*{{vandal|' + vandal + '}}'){ |
|||
add = false; |
|||
} |
|||
} |
|||
} |
|||
if(add){ |
|||
document.getElementById('bodyContent').innerHTML += '<br />No report found, adding...'; |
|||
} |
|||
else{ |
|||
//alert('CSD tag found'); |
|||
document.getElementById('bodyContent').innerHTML += '<br />Report found, will not add...'; |
|||
return; |
|||
} |
|||
//let's do something expiremntal, to see if it's an IP address |
|||
var test = username.split('.'); |
|||
if(test[3]) { |
|||
pagetext += '\n*{{IPvandal|' + vandal + '}} - ' + reason + ' --~' + '~' + '~' + '~'; |
|||
} |
|||
else { |
|||
pagetext += '\n*{{vandal|' + vandal + '}} - ' + reason + ' --~' + '~' + '~' + '~'; |
|||
} |
|||
var params = { |
|||
dialog = new Dialog({ |
|||
action : 'edit', |
|||
size: 'medium' |
|||
title : AIVpageName, |
|||
}); |
|||
section : section, |
|||
summary : 'Reporting [[Special:Contributions/' + vandal + '|' + vandal + ']] using [[WP:ARV|ARV 2.2]].', |
|||
minor : null, |
|||
text : pagetext, |
|||
token : edittoken |
|||
} |
|||
document.getElementById('bodyContent').innerHTML += '<br />Submitting form...'; |
|||
var windowManager = new OO.ui.WindowManager(); |
|||
$('body').append(windowManager.$element); |
|||
windowManager.addWindows([dialog]); |
|||
windowManager.openWindow(dialog); |
|||
} |
|||
var xmlhttp = sajax_init_object(); |
|||
function assignPermission(revId) { |
|||
xmlhttp.overrideMimeType('application/json'); |
|||
permaLink = '[[Special:Diff/' + revId + '|Requested]]'; |
|||
xmlhttp.open( 'POST' , mw.config.get('wgServer') + mw.config.get('wgScriptPath') + '/api.php', true); |
|||
return api.postWithToken( 'userrights', { |
|||
xmlhttp.setRequestHeader('Content-type','application/x-www-form-urlencoded'); |
|||
action: 'userrights', |
|||
xmlhttp.send( AIVparams(params) ); |
|||
format: 'json', |
|||
} |
|||
user: userName.replace(/ /g, '_'), |
|||
add: permission, |
|||
reason: '+' + permission + '; ' + permaLink + ' at [[TW:RfP]]', |
|||
expiry: 'infinity', |
|||
tags: 'userRightsManagerTW' |
|||
}); |
|||
} |
|||
function AIVparams( arr ) { |
|||
var resarr = Array(); |
|||
return api.get({ |
|||
for( var i in arr ) { |
|||
'action': 'query', |
|||
if( typeof arr[i] == 'undefined' ) { |
|||
'pageids': mw.config.get('wgArticleId'), |
|||
continue; |
|||
'prop': 'revisions', |
|||
} |
|||
'rvslots': '*', |
|||
var res; |
|||
'rvlimit': 1, |
|||
if( arr[i] instanceof Array ){ |
|||
'rvprop': 'content', |
|||
var v = Array(); |
|||
'rvsection': sectionId |
|||
for(var j = 0; j < arr[i].length; ++j ) { |
|||
}).then(function(data){ |
|||
v[j] = encodeURIComponent( arr[i][j] ); |
|||
var newContent = data['query']['pages'][mw.config.get('wgArticleId')]['revisions'][0]['slots']['main']['*'].replace('|status=|by=', '|status=done|by='+mw.config.get('wgUserName')) + closingRemarks |
|||
} |
|||
return api.postWithToken( 'edit', { |
|||
res = v.join('|'); |
|||
'action': 'edit', |
|||
} else { |
|||
'pageid': mw.config.get('wgArticleId'), |
|||
res = encodeURIComponent( arr[i] ); |
|||
'section': sectionId, |
|||
} |
|||
'text': newContent, |
|||
resarr.push( encodeURIComponent( i ) + '=' + res ); |
|||
'tags': 'userRightsManagerTW', |
|||
} |
|||
summary: '/* User:' + userName + ' */ done' |
|||
return resarr.join('&'); |
|||
}) |
|||
} |
|||
}); |
|||
} |
|||
})(); |
|||
// </nowiki> |
Revision as of 17:25, 10 February 2022
View source for User:Lightdarkness/aiv.js
← User:Lightdarkness/aiv.js
Jump to navigationJump to search
You do not have permission to edit this page, for the following reasons:
$(document).ready(AIV);
var AIVpageName = 'Wikipedia:Administrator_intervention_against_vandalism';
var section = '1';
var vandal;
var reason;
var username;
function addlilinkAIV(url, name, id){
mw.util.addPortletLink( 'p-cactions', url, name, id, null, null );
}
function AIV(){
if (document.title.indexOf("User talk:") != -1){
username = encodeURIComponent( mw.config.get('wgTitle') );
var test = username.split('.');
if(test[3]) {
addlilinkAIV('javascript:AIVandal("' + username + '")', 'Report IP', 'td-report');
}
else {
addlilinkAIV('javascript:AIVandal("' + username + '")', 'Report', 'td-report');
}
}
if (document.title.indexOf("User contributions") != -1){
username = location.href.split('/')[5];
if(username == undefined || username == ""){
//if this is the case, then something is up
if(location.href.indexOf("&target=")){
//it looks like we came here from a target link, lets just take the username from that
username = location.href.split('=')[2];
}
}
addlilinkAIV('javascript:AIVandal("' + username + '")', 'Report', 'td-report');
}
}
function AIVandal(vandalU){
vandal = vandalU;
if(vandal == document.getElementById('pt-userpage').getElementsByTagName('a')[0].innerHTML){
alert('You don\'t want to report yourself, do you?');
return;
}
reason = prompt('Reason?:');
if(!reason)
return;
document.getElementById('bodyContent').innerHTML = 'Please wait' + '...';
document.getElementById('bodyContent').innerHTML += '<br />Grabbing page...';
$.ajax({
type: 'GET',
url: mw.config.get('wgServer') + mw.config.get('wgScriptPath') + '/api.php?action=query&prop=info|revisions&format=xml&intoken=edit&rvprop=content&titles=' + AIVpageName + '&rvsection=' + section,
dataType: "xml",
success: function(xml){
var pagetext = $(xml).find('rev').text();
var edittoken = $(xml).find('page').attr('edittoken');
PageReady(pagetext, edittoken);
},
error: function(){
document.getElementById('bodyContent').innerHTML += '<br />Error reading page: ' + AIVpageName;
}
});
}
function PageReady(pagetext, edittoken){
var x;
var myArray = pagetext.split(" ");
var add = true;
document.getElementById('bodyContent').innerHTML += '<br />Searching for existing report...';
for (x=0; x < myArray.length; x++)
{
var myArray2 = myArray[x].split(/\n/);
var y;
for (y=0; y < myArray2.length; y++ ){
if(myArray2[y] == '{{IPvandal|' + vandal + '}}' ||
myArray2[y] == '*{{IPvandal|' + vandal + '}}' ||
myArray2[y] == '{{vandal|' + vandal + '}}' ||
myArray2[y] == '*{{vandal|' + vandal + '}}'){
add = false;
}
}
}
if(add){
document.getElementById('bodyContent').innerHTML += '<br />No report found, adding...';
}
else{
//alert('CSD tag found');
document.getElementById('bodyContent').innerHTML += '<br />Report found, will not add...';
return;
}
//let's do something expiremntal, to see if it's an IP address
var test = username.split('.');
if(test[3]) {
pagetext += '\n*{{IPvandal|' + vandal + '}} - ' + reason + ' --~' + '~' + '~' + '~';
}
else {
pagetext += '\n*{{vandal|' + vandal + '}} - ' + reason + ' --~' + '~' + '~' + '~';
}
var params = {
action : 'edit',
title : AIVpageName,
section : section,
summary : 'Reporting [[Special:Contributions/' + vandal + '|' + vandal + ']] using [[WP:ARV|ARV 2.2]].',
minor : null,
text : pagetext,
token : edittoken
}
document.getElementById('bodyContent').innerHTML += '<br />Submitting form...';
var xmlhttp = sajax_init_object();
xmlhttp.overrideMimeType('application/json');
xmlhttp.open( 'POST' , mw.config.get('wgServer') + mw.config.get('wgScriptPath') + '/api.php', true);
xmlhttp.setRequestHeader('Content-type','application/x-www-form-urlencoded');
xmlhttp.send( AIVparams(params) );
}
function AIVparams( arr ) {
var resarr = Array();
for( var i in arr ) {
if( typeof arr[i] == 'undefined' ) {
continue;
}
var res;
if( arr[i] instanceof Array ){
var v = Array();
for(var j = 0; j < arr[i].length; ++j ) {
v[j] = encodeURIComponent( arr[i][j] );
}
res = v.join('|');
} else {
res = encodeURIComponent( arr[i] );
}
resarr.push( encodeURIComponent( i ) + '=' + res );
}
return resarr.join('&');
}