Jump to content

Topic on Project:Support desk/Flow

[RESOLVED] Vector - Hide Toolbox for Anonymous Users

21
Holygamer (talkcontribs)

On the Vector skin I would like to hide the Toolbox for Anonymous users. How can I do that? Also is there any way to decide which links appear in the Toolbox as for exmaple I don't need the print link to show.

Subfader (talkcontribs)
Holygamer (talkcontribs)

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.

Subfader (talkcontribs)

Hack the skin if hiding via CSS is not enough.

Holygamer (talkcontribs)

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

Subfader (talkcontribs)

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.

Holygamer (talkcontribs)

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.

88.130.108.68 (talkcontribs)

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.

Subfader (talkcontribs)

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

Subfader (talkcontribs)

^^Or was it instead of checking the usergroup?

Holygamer (talkcontribs)

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.

Subfader (talkcontribs)

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;
ZKs (talkcontribs)

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

MarkTraceur (talkcontribs)

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!

Holygamer (talkcontribs)

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;
88.130.110.243 (talkcontribs)

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.

184.56.175.116 (talkcontribs)

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.

71.85.100.18 (talkcontribs)

Solution worked:

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

thank you sir.

85.240.32.6 (talkcontribs)

This works like a charm!!

Thanks a lot!

David

Willazilla (talkcontribs)

Very awesome! Thanks!

216.46.3.162 (talkcontribs)

Works! Thank you!

Reply to "[RESOLVED] Vector - Hide Toolbox for Anonymous Users"