[MediaWiki-l] Show a different sidebar for anonymous users

Ingo Gabriel internet at unitas.org
Fri Mar 24 14:25:53 UTC 2017


Here we go.

You will need to create an (empty) wiki page MediaWiki:Anon_sidebar or
with any content you like to show in the sidebar to anonymous users.

Good luck.

# disable sidebar and toolbox for anonymous user

# advice from mediawiki
$wgEnableSidebarCache = false;

$wgHooks['SkinBuildSidebar'][] = 'lfHideSidebar';
/**
 * Show a different sidebar for anonymous users.
 * based on https://www.mediawiki.org/wiki/Manual:Interface/Sidebar/Hacks
 *
 * $skin Skin object
 * $bar array Contains the array items, out of which the sidebar will be
created.
 * @return true
 */
function lfHideSidebar( $skin, &$bar ) {
  global $wgUser;
  // Hide sidebar for anonymous users
  if ( !$wgUser->isLoggedIn() ) {
    // Shows a special anonymous sidebar.
    $bar = array(
      // Returns the message text of that sidebar with only
{{-transformation done.
      // Setting array keys "text"; array keys "href" and "active" stay
unset.
        'text' => wfMessage( 'anon_sidebar' )->inContentLanguage()->text(),
    );
  } else {
    // No changes, just display the sidebar as usual.
  }
  return true;
}

$wgHooks['BaseTemplateToolbox'][] = 'modifyToolbox';
/**
 * Show a different toolbox in sidebar for anonymous users.
 * based on https://www.mediawiki.org/wiki/User:Seb35/modifyToolbox
 *
 * $skin template object
 * $toolbox array Contains the array items, out of which the toolbox
will be created (without headline)
 * @return true
 */
function modifyToolbox( BaseTemplate $baseTemplate, array &$toolbox ) {
    global $wgUser;

    $emptyToolbox = array();

    if ( !$wgUser->isLoggedIn() ) {
        // provide empty toolbox
        $toolbox = $emptyToolbox;
    } else {
       // No changes, just display the existing toolbox as usual.
    }

    return true;
}


Am 24.03.2017 um 15:19 schrieb Phil Legault:
> If you could that would be great thanks
>
>
>
> ________________________________
> From: MediaWiki-l <mediawiki-l-bounces at lists.wikimedia.org> on behalf of Ingo Gabriel <internet at unitas.org>
> Sent: Friday, March 24, 2017 10:16 AM
> To: MediaWiki announcements and site admin list
> Subject: Re: [MediaWiki-l] Show a different sidebar for anonymous users
>
> We included the hook code and php function into the Localsettings.php
>
> and created the additional page for the anon-sidebar as wiki page
>
> I can provide the php code if interested in.
>
> Best regards
> Ingo
>
> Am 24.03.2017 um 15:00 schrieb Phil Legault:
>> Ya it seems I only get the text printout or it will just show "text" in the sidebar
>>
>>
>> ________________________________
>> From: MediaWiki-l <mediawiki-l-bounces at lists.wikimedia.org> on behalf of Ingo Gabriel <internet at unitas.org>
>> Sent: Friday, March 24, 2017 8:43 AM
>> To: MediaWiki announcements and site admin list
>> Subject: Re: [MediaWiki-l] Show a different sidebar for anonymous users
>>
>> Hi,
>>
>> we are using the solution from
>>
>> https://www.mediawiki.org/wiki/Manual:Interface/Sidebar/Hacks
> Manual:Interface/Sidebar/Hacks - MediaWiki<https://www.mediawiki.org/wiki/Manual:Interface/Sidebar/Hacks>
> www.mediawiki.org
> This page lists hacks that used to be mentioned in Manual:Interface/Sidebar. Change sidebar content when logged in (PHP) [edit source] In your LocalSettings.php file ...
>
>
>
>> Manual:Interface/Sidebar/Hacks - MediaWiki<https://www.mediawiki.org/wiki/Manual:Interface/Sidebar/Hacks>
> Manual:Interface/Sidebar/Hacks - MediaWiki<https://www.mediawiki.org/wiki/Manual:Interface/Sidebar/Hacks>
> www.mediawiki.org
> This page lists hacks that used to be mentioned in Manual:Interface/Sidebar. Change sidebar content when logged in (PHP) [edit source] In your LocalSettings.php file ...
>
>
>
>> www.mediawiki.org<http://www.mediawiki.org>
>> This page lists hacks that used to be mentioned in Manual:Interface/Sidebar. Change sidebar content when logged in (PHP) [edit source] In your LocalSettings.php file ...
>>
>>
>>
>> (you will need the modification from the talk page)
>>
>> We added additional handling of the toolbox section, too, by assigning
>> similar solution to the hook $wgHooks['BaseTemplateToolbox'][] based on
>> https://www.mediawiki.org/wiki/User:Seb35/modifyToolbox
>> User:Seb35/modifyToolbox - MediaWiki<https://www.mediawiki.org/wiki/User:Seb35/modifyToolbox>
>> www.mediawiki.org<http://www.mediawiki.org>
>> A small code snippet to allow administrators to modify the toolbox through MediaWiki:Sidebar. For example, move the "Recent changes" from the navigation to the toolbox:
>>
>>
>>
>>
>> Ingo
>>
>> Am 24.03.2017 um 12:57 schrieb Phil Legault:
>>> Has anyone found a solution for show different sidebar for anonymous users?
>>>
>>>
>>> As always thanks for your help,
>>>
>>> Phil
>>> _______________________________________________
>>> MediaWiki-l mailing list
>>> To unsubscribe, go to:
>>> https://lists.wikimedia.org/mailman/listinfo/mediawiki-l
>> --
>> Ingo Gabriel
>>
>>
>>
>>
>> _______________________________________________
>> MediaWiki-l mailing list
>> To unsubscribe, go to:
>> https://lists.wikimedia.org/mailman/listinfo/mediawiki-l
>> _______________________________________________
>> MediaWiki-l mailing list
>> To unsubscribe, go to:
>> https://lists.wikimedia.org/mailman/listinfo/mediawiki-l
>
>
> _______________________________________________
> MediaWiki-l mailing list
> To unsubscribe, go to:
> https://lists.wikimedia.org/mailman/listinfo/mediawiki-l
> _______________________________________________
> MediaWiki-l mailing list
> To unsubscribe, go to:
> https://lists.wikimedia.org/mailman/listinfo/mediawiki-l





More information about the MediaWiki-l mailing list