User:Void/findInactiveSysops.js: Difference between revisions

revert last update as it's not loading
(revisions property without rvslots is depreciated)
(revert last update as it's not loading)
Line 1:
/* jslint strict:false */
//<nowiki>
//This script automates the process of finding inactive sysops.
Line 5 ⟶ 4:
//Output is in the format of "[[User:Example|Example]] || [[Special:PermanentLink/1234|timestamp]] || [[Special:Log/Example|timestamp]]"
mw.loader.using(['oojs-ui', 'mediawiki.util']).done( function () {
var scriptActivationLink = mw.util.addPortletLink(
'p-tb',
'#',
'Find Inactive Sysops',
'pt-testscript',
'Replaces the contents of the current page with a list of inactive sysops',
null,
'#pt-adminlinks'
);
 
$(var scriptActivationLink )= mw.clickutil.addPortletLink( function () {
'p-tb',
var progressBar = new OO.ui.ProgressBarWidget();
'#',
var progressField = new OO.ui.FieldLayout(
'Find Inactive Sysops',
progressBar,
'pt-testscript',
{
'Replaces the contents of the current page with a list of inactive sysops',
label: "Fetching users...",
null,
align: 'top'
'#pt-adminlinks'
}
);
 
$( scriptActivationLink ).click( function () {
var textPanel = new OO.ui.PanelLayout( {
var doThis = confirm('Do you want to run the script?');
expanded: false,
if( doThis ) {
framed: false,
padded: false,
} );
 
var canSave = false;
function InactiveUsersProc( config ) {
InactiveUsersProc.super.call( this, config );
}
OO.inheritClass( InactiveUsersProc, OO.ui.ProcessDialog );
 
InactiveUsersProc.static.name = "Inactive Users Process";
InactiveUsersProc.static.title = "List of Inactive Users:";
InactiveUsersProc.static.actions = [
{
action: "save",
label: "Update",
flags: "primary"
},
{
label: "Cancel",
flags: "safe"
}
];
 
InactiveUsersProc.prototype.initialize = function() {
InactiveUsersProc.super.prototype.initialize.apply( this, arguments );
 
this.content = new OO.ui.FieldsetLayout();
this.content.addItems([ progressField ]);
this.content.$element.css( 'padding', '1em' );
 
this.$body.append( this.content.$element );
};
InactiveUsersProc.prototype.getActionProcess = function( action ) {
var dialog = this;
if( action && canSave ) {
return new OO.ui.Process( function() {
if( action == "save" ) {
updList();
}
 
dialog.close( {
action: action
} );
});
}
return InactiveUsersProc.super.prototype.getActionProcess.call( this, action );
};
InactiveUsersProc.prototype.getBodyHeight = function() {
return this.content.$element.outerHeight( true );
};
var windowManager = new OO.ui.WindowManager();
var inactiveUsersProc = new InactiveUsersProc( {
size: "large"
} );
 
windowManager.addWindows([ inactiveUsersProc ]);
$('#bodyContent').append(windowManager.$element);
windowManager.openWindow(inactiveUsersProc);
 
var checked = 0;
var inactive = [];
 
// Get user list
$.getJSON(
//Get userlist
mw.util.wikiScript( 'api' ),
mw.util.wikiScript( 'api' ),
{
format: 'json',{
action format: 'queryjson',
list action: 'allusersquery',
list: 'allusers',
augroup: 'bot|sysop|bureaucrat|consul|autopatrolled|rollbacker|interface-admin|flow-bot',
augroup: 'bot|sysop|bureaucrat|consul|autopatrolled|rollbacker|interface-admin|flow-bot',
aulimit: 150 // Unlikely to be more than 150 privilged users
aulimit: 150, //Unlikely to be more than 150 privilged users
}
).done( function ( data ) { }
try).done( function ( data ) {
var users = data.query.allusers; try {
var userlistusers = []data.query.allusers;
var userlist = [];
users.forEach( function( object ) {
userlist.push( object.name );
});
filterUsers( userlist );
}
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 filterUsers ( userlist ) {
users.forEach( function( object ) {
var userstring = userlist.pushtoString( object.name );
var exempt = ["John", "Void", "NDKilla", "Reception123", "Revi", "Southparkfan", "Abuse filter", "Void-bot", "Voidwalker", "Paladox", "Zppix", "ZppixBot", "RhinosF1", "MediaWiki message delivery", "ZI Jony", "Bonnedav", "Babel AutoCreate", "HeartsDo"];
});
for ( i = 0; i < exempt.length; i++ ) {
filterUsers( userlist );
userstring = userstring.replace( exempt[i] + ",", "" );
}
}
catch ( e ) {
var reducedList = userstring.split( "," );
console.log( "Content request error: " + e.message );
var tribsData;
console.log( "Content request response: " + JSON.stringify( data ) );
var logsData;
}
//Visual output onto the page you activate the script on
} ).fail( function () {
$( "#mw-content-text" ).replaceWith( "The following users are inactive:" + "<ul id=\"inactiveList\" style=\"list-style-type:none;list-style-image:none;\"></ul>" );
console.log( "While getting the userlist, there was an AJAX error." );
for ( x = 0; x < reducedList.length; x++ ) {
} );
checkUser( reducedList[x] );
}
var updButton = new OO.ui.ButtonWidget( {
label: 'Update Inactive Administrators?',
id: 'upd-inactive-bttn'
} );
$("#inactiveList").after( updButton.$element.click( function() { updList(); } ) );
}
 
function filterUsers checkUser( userlistuser ) {
$.getJSON(
var userstring = userlist.toString();
//Get contribs and log entries
var exempt = ["John", "Void", "NDKilla", "Reception123", "Revi", "Southparkfan", "Abuse filter", "Void-bot", "Voidwalker", "Paladox", "Zppix", "ZppixBot", "RhinosF1", "MediaWiki message delivery", "ZI Jony", "Bonnedav", "Babel AutoCreate", "HeartsDo"];
mw.util.wikiScript( 'api' ),
{
format: 'json',
action: 'query',
list: 'logevents|usercontribs',
leprop: 'timestamp',
ledir: 'older',
leuser: user,
lelimit: 1, //We only need the most recent log action/edit
uclimit: 1,
ucuser: user,
ucdir: 'older',
ucprop: 'timestamp|ids'
}
).done( function ( data ) {
try {
tribsData = data.query.usercontribs;
logsData = data.query.logevents;
var activeLogs, activeTribs, active;
var tribsInfo;
 
if( typeof( logsData[0].timestamp ) != "undefined" ) {
for ( i = 0; i < exempt.length; i++ ) {
activeLogs = compareDates( logsData[0].timestamp, "logs" );
userstring = userstring.replace( exempt[i] + ",", "" );
}
}
else {
activeLogs = false;
}
if( typeof( tribsData[0] ) != "undefined" ) {
tribsInfo = tribsData[0].revid + "|" + tribsData[0].timestamp;
activeTribs = compareDates( tribsInfo, "tribs" );
}
else {
activeTribs = false;
}
if( activeLogs === false && activeTribs === false ) {
console.log( user + " is inactive" );
listInactiveUsers( user, tribsData, logsData );
}
}
catch ( e ) {
console.log( "Content request error: " + e.message );
console.log( "Content request response: " + JSON.stringify( data ) );
}
} ).fail(/*console.log( "While getting the userlist, there was an AJAX error." )*/);
}
 
function compareDates ( data, dataType ) {
var reducedList = userstring.split( "," );
//Gets current date in yyyymmdd
for ( x = 0; x < reducedList.length; x++ ) {
var today = new Date();
checkUser( reducedList[x], reducedList.length );
var dd = today.getDate();
}
var mm = today.getMonth() + 1; //January is 0!
}
var yyyy = today.getFullYear();
//Set back 3 months
mm -= 3;
if( mm < 0 ) {
mm += 12;
yyyy -= 1;
}
if( dd < 10 ) {
dd = '0' + dd;
}
 
if( mm<10 ) {
function checkUser( user, total ) {
mm = '0' + mm;
$.getJSON(
}
mw.util.wikiScript( 'api' ),
today = '' + yyyy + mm + dd; //This is a string
{
format: 'json',
action: 'query',
list: 'logevents|usercontribs',
leprop: 'timestamp',
ledir: 'older',
leuser: user,
lelimit: 1, //We only need the most recent log action/edit
uclimit: 1,
ucuser: user,
ucdir: 'older',
ucprop: 'timestamp|ids'
}
).done( function ( data ) {
try {
var tribsData = data.query.usercontribs;
var logsData = data.query.logevents;
var activeLogs, activeTribs, active, tribsInfo;
 
var date;
if( typeof( logsData[0].timestamp ) != "undefined" ) {
var isActive;
activeLogs = compareDates( logsData[0].timestamp, "logs" );
if( dataType === "logs" ) {
} else {
date = data.slice( 0, data.indexOf('T') );
activeLogs = false;
date = date.replace( "-", "" );
}
}
else if( dataType === "tribs" ) {
date = data.slice( data.indexOf('|') + 1, data.indexOf('T') );
date = date.replace( "-", "" );
}
if ( date < today ) {
isActive = false;
}
else {
isActive = true;
}
return isActive;
}
 
function listInactiveUsers( userName, tribsArray, logsArray ) {
if( typeof( tribsData[0] ) != "undefined" ) {
var userLink = "[[User:<a href=\"https://publictestwiki.com/wiki/Special:Contribs/" + userName + "\">" + userName + "</a>|" + userName + "]]";
tribsInfo = tribsData[0].revid + "|" + tribsData[0].timestamp;
var tribsInfo;
activeTribs = compareDates( tribsInfo, "tribs" );
if( tribsArray[0] !== undefined ) {
} else {
tribsInfo = tribsArray[0].timestamp;
activeTribs = false;
tribsInfo = tribsInfo.slice( 0, tribsInfo.indexOf("T") );
}
tribsInfo = tribsArray[0].revid + "|" + tribsInfo;
tribsInfo = "[[Special:PermanentLink/" + tribsInfo + "]]";
}
else {
tribsInfo = 'None';
}
var logsInfo = logsArray[0].timestamp;
logsInfo = logsInfo.slice( 0, logsInfo.indexOf("T") );
logsInfo = "[[Special:Log/" + userName + "|" + logsInfo + "]]";
$("#inactiveList").append( "<li>" + userLink + " || " + tribsInfo + " || " + logsInfo + "</li>" );
}
 
function updList() {
if( activeLogs === false && activeTribs === false ) {
var list = $("#inactiveList")[0].innerText;
inactive.push([user, tribsData, logsData]);
list = '|-\n|' + list;
}
while( list.indexOf("\n[[User:") > 0 ) {
 
list = list.substr( 0, list.indexOf( "\n[[User:" ) ) + '\n|-\n|' + list.substr( list.indexOf( "\n[[User:" ) + 1 );
checked++;
}
progressBar.setProgress( parseInt(checked / total) * 100 );
$.getJSON(
 
mw.util.wikiScript( 'api' ),
if( checked == total ) {
listInactiveUsers();{
} format: 'json',
} catch ( e )action: {'query',
pageids: 238,
console.log( "Content request error: " + e.message );
prop: 'revisions',
console.log( "Content request response: " + JSON.stringify( data ) );
rvprop: 'content'
}
} ); }
).done( function ( data ) {
}
try {
var wtext = data.query.pages[238].revisions[0]['*'];
function compareDates ( data, dataType ) {
wtext = wtext.substr( 0, wtext.indexOf("|-") ) + list + '\n' + wtext.substr( wtext.indexOf( "|}" ) );
//Gets current date in yyyymmdd
$.ajax( {
var today = new Date();
url: mw.util.wikiScript( 'api' ),
var dd = today.getDate();
type: 'POST',
var mm = today.getMonth() + 1; //January is 0!
dataType: 'json',
var yyyy = today.getFullYear();
data: {
 
//Set back 3 months
mm -= 3;
if( mm < 0 ) {
mm += 12;
yyyy -= 1;
}
 
if( dd < 10 ) {
dd = '0' + dd;
}
 
if( mm<10 ) {
mm = '0' + mm;
}
 
today = '' + yyyy + mm + dd; //This is a string
var date;
var isActive;
 
if( dataType === "logs" ) {
date = data.slice( 0, data.indexOf('T') );
date = date.replace( "-", "" );
} else if( dataType === "tribs" ) {
date = data.slice( data.indexOf('|') + 1, data.indexOf('T') );
date = date.replace( "-", "" );
}
 
return date >= today;
}
 
function listInactiveUsers() {
sorted = inactive.sort( function( a, b ) {
return a[0].localeCompare( b[0] );
} );
 
for( var i in sorted ) {
var userName = sorted[i][0];
var tribsArray = sorted[i][1];
var logsArray = sorted[i][2];
var userLink = "[[User:<a href=\"https://publictestwiki.com/wiki/Special:Contribs/" + userName + "\">" + userName + "</a>|" + userName + "]]";
 
var tribsInfo;
if( tribsArray[0] !== undefined ) {
tribsInfo = tribsArray[0].timestamp;
tribsInfo = tribsInfo.slice( 0, tribsInfo.indexOf("T") );
tribsInfo = tribsArray[0].revid + "|" + tribsInfo;
tribsInfo = "[[Special:PermanentLink/" + tribsInfo + "]]";
} else {
tribsInfo = 'None';
}
 
var logsInfo = logsArray[0].timestamp;
logsInfo = logsInfo.slice( 0, logsInfo.indexOf("T") );
logsInfo = "[[Special:Log/" + userName + "|" + logsInfo + "]]";
 
textPanel.$element.append( "<li>" + userLink + " || " + tribsInfo + " || " + logsInfo + "</li>" );
}
inactiveUsersProc.content.clearItems();
inactiveUsersProc.content.addItems([textPanel]);
inactiveUsersProc.updateSize();
canSave = true;
}
function updList() {
var list = textPanel.$element[0].innerText;
list = '|-\n|' + list;
while( list.indexOf("\n[[User:") > 0 ) {
list = list.substr( 0, list.indexOf( "\n[[User:" ) ) + '\n|-\n|' + list.substr( list.indexOf( "\n[[User:" ) + 1 );
}
 
// Get contents of TestWiki:Inactivity/Inactive administrators
$.getJSON(
mw.util.wikiScript( 'api' ),
{
format: 'json',
action: 'queryedit',
pageidstitle: 238'TestWiki:Inactivity/Inactive administrators',
proptext: 'revisions'wtext,
rvpropsummary: 'content[[User:Void/findInactiveSysops.js|Automatically]] updating list',
rvslotstoken: mw.user.tokens.get( 'maincsrfToken' ),
}
} ).done( function ( data ) {
alert( "Updated TestWiki:Inactivity/Inactive administrators" );
try {
var reload = new OO.ui.ButtonWidget( { label: 'Load original page' } );
var wtext = data.query.pages[238].revisions[0].slots.main['*'];
$('#upd-inactive-bttn').replaceWith( reload.$element.click( function() { window.location.reload(); } ) );
wtext = wtext.substr( 0, wtext.indexOf("|-") ) + list + '\n' + wtext.substr( wtext.indexOf( "|}" ) );
} ).fail( function ( e, data ) {
console.log( e.message );
console.log( JSON.stringify( data ) );
} );
}
catch( e ) {
// ignore
}
} ).fail( function ( e, data ) {
console.log( e.message );
console.log( JSON.stringify( data ) );
} );
}
 
$.ajax( {
url: mw.util.wikiScript( 'api' ),
type: 'POST',
dataType: 'json',
data: {
format: 'json',
action: 'edit',
title: 'TestWiki:Inactivity/Inactive administrators',
text: wtext,
summary: '[[User:Void/findInactiveSysops.js|Automatically]] updating list',
token: mw.user.tokens.get( 'csrfToken' ),
}
} ).done( function() {
alert( "Updated TestWiki:Inactivity/Inactive administrators" );
} ).fail( function ( e, data ) {
console.log( e.message );
console.log( JSON.stringify( data ) );
} );
}
catch( e ) {
// ignore
}
} ).fail( function ( e, data ) {
console.log( e.message );
console.log( JSON.stringify( data ) );
} );
}
} );
});
//</nowiki>