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

Valerio Pelliccioni vmp at silkwood.it
Mon Mar 27 13:36:18 UTC 2017


Hello,
my wiki at http://tunearch.org <http://tunearch.org/> uses two sidebar (one for anonymous and one for subscribed users) and switches between them using this modified buildSidebar() function:

________________________________________________________
In /home/tunearch/public_html/w/includes/skins/Skin.php
	function buildSidebar() {
		global $wgEnableSidebarCache, $wgSidebarCacheExpiry;
		global $wgUser;

		$that = $this;
		$callback = function () use ( $that ) {
			$bar = [];
			global $wgUser;
			if ($wgUser->isLoggedIn()) {
				$that->addToSidebar( $bar, 'sidebar' );
			} else {
				$that->addToSidebar( $bar, 'anon_sidebar' );
			}	
				
			Hooks::run( 'SkinBuildSidebar', [ $that, &$bar ] );

			return $bar;
		};

		if ( $wgEnableSidebarCache ) {
			$cache = ObjectCache::getMainWANInstance();
			if ($wgUser->isLoggedIn()) {
			$sidebar = $cache->getWithSetCallback(
				$cache->makeKey( 'sidebar', $this->getLanguage()->getCode() ),
				MessageCache::singleton()->isDisabled()
					? $cache::TTL_UNCACHEABLE // bug T133069
					: $wgSidebarCacheExpiry,
				$callback,
				[ 'lockTSE' => 30 ]
			);
			} else {
			$sidebar = $cache->getWithSetCallback(
				$cache->makeKey( 'anon_sidebar', $this->getLanguage()->getCode() ),
				MessageCache::singleton()->isDisabled()
					? $cache::TTL_UNCACHEABLE // bug T133069
					: $wgSidebarCacheExpiry,
				$callback,
				[ 'lockTSE' => 30 ]
			);
			}
		} else {
			$sidebar = $callback();
		}


		// Apply post-processing to the cached value
		Hooks::run( 'SidebarBeforeOutput', [ $this, &$sidebar ] );

		return $sidebar;
	}

where the anon_sidebar is 

http://tunearch.org/wiki/MediaWiki:Anon_sidebar <http://tunearch.org/wiki/MediaWiki:Anon_sidebar>
* Orientation
** Special:UserLogin|Login
** TTA|mainpage-description
** A collection of tunes|What
** help|How
** Acknowledgments|Acknowledgments

* The Index
** Category:Tune|All tunes
** Special:BrowseData/Tune|Drill down
** Special:RunQuery/TuneQuery|Query Interface
** Special:Browse/{{NAMESPACE}}:{{PAGENAME}}|Browse Properties

* Issues
** Tune_History_Articles|Magazines
** Tune_books|Tune Books
Valerio Pelliccioni
----
e-mail: vmp at silkwood.it <mailto:vmp at silkwood.it>
mob: +39 3487649160
www: http://tunearch.org <http://tunearch.org/>

while the ordinary Sidebar is:

http://tunearch.org/wiki/MediaWiki:Sidebar <http://tunearch.org/wiki/MediaWiki:Sidebar>
* Orientation
** TTA|mainpage-description
** A collection of tunes|What
** help|Getting started
** ABCSandbox|ABC SandBox
** Acknowledgments| Acknowledgments
** {{fullurl:{{FULLPAGENAME}}|printable=yes}} | Printable version

* Contribution
** Special:FormEdit/Abc tune|Add tunes
** Special:Upload|Upload
** Special:SpecialPages|Special Pages

* The Index
** Category:Tune|All tunes
** Special:BrowseData/Tune|Drill down
** Special:RunQuery/TuneQuery|Query the Archive
** Special:Browse/{{NAMESPACE}}:{{PAGENAME}}|Browse Properties

* Issues
** Tune_History_Articles|Magazines
** Tune_books|Tune Books

I don’t know if this is the most elegant solution or if it fits your needs, but it works for me.

Regards.

Valerio
Valerio Pelliccioni
----
e-mail: vmp at silkwood.it
mob: +39 3487649160
www: http://tunearch.org






More information about the MediaWiki-l mailing list