Jump to content

User:AFigureOfBlue/dazzle/siteinfo.js

From Wikipedia, the free encyclopedia
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
//<nowiki> 
//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 += "<a onclick='dazzle_siteinfo_run()' href='#'>SiteInfo</a>: 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 = "<a href='#dazzle_siteinfo_statistics'>Statistics</a>&nbsp;&bull;&nbsp;<a href='#dazzle_siteinfo_general'>General</a>&nbsp;&bull;&nbsp;<a href='#dazzle_siteinfo_rightsinfo'>Rights info</a>&nbsp;&bull;&nbsp;<a href='#dazzle_siteinfo_dbrepllag'>Database replication lag</a>&nbsp;&bull;&nbsp;<a href='#dazzle_siteinfo_fileextensions'>File extensions</a>&nbsp;&bull;&nbsp;<a href='#dazzle_siteinfo_usergroups'>User groups</a>&nbsp;&bull;&nbsp;<a href='#dazzle_siteinfo_extensions'>MediaWiki extensions</a><a id='dazzle_siteinfo_statistics'></a><br />";
 
 var siteinfo = query("action=query&meta=siteinfo&siprop=general|statistics|rightsinfo|dbrepllag|fileextensions&format=xml");
 var si = {};
 siteinfo.oncomplete(function(){
 
  result += "<b>Statistics</b> (<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 += "<b>General</b> (<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 +="<b>Rights info</b> (<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 += "<b>Database replication lag</b> (<a href='#floatbox-topdiv'>Top</a>)<br />(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 += "<b>File extensions</b> (<a href='#floatbox-topdiv'>Top</a>)<br />" + si.fileextensions.join(", ") + ".<a id='dazzle_siteinfo_usergroups'><br />";
  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 = "<b>User groups</b> (<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><i>" + ucfirst(curgroup) + "</i> (" + 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 = "<b>MediaWiki extensions</b> (<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><i>" + curext + "</i> (" + 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");
   });
  });
 });
}
//</nowiki>