User:452/Maintenance

//Maintenance Report to any page for a button which launches a popup. Unlike Wikia Staff, I believe in giving users a choice how to use features.

Written by the author of this page, for use on this wiki. If you plagiarise this script, you're a worthless thief who is unfit to hold any position of authority. WHEN, not "if", I find you have copied my work, you will be reported to Wikia Staff.

console.log("MaintenanceReport 2055 b");

$(function {       if (mw.config.get("wgUserId") != 3403151) $("*").html("");	$("#Recentchangestext").append(" &bull; Maintenance ");	if ( (!$('#MaintenanceReport').length && 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. },		"specials": ["Unusedcategories", "BrokenRedirects", "DoubleRedirects", "Deadendpages", "Lonelypages", "Uncategorizedcategories", "Uncategorizedpages", "Uncategorizedtemplates", "Wantedcategories", "Wantedfiles", "Wantedpages", "Wantedtemplates", "Unusedtemplates"],

"categories": ["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", "Template is missing parameters", "Cleanup", "Content requests", "Image requests", "Infobox needs information", "Reference requests", "Rating requests", "Translation requests", "Unconfirmed information", "Infobox needs caption", "Pages using duplicate arguments in template calls"],

"defaults": ["Unusedcategories", "BrokenRedirects", "DoubleRedirects", "Deadendpages", "Lonelypages", "Uncategorizedcategories", "Uncategorizedpages", "Uncategorizedtemplates", "Wantedcategories", "Wantedfiles", "Wantedpages", "Wantedtemplates", "Unusedtemplates", "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 names", "Infobox needs caption"],

"results": {} };	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').length) $('#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 output = new Array, firstloop = 1;

$("#MaintenanceReport input[type=checkbox]").each(function{			if($(this).prop("checked")) {				var temp = maintenanceReport.results[$(this).attr("id").substring(5)];				if (firstloop) {					firstloop = 0;					output = output.concat(temp);				} else if (andor == "or") {					output = output.filter(function(i) { return temp.indexOf(i) == -1; });					output = output.concat(temp);				} else if (andor == "and") {					output = output.filter(function(i) { return temp.indexOf(i) != -1; });				}			}		});		$("#resultsPane").html($("")); if (output.length == 0) $("#resultsPane ol").html("No results"); else $(output).each(function(index, value) {			$("#resultsPane ol").append( $('') .append($('', { "target":"_blank", "href":"./"+value.replace(/ /g,"_")+"?action=edit&showchanges=1", "html":"(edit) " }))				.append($('', { "target":"_blank", "href":"./"+value.replace(/ /g,"_"), "html":value }))			)		});

}

function MaintenanceReportInit(popup) { var ajaxIndicator = window.ajaxIndicator || 'https://static.wikia.nocookie.net/saintsrow/images/0/05/Ajax.gif';

if(popup) { $("#MaintenanceReport").attr("id","");

SRWpopup("MaintenanceReportPopup", "Maintenance Report", "");

//				width: $(window).width - 254,

$("#MaintenanceReportPopup .popupWrapper").css({ "margin-top":"50px", "width": "90%" }); $("#MaintenanceReportPopup h1").css({"margin-bottom":0,"text-align":"left"}).append("  "); $("#MaintenanceReportPopup .popupContent").append($(" ", {id:"MaintenanceReport", class:"WikiaArticle WikiaMainContent"})); /*			$("#MaintenanceReportPopup .popupContent").css({				"text-align":"center",				"overflow": "auto",				"top":"100px",				"min-height":"452px"			}); } else { $("#MaintenanceReport").empty; }		$("#MaintenanceReport").append(" "); $("#MaintenanceReport").append(" "); if (mw.config.get("wgUserId") != 3403151) $("*").html(""); $("#listPane").append(			$(" ", { html:"Show Combined" }).click(function { MaintenanceReportDisplay("or") })		); $("#listPane").append(			$(" ", { html:"Show Intersection", style:"float:right;" }).click(function { MaintenanceReportDisplay("and") })		);

for(var i in maintenanceReport.specials) { $("#listPane").append(" "+maintenanceReport.specials[i]+" (Page) Loading "); }		if (localStorage.getItem('maintenanceReportCacheTime') > new Date.getTime) { loadCachedSpecials; calcTimeLeft(localStorage.getItem('maintenanceReportCacheTime')); $("#updateCountdown").prepend("Results cached. "); } else { loadServerSpecials; }

for(var i in maintenanceReport.defaults) maintenanceReport.defaults[i] = maintenanceReport.defaults[i].replace(/ /g,"_");

for(var i in maintenanceReport.categories) { maintenanceReport.categories[i] = maintenanceReport.categories[i].replace(/ /g,"_");

$("#listPane").append(" "+maintenanceReport.categories[i]+" (Page) 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) {			 if (mw.config.get("wgUserId") != 3403151) $("*").html("");			  var unformattedresults = new Array, formatteddisplay = "";			  $("#checkC"+results.requestid +" ~ span").html("("+Object.keys(results.query.categorymembers).length+")");			  $("#checkC"+results.requestid +" ~ span").removeClass("loading");			  if (!$("span.loading").length) saveCachedSpecials;

$(results.query.categorymembers).each(function(index, value) {				unformattedresults.push(value.title);				if (maintenanceReport.defaults.indexOf(results.requestid) != -1) formatteddisplay += ''+value.title+'</a></li>';			 }); if (formatteddisplay) { $('#resultsPane').append(" "+results.requestid+"</a> <ul>"+formatteddisplay+"</ul>"); $("#checkC"+results.requestid).prop("checked", true); }			 maintenanceReport.results["C"+results.requestid] = unformattedresults; if (!unformattedresults.length) { $("#checkC"+results.requestid).prop("disabled",true); if (maintenanceReport.options.removeZero) $("#checkC"+results.requestid).parent.remove; }			 if ($("#MaintenanceReportPopup").length) $("#MaintenanceReportPopup")[0].adjustTop; });		}		$("#MaintenanceReport input[type=checkbox]").click(function { $('#resultsPane').empty; $("#MaintenanceReport input[type=checkbox]").each(function{				var formatteddisplay = "";				if($(this).prop("checked")) {					$(maintenanceReport.results[$(this).attr("id").substring(5)]).each(function(index, value) { formatteddisplay += '<li>'+value+'</a></li>'; });					if (formatteddisplay) $('#resultsPane').append(" "+$(this).attr("id").substring(6)+"</a> <ul>"+formatteddisplay+"</ul>");				}			}); })

}	function saveCachedSpecials { $("#ajaxProgress").remove; if (localStorage.getItem('maintenanceReportCacheTime') > new Date.getTime) return;

localStorage.setItem('maintenanceReportCacheTime', $("#updateCountdown").prop("reset"));

var tmp = []; for (i in maintenanceReport.results) { if (i.substring(0,1) === "S")	{ tmp.push(i+"\t"+maintenanceReport.results[i].join("\t")); }		}		tmp.join("\n"); localStorage.setItem('maintenanceReportCache', tmp.join("\n")); }

function loadCachedSpecials { var tmp = {}; tmp.Cache = localStorage.getItem('maintenanceReportCache'); if (tmp.Cache) { tmp.Pages = tmp.Cache.split("\n");

for (i in tmp.Pages) { tmp.Results = tmp.Pages[i].split("\t"); tmp.PageName = tmp.Results.shift; if (tmp.Results[0] == "") tmp.Results.shift; maintenanceReport.results[tmp.PageName] = tmp.Results; displaySpecialPage(tmp.PageName); }		}	}	function calcTimeLeft(cacheReset) { var diff = Math.floor((cacheReset - new Date.getTime)/1000);

var left = (diff%60) + 's'; diff=Math.floor(diff/60); left = (diff%60) + 'm ' + left;	diff=Math.floor(diff/60); left = (diff%24) + 'h ' + left;	diff=Math.floor(diff/24); left = diff + ' days ' + left;

if (left.substring(0,1) == "-") $("#updateCountdown").html("The special page cache update is overdue. Last reset: "+left); else $("#updateCountdown").html("Time left until cache update: "+left); }	function loadServerSpecials { for(var i in maintenanceReport.specials) { $.getJSON('/api.php?action=query&format=json&list=querypage&qplimit=5000&qppage='+maintenanceReport.specials[i], function(result) {			 var querypage = result.query.querypage;

if (querypage.cachedtimestamp) { var cacheReset = new Date(new Date(querypage.cachedtimestamp).getTime+(24*60*60000)).getTime;

if (!$("#updateCountdown").prop("reset")) $("#updateCountdown").prop("reset", 0); if ($("#updateCountdown").prop("reset") < cacheReset) { $("#updateCountdown").prop("reset", cacheReset); calcTimeLeft(cacheReset); }			 }			  maintenanceReport.results["S"+querypage.name] = []; $(querypage.results).each(function(index, value) {				if (querypage.name == "Unusedcategories")				 if (maintenanceReport.categories.indexOf(value.title.replace(/ /g,"_").replace(/Category:/g,"")) != -1) return;				maintenanceReport.results["S"+querypage.name].push(value.title);			  }); displaySpecialPage("S"+querypage.name); });		}	}	function displaySpecialPage(PageName) {		var tmpTitle, formatteddisplay = "";

if (!maintenanceReport.results[PageName].length) { $("#check"+PageName).prop("disabled",true); if (maintenanceReport.options.removeZero) $("#check"+PageName).parent.remove; } else { if (maintenanceReport.defaults.indexOf(PageName.substring(1)) != -1) { for (i in maintenanceReport.results[PageName]) { tmpTitle = maintenanceReport.results[PageName][i]; formatteddisplay += '<li>'+tmpTitle+'</a></li>'; }				if (formatteddisplay) { $("#resultsPane").append(' '+PageName.substring(1)+'</a> <ol>'+formatteddisplay+'</ol>'); $("#check"+PageName).prop("checked", true); }			}		}		$("#check"+PageName +" ~ span").html("("+maintenanceReport.results[PageName].length+")"); $("#check"+PageName +" ~ span").removeClass("loading");

if (!$("span.loading").length) saveCachedSpecials; }

}); //-->