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 19:00, 8 February 2011 (cl). 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".
	- classes can be wrapped around each other. The one with the highest priority is the innermost class.
*/

// Settings ('X' is replaced with the group)
var hideText = 'not-for-X';
var showText = 'for-X-only';
var hiddenStyle = 'display: none;';

// do (anonymous) first; they have NO groups
if (!wgUserGroups)
{
	appendCSS('.not-for-anonymous { ' + hiddenStyle + ' }');
}
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 { ' + hiddenStyle + ' }');
}

function createGroupCss(group)
{
	if (userHasGroup(group)) appendCSS('.' + hideText.replace('X', group) + ' { ' + hiddenStyle + ' }'); // 'not-for-X'
	else appendCSS('.' + showText.replace('X', group) + ' { ' + hiddenStyle + ' }'); // 'for-X-only'	
}

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

	return false;
}