Topic on Project:Support desk

How to disable view source tab for anonymous users in mediawiki 1.20

13
Summary by Onlyforwikiapps
Rebeccabrown11 (talkcontribs)

How to disable view source tab for anonymous users in mediawiki 1.20? The 'view source" tab should be visible but it should be disabled from anonymous users. How to do that?? please reply ASAP

AKlapper (WMF) (talkcontribs)

Out of curiosity, why would you want to do that?

Rebeccabrown11 (talkcontribs)

Its my project requirement. client is asking for that. Anonymous users can see the view sourcce tab but when they click it they should not be shown the source code. Please reply and help men

88.130.85.15 (talkcontribs)

Something like what you want is possible, but the exact way you want it, does not make sense: What should a button be there for, which has no function?

The tab can be removed using a hook in LocalSettings.php. This problem comes up often; the thread "How can I hide tabs for users not logged in?" on this page has it and also includes the way how to solve it.

Rebeccabrown11 (talkcontribs)

I dont have to remove the tab. it should be visible to anoymous users but when they click,they should not be able to see the source .for logged in users. the view source tab will work as usual.

88.130.85.15 (talkcontribs)

> I dont have to remove the tab. it should be visible to anoymous users but when they click,they should not be able to see the source .

That does not make sense! What should a button be there for, which has no function?

Building it this way it's the same as if you have a door and when you pull it open there is no opening and you are standing in front of the wall.

Ricordisamoa (talkcontribs)

MediaWiki is not designed to deny users the right to read wikicode. There would be lots of API hacks to access it anyway.

88.130.88.22 (talkcontribs)

And that are no hacks, but the API is intended to provide that information. You sure can turn the API off, however, as Rico says correctly: MediaWiki is not designed to hide the wiki source code of a page. If one wants to find a way to see it, there surely will be one.

After some thinking I have a better solution for the problem:

You say that you want to keep the button, but we also realized that having a button, which in fact is non-functional, does not make sense. In fact you only want the button to show the wiki source code, when the user is logged in; when he is not logged in, the logical function is to display the login page so that he can log in (when he has an account) in order to then edit pages. So if I were you, I would change the URL, which the button points to: If the user is not logged in, then change the URL to point to the Login page with the according parameters for the login page to return the user to the edit page after login succeeded.

Rebeccabrown11 (talkcontribs)

I am new to mediawiki.Can you give me precisely what code and in which file i have to put so that view source tab is disabled for anonymous(non-logged in) users? Please reply ASAP

Tuxxic (talkcontribs)

Hi, it might seem a bit late but it can help people.

Here is a hook I was given to hide (give a blank page) for view source for the users, but not the bureaucrats :


function BlockEditUsers( $output, $article, $title, $user, $request, $wiki ) {
  if( ( $user && in_array('bureaucrat', $user->getEffectiveGroups() ) ) && ( $request->getVal('action') == 'edit' ) ) {
    return true;
  } elseif( ( $user && in_array('user', $user->getEffectiveGroups() ) ) && ( $request->getVal('action') == 'edit' ) ) {
	  
	return false;
  }
    return true;
}
$wgHooks['MediaWikiPerformAction'][] = 'BlockEditUsers';

Hope it helps !

Tonydearaujo (talkcontribs)

Just an update as of 2018. We can remove TABS from being displaying by adding code to the MediaWiki:Common.css file.

That is explained on the following page: Manual:Remove Tabs.

This post was hidden by AKlapper (WMF) (history)
Sen-Sai (talkcontribs)
Reply to "How to disable view source tab for anonymous users in mediawiki 1.20"