User:Joepayne/stripRights.js: Difference between revisions
From Test Wiki
User:Joepayne/stripRights.js (view source)
Revision as of 02:55, 17 February 2018
, 17 February 2018Fixes
(New script) |
(Fixes) |
||
Line 1: | Line 1: | ||
//Script to | //Script to strip rights from a user on one click | ||
//To do: add toggles for different skins | //To do: add toggles for different skins | ||
if( mw.config.get("wgRelevantUserName") ) { | if( mw.config.get("wgRelevantUserName") ) { | ||
Line 20: | Line 20: | ||
'sidebar', | 'sidebar', | ||
'#', | '#', | ||
'Strip | 'Strip rights', | ||
'pt- | 'pt-striprightslink', | ||
'Remove | 'Remove standard rights from this user' | ||
); | ); | ||
Line 54: | Line 54: | ||
if(data.query.users[0].groups.indexOf(!'sysop') >= 0) {/* Do nothing */} | if(data.query.users[0].groups.indexOf(!'sysop') >= 0) {/* Do nothing */} | ||
else { | else { | ||
check = confirm("Do you want to remove " + username + "'s | check = confirm("Do you want to remove " + username + "'s rights on this wiki?"); | ||
if (check) { | if (check) { | ||
stripRights(username); | |||
alertUser(username); | alertUser(username); | ||
alert(username + " | alert(username + " has had all rights removed"); | ||
} | } | ||
} | } | ||
Line 71: | Line 71: | ||
} | } | ||
function | function stripRights(username) { | ||
$.getJSON( | $.getJSON( | ||
//Get userrights token | //Get userrights token | ||
Line 84: | Line 84: | ||
try { | try { | ||
var rightsToken = data.query.tokens.userrightstoken; | var rightsToken = data.query.tokens.userrightstoken; | ||
// | //Strip rights | ||
$.ajax( { | $.ajax( { | ||
url: mw.util.wikiScript( 'api' ), | url: mw.util.wikiScript( 'api' ), | ||
Line 93: | Line 93: | ||
action: 'userrights', | action: 'userrights', | ||
user: username, | user: username, | ||
remove: 'sysop', | remove: 'sysop|bureaucrat', | ||
reason: 'Procedural | reason: 'Procedural removal as per [[Test Wiki:Inactivity Policy]]', | ||
token: rightsToken, | token: rightsToken, | ||
} | } | ||
} ).done(console.log( "Removed | } ).done(console.log( "Removed rights from: " + username ) | ||
).fail( function ( e, data ){ | ).fail( function ( e, data ){ | ||
console.log( e.message ); | console.log( e.message ); | ||
Line 124: | Line 124: | ||
summary: 'Notification', | summary: 'Notification', | ||
nocreate: 1, | nocreate: 1, | ||
appendtext: 'Your | appendtext: 'Your rights have been revoked for inactivity.', | ||
token: mw.user.tokens.get( 'csrfToken' ) | token: mw.user.tokens.get( 'csrfToken' ) | ||
} | } | ||
Line 145: | Line 145: | ||
summary: 'Notification', | summary: 'Notification', | ||
createonly: 1, | createonly: 1, | ||
text: 'Your | text: 'Your rights have been revoked for inactivity.', | ||
token: mw.user.tokens.get( 'csrfToken' ) | token: mw.user.tokens.get( 'csrfToken' ) | ||
} | } |