MediaWiki:Gadget-SpecialPages.js/UserRights.js

( function ( mw, $ ) {	if(mw.config.get("wgCanonicalSpecialPageName") === "Userrights"){		//INITIALIZE VARIABLES		// 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 0 to start		var urEditCount = 0;		// 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 0 to start, may need to go back further at some point		var urAgeInMonths = 0;		// 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{ 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;"); }				}			}			if(urAgeInMonths >= 6){ $(".age").css({"color": "#0F0", "font-size": "12pt"}).html("&#x2714;"); }			/* 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;"); }			// Add the registration date and edit count to the bottom left cell in the table $("#groups-userstats-js").html("This account is " + urAgeInMonths + " months old and has made " + numformat(urEditCount) + " edits."); // 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);				console.log("Collected:\nEdits: %f\nRegistration: %s\nAge in months: %f\nToday in months: %f\nAccount is %f months old\n", urEditCount, urRegistration, urAgeInMonths, currDateInMonths, (currDateInMonths - urAgeInMonths));				urAgeInMonths = (currDateInMonths - urAgeInMonths);				updateInfo;			},			fail: function(reason){ console.error("failed: %o", reason); }		});	} } )( mediaWiki, jQuery );