Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F29748566
raw.txt
No One
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Authored By
Legoktm
Jul 12 2019, 6:32 AM
2019-07-12 06:32:57 (UTC+0)
Size
3 KB
Referenced Files
None
Subscribers
None
raw.txt
View Options
/*
* 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();
File Metadata
Details
Attached
Mime Type
text/plain; charset=utf-8
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
7726241
Default Alt Text
raw.txt (3 KB)
Attached To
Mode
P8739 (An Untitled Masterwork)
Attached
Detach File
Event Timeline
Log In to Comment