MediaWiki:MaintenanceReport.js

/* There are two ways to view MaintenanceReport: a div or a modal.

*Special:MaintenanceReport to auto-start in a div *Add to any page to auto-start in a div *Or, add Maintenance Report to any page for a button which launches a modal popup.



$(function {	if ( (!$('#MaintenanceReport').size && mw.config.get('wgCanonicalNamespace')+":"+mw.config.get('wgTitle') != "Special:MaintenanceReport") || typeof window.maintenanceReport != "undefined" ) return; //skip non-relevant pages and avoid duplicate instances.

window.maintenanceReport = { "options": { removeZero: 1, 		//set to true to remove pages with zero results addButton: false 		//set to true to add a button instead of autostarting. } };

maintenanceReport.results = {}; maintenanceReport.specials = new Array("Unusedcategories", "BrokenRedirects", "DoubleRedirects", "Deadendpages", "Lonelypages", "Uncategorizedcategories", "Uncategorizedpages", "Uncategorizedtemplates", "Wantedcategories", "Wantedfiles", "Wantedpages", "Wantedtemplates", "Unusedtemplates"); maintenanceReport.categories = new Array("Lonelypages", "DPL queries with no results", "DPL queries with errors", "Deletion proposals", "Merge proposals", "Dialogue template with one line", "Broken references", "Broken file links","Template errors","ParserFunction errors", "Template has invalid parameters","References needing descriptions","References needing names","Cleanup","Content requests","Image requests","Infobox needs information","Reference requests","Rating requests","Translation requests","Unconfirmed information");

if (mw.config.get('wgCanonicalNamespace')+":"+mw.config.get('wgTitle') == "Special:MaintenanceReport") { $("title").html("Maintenance Report"); $("#WikiaPageHeader h1").html("Maintenance Report"); $("h1#firstHeading").html("Maintenance Report"); $("#mw-content-text").html($(" ", {id:"MaintenanceReport" }) ); }	if (maintenanceReport.options.addButton) $('#MaintenanceReport').after($(" "), $(" ", { id:"MaintenanceReport", class:"button", html:"Start Maintenance Report" })).remove; if ($('#MaintenanceReport.button').size) $('#MaintenanceReport.button').click(function { MaintenanceReportInit(1) }); else MaintenanceReportInit; });

function showResult(message, result) { if (typeof window.MaintenanceReportNotify != "undefined") window.MaintenanceReportNotify.hide; window.MaintenanceReportNotify = new BannerNotification(message, result).show; }

function MaintenanceReportDisplay(andor) { var temp, output = new Array; $("input").each(function{		if($(this).attr("checked")) {			temp = maintenanceReport.results[$(this).attr("id").substring(5)];			if (!output.length) {				output = output.concat(temp);			} else if (andor == 1) {				output = output.filter(function(i) { return temp.indexOf(i) == -1; });									output = output.concat(temp);			} else if (andor == 2) {				output = output.filter(function(i) { return temp.indexOf(i) != -1; });			}		}	});	$("#resultsPane ol").html(""); $(output).each(function(index, value) { 		$("#resultsPane ol").append(''+value+'');	}); }

function MaintenanceReportInit(modal) { var ajaxIndicator = window.ajaxIndicator || 'http://images.wikia.nocookie.net/common/skins/common/images/ajax.gif'; if(modal) { $("#MaintenanceReport").attr("id",""); $.showCustomModal('Maintenance Report', null, {			id: 'MaintenanceReportModal',			width: $(window).width - 254,		}); $(".modalContent").remove; $("#MaintenanceReportModal").css({"top":"100px","min-height":"452px"}); $("#MaintenanceReportModal h1").css({"margin-bottom":0,"text-align":"left"}).append("  "); $("#MaintenanceReportModal").append($(" ", {id:"MaintenanceReport", class:"WikiaArticle"})); $("#MaintenanceReportModal").css({			"text-align":"center",			overflow: "auto",		}); } else { $("#MaintenanceReport").empty; }	$("#MaintenanceReport").append(" "); $("#MaintenanceReport").append(" "); $("#listPane").append(		$(" ", { id:"MaintenanceReportDisplay1", html:"Show Combined" }).click(function { MaintenanceReportDisplay(1) })	); $("#listPane").append(		$(" ", { id:"MaintenanceReportDisplay2", html:"Show Intersection", style:"float:right;" }).click(function { MaintenanceReportDisplay(2) })	);

for(var i in maintenanceReport.specials) { $("#listPane").append(" "+maintenanceReport.specials[i]+" (View) Loading "); $.getJSON('/api.php?action=query&format=json&list=querypage&qplimit=5000&qppage='+maintenanceReport.specials[i], function(result) {		 var formattedresults = new Array;		  var querypage = result.query.querypage;		  $(querypage.results).each(function(index, value) { if (querypage.name == "Unusedcategories") if (maintenanceReport.categories.indexOf("value.title") == -1) return; formattedresults.push(value.title); });		 $("#checkS"+querypage.name +" ~ span").html(" ("+formattedresults.length+")");		  		  $("#checkS"+querypage.name +" ~ span").removeClass("loading");		  if (!$("span.loading").size) $("#ajaxProgress").remove;

maintenanceReport.results["S"+querypage.name] = formattedresults;

if (!formattedresults.length) { $("#checkS"+querypage.name).prop("disabled",true); if (maintenanceReport.options.removeZero) $("#checkS"+querypage.name).parent.remove; }		 if (querypage.cachedtimestamp) { diff = count=Math.floor((new Date(new Date(querypage.cachedtimestamp).getTime+(24*60*60000)).getTime-new Date.getTime)/1000); if ($("#updateCountdown").attr("left") < diff) { $("#updateCountdown").attr("left", diff); var left = (diff%60) + 's';					diff=Math.floor(diff/60); if(diff > 0) left = (diff%60) + 'm ' + left;	diff=Math.floor(diff/60); if(diff > 0) left = (diff%24) + 'h ' + left;	diff=Math.floor(diff/24); if(diff > 0) left = diff + ' days ' + left; $("#updateCountdown").html("Time left until cache update: "+left); }		 }		});	}

for(var i in maintenanceReport.categories) { $("#listPane").append(" "+maintenanceReport.categories[i]+" (View) Loading ");

$.getJSON('/api.php?action=query&format=json&list=categorymembers&cmlimit=5000&cmtitle=Category:'+maintenanceReport.categories[i]+'&requestid='+maintenanceReport.categories[i].replace(/ /g,""), function(results) {		 formattedresults = new Array;		  $("#checkC"+results.requestid +" ~ span").html("("+Object.keys(results.query.categorymembers).length+")");		  $("#checkC"+results.requestid +" ~ span").removeClass("loading");		  if (!$("span.loading").size) $("#ajaxProgress").remove;		  $(results.query.categorymembers).each(function(index, value) { formattedresults.push(value.title); });		 maintenanceReport.results["C"+results.requestid] = formattedresults;		  if (!formattedresults.length) {		  	$("#checkC"+results.requestid).prop("disabled",true);		  	if (maintenanceReport.options.removeZero) $("#checkC"+results.requestid).parent.remove;		  }		}); } }