Jump to content

User:Animum/usergroups.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Animum (talk | contribs) at 01:45, 10 June 2009 (--). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
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.
var usergroups = {
    "originalName" : function(name) { //Finds the original name of a user in the event of a detected rename
        var from = name.substring(1,0);
        var req = sajax_init_object();
        req.open("GET", wgScript + "?title=Category:Redirects_to_requests_for_adminship&from=" + from, false);
        req.send(null);
        var content = req.responseText.split("bodyContent")[1].split("visualClear")[0];
        if(content.indexOf(name) != -1) {
            var redirect = content.substring(content.indexOf(name)-33).split("\"")[0];
            var req2 = sajax_init_object();
            req2.open("GET", wgScript + "?title=" + 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 req;
        } 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 from = user.substring(1,0);
        var req = sajax_init_object();
        req.open("GET", wgScript + "?title=Category:Successful_requests_for_adminship&from=" + from, false);
        req.send(null);  
        with(req.responseText.split("bodyContent")[1].split("visualClear")[0]) {
            if(indexOf(user) == -1) {
                return false;
            } else {
                return "/wiki/" + substring(indexOf(user)-33).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 "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 "developer"     : return "m:System_administrators";
                break;
            default              : return "User_access_levels";
        }
    },
    "download" : function() {
        var rfa = this.findRFA(wgTitle);
        var req = sajax_init_object();
        req.open("GET", "http://en.wikipedia.org/w/api.php?action=query&list=allusers&auprop=groups&aulimit=1&format=json&aufrom=" + 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 a member of the following group" + (data.groups.length > 1 ? "s" : "") + ": ";
                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] + "</b></a><b>" + (rfa && data.groups[i] == "sysop" ? " (<a href=\"" + rfa + "\">rfa</a>)" : "") + (!data.groups[i+1] ? " " : ", ") + "</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");
    }
});