User:AFigureOfBlue/dazzle/siteinfo.js

// //This code is a mess. It could probably be cleaned up at some point, but it works and improving it is low on my to-do list. if (typeof(DazzleConfig) == 'undefined') {DazzleConfig = {};} if (typeof(DazzleConfig.siteinfo_link) == 'undefined') {DazzleConfig.siteinfo_link = "toolbox";} $(function{ if (DazzleConfig.siteinfo_link == "toolbox") { if (mw.config.get('wgPageName') == "Wikipedia:Dazzle!/Toolbox") {   var toolbox = id("dazzle_toolbox_div");   toolbox.innerHTML += "SiteInfo: View general information about the current wiki, including statistics, user group rights, extensions, and more.";  } } else {  addDazzleLink("javascript:dazzle_siteinfo_run;", "SiteInfo", "dz-siteinfo", "View general information and statistics about the wiki"); } }); function dazzle_siteinfo_run{ var floatbox = new Floatbox("Site info", "Khaki"); set_status("Loading...", "Black"); var result = "Statistics &bull; General &bull; Rights info &bull; Database replication lag &bull; File extensions &bull; User groups &bull; MediaWiki extensions<a id='dazzle_siteinfo_statistics'></a> "; var siteinfo = query("action=query&meta=siteinfo&siprop=general|statistics|rightsinfo|dbrepllag|fileextensions&format=xml"); var si = {}; siteinfo.oncomplete(function{ result += "Statistics (<a href='#floatbox-topdiv'>Top</a>)<ul style='-moz-column-count: 2; -webkit-column-count: 2; -column-count: 2; font-size: small;'>";  var statistics = ["pages", "articles", "edits", "images", "users", "activeusers", "admins", "jobs"];  si.statistics = {};  for (var i = 0; i < statistics.length; i += 1) {   si[statistics[i]] = siteinfo.responseXML.getElementsByTagName("statistics")[0].getAttribute(statistics[i]);   si.statistics[statistics[i]] = siteinfo.responseXML.getElementsByTagName("statistics")[0].getAttribute(statistics[i]);  }  for (var i in si.statistics) {   result += "<li>" + ucfirst(i) + ": " + parseInt(si.statistics[i], 10).toLocaleString + "</li>";  }  result += "</ul><a id='dazzle_siteinfo_general'></a>";  var general = ["articlepath", "base", "case", "dbtype", "dbversion", "fallback8bitEncoding", "generator", "lang", "phpsapi", "phpversion", "mainpage", "rights", "script", "scriptpath", "server", "sitename", "timeoffset", "timezone", "variantarticlepath", "wikiid", "writeapi"]; si.general = {}; for (var i = 0; i < general.length; i += 1) { si[general[i]] = siteinfo.responseXML.getElementsByTagName("general")[0].getAttribute(general[i]); si.general[general[i]] = siteinfo.responseXML.getElementsByTagName("general")[0].getAttribute(general[i]); } result += "General (<a href='#floatbox-topdiv'>Top</a>)<ul style='-moz-column-count: 2; -webkit-column-count: 2; -column-count: 2; font-size: small;'>"; for (var i in si.general) { result += "<li>" + ucfirst(i) + ": " + si.general[i] + "</li>"; } result += "</ul><a id='dazzle_siteinfo_rightsinfo'></a>"; var rightsinfo = ["url", "text"]; si.rightsinfo = {}; for (var i = 0; i < rightsinfo.length; i += 1) { si[rightsinfo[i]] = siteinfo.responseXML.getElementsByTagName("rightsinfo")[0].getAttribute(rightsinfo[i]); si.rightsinfo[rightsinfo[i]] = siteinfo.responseXML.getElementsByTagName("rightsinfo")[0].getAttribute(rightsinfo[i]); } result +="Rights info (<a href='#floatbox-topdiv'>Top</a>)<ul style='-moz-column-count: 2; -webkit-column-count: 2; -column-count: 2; font-size: small;'>"; for (var i in si.rightsinfo) { result += "<li>" + ucfirst(i) + ": " + si.rightsinfo[i] + "</li>"; } result += "</ul><a id='dazzle_siteinfo_dbrepllag'></a>"; var dbrepllag = ["host", "lag"]; si.dbrepllag = {}; for (var i = 0; i < dbrepllag.length; i += 1) { si[dbrepllag[i]] = siteinfo.responseXML.getElementsByTagName("db")[0].getAttribute(dbrepllag[i]); si.dbrepllag[dbrepllag[i]] = siteinfo.responseXML.getElementsByTagName("db")[0].getAttribute(dbrepllag[i]); } result += "Database replication lag (<a href='#floatbox-topdiv'>Top</a>) (highest replag only)<ul style='-moz-column-count: 2; -webkit-column-count: 2; -column-count: 2; font-size: small;'>"; for (var i in si.dbrepllag) { result += "<li>" + ucfirst(i) + ": " + si.dbrepllag[i] + "</li>"; } result += "</ul><a id='dazzle_siteinfo_fileextensions'></a>"; var fileextensions = siteinfo.responseXML.getElementsByTagName("fe"); si.fileextensions = []; for (var i = 0; i < fileextensions.length; i += 1) { si.fileextensions[i] = fileextensions[i].getAttribute("ext"); } result += "File extensions (<a href='#floatbox-topdiv'>Top</a>) " + si.fileextensions.join(", ") + ".<a id='dazzle_siteinfo_usergroups'> "; floatbox.mainbox.innerHTML += result; var usergroupinfo = query("action=query&meta=siteinfo&siprop=usergroups&sinumberingroup=sinumberingroup&format=xml"); var ui = {}; usergroupinfo.oncomplete(function{  var groups = usergroupinfo.responseXML.getElementsByTagName("group");   ui.groups = {};   ui.allgroups = [];   for (var i = 0; i < groups.length; i += 1) {    var curgroup = groups[i];    ui.allgroups[i] = curgroup.getAttribute("name");    ui[curgroup.getAttribute("name")] = {"number": curgroup.getAttribute("number"), "permissions": []};    ui["group" + i] = {"name": curgroup.getAttribute("name"), "number": curgroup.getAttribute("number"), "permissions": []};    var permissions = curgroup.firstChild.childNodes;    for (var j = 0; j < permissions.length; j += 1) {     ui[curgroup.getAttribute("name")].permissions[j] = permissions[j].firstChild.nodeValue;     ui["group" + i].permissions[j] = permissions[j].firstChild.nodeValue;    }   }   result = "User groups (<a href='#floatbox-topdiv'>Top</a>)<ul style='font-size: small;'>";   for (var i = 0; i < ui.allgroups.length; i += 1) { var curgroup = ui.allgroups[i]; result += "<li>" + ucfirst(curgroup) + " (" + ui[curgroup].number + "): " + ui[curgroup].permissions.join(", ") + ".</li>"; }  result += "</ul><a id='dazzle_siteinfo_extensions'></a>"; floatbox.mainbox.innerHTML += result; var extensioninfo = query("action=query&meta=siteinfo&siprop=extensions&format=xml"); var ei = {}; extensioninfo.oncomplete(function{   var extensions = extensioninfo.responseXML.getElementsByTagName("ext");    ei.extensions = {};    ei.allextensions = [];    for (var i = 0; i < extensions.length; i += 1) {     var curext = extensions[i];     ei.allextensions[i] = curext.getAttribute("name");     ei[curext.getAttribute("name")] = {"type": curext.getAttribute("type"), "description": curext.getAttribute("description"), "descriptionmsg": curext.getAttribute("descriptionmsg"), "author": curext.getAttribute("author")};     ei["ext" + i] = {"name": curext.getAttribute("name"), "type": curext.getAttribute("type"), "description": curext.getAttribute("description"), "descriptionmsg": curext.getAttribute("descriptionmsg"), "author": curext.getAttribute("author")};    }    ei.allextensions.sort;    result = "MediaWiki extensions (<a href='#floatbox-topdiv'>Top</a>)<ul style='font-size: small;'>"; for (var i = 0; i < ei.allextensions.length; i += 1) { var curext = ei["ext" + i].name; var curdesc = ei["ext" + i].description; if (!curdesc) { curdesc = "No description"; }    result += "<li>" + curext + " (" + ei["ext" + i].type + "): " + wikilinkstoanchors(cleanwikitags(ucfirst(curdesc))) + " (author[s]: " + ei["ext" + i].author + ").</li>"; }   result += "</ul>"; floatbox.mainbox.innerHTML += result; set_status("Done!", "Black"); }); }); }); } //