How can I hide tabs for users not logged in?

Fragment of a discussion from Project:Support desk
Jump to: navigation, search

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

Tim (SVG)08:42, 28 May 2012

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

125.21.230.6808:56, 28 May 2012

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;
}
Tim (SVG)09:02, 28 May 2012

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

Brocchinia (talk)08:49, 31 August 2012

What version of MediaWiki do you use and how are the settings of your wiki's user rights? Sorry for my late reply!

Tim (SVG)11:11, 19 September 2012

Hi Tim,

is your extension still working with version 1.19.2. Maybe because of some different code in the newest vector skin? Thanks a lot!

Tickihgk (talk)22:43, 2 November 2012