User:AFigureOfBlue/dazzle/siteinfo.js
Appearance
(Redirected from User:Drilnoth/dazzle/siteinfo.js)
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
Documentation for this user script can be added at User:AFigureOfBlue/dazzle/siteinfo. |
//<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> • <a href='#dazzle_siteinfo_general'>General</a> • <a href='#dazzle_siteinfo_rightsinfo'>Rights info</a> • <a href='#dazzle_siteinfo_dbrepllag'>Database replication lag</a> • <a href='#dazzle_siteinfo_fileextensions'>File extensions</a> • <a href='#dazzle_siteinfo_usergroups'>User groups</a> • <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>