How can I hide tabs for users not logged in?
My Versions: MediaWiki: 1.16.5, PHP: 5.2.17, MySQL: 5.1.61
I'm using the Vector skin. I would like to hide the following tabs to people who do not have the right to use them. Is there any way to do this?
Discussion, View History, Edit, Arrow
The following is simple CSS but it should work:
$wgHooks['SkinTemplateSetupPageCss'][] = 'wfHideVariousTabsFromAnonymous'; function wfHideVariousTabsFromAnonymous( &$hidetabcss ) { global $wgUser; if ( !$wgUser->isLoggedIn() ) { $hidetabcss .= 'li#ca-history, li#ca-viewsource, li#ca-edit, li#ca-talk, .vectorMenu { display: none; }'; } return true; }
Thanks but that only hides the tabs. The tabs are still there in the code. Is there any way to make the tabs not show in the first place and where should I put the code in the Vector skin? Thanks
There is no extension but there might be hooks that could be used. I'll look for it tomorrow.
What gives me this idea is that Hurricane Electric's wiki (found somewhere on he.net) succeeds in hiding all the special pages and all the tabs.
LQT hides various tabs so I'll take a look inside its files. It's maybe in /mediawiki/trunk/extensions/LiquidThreads/classes/Dispatch.php but I just took a short look.
and the HE wiki uses Monobook. However, it looks like SVG might be able to make this a wholly new extension.
Can be catched up by:
$wgHooks['SkinTemplateNavigation'][] = 'fnHideVariousTabsFromAnonymousVector'; function fnHideVariousTabsFromAnonymousVector( SkinTemplate &$sktemplate, array &$links ) { // the old '$content_actions' array is thankfully just a // sub-array of this one fnHideVariousNamespaceTabsFromAnonymous( $sktemplate, $links['namespaces'] ); fnHideVariousActionTabsFromAnonymous( $sktemplate, $links['views'] ); return true; }
It would be great if all users knew it; since they don't, an extension is a better way of presenting this to users. Perhaps include in Extension:Vector?
Here it is for Vector skin. And don't remove my name, it's a real extension. Just create HideVariousTabsFromUnauthorizedUsers.php, put this code into it, include it in LocalSettings.php and if anonymous users DON'T have edit permission, it'll work. Actions at the arrow shouldn't need to be removed because I can't see an action shown under the arrow that can be executed by anonymous users with default or restricted permissions.
<?php /** * HideVariousTabsFromUnauthorizedUsers * * @package MediaWiki * @subpackage Extensions * * @author: Tim 'SVG' Weyer <t.weyer@ymail.com> * * @copyright Copyright (C) 2012 Tim Weyer * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later * */ $wgExtensionCredits['other'][] = array( 'path' => __FILE__, 'name' => 'HideVariousTabsFromUnauthorizedUsers', 'author' => array( 'Tim Weyer' ), 'url' => 'https://www.mediawiki.org/wiki/User:SVG', 'description' => 'Disables various view and namespace tabs from users without <tt>edit</tt> permission for Vector skin', 'version' => '04-12-2012', ); // Hooks $wgHooks['SkinTemplateNavigation'][] = 'fnHVTFUUremoveTabsFromVector'; // Tabs of view to remove $wgHVTFUUviewsToRemove = array( 'view' /* read */, 'edit', 'addsection' /* on talkpages */, 'history' ); /** * @param $sktemplate Title * @param $links * @return bool */ function fnHVTFUUremoveTabsFromVector( SkinTemplate &$sktemplate, array &$links ) { global $wgUser, $wgHVTFUUviewsToRemove; // Only remove tabs if user isn't allowed to edit pages if ( $wgUser->isAllowed( 'edit' ) ) { return false; } // Generate XML IDs from namespace names $subjectId = $sktemplate->mTitle->getNamespaceKey( '' ); // Determine if this is a talk page $isTalk = $sktemplate->mTitle->isTalkPage(); // Remove talkpage tab if ( $subjectId == 'main' ) { $talkId = 'talk'; } else { $talkId = "{$subjectId}_talk"; } if ( !$isTalk && $links['namespaces'][$talkId] ) unset( $links['namespaces'][$talkId] ); // Remove actions tabs foreach ( $wgHVTFUUviewsToRemove as $view ) { if ( $links['views'][$view] ) unset( $links['views'][$view] ); } return true; }
Works perfectly. Thanks. However the View Source tab still shows. Although you don't need permission to view that tab I would like to remove it as it's wasteful to Search Engine Optimization.
Sorry, forgot this tab because I didn't remove the edit permission when I was coding it. Just add 'viewsource' to $wgHVTFUUviewsToRemove array and it should work.
A long extension name at that :)
Which version of mediawiki is this for?
I think I've followed the instructions above, but get an internal server error on
// Generate XML IDs from namespace names
$subjectId = $sktemplate->mTitle->getNamespaceKey( '' );
// Determine if this is a talk page
$isTalk = $sktemplate->mTitle->isTalkPage();
I've coded it in MediaWiki 1.17.0. Due to Holygamer's testimony, it does also work with MediaWiki 1.16.5 and I've checked both Vector.php. It might not work with MediaWiki 1.18, the code of Vector.php is quite different.
For MediaWiki 1.19, try this:
function fnHVTFUUremoveTabsFromVector( SkinTemplate &$sktemplate, array &$links ) { global $wgUser, $wgHVTFUUviewsToRemove; // Only remove tabs if user isn't allowed to edit pages if ( $wgUser->isAllowed( 'edit' ) ) { return false; } // Remove talkpage tab if ( isset( $links['namespaces']['talk'] )) unset( $links['namespaces']['talk'] ); // Remove actions tabs foreach ( $wgHVTFUUviewsToRemove as $view ) { if ( isset( $links['views'][$view] )) unset( $links['views'][$view] ); } return true; }
HI I am using Midiawiki-1.18.3 version. i have followed the following suggestion to hide "view source" tab for anonymous user.
URL - http://www.mediawiki.org/wiki/Extension:ProtectSource#Configuration
But still i could see option. so please help me solve this.
Operation system: Windows-xp
Rgds, Mohan
You just need to add 'viewsource' to $wgHVTFUUviewsToRemove array and it'll work. I don't get how is this related to ProtectSource extension. HideVariousTabsFromUnauthorizedUsers is NOT ProtectSource.
HI Tim,
Could you please tell me in detail. Like do i need to update "LocalSettings.php" with below changes? $wgHVTFUUviewsToRemove['*']['viewsource'] = false; (or) do i need add like $wgHVTFUUviewsToRemove = array('viewsource');
I tried above given two option still i am able to see "View Source".
Thanks, Mohan
Hide viewsource tab for users without edit permission (usually unregistered users if you've set it so): $wgHVTFUUviewsToRemove = array( 'viewsource' );
Hi Tim,
i want to hide "View Source" Tab for Anonymous users. In the LocalSettings.php If i set $wgGroupPermissions['*']['edit'] = false; then its hides the Edit Tab, Where as if i set $wgHVTFUUviewsToRemove = array( 'viewsource' ); its still shows the "View soruce" tab. So could you please help me. Thanks in advance.
Thanks, Mohan
If you are not loggedin, you shouldn't be able to see viewsource tab (and no edit tab because edit tab gets into viewsource tab if you have no permission to edit pages). Do you use my code from above? You can try to purge the cache with ?action=purge
Hi Tim,
i am not logged in but still it shows the "View source" tab. Can you tell me which code & in which file i have to update your code? bcoz my mediawiki version is -1.18.3. The tell me how to try Purge option (under in which file). Rgds, Mohan
Create folder HideVariousTabsFromUnauthorizedUsers in extensions directory, create HideVariousTabsFromUnauthorizedUsers.php file in HideVariousTabsFromUnauthorizedUsers folder and add the code below to your this file. Then add require_once ( "$IP/extensions/HideVariousTabsFromUnauthorizedUsers/HideVariousTabsFromUnauthorizedUsers.php" ); to your LocalSettings.php. Remove $wgGroupPermissions['*']['edit'] = false; and any other earlier setting of HideVariousTabsFromUnauthorizedUsers extension from LocalSettings.php.
<?php /** * HideVariousTabsFromUnauthorizedUsers * * @package MediaWiki * @subpackage Extensions * * @author: Tim 'SVG' Weyer <t.weyer@ymail.com> * * @copyright Copyright (C) 2012 Tim Weyer * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later * */ $wgExtensionCredits['other'][] = array( 'path' => __FILE__, 'name' => 'HideVariousTabsFromUnauthorizedUsers', 'author' => array( 'Tim Weyer' ), 'url' => 'https://www.mediawiki.org/wiki/User:SVG', 'description' => 'Disables various view tabs (and originally also namespace tabs) from users without <tt>edit</tt> permission for Vector skin', 'version' => '05-28-2012', ); // Hooks $wgHooks['SkinTemplateNavigation'][] = 'fnHVTFUUremoveTabsFromVector'; // Tabs of view to remove $wgHVTFUUviewsToRemove = array( 'viewsource' ); // Remove 'edit' permission from anonymous users $wgGroupPermissions['*']['edit'] = false; /** * @param $sktemplate Title * @param $links * @return bool */ function fnHVTFUUremoveTabsFromVector( SkinTemplate &$sktemplate, array &$links ) { global $wgUser, $wgHVTFUUviewsToRemove; // Only remove tabs if user isn't allowed to edit pages if ( $wgUser->isAllowed( 'edit' ) ) { return false; } // Remove actions tabs foreach ( $wgHVTFUUviewsToRemove as $view ) { if ( $links['views'][$view] ) unset( $links['views'][$view] ); } return true; }
Hi Tim
It seems to work so far for me, THANKS for this extension. I altered this
// Tabs of view to remove
$wgHVTFUUviewsToRemove = array( 'edit', 'history', 'read', 'talk', 'viewsource' );
But it looks like it only works in the main namespace. Tabs of Pages in the MediaWiki or User Namespace still appear. Any ideas ? If possible I would like to hide all Tabs for unlogged users
Hi Tim,
i want to hide "View Source" Tab for Anonymous users. In the LocalSettings.php If i set $wgGroupPermissions['*']['edit'] = false; then its hides the Edit Tab, Where as if i set $wgHVTFUUviewsToRemove = array( 'viewsource' ); its still shows the "View soruce" tab. So could you please help me. Thanks in advance.
Here my requirement is that Anonymous users should not see "Edit & View Source" tabs.
Thanks, Mohan
Duplicate striked by SVG.
This worked for me, on the Vector Theme : protected function renderPortals( $portals ) {
global $wgUser;
then : case 'TOOLBOX':
if($wgUser->isAllowed( 'edit' )) {
$this->renderPortal('tb', $this->getToolbox(), 'toolbox', 'SkinTemplateToolboxEnd');
}
break;