User:Void/common.js: Difference between revisions

From TestWiki
Content added Content deleted
(it's not as effective, but it works for now; need to replace most of the .push with string methods (arrays DON'T work))
(befuddling)
Line 57: Line 57:
var reducedList = userstring.split(",");
var reducedList = userstring.split(",");
//console.log(reducedList);
//console.log(reducedList);
var returnedData;
var logsData;
var logsString = "\"timestamp\":\""; //Set these here, because I'm too lazy to count the length myself
var tribsString = "\"revid\":";
var tribsInfo = [];
var tribsData;
var tribsData;
var logsInfo = [];
var logsInfo = [];
var logsData;
var tribsInfo = [];
for (x = 0; x < reducedList.length; x++){
for (x = 0; x < reducedList.length; x++){
logsData = getData( reducedList, "logevents", x );
tribsData = getData( reducedList, "usercontribs", x );
logsInfo.push(logsData);
tribsInfo.push(tribsData);
}
//console.log(reducedList);
console.log(logsInfo[0]);
console.log(tribsInfo[0]);
//compareDates(reducedList, logsInfo, tribsInfo);
}
function getData( reducedList, type, x ){
$.getJSON(
$.getJSON(
//Get contribs and log entries
//Get contribs and log entries
Line 71: Line 79:
format: 'json',
format: 'json',
action: 'query',
action: 'query',
list: 'logevents|usercontribs',
list: type,
leprop: 'timestamp',
leprop: 'timestamp',
ledir: 'older',
ledir: 'older',
Line 83: Line 91:
).done( function ( data ) {
).done( function ( data ) {
try {
try {
var returnedData;
var logsString = "\"timestamp\":\""; //Set these here, because I'm too lazy to count the length myself
var tribsString = "\"revid\":";
var tribsData;
var logsData;
returnedData = JSON.stringify( data );
returnedData = JSON.stringify( data );
//console.log(returnedData);
//console.log(returnedData);
logsData = returnedData.slice( returnedData.indexOf( logsString ) + logsString.length, returnedData.indexOf('T') );
logsData = returnedData.slice( returnedData.indexOf( logsString ) + logsString.length, returnedData.indexOf('T') );
//console.log(logsData);
//console.log(logsData);
tribsData = returnedData.slice( returnedData.indexOf( tribsString ) + tribsString.length, returnedData.indexOf(",\"parentid\"") );
if ( tribsData.indexOf( tribsString ) >= 0 ) {
tribsData = tribsData + '|' + returnedData.slice( returnedData.lastIndexOf( logsString ) + logsString.length, returnedData.lastIndexOf('T'));
tribsData = returnedData.slice( returnedData.indexOf( tribsString ) + tribsString.length, returnedData.indexOf(",\"parentid\"") );
tribsData = tribsData + '|' + returnedData.slice( returnedData.lastIndexOf( logsString ) + logsString.length, returnedData.lastIndexOf('T'));
}
//console.log(tribsData);
//console.log(tribsData);
if( logsData.length > 0 ) {
if( logsData.length > 0 && type == "logevents") {
//logsInfo.push(logsData); DO NOT PUSH OBJECTS TO AN ARRAY!
return logsData;
}
}
else {
else if( type == "logevents" ) {
//logsInfo.push(null);
return null;
}
}
if( tribsData.length > 0 ) {
if( tribsData.length > 0 && type == "usercontribs" ) {
//tribsInfo.push(tribsData);
return tribsData;
}
}
else {
else if( type == "usercontribs" ) {
//tribsInfo.push(null);
return null;
}
}
}
}
Line 108: Line 123:
}
}
} ).fail(/*console.log( "While getting the userlist, there was an AJAX error." )*/);
} ).fail(/*console.log( "While getting the userlist, there was an AJAX error." )*/);
}
//console.log(reducedList);
//console.log(logsInfo[0]);
//console.log(tribsInfo[0]);
//compareDates(reducedList, logsInfo, tribsInfo);
}
}
function compareDates (reducedList, logsInfo, tribsInfo){
function compareDates (reducedList, logsInfo, tribsInfo){

Revision as of 21:37, 11 November 2016

mw.loader.load('//en.wikipedia.org/w/index.php?action=raw&ctype=text/javascript&title=User:Writ_Keeper/Scripts/massRevdel.js');
mw.loader.load('//en.wikipedia.org/w/index.php?action=raw&ctype=text/javascript&title=User:Writ_Keeper/Scripts/massRollback.js');
mw.loader.load('//www.mediawiki.org/w/index.php?title=MediaWiki:Gadget-DotsSyntaxHighlighter.js&action=raw&ctype=text/javascript');
mw.loader.load('//tools-static.wmflabs.org/meta/scripts/pathoschild.templatescript.js');
//mw.loader.load('//publictestwiki.com/w/index.php?title=User:Void/testing.js&action=raw&ctype=text/javascript');

//Testing js to automate finding inactive sysops. Currently logs usernames, logevent timestamps, and revision ids|timestamps.
var testlink = mw.util.addPortletLink(
    'p-personal',
    '#',
    'Test Script',
    'pt-testscript',
    'Test this piece of JS',
    null,
    '#pt-adminlinks'
);

$( testlink ).click( function () {
	var doThis = confirm('Do you want to run the script?');
	if( doThis ){
		$.getJSON(
			//Get userlist
            mw.util.wikiScript('api'),
            {
                format: 'json',
                action: 'query',
                list: 'allusers',
                augroup: 'sysop',
                aulimit: 50, //Set limit to 50 as there are no more than 50 sysops
            }
        ).done( function ( data ) {
            try {
            	var users = data.query.allusers;
            	var userlist = [];
            	users.forEach(function(object){
            		userlist.push(object.name);
            	});
            	//console.log(userlist);
            	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","Pup","Void","NDKilla","Reception123","Revi","Southparkfan","Abuse filter"];
	for (i = 0; i < exempt.length; i++){
		userstring = userstring.replace(exempt[i]+",","");
	}
	var reducedList = userstring.split(",");
	//console.log(reducedList);
	var logsData;
	var tribsData;
	var logsInfo = [];
	var tribsInfo = [];
	for (x = 0; x < reducedList.length; x++){
		logsData = getData( reducedList, "logevents", x );
		tribsData = getData( reducedList, "usercontribs", x );
		logsInfo.push(logsData);
		tribsInfo.push(tribsData);
	}
	//console.log(reducedList);
	console.log(logsInfo[0]);
	console.log(tribsInfo[0]);
	//compareDates(reducedList, logsInfo, tribsInfo);
}
function getData( reducedList, type, x ){
		$.getJSON(
		//Get contribs and log entries
            mw.util.wikiScript('api'),
            {
                format: 'json',
                action: 'query',
                list: type,
                leprop: 'timestamp',
                ledir: 'older',
                leuser: reducedList[x],
                lelimit: 1, //We only need the most recent log action/edit
                uclimit: 1,
                ucuser: reducedList[x],
                ucdir: 'older',
                ucprop: 'timestamp|ids'
            }
        ).done( function ( data ) {
            try {
            	var returnedData;
				var logsString = "\"timestamp\":\""; //Set these here, because I'm too lazy to count the length myself
				var tribsString = "\"revid\":";
				var tribsData;
				var logsData;
            	returnedData = JSON.stringify( data );
            	//console.log(returnedData);
            	logsData = returnedData.slice( returnedData.indexOf( logsString ) + logsString.length, returnedData.indexOf('T') );
            	//console.log(logsData);
            	if ( tribsData.indexOf( tribsString ) >= 0 ) {
            		tribsData = returnedData.slice( returnedData.indexOf( tribsString ) + tribsString.length, returnedData.indexOf(",\"parentid\"") );
            		tribsData = tribsData + '|' + returnedData.slice( returnedData.lastIndexOf( logsString ) + logsString.length, returnedData.lastIndexOf('T'));
            	}
            	//console.log(tribsData);
            	if( logsData.length > 0 && type == "logevents") {
            		return logsData;
            	}
            	else if( type == "logevents" ) {
            		return null;
            	}
            	if( tribsData.length > 0 && type == "usercontribs" ) {
            		return tribsData;
            	}
            	else if( type == "usercontribs" ) {
            		return null;
            	}
            }
        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 (reducedList, logsInfo, tribsInfo){
	//Gets current date 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
	//console.log(today);
	var isActive = [];
	var logdate;
	var tribdate;
	//for (i=0; i < reducedList.length; i++){
		logdate = logsInfo[0].slice(0,logsInfo[0].indexOf('T'));
		logdate = logdate.replace("-","");
		tribdate = tribsInfo[0].slice(tribsInfo[0].indexOf('|'), tribsInfo[0].indexOf('T'));
		tribdate = tribdate.replace("-","");
		if (logdate < today || tribdate < today){
			isActive.push(false);
		}
		else{
			isActive.push(true);
		}
	//}
	console.log(isActive);
}