[RESOLVED] Vector - Hide Toolbox for Anonymous Users

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

Thread:Project:Support_desk/How_to_hide_portions_of_text_from_site_visitors

Subfader (talk)11:09, 16 February 2012

Thanks but that doesn't stop the Toolbox links appearing in the source code. Those links are hurtful to Search Engine Optimization. I would like to completely remove the Toolbox for users not logged in.

Holygamer (talk)11:55, 16 February 2012

Hack the skin if hiding via CSS is not enough.

Subfader (talk)17:40, 16 February 2012

Any idea how? I found a tip on how to to that for the Monobook skin but that method doesn't work for Vector.

Holygamer (talk)17:43, 16 February 2012

skins/Vector.php: I guess it's added via

private function renderPortals( $portals ) {
...
                if ( !isset( $portals['TOOLBOX'] ) ) {
                        $portals['TOOLBOX'] = true;
                }

Try

private function renderPortals( $portals ) {
global $wgUser;
...
                if ( !isset( $portals['TOOLBOX'] ) && $wgUser->isAllowed('move') ) {
                        $portals['TOOLBOX'] = true;
                }

Adjust 'move' to the userright which loggedin users are allowed to and anons not.

Subfader (talk)20:18, 16 February 2012

Hi, my code doesn't look the same as that so I wasn't sure what to do. This is what I have in that file by default:

private function renderPortals( $portals ) { // Force the rendering of the following portals if ( !isset( $portals['SEARCH'] ) ) $portals['SEARCH'] = true; if ( !isset( $portals['TOOLBOX'] ) ) $portals['TOOLBOX'] = true;

if ( !isset( $portals['LANGUAGES'] ) ) $portals['LANGUAGES'] = true; // Render portals foreach ( $portals as $name => $content ) { echo "\n\n"; switch( $name ) { case 'SEARCH': break; case 'TOOLBOX': ?>

Could you please tell me what I should use instead of the above.

Holygamer (talk)03:09, 17 February 2012
 

I would not check, if the user is allowed to move a page. Instead I would check for the user being logged in. You can get that information by setting global $wgUser;. Then $wgUser->isLoggedIn() will return TRUE if the user is logged in, otherwise FALSE.

88.130.108.6809:59, 17 February 2012

The 'move' userrright was just an example. Some time ago a dev told me that checking userrights is better than for isLoggedIn.

Subfader (talk)15:16, 17 February 2012

^^Or was it instead of checking the usergroup?

Subfader (talk)15:28, 18 February 2012

Hi, I still don't know what I'm supposed to do to hide the Toolbox from anonymous users! I've got MediaWiki 1.16.5

This is what I have in that file by default:

private function renderPortals( $portals ) { // Force the rendering of the following portals if ( !isset( $portals['SEARCH'] ) ) $portals['SEARCH'] = true; if ( !isset( $portals['TOOLBOX'] ) ) $portals['TOOLBOX'] = true;

if ( !isset( $portals['LANGUAGES'] ) ) $portals['LANGUAGES'] = true; // Render portals foreach ( $portals as $name => $content ) { echo "\n\n"; switch( $name ) { case 'SEARCH': break; case 'TOOLBOX': ?>

Could you please tell me what I should use instead of the above.

Holygamer (talk)15:33, 18 February 2012

Replace

private function renderPortals( $portals ) { // Force the rendering of the following portals
 if ( !isset( $portals['SEARCH'] ) ) $portals['SEARCH'] = true;
 if ( !isset( $portals['TOOLBOX'] ) ) $portals['TOOLBOX'] = true;

with:

private function renderPortals( $portals ) { // Force the rendering of the following portals
global $wgUser;
 if ( !isset( $portals['SEARCH'] ) ) $portals['SEARCH'] = true;
 if ( !isset( $portals['TOOLBOX'] ) && $wgUser->isLoggedIn() ) $portals['TOOLBOX'] = true;
Subfader (talk)10:36, 19 February 2012

that code doesn't work for me :f id really like to get this fixed, please help me xD

ZKs (talk)00:41, 1 June 2012
 

Small alternative solution, in case the one above doesn't work for you:

Change

private function renderPortals( $portals ) { // Force the rendering of the following portals
    if ( !isset( $portals['SEARCH'] ) ) $portals['SEARCH'] = true;

to

private function renderPortals( $portals ) { // Force the rendering of the following portals
    global $wgUser;
    if ( !isset( $portals['SEARCH'] ) ) $portals['SEARCH'] = true;

then change

case 'TOOLBOX':
    $this->renderPortal( 'tb', $this->getToolbox(), 'toolbox', 'SkinTemplateToolboxEnd' );

to

case 'TOOLBOX':
    if ( $wgUser->isLoggedIn() ) {
        $this->renderPortal( 'tb', $this->getToolbox(), 'toolbox', 'SkinTemplateToolboxEnd' );
    }

This checks the user login state even if the $portals array already has TOOLBOX defined. Best of luck!

MarkTraceur (talk)18:57, 1 June 2012

I have MediaWiki 1.16.5. At one point the 1st solution you suggested worked. However on a new installation neither method is working for me. This is how my code looks by default:

private function renderPortals( $portals ) {
// Force the rendering of the following portals
if ( !isset( $portals['SEARCH'] ) ) $portals['SEARCH'] = true;
if ( !isset( $portals['TOOLBOX'] ) ) $portals['TOOLBOX'] = true;

if ( !isset( $portals['LANGUAGES'] ) ) $portals['LANGUAGES'] = true;
Holygamer (talk)22:52, 11 January 2013

Hacking the MW source is bad. Don't do it!

Instead check if there is a hook which allows modifying the toolbox.

Apart from that I still do not understand why these links should be bad for SEO.

88.130.110.24301:38, 12 January 2013
 

This worked perfectly. I am using Media Wiki more of as a Knowledge base than as a Community Wiki, SEO really doesn't concern me here. I basically want to lock down the Wiki for reading purposes only and there are certain things they do not need to have access to as a reader.

184.56.175.11605:11, 26 February 2013
 

Solution worked:

MarkTraceur (talk)‎18:57, 1 June 2012

thank you sir.

71.85.100.1802:03, 11 March 2014
 

This works like a charm!!

Thanks a lot!

David

davidbrito12:33, 7 April 2014
 

Very awesome! Thanks!

Willazilla (talk)22:33, 15 February 2015