Jump to content

User:Gary/user groups.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Gary (talk | contribs) at 20:16, 2 February 2011 (add notes). 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.
/*
	USER GROUPS SCRIPT


	NORMAL GROUPS (18 total, as of February 2, 2011):
	
	(all)
	accountcreator
	sysop (administrator)
	autoreviewer (auto patrolled)
	bot
	bureaucrat
	checkuser
	confirmed
	abusefilter (edit filter manager)
	founder
	ipblock-exempt
	import
	oversight
	researcher
	reviewer
	rollbacker
	steward
	transwiki
	
	
	SPECIAL GROUPS (3)
	(anonymous)
	autoconfirmed
	user
	
	
	EXAMPLE USAGE (all nouns are in singular form):
	
		<div class="for-sysop-only"></div>
	
	AND
	
		<div class="not-for-sysop"></div>
	
	
	NOTES
	
	- (all) has no associated class.
	- The associated class for (anonymous) uses "anonymous".
*/

// do (anonymous) first; they have NO groups
if (!wgUserGroups)
{
	appendCSS('.not-for-anonymous { display: none; }');
}
else
{
	// normal user groups; (all) group is missing
	var allUserGroups = { 'accountcreator': true, 'sysop': true, 'autoreviewer': true, 'bot': true, 'bureaucrat': true, 'checkuser': true, 'confirmed': true, 'abusefilter': true, 'founder': true, 'ipblock-exempt': true, 'import': true, 'oversight': true, 'researcher': true, 'reviewer': true, 'rollbacker': true, 'steward': true, 'transwiki': true, };
	for (var group in allUserGroups) createGroupCss(group);

	// special user groups; (anonymous) is missing, will do last
	var specialUserGroups = { 'autoconfirmed': true, 'user': true, };
	for (var group in specialUserGroups) createGroupCss(group);
	
	// (anonymous) users
	appendCSS('.for-anonymous-only { display: none; }');
}

function createGroupCss(group)
{
	if (userHasGroup(group)) appendCSS('.not-for-' + group + ' { display: none; }'); // 'not-for-X'
	else appendCSS('.for-' + group + '-only { display: none; }'); // 'for-X-only'	
}

function userHasGroup(group)
{
	for (var i = 0; i < wgUserGroups.length; i++)
	{
		if (group == wgUserGroups[i])
			return true;
	}

	return false;
}