User:Cqm/adminreport.js

/** * Admin report * by User:Cåm */ /*jshint devel:true, jquery:true, indent:4 */ /*global mediaWiki */ (function ($, mw) {	var reportPages = [		'RuneScape:Active_discussions',		'User:Cåm/Scrapbook_7'	];	if ($.inArray(mw.config.get('wgPageName'), reportPages) === -1) {		return;	}	var jsonRequests = {		editDate: [			// requestsForPermissions			{				url: 'RuneScape:Requests_for_permissions',				pageid: '239188',				appendid: 'permissions'			},			// autoWikiBroswer			{				url: 'RuneScape:AutoWikiBrowser/Requests',				pageid: '211974',				appendid: 'awbRequests'			},			// adminRequests			{				url: 'RuneScape:Administrator_requests',				pageid: '197645',				appendid: 'adminRequests'			},			// userHelp			{				url: 'RuneScape:User_help',				pageid: '92936',				appendid: 'userHelp'			},			// counterVandalismUnit			{				url: 'RuneScape:Counter-Vandalism_Unit',				pageid: '3558',				appendid: 'cvu'			}		],		numberInCat: [			// speedyMove			{				url: 'Category:Speedy_move_candidates',				appendid: 'speedyMove' },			// speedyDeletion {				url: 'Category:Speedy_deletion_candidates', appendid: 'speedyDel' },			// requestsForClosure {				url: 'Category:Requests_for_closure', appendid: 'rfClosure' }		],		specialPageReport: [ // brokenRedirects {				url: '', appendid: '' },			// doubleRedirects {				url: '', appendid: '' },			// unusedCategories {				url: '', appendid: '' },			// unusedImages {				url: '', appendid: '' },			// wantedCategories {				url: '', appendid: '' },			// wantedfiles {				url: '', appendid: '' },			// wantedPages {				url: '', appendid: '' },			// wantedtemplates {				url: '', appendid: '' }		]	};

$('#mw-content-text').prepend('  ' +	// permissions	'Permissions  &bull; ' +	// awb requests	'AWB  &bull; ' +	// admin requests	'Admin requests  &bull; ' +	// user help	'User help  &bull; ' +	// cvu	'CVU ' + ' ' +	// speedy move 'Speedy move  &bull; ' + // speedy deletion 'Speedy del  &bull; ' + // requests for closure 'Closure </a>' + ' ' +	'RecentChanges</a> &bull; ' + 'RCH</a> &bull; ' + 'AbuseLog</a> &bull; ' + 'RC Patrol</a>' + ' ' +	// special page report here '  ');	/**	 * Show facebook throbber until loaded	 * Nothing is bound to ajaxStart, but this doesn't work without it being there	 */	$(document).ajaxStart.ajaxStop(function  { $('#reportLoading').hide; $('#reportInner').css('display', 'block'); });

/**	 * Time function * Returns difference between current time and timestamp returned by MediaWiki * Null edits will alter the edit date but aren't shown in ?action=history * 	 * Thanks to Bjelli - http://codereview.stackexchange.com/users/9254/bjelli * For help with this - http://codereview.stackexchange.com/questions/25807/cleaning-up-an-if-else-statement *	 * Inspired by http://momentjs.com */	var unitMillisecondFactors = { ' Millisecond': 1000, ' Second': 60, ' Minute': 60, ' Hour': 24, ' Day': 356, ' Year': 100, };

function time(timestamp) { var n = new Date - new Date(timestamp); for (var unit in unitMillisecondFactors) { var factor = unitMillisecondFactors[unit]; if (n < factor) { n = Math.floor(n); if (n === 1) { return n + unit; } else { return n + unit + 's'; }			}			n = n / factor; }	}

/**	 * Reports the date the page was last edited * Requires individual page ids to access timestamp */ 	var mwtime;

// Requests for permissions - 239188 $.getJSON('/api.php?action=query&prop=info&titles=RuneScape:Requests_for_permissions&format=json', function (data) {		mwtime = data.query.pages['239188'].touched;		$('#permissions').html(time(mwtime));	}); // AutoWikiBrowser requests - 211974 $.getJSON('/api.php?action=query&prop=info&titles=RuneScape:AutoWikiBrowser/Requests&format=json', function (data) {		mwtime = data.query.pages['211974'].touched;		$('#awbRequests').html(time(mwtime));	}); // Administrator requests - 197645 $.getJSON('/api.php?action=query&prop=info&titles=RuneScape:Administrator_requests&format=json', function (data) {		mwtime = data.query.pages['197645'].touched;		$('#adminRequests').html(time(mwtime));	}); // User help - 92936 $.getJSON('/api.php?action=query&prop=info&titles=RuneScape:User_help&format=json', function (data) {		mwtime = data.query.pages['92936'].touched;		$('#userHelp').html(time(mwtime); });	// Counter-vandalism unit - 3558	$.getJSON('/api.php?action=query&prop=info&titles=RuneScape:Counter-Vandalism_Unit&format=json', function (data) { mwtime = data.query.pages['3558'].touched; $('#cvu').html(time(mwtime);	}); /**	 * Reports the number of pages in a category * Adjusted to account for RuneScape:Placeholder */	// Speedy move candidates $.getJSON('/api.php?action=query&list=categorymembers&cmtitle=Category:Speedy_move_candidates&format=json', function (data) {		members = data.query.categorymembers.length;		catLength = members - 1;		$('#speedyMove').html(catLength);	}); // Speedy deletion candidates $.getJSON('/api.php?action=query&list=categorymembers&cmtitle=Category:Speedy_deletion_candidates&format=json', function (data) {		members = data.query.categorymembers.length;		catLength = members - 1;		$('#speedyDel').html(catLength);	}); // Requests for closure $.getJSON('/api.php?action=query&list=categorymembers&cmtitle=Category:Requests_for_closure&format=json', function (data) {		members = data.query.categorymembers.length;		catLength = members - 1;		$('#rfClosure').html(catLength);	}); /**	 * Special page report * Adapted from MediaWiki:Common.js/spreport.js */	// @todo convert w:c:camtest:MediaWiki:Maintenance }(jQuery, mediaWiki)); /* */