User:Void/common.js: Difference between revisions
Content added Content deleted
(accidentally removed this) |
(currently logs inactive users into the console) |
||
Line 15: | Line 15: | ||
); |
); |
||
//Testing js to automate finding inactive sysops. Currently logs |
//Testing js to automate finding inactive sysops. Currently logs inactive users into the console. |
||
/* |
|||
var testlink = mw.util.addPortletLink( |
var testlink = mw.util.addPortletLink( |
||
'p-personal', |
'p-personal', |
||
Line 66: | Line 65: | ||
} |
} |
||
var reducedList = userstring.split(","); |
var reducedList = userstring.split(","); |
||
//console.log(reducedList); |
|||
var tribsData; |
var tribsData; |
||
var logsData; |
var logsData; |
||
Line 89: | Line 87: | ||
try { |
try { |
||
tribsData = data.query.usercontribs; |
tribsData = data.query.usercontribs; |
||
⚫ | |||
logsData = data.query.logevents; |
logsData = data.query.logevents; |
||
//console.log(logsData[0].timestamp); |
|||
console.log(tribsData[0].user); |
|||
var activeLogs, activeTribs, active; |
var activeLogs, activeTribs, active; |
||
var tribsInfo; |
var tribsInfo; |
||
if(typeof(logsData[0].timestamp) != "undefined") { |
if(typeof(logsData[0].timestamp) != "undefined") { |
||
activeLogs = compareDates( logsData[0].timestamp, "logs" ); |
|||
//activeLogs = compareDates( logsData[0].timestamp, "logs" ); |
|||
} |
} |
||
else { |
else { |
||
activeLogs = false; |
|||
activeLogs = null; |
|||
} |
} |
||
if( typeof(tribsData[0]) != "undefined" ) { |
if( typeof(tribsData[0]) != "undefined" ) { |
||
tribsInfo = (tribsData[0].revid+"|"+tribsData[0].timestamp); |
tribsInfo = (tribsData[0].revid+"|"+tribsData[0].timestamp); |
||
activeTribs = compareDates( tribsInfo, "tribs" ); |
|||
//activeTribs = compareDates( tribsInfo, "tribs" ); |
|||
} |
} |
||
else { |
else { |
||
activeTribs = false; |
|||
} |
|||
if( activeLogs === false && activeTribs === false ) { |
|||
⚫ | |||
} |
} |
||
} |
} |
||
Line 117: | Line 111: | ||
console.log( "Content request response: " + JSON.stringify( data ) ); |
console.log( "Content request response: " + JSON.stringify( data ) ); |
||
} |
} |
||
} ).fail(/*console.log( "While getting the userlist, there was an AJAX error." )*/ |
} ).fail(/*console.log( "While getting the userlist, there was an AJAX error." )*/); |
||
} |
} |
||
} |
} |
||
Line 141: | Line 135: | ||
} |
} |
||
today = ''+yyyy+mm+dd; //This is a string |
today = ''+yyyy+mm+dd; //This is a string |
||
//console.log(today); |
|||
var date; |
var date; |
||
var isActive; |
var isActive; |
||
if( dataType === "logs" ){ |
if( dataType === "logs" ){ |
||
date = data.slice(0, |
date = data.slice(0,data.indexOf('T')); |
||
date = |
date = date.replace("-",""); |
||
} |
} |
||
else if( dataType === "tribs" ){ |
else if( dataType === "tribs" ){ |
||
date = |
date = data.slice(data.indexOf('|') + 1, data.indexOf('T')); |
||
date = |
date = date.replace("-",""); |
||
} |
} |
||
if (date < today){ |
if (date < today){ |
||
Line 158: | Line 152: | ||
isActive = true; |
isActive = true; |
||
} |
} |
||
console.log(isActive); |
|||
return isActive; |
return isActive; |
||
} |
} |
||
*/ |
Revision as of 20:45, 7 December 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');
mw.util.addPortletLink(
'p-personal',
mw.util.getUrl("Special:AbuseLog"),
'AbuseLog',
'pt-abuseloglink',
'View the Abuse Log',
null,
'#pt-watchlist'
);
//Testing js to automate finding inactive sysops. Currently logs inactive users into the console.
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);
});
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(",");
var tribsData;
var logsData;
for (x = 0; x < reducedList.length; x++){
$.getJSON(
//Get contribs and log entries
mw.util.wikiScript('api'),
{
format: 'json',
action: 'query',
list: 'logevents|usercontribs',
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 {
tribsData = data.query.usercontribs;
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 ) {
console.log(tribsData[0].user + " is inactive");
}
}
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 ){
//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
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;
}