I found the solution (thank to https://sangkrit.net/how-to-hide-mediawiki-sidebar-from-visitors/):
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.