User:Animum/usergroups.js
Appearance
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:Animum/usergroups. This user script seems to have an accompanying .css page at User:Animum/usergroups.css. |
var usergroups = {
"originalName" : function(name) { //Finds the original name of a user in the event of a detected rename
var req = sajax_init_object();
req.open("GET", wgScript + "?title=Category:Redirects_to_requests_for_adminship&from=" + encodeURIComponent(name), false);
req.send(null);
var content = req.responseText.split("<div id=\"mw-pages\">")[1].split("</div>")[0];
if(content.indexOf("adminship/" + name + '"') != -1) {
var redirect = content.substring(content.indexOf("adminship/" + name + '"')-23).split("\"")[0];
var req2 = sajax_init_object();
req2.open("GET", wgScript + "?title=" + encodeURIComponent(redirect) + "&action=edit", false);
req2.send(null);
var content2 = req2.responseText.split("bodyContent")[1].split("visualClear")[0];
return content2.split(/\#[rR][eE][dD][iI][rR][eE][cC][tT] ?\[\[/)[1].split("]]")[0].split("/")[1]; //The original name
delete req2;
} else {
return false;
}
delete req;
},
"findRFA" : function(user_) {
var user = this.originalName(user_) || user_; //If there is a rename, use the original name; else, use the name provided.
var req = sajax_init_object();
req.open("GET", wgScript + "?title=Category:Successful_requests_for_adminship&from=" + encodeURIComponent(user), false);
req.send(null);
with(req.responseText.split("<div id=\"mw-pages\">")[1].split("</div>")[0]) {
if(indexOf("adminship/" + user + '"') == -1) {
jsMsg("RfA was missing from <a href=\"/wiki/Category:Successful_requests_for_adminship\">Category:Successful requests for adminship</a> or <a href=\"/wiki/Category:Redirects_to_requests_for_adminship\">Category:Redirects to requests for adminship</a>");
} else {
location.href = "/wiki/" + substring(indexOf("adminship/" + user + '"')-23).split("\"")[0]; //Why 33? "Wikipedia:Requests for adminship/" is 33 characters long.
}
}
delete req;
},
"link" : function (link) {
switch(link) {
case "accountcreator": return "User_access_levels#Accountcreator";
break;
case "rollbacker" : return "Rollback_feature";
break;
case "ipblock-exempt": return "User_access_levels#Ipblock-exempt";
break;
case "confirmed" : return "User_access_levels#Confirmed";
break;
case "sysop" : return "Administrators";
break;
case "oversight" : return "Oversight";
break;
case "checkuser" : return "CheckUser";
break;
case "bot" : return "Bots";
break;
case "bureaucrat" : return "Bureaucrats";
break;
case "abusefilter" : return "Edit_filter";
break;
default : return "User_access_levels";
}
},
"download" : function() {
var req = sajax_init_object();
req.open("GET", wgScriptPath + "/api.php?action=query&list=allusers&auprop=groups&aulimit=1&format=json&aufrom=" + encodeURIComponent(wgTitle), false);
req.send(null);
var data = eval("(" + req.responseText + ")").query.allusers[0];
if(data) {
if(data.groups) {
document.getElementById("contentSub").innerHTML += "<br /><b>" + wgTitle + " is " + (data.groups[0].substring(0, 1).search(/[aeiou]/) != -1 ? "an " : "a ") + "</b>"; //Is the first letter of the first usergroup a vowel? If so, use "an"; if not, use "a."
for(i=0; i<20; i++) { //Why 20? 20 is a high number.
if(data.groups[i]) {
document.getElementById("contentSub").innerHTML += "<a href=\"/wiki/Wikipedia:" + this.link(data.groups[i]) + "\"><b>" + data.groups[i] + (data.groups[i] == "confirmed" ? " user" : "") + "</b></a><b>" + (data.groups[i] == "sysop" ? " (</b><a href=\"javascript:usergroups.findRFA('" + wgTitle.replace(/\'/g, "\\'") + "')\"><b>rfa</b></a><b>)" : "") + (!data.groups[i+1] ? "." : (data.groups.length == 2 ? " and " : ", " + (!data.groups[i+2] ? "and " : ""))) + "</b>";
} else {
break;
}
}
} else {
document.getElementById("contentSub").innerHTML += "<br /><b>" + wgTitle + " is not in any special user groups.";
}
}
}
};
addOnloadHook(function() {
if((wgNamespaceNumber == 2 || wgNamespaceNumber == 3) && wgPageName.indexOf("/") == -1) {
importStylesheet("User:Animum/usergroups.css");
addPortletLink("p-cactions", "javascript:usergroups.download()", "$", "ca-usergroups");
}
});