You can suppress the display of the sidebar from anonymous and un-logged-in users on your MediaWiki website. This can be done by creating a new PHP file in extensions folder then including the code in LocalSettings.php file.
Login to your MediaWiki website’s file manager or FTP, navigate to /extensions directory located in your site’s root and create a new folder /HideSidebar.
Open the folder, create a new PHP file with name HideSidebar.php and paste the following code:
<?php if ( !defined( 'MEDIAWIKI' ) ) { echo "Not a valid entry point"; exit( 1 ); } $wgExtensionCredits['other'][] = array( 'path' => __FILE__, 'name' => 'HideSidebar', 'version' => '1.0.1', 'author' => 'Jlerner', 'url' => 'https://www.mediawiki.org/wiki/Extension:HideSidebar', 'description' => 'Allows to hide the sidebar from anonymous users', ); $wgHooks['SkinBuildSidebar'][] = 'efHideSidebar'; function efHideSidebar($skin, &$bar) { global $wgUser; // Hide sidebar for anonymous users if (!$wgUser->isLoggedIn()) { $url = Title::makeTitle(NS_SPECIAL, 'UserLogin')->getLocalUrl(); $bar = array( 'navigation' => array( array('text' => 'Login', 'href' => $url, 'id' => 'n-login', 'active' => '') ) ); } return true; }
Now open LocalSettings.php file and add this line of code:
require_once "$IP/extensions/HideSidebar/HideSidebar.php";
Save changes and you are done.
Thanks. It works for me.
Thanks a lot ! Worked with mediawiki 1.36
For newer versions of mediawiki you need to make a couple changes
Replace
global $wgUser;
with
$user = RequestContext::getMain()->getUser();
Replace
if (!$wgUser->isLoggedIn()) {
with
if ($user->getId() == 0) {