Page MenuHomePhabricator
Paste P8739

(An Untitled Masterwork)
ActivePublic

Authored by Legoktm on Jul 12 2019, 6:32 AM.
/*
* This script allows to count the number of times a steward has used CheckUser on a wiki.
* It was written in response in to [[Talk:Stewards/CheckUser_statistics_for_loginwiki#Update_required]]
* but can be used for other wikis too.
*
* To run the script, change the month as needed (see queryCheckUserLog() function) and run
* it on your browser console on Special:BlankPage.
*
* Caveats:
* - Only current stewards are counted. Previous stewards' stats have to be counted manually.
* - It assumes that the no. of CUs per steward is maximum 4000 (can be easily changed if needed).
* - It assumes that the max no. of stewards is 150 (also changeable)
*/
var api = new mw.Api();
function getStewards() {
return api.get( {
format: 'json',
action: 'query',
list: 'globalallusers',
agugroup: 'steward',
agulimit: 150 // We probably won't have stewards more than this anytime soon
} );
}
function queryCheckUserLog( username ) {
return api.get( {
format: 'json',
list: 'checkuserlog',
culuser: username,
cullimit: 4000, // eh.. hopefully no one does more than this in a month
culdir: 'newer',
// Please don't change the format unless you know what you're doing or it might break
culfrom: new Date( '1 January 2016 UTC' ).toISOString(), // Start date
culto: new Date( '1 February 2016 UTC' ).toISOString() // End date
} );
}
function appendToPage( text ) {
// Note: text must be trusted!
$( '#mw-content-text' ).append( text + '<br/>' );
}
function getStatsTable( entries ) {
var html =
'<table class="wikitable sortable">\n'
+ '<tr>'
+ '<th> Username </th>'
+ '<th> Count </th>'
+ '</tr>\n';
$.each( entries, function( i, entry ) {
html += '<tr>'
+ '<td>' + mw.html.escape( entry.name ) + '</td>'
+ '<td>' + mw.html.escape( entry.count ) + '</td>'
+ '</tr>\n';
} );
html += '</table>';
return html;
}
function init() {
getStewards().done( function( data ) {
var stewards = data.query.globalallusers,
stewardCount = stewards.length,
totalCount = 0,
stats = [];
promises = []; // promise for all query api requests
appendToPage( '<span id="cu-status">Querying... Please wait.</span>' );
var $status = $( '#cu-status' );
$.each( stewards, function( i, info ) {
var username = info.name;
var queryPromise = queryCheckUserLog( username );
promises.push( queryPromise );
queryPromise.done( function( data ) {
if ( !data.query ) {
onError( data );
}
var cuCount = data.query.checkuserlog.entries.length;
stats.push( {
name: username,
count: cuCount
} );
totalCount += cuCount;
} ).fail( function( data ) {
onError( data );
} );
function onError( data ) {
$status.text( 'Error occured in querying.' );
throw 'Error while querying ' + mw.html.escape( username ) + ' details: ' + JSON.stringify( data );
}
} );
$.when.apply( $, promises ).done( function() {
// Output table once we've the all stats data needed
$status.text( 'Total: ' + totalCount);
appendToPage( getStatsTable( stats ) );
mw.loader.using( 'jquery.tablesorter', function() {
$( 'table' ).tablesorter();
} );
});
} );
}
init();

Event Timeline

Legoktm created this paste.Jul 12 2019, 6:32 AM
Legoktm edited the content of this paste. (Show Details)