User:Hoggwild5/ExtraSidebar
The function below can be copied and pasted into the skins.php file you wish to modify, after the following:
function initPage( &$out ) {
SkinTemplate::initPage( $out );
$this->skinname = 'monobook';
$this->stylename = 'monobook';
$this->template = 'MonoBookTemplate';
}
Make sure the function is part of the first class in the skins file, the one that extends SkinTemplate.
Code
edit function buildSidebar() {
global $wgLang, $wgContLang, $wgUser;
$fname = 'SkinTemplate::buildSidebar';
wfProfileIn( $fname );
$bar = array();
$lines = explode( "\n", wfMsgForContent( 'sidebar' ) );
if($wgUser->isLoggedIn()){
$lines2 = explode( "\n", wfMsgForContent( 'sidebar-internal' ) );
$lines = array_merge($lines, $lines2);
}
$heading = '';
foreach ($lines as $line) {
if (strpos($line, '*') !== 0)
continue;
if (strpos($line, '**') !== 0) {
$line = trim($line, '* ');
$heading = $line;
} else {
if (strpos($line, '|') !== false) { // sanity check
$line = explode( '|' , trim($line, '* '), 2 );
$link = wfMsgForContent( $line[0] );
if ($link == '-')
continue;
if (wfEmptyMsg($line[1], $text = wfMsg($line[1])))
$text = $line[1];
if (wfEmptyMsg($line[0], $link))
$link = $line[0];
if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $link ) ) {
$href = $link;
} else {
$title = Title::newFromText( $link );
if ( $title ) {
$title = $title->fixSpecialName();
$href = $title->getLocalURL();
} else {
$href = 'INVALID-TITLE';
}
}
$bar[$heading][] = array(
'text' => $text,
'href' => $href,
'id' => 'n-' . strtr($line[1], ' ', '-'),
'active' => false
);
} else { continue; }
}
}
wfProfileOut( $fname );
return $bar;
}
Notes
edit- Because the sidebar changes depending on the logged in status of the user, caching for the sidebar has to be disabled. This is a small performance hit, and one that should not be noticable on any but the most active sites. If you have been using $wgEnableSidebarCache or $wgSidebarCacheExpiry, these settings will no longer function for any skin utilizing this sidebar.