Forum:How to make a section only visible to anonymous users?

Hello! I need to put a new div section with a specific message on the main page of Mass Effect Answers wiki. The problem is, I need it to only show itself to anonymous users. Can anyone say, is this possible, and how to do it? Mitranim 08:54, August 1, 2011 (UTC)


 * You could make the div hide as default with css, and then use js to display it if the user rights match those of an anon. I think this code should work:
 * Tag the div with a class of 'anonmessage'.
 * Add the following code to wikia.css:

.anonmessage { display: none }
 * Add the following code to wikia.js:

function AnonMessage { if(window.wgUserGroups && (wgUserGroups.indexOf("null")) != -1) { $('.anonmessage').css({"display": 'inline'}); } } $(AnonMessage);




 * Close, but wgUserGroups isn't a string, so that'll break. You'll want this:

 function AnonMessage { if(wgUserGroups == null) { $('.anonmessage').css('display', 'inline'); } } addOnloadHook(AnonMessage)
 * It may have problems displaying properly because it's inline, but that can be fixed by changing it to block.


 * It works! Cool … — Spike Toronto  17:47, August 1, 2011 (UTC)
 * Can also be modified for showing sysop only messages, or autoconfirmed only messages, or even weird stuff like emailconfirmed only messages. It's also worth noting just for future reference that hiding messages from users who aren't in certain user groups has been discussed before, and it's not such a bad thing, considering anyone can view the source of the page and read what's inside the div.

Tagging FAQ. -- Fandyllic (talk &middot; contr) 1 Aug 2011 11:25 AM Pacific


 * Very good Fandy. This could prove quite ueseful: messages just for anons where you want to encourage them, perhaps, to create an account and get to use all of the features of a wiki; or, messages on pages where you want to draw the attention of sysops, such as backlog pages, deletion discussions; etc. Only, one question: if it’s   for anonymous users, what is it for, say, Administrators?   ? Bureaucrats &rarr;   ? Thanks! — Spike Toronto  20:28, August 1, 2011 (UTC)


 * You can define yourself what class to use in the Javascript. You can for example use this for admins:

function hasGroup(group) { for (var i in wgUserGroups) { if (wgUserGroups[i] == group) return true; }   return false; } /* Shows messages for Admins */ function showAdmMessage { if (hasGroup('sysop')) { $('.adminmessage').css({'display': 'block !important'}); } }

addOnloadHook(showAdmMessage);
 * In that case it'd be .adminmessage - Tjcool007 (Talk) 20:35, August 1, 2011 (UTC)

Thank you for your answers! I followed some of the posted suggestions, and it indeed works. Took me a bit of trial and error until I learned that class names are case sensitive, but still. ^_^ Thanks to everyone for your help. Mitranim 16:03, August 2, 2011 (UTC)
 * From what I see of the code here, it relies on no special extension to mediawiki. Am I right?
 * 01:19, August 3, 2011 (UTC)
 * Yep, you don't need an extension. It's just JS.