MediaWiki:Gadget-SpecialPages.js/UserRights.js

( function ( mw, $ ) {	if(mw.config.get("wgCanonicalSpecialPageName") === "Userrights"){		//INITIALIZE VARIABLES		// Define the api check variables		var apiAllusersDone = false;		var apiAllusersFailed = false;		var apiUsercontribsDone = false;		var apiUsercontribsFailed = false;		// Get the username from the page title from mw.config variables		var urUsername = mw.config.get("wgTitle").substr(mw.config.get("wgTitle").indexOf("/")+1, mw.config.get("wgTitle").length);// or $('#username').val;		// Define edit count as -1 to start		var urEditCount = -1;		// Define registration time as empty to start, may modify this to epoch later and return a message warning about created before reg date existed		var urRegistration = "";		// Define user's age in months since Jan 2000 as -1 to start, may need to go back further at some point		var urAgeInMonths = -1;		// Check to see if the VIP checkbox is checked and if it is, they are a VIP already && set isVIP to false for viewing user var urVIP = $("#wpGroup-ddowikivip").is(":checked"); var isVIP = false; // Check to see if the SU checkbox is checked and if it is, they are a SU already && set isSU to false for viewing user var urSU = $("#wpGroup-superuser").is(":checked"); var isfSU = false; // Check to see if the admin checkbox is checked and if it is, they are an admin already && set isAdmin to false for viewing user var urAdmin = $("#wpGroup-sysop").is(":checked"); var isAdmin = false; // Check to see if the crat checkbox is checked and if it is, they are a crat already && set isCrat to false for viewing user var urCrat = $("#wpGroup-bureaucrat").is(":checked"); var isCrat = false; // Check to see if the steward checkbox is checked and if it is, they are a steward already && set isSteward to false for viewing user var urSteward = $("#wpGroup-steward").is(":checked"); var isSteward = false; // Check to see if the bot checkbox is checked and if it is, they are a bot already && set isBot to false for viewing user var urBot = $("#wpGroup-bot").is(":checked"); var isBot = false; // Get viewing user's groups for (var group in wgUserGroups){ switch (wgUserGroups[group]){ case "ddowikivip": isVIP = true; break; case "superuser": isSU = true; break; case "sysop": isAdmin = true; break; case "bureaucrat": isCrat = true; break; case "steward": isSteward = true; break; case "bot": isBot = true; break; default: break; }		}		// Define a new date constructor var currDate = new Date; // Calculate the current number of months since Jan 2000 var currDateInMonths = currDate.getFullYear * 12 + currDate.getMonth;

// function to format numbers with commas function numformat(nStr){ nStr += ''; x = nStr.split('.'); x1 = x[0]; x2 = x.length > 1 ? '.' + x[1] : ''; var rgx = /(\d+)(\d{3})/; while (rgx.test(x1)) { x1 = x1.replace(rgx, '$1' + ',' + '$2'); }			return x1 + x2; }

// Update the table function updateInfo{ /* Need to get edit history to look for gaps and last contribution (doesn't have to be an edit, a move, delete, protect etc counts) if(urGapLong <= *//* 1 month /*){*/ $(".mo-gap").html("?");/* $(".mo-gap").css({"color": "#0F0", "font-size": "12pt"}).html("&#x2714;"); }			if(urLongGaps <= 3){*/ $(".no-gaps").html("?");/* $(".no-gaps").css({"color": "#0F0", "font-size": "12pt"}).html("&#x2714;"); }			if(urActive === true){*/ $(".active").html("?");/* $(".active").css({"color": "#0F0", "font-size": "12pt"}).html("&#x2714;"); }			*/			if(urAdmin === true){ $(".is-admin").css("color", "#0F0").html("&#x2714;"); }			// If they are a VIP but not a crat or stewart, then show the message about what the * means if (isVIP === true && !(isCrat === true || isSteward === true)){ $("#groups-add-noremove").removeClass("hidden"); }			// Change the exclaimation mark to a semicolon $("#groups-qualified-js").html(":"); // Unhide completed table $("#groups-add-table-js").removeClass("hidden"); }		$.ajax({			url: mw.config.get( 'wgScriptPath' ) + '/api.php?action=query&format=json&list=allusers&auprop=editcount|registration&aulimit=1&aufrom=' + encodeURIComponent(urUsername),			dataType: 'json',			success: function(data){				urEditCount = data.query.allusers[0].editcount;				urRegistration = data.query.allusers[0].registration;				if(typeof(urRegistration) != "undefined"){					urRegistration = new Date(urRegistration);				} else {					urRegistration = new Date(1999, 11, 30);				}				urAgeInMonths = ((urRegistration.getFullYear * 12) + urRegistration.getMonth);				urAgeInMonths = (currDateInMonths - urAgeInMonths);				if(urEditCount >= 0){								if(urEditCount >= 100){						$(".100").css({"color": "#0F0", "font-size": "12pt"}).html("&#x2714;");						if(urEditCount >= 250){							$(".250").css({"color": "#0F0", "font-size": "12pt"}).html("&#x2714;");							if(urEditCount >= 1000){ $(".1k").css({"color": "#0F0", "font-size": "12pt"}).html("&#x2714;"); }						}					}				} else { $(".100").html("?") $(".250").html("?") $(".1k").html("?") }				// If account is 6+ months old, tick box in green. If account is between 3-6 months old, tick it in yellow if(urAgeInMonths >= 6){ $(".age").css({"color": "#0F0", "font-size": "12pt"}).html("&#x2714;"); }				else if(urAgeInMonths >= 3 && urAgeInMonths < 6){ $(".age").css({"color": "#AA0", "font-size": "12pt"}).html("&#x2714;"); } else { /* Account isn't at least 3 months old, change nothing */ }				// Add the registration date and edit count to the bottom left cell in the table // Create text string var textUserStats = "This "; if (urAgeInMonths < 0 || isNaN(urAgeInMonths)){ textUserStats += "account is too old "; }				else if (urAgeInMonths === 0){ textUserStats += "is a new account "; }				else if(urAgeInMonths === 1){ textUserStats += "account is a month old "; } else { textUserStats += "account is " + urAgeInMonths + " months old "; }				textUserStats += "and has made "; if (urEditCount < 0 || isNaN(urEditCount)){ textUserStats += "an undefined number of edits."; }				else if (urEditCount === 0){ textUserStats += "no edits."; }				else if(urEditCount === 1){ textUserStats += "an edit."; } else { textUserStats += numformat(urEditCount) + " edits."; }				$("#groups-userstats-js").html( textUserStats ); apiAllusersDone = true; updateInfo; },			fail: function(reason){ $(".100").html("??") $(".250").html("???</a>") $(".1k").html("???</a>") $(".age").css({"color": "#AA0", "font-size": "12pt"}).html("???</a>"); console.error("apiAllusers failed: %o", reason); apiAllusersFailed = true; }		});	} } )( mediaWiki, jQuery );