User:Void/findInactiveSysops.js: Difference between revisions

add shiny new interface
No edit summary
(add shiny new interface)
Line 16:
 
$( scriptActivationLink ).click( function () {
var progressBar = new OO.ui.ProgressBarWidget();
var doThis = confirm('Do you want to run the script?');
var progressField = new OO.ui.FieldLayout(
if( doThis ) {
progressBar,
$.getJSON(
{
//Get userlist
label: "Fetching users...",
mw.util.wikiScript( 'api' ),
align: 'top'
{
}
format: 'json',
);
action: 'query',
var textPanel = new OO.ui.PanelLayout( {
list: 'allusers',
expanded: false,
augroup: 'bot|sysop|bureaucrat|consul|autopatrolled|rollbacker|interface-admin|flow-bot',
framed: false,
aulimit: 150, //Unlikely to be more than 150 privilged users
padded: false,
}
} );
).done( function ( data ) {
var canSave = false;
try {
var users = data.query.allusers;
function InactiveUsersProc( config ) {
var userlist = [];
InactiveUsersProc.super.call( this, config );
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 ) {
var userstring = userlist.toString();
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++ ) {
userstring = userstring.replace( exempt[i] + ",", "" );
}
var reducedList = userstring.split( "," );
var tribsData;
var logsData;
//Visual output onto the page you activate the script on
$( "#mw-content-text" ).replaceWith( "The following users are inactive:" + "<ul id=\"inactiveList\" style=\"list-style-type:none;list-style-image:none;\"></ul>" );
for ( x = 0; x < reducedList.length; x++ ) {
checkUser( reducedList[x] );
}
OO.inheritClass( InactiveUsersProc, OO.ui.ProcessDialog );
var updButton = new OO.ui.ButtonWidget( {
InactiveUsersProc.static.name = "Inactive Users Process";
label: 'Update Inactive Administrators?',
InactiveUsersProc.static.title = "List of Inactive Users:";
id: 'upd-inactive-bttn'
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 ]);
$("#inactiveList").after( updButton.$element.click( function() { updList(); } ) );
$('#bodyContent').append(windowManager.$element);
}
windowManager.openWindow(inactiveUsersProc);
 
var checked = 0;
function checkUser( user ) {
var inactive = [];
$.getJSON(
//Get userlist
//Get contribs and log entries
mw.util.wikiScript( 'api' ),
{
format: 'json',
action: 'query',
list: 'logevents|usercontribsallusers',
augroup: 'bot|sysop|bureaucrat|consul|autopatrolled|rollbacker|interface-admin|flow-bot',
leprop: 'timestamp',
aulimit: 150, //Unlikely to be more than 150 privilged users
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 {
tribsDatavar users = data.query.usercontribsallusers;
logsDatavar userlist = data.query.logevents[];
users.forEach( function( object ) {
var activeLogs, activeTribs, active;
userlist.push( object.name var tribsInfo);
});
 
filterUsers( userlist );
if( typeof( logsData[0].timestamp ) != "undefined" ) {
activeLogs = compareDates( logsData[0].timestamp, "logs" );
}
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 ) {
Line 114 ⟶ 107:
console.log( "Content request response: " + JSON.stringify( data ) );
}
} ).fail( function () {
} ).fail(/*console.log( "While getting the userlist, there was an AJAX error." )*/);
console.log( "While getting the userlist, there was an AJAX error." );
}
} );
 
function compareDates ( data, dataType ) {
function filterUsers ( userlist ) {
//Gets current date in yyyymmdd
var todayuserstring = new Dateuserlist.toString();
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"];
var dd = today.getDate();
for ( i = 0; i < exempt.length; i++ ) {
var mm = today.getMonth() + 1; //January is 0!
userstring = userstring.replace( exempt[i] + ",", "" );
var yyyy = today.getFullYear();
}
//Set back 3 months
var reducedList = userstring.split( "," );
mm -= 3;
for ( x = 0; x < reducedList.length; x++ ) {
if( mm < 0 ) {
checkUser( reducedList[x], reducedList.length );
mm += 12;
}
yyyy -= 1;
}
if(function ddcheckUser( <user, 10total ) {
$.getJSON(
dd = '0' + dd;
mw.util.wikiScript( 'api' ),
}
{
 
format: 'json',
if( mm<10 ) {
mm = '0' + mm; action: 'query',
list: 'logevents|usercontribs',
}
leprop: 'timestamp',
today = '' + yyyy + mm + dd; //This is a string
ledir: 'older',
 
leuser: user,
var date;
lelimit: 1, //We only need the most recent log action/edit
var isActive;
uclimit: 1,
if( dataType === "logs" ) {
ucuser: user,
date = data.slice( 0, data.indexOf('T') );
ucdir: 'older',
date = date.replace( "-", "" );
ucprop: 'timestamp|ids'
}
).done( function ( data ) {
try {
var tribsData = data.query.usercontribs;
var logsData = data.query.logevents;
var activeLogs, activeTribs, active;
var tribsInfo;
if( typeof( logsData[0].timestamp ) != "undefined" ) {
activeLogs = compareDates( logsData[0].timestamp, "logs" );
}
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 ) {
inactive.push([user, tribsData, logsData]);
}
checked++;
progressBar.setProgress( parseInt(checked / total) * 100 );
if( checked == total ) {
listInactiveUsers();
}
}
catch ( e ) {
console.log( "Content request error: " + e.message );
console.log( "Content request response: " + JSON.stringify( data ) );
}
} );
}
else if( dataType === "tribs" ) {
function compareDates ( data, dataType ) {
date = data.slice( data.indexOf('|') + 1, data.indexOf('T') );
date//Gets =current date.replace( "-", ""in );yyyymmdd
var today = new Date();
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 ) {
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( "-", "" );
}
if ( date < today ) {
isActive = false;
}
else {
isActive = true;
}
return isActive;
}
if ( date < today ) {
function listInactiveUsers() {
isActive = false;
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;
}
else {
function updList() {
isActive = true;
var list = textPanel.$element[0].innerText;
}
list = '|-\n|' + list;
return isActive;
while( list.indexOf("\n[[User:") > 0 ) {
}
list = list.substr( 0, list.indexOf( "\n[[User:" ) ) + '\n|-\n|' + list.substr( list.indexOf( "\n[[User:" ) + 1 );
 
}
function listInactiveUsers( userName, tribsArray, logsArray ) {
$.getJSON(
var userLink = "[[User:<a href=\"https://publictestwiki.com/wiki/Special:Contribs/" + userName + "\">" + userName + "</a>|" + userName + "]]";
mw.util.wikiScript( 'api' ),
var tribsInfo;
{
if( tribsArray[0] !== undefined ) {
format: 'json',
tribsInfo = tribsArray[0].timestamp;
action: 'query',
tribsInfo = tribsInfo.slice( 0, tribsInfo.indexOf("T") );
pageids: 238,
tribsInfo = tribsArray[0].revid + "|" + tribsInfo;
prop: 'revisions',
tribsInfo = "[[Special:PermanentLink/" + tribsInfo + "]]";
rvprop: 'content'
}
}
else {
).done( function ( data ) {
tribsInfo = 'None';
try {
}
var wtext = data.query.pages[238].revisions[0]['*'];
var logsInfo = logsArray[0].timestamp;
wtext = wtext.substr( 0, wtext.indexOf("|-") ) + list + '\n' + wtext.substr( wtext.indexOf( "|}" ) );
logsInfo = logsInfo.slice( 0, logsInfo.indexOf("T") );
$.ajax( {
logsInfo = "[[Special:Log/" + userName + "|" + logsInfo + "]]";
url: mw.util.wikiScript( 'api' ),
$("#inactiveList").append( "<li>" + userLink + " || " + tribsInfo + " || " + logsInfo + "</li>" );
type: 'POST',
}
dataType: 'json',
 
data: {
function updList() {
format: 'json',
var list = $("#inactiveList")[0].innerText;
action: 'edit',
list = '|-\n|' + list;
title: 'TestWiki:Inactivity/Inactive administrators',
while( list.indexOf("\n[[User:") > 0 ) {
text: wtext,
list = list.substr( 0, list.indexOf( "\n[[User:" ) ) + '\n|-\n|' + list.substr( list.indexOf( "\n[[User:" ) + 1 );
summary: '[[User:Void/findInactiveSysops.js|Automatically]] updating list',
token: mw.user.tokens.get( 'csrfToken' ),
}
} ).done( function() {
alert( "Updated TestWiki:Inactivity/Inactive administrators" );
var reload = new OO.ui.ButtonWidget( { label: 'Load original page' } );
$('#upd-inactive-bttn').replaceWith( reload.$element.click( function() { window.location.reload(); } ) );
} ).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 ) );
} );
}
} );
$.getJSON(
mw.util.wikiScript( 'api' ),
{
format: 'json',
action: 'query',
pageids: 238,
prop: 'revisions',
rvprop: 'content'
}
).done( function ( data ) {
try {
var wtext = data.query.pages[238].revisions[0]['*'];
wtext = wtext.substr( 0, wtext.indexOf("|-") ) + list + '\n' + wtext.substr( wtext.indexOf( "|}" ) );
$.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" );
var reload = new OO.ui.ButtonWidget( { label: 'Load original page' } );
$('#upd-inactive-bttn').replaceWith( reload.$element.click( function() { window.location.reload(); } ) );
} ).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 ) );
} );
}
 
});