_ _    _ _____  ___   __                       
 __      _(_) | _(_)___ / ( _ ) / /_   ___ ___  _ __ ___  
 \ \ /\ / / | |/ / | |_ \ / _ \| '_ \ / __/ _ \| '_ ` _ \ 
  \ V  V /| |   <| |___) | (_) | (_) | (_| (_) | | | | | |
   \_/\_/ |_|_|\_\_|____/ \___/ \___(_)___\___/|_| |_| |_|

User:MastCell/user-rights.js

This article will address User:MastCell/user-rights.js from a broad and deep perspective, with the aim of providing the reader with a complete and detailed vision of this topic. The importance of User:MastCell/user-rights.js in today's society is undeniable, so it is essential to delve into its meaning, origin, development and repercussions. Through an exhaustive and rigorous analysis, the aim is to shed light on the different aspects that revolve around User:MastCell/user-rights.js, providing relevant and updated information that allows us to understand its relevance today. Likewise, different points of view and opinions of experts on the subject will be explored, in order to enrich the debate and offer a plural and enriching vision about User:MastCell/user-rights.js.
/* 
 * User rights script
 * By MastCell
 * ------------------
 * Adds information on user rights (sysop, checkuser, etc) to the heading on user pages.
 * Heavily borrowed and lightly adapted from User:Splarka/sysopdectector.js
 */


/* 
 * Namespace check: Add user rights info if this is a userpage or talkpage
 * If this is a user or usertalk subpage (e.g. "User:Example/subpage"), we'll leave out
 * the info. We'll also leave it out if we're editing or submitting an edit.
 */

if ((mw.config.get('wgNamespaceNumber') == 2 || mw.config.get('wgNamespaceNumber') == 3)
	&& mw.config.get('wgTitle').indexOf('/') == -1
	&& mw.config.get('wgAction') != 'edit'
	&& mw.config.get('wgAction') != 'submit') {
		addOnloadHook(mcShowUserGroups);
}

function mcShowUserGroups() {
	var url = mw.config.get('wgServer') + mw.config.get('wgScriptPath');
	url += '/api.php?action=query&format=json&list=users&usprop=groups|blockinfo|editcount|registration';
	url += '&callback=mcDisplayUserRightsInfo&maxage=3600&smaxage=3600&ususers=';
	url += encodeURIComponent(mw.config.get('wgTitle'));
	importScriptURI(url);
}

function mcDisplayUserRightsInfo(queryObj) {
	// Check to make sure the query returned a user; otherwise, return
	if (!queryObj || !queryObj) {
		return;
	}
	
	var user = queryObj;
	if (user.length === 0) {
		return;
	}
	user = user;
	
	// If the user is an IP ("invalid") or unregistered ("missing"), return
	if (user === "" || user === "") return;
	
	var userRightStr = "";
	
	// Get registration Date
	if (user) {
		var regDate = user.split("T");
		var regDateObj = new Date(regDate);
		userRightStr += ("Registered " + (regDateObj.getMonth() + 1) + "/" + regDateObj.getDate() + "/" + regDateObj.getFullYear() + "; ");
	}
	
	// Get edit count
	if (user) {
		userRightStr += (user + " edits");
	}
	
	// Get user rights
	if (user) {
		var numRights = 0;
		var groupLength = user.length;
		
		for (var i = 0; i < groupLength; i++) {
			// We'll ignore the groups "*" and "users", since everyone belongs to them
			var currentGroup = user;
			if ((currentGroup != "*") && (currentGroup != "user")) {
				if (numRights === 0) {
					userRightStr += "; ";
				} else {
					userRightStr += ", ";
				}

                                if (currentGroup == "sysop") {
                                        userRightStr += "<span style='text-shadow: green 0px 0px 10px'>";
                                        userRightStr += currentGroup;
                                        userRightStr += "</span>";
                                } else if (currentGroup == "bureaucrat") {
                                        userRightStr += "<span style='text-shadow: yellow 0px 0px 10px'>";
                                        userRightStr += currentGroup;
                                        userRightStr += "</span>";
                                } else if (currentGroup == "checkuser") {
                                        userRightStr += "<span style='text-shadow: red 0px 0px 10px'>";
                                        userRightStr += currentGroup;
                                        userRightStr += "</span>";
                                } else if (currentGroup == "oversight") {
                                        userRightStr += "<span style='text-shadow: cyan 0px 0px 10px'>";
                                        userRightStr += currentGroup;
                                        userRightStr += "</span>";
                                } else {
				        userRightStr += currentGroup;
                                }
				numRights++;
			}
		}
	}
	
	// If currently blocked, mention it
	if (user) {
		var blockLogURL = mw.config.get('wgServer') + mw.config.get('wgScriptPath') + "/index.php?title=Special:Log/block&page=" + encodeURIComponent(mw.config.get('wgPageName'));
		userRightStr += "; <a href='" + blockLogURL + "'>currently blocked</a>";
	}
	
	// Attach the info where we want it
	$('#siteSub').before("<div id='mcUserRights' style='font-size: smaller'>" + userRightStr + "</div>");
}