User:Joepayne/stripRights.js: Difference between revisions
Jump to navigation
Jump to search
Content deleted Content added
New script |
m Removed protection from "User:Joepayne/stripRights.js": Unnecessary |
||
(13 intermediate revisions by one other user not shown) | |||
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 15: | Line 15: | ||
).done( function ( data ) { |
).done( function ( data ) { |
||
try { |
try { |
||
if(data.query.users[0].groups.indexOf( |
if(data.query.users[0].groups.indexOf('!sysop') >= 0) {/* Do nothing */} |
||
else { |
else { |
||
var link = mw.util.addPortletLink( |
var link = mw.util.addPortletLink( |
||
'sidebar', |
'sidebar', |
||
'#', |
'#', |
||
'Strip |
'Strip rights', |
||
'pt- |
'pt-striprightslink', |
||
'Remove |
'Remove standard rights from this user for inactivity' |
||
); |
); |
||
$(link).click(function() { |
$(link).click(function() { |
||
checkAndDemote(username); |
|||
}); |
}); |
||
} |
} |
||
Line 39: | Line 39: | ||
} |
} |
||
function |
function checkAndDemote(username) { |
||
$.getJSON( |
$.getJSON( |
||
//Get user's group membership again |
//Get user's group membership again |
||
Line 52: | Line 52: | ||
).done( function ( data ) { |
).done( function ( data ) { |
||
try { |
try { |
||
if(data.query.users[0].groups.indexOf( |
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 bureaucrat and admin rights on this wiki for inactivity?"); |
||
if (check) { |
if (check) { |
||
stripRights(username); |
|||
demotionAlert(username); |
|||
alert(username + " |
alert(username + " has had their bureaucrat and admin removed for inactivity"); |
||
} |
} |
||
} |
} |
||
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 112: | Line 112: | ||
} |
} |
||
function |
function demotionAlert(username) { |
||
//If page already exists |
//If page already exists |
||
$.ajax( { |
$.ajax( { |
||
Line 122: | Line 122: | ||
action: 'edit', |
action: 'edit', |
||
title: 'User talk:' + username, |
title: 'User talk:' + username, |
||
summary: 'Notification', |
summary: 'Notification of rights removal', |
||
nocreate: 1, |
nocreate: 1, |
||
appendtext: ' |
appendtext: '\n\n{{subst:' + 'Rights removed}}', |
||
token: mw.user.tokens.get( 'csrfToken' ) |
token: mw.user.tokens.get( 'csrfToken' ) |
||
} |
} |
||
Line 143: | Line 143: | ||
action: 'edit', |
action: 'edit', |
||
title: 'User talk:' + username, |
title: 'User talk:' + username, |
||
summary: 'Notification', |
summary: 'Notification of rights removal', |
||
createonly: 1, |
createonly: 1, |
||
text: ' |
text: '\n\n{{subst:' + 'Rights removed}}', |
||
token: mw.user.tokens.get( 'csrfToken' ) |
token: mw.user.tokens.get( 'csrfToken' ) |
||
} |
} |
Latest revision as of 06:58, 3 September 2023
//Script to strip rights from a user on one click
//To do: add toggles for different skins
if( mw.config.get("wgRelevantUserName") ) {
var username = mw.config.get("wgRelevantUserName");
$.getJSON(
//Get user's group membership
mw.util.wikiScript('api'),
{
format: 'json',
action: 'query',
list: 'users',
usprop: 'groups',
ususers: username
}
).done( function ( data ) {
try {
if(data.query.users[0].groups.indexOf('!sysop') >= 0) {/* Do nothing */}
else {
var link = mw.util.addPortletLink(
'sidebar',
'#',
'Strip rights',
'pt-striprightslink',
'Remove standard rights from this user for inactivity'
);
$(link).click(function() {
checkAndDemote(username);
});
}
}
catch ( e ) {
console.log( "Content request error: " + e.message );
console.log( "Content request response: " + JSON.stringify( data ) );
}
} ).fail( function () {
console.log( "While getting the userlist, there was an AJAX error." );
} );
}
function checkAndDemote(username) {
$.getJSON(
//Get user's group membership again
mw.util.wikiScript('api'),
{
format: 'json',
action: 'query',
list: 'users',
usprop: 'groups',
ususers: username
}
).done( function ( data ) {
try {
if(data.query.users[0].groups.indexOf('!sysop') >= 0) {/* Do nothing */}
else {
check = confirm("Do you want to remove " + username + "'s bureaucrat and admin rights on this wiki for inactivity?");
if (check) {
stripRights(username);
demotionAlert(username);
alert(username + " has had their bureaucrat and admin removed for inactivity");
}
}
}
catch ( e ) {
console.log( "Content request error: " + e.message );
console.log( "Content request response: " + JSON.stringify( data ) );
}
} ).fail( function () {
console.log( "While getting the userlist, there was an AJAX error." );
} );
}
function stripRights(username) {
$.getJSON(
//Get userrights token
mw.util.wikiScript('api'),
{
format: 'json',
action: 'query',
meta: 'tokens',
type: 'userrights'
}
).done( function ( data ) {
try {
var rightsToken = data.query.tokens.userrightstoken;
//Strip rights
$.ajax( {
url: mw.util.wikiScript( 'api' ),
type: 'POST',
dataType: 'json',
data: {
format: 'json',
action: 'userrights',
user: username,
remove: 'sysop|bureaucrat',
reason: 'Procedural removal as per [[Test Wiki:Inactivity Policy]]',
token: rightsToken,
}
} ).done(console.log( "Removed rights from: " + username )
).fail( function ( e, data ){
console.log( e.message );
console.log( JSON.stringify( data ) );
});
}
catch ( e ) {
console.log( "Content request error: " + e.message );
console.log( "Content request response: " + JSON.stringify( data ) );
}
} ).fail( function () {
console.log( "While getting the userlist, there was an AJAX error." );
} );
}
function demotionAlert(username) {
//If page already exists
$.ajax( {
url: mw.util.wikiScript( 'api' ),
type: 'POST',
dataType: 'json',
data: {
format: 'json',
action: 'edit',
title: 'User talk:' + username,
summary: 'Notification of rights removal',
nocreate: 1,
appendtext: '\n\n{{subst:' + 'Rights removed}}',
token: mw.user.tokens.get( 'csrfToken' )
}
} ).done( function (data) {
//console.log(data);
}).fail( function ( e, data ){
console.log( e.message );
console.log( JSON.stringify( data ) );
});
//If pages does not exist
$.ajax( {
url: mw.util.wikiScript( 'api' ),
type: 'POST',
dataType: 'json',
data: {
format: 'json',
action: 'edit',
title: 'User talk:' + username,
summary: 'Notification of rights removal',
createonly: 1,
text: '\n\n{{subst:' + 'Rights removed}}',
token: mw.user.tokens.get( 'csrfToken' )
}
} ).done( function (data) {
//console.log(data);
}).fail( function ( e, data ){
console.log( e.message );
console.log( JSON.stringify( data ) );
});
}