In a MediaWiki-based non-communal website there are some HTML elements that should be presented only for logged-in-users (an administration menu or some of its links).

Usually if I want to hide something for a certain group of users like anonymous users I browse into the website when logged-out, and then take a <body> CSS ID or Class like #anonymous-user to create some condition like this:

#anonymous-user .administration-menu {display: none}

I tried to search for a <body> CSS ID or Class that I could utilize to hide things for anonymous users in MediaWiki but found none.

How could I create one myself?

  • All display:none is doing is hiding a section of a page if a user is using your stylesheet, which they can turn off. If there are links only for admins that is a very bad way of operating. Instead you should have a server variable set when a user is logged in, test for that, and only if it's set then create in PHP the section containing the links. MediaWiki tests for logged in users with if ( $user->isLoggedIn() ) {, see eg user.php. – pbhj Jun 17 at 21:46

Do not ever hide elements through JS, CSS or any other front-end script, sheet or technique. A user can turn off JS, disable your CSS or use "Developer Tools" on Chrome, Firefox or whatever Browser they might be using and have access to all the links, features and functionality as if they were logged on. So it is a terrible and potentially dangerous practice to do so.

The difference in the content displayed to a user (whether logged in or not) must come from the server, and must not ever be evaluated clientside (browser).

Please share what CMS or Web Application Framework you are using, and I may be able to help you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.