Manual:Interface/Sidebar/Hacks
|
|
This MediaWiki page is inactive and kept for historical interest. It may document extensions or features that are obsolete and/or no longer supported. Do not rely on the information here being up-to-date. |
This page lists hacks that used to be mentioned in Manual:Interface/Sidebar. These have been removed because they involve modifying the core .php code and are not supported. They are only here for historical interest.
Contents |
[edit] Change sidebar content when logged in (PHP)
To get anonymous users to have their own sidebars change includes/Skin.php. There is a function called buildSidebar. Edit this function to check for $wgUser->isLoggedIn() and call a different system message than sidebar.
if ($wgUser->isLoggedIn()) { $lines = explode( "\n", wfMsgForContent( 'sidebar' ) ); } else { $lines = explode( "\n", wfMsgForContent( 'anon_sidebar' ) ); }
Then in your Wiki, go to MediaWiki:anon_sidebar and create your new sidebar. You may need to add $wgUser to the list of global variables in the buildSidebar().
You'll also have to add $wgUser in the globals declaration of the function.
[edit] Allow wiki markup (PHP)
Many people on support desk have been asking about how to put arbitrary wikitext into the side bar. You can hack your skins/Monobook.php file (if you're using monobook) and replace the following section of code.
[edit] MediaWiki < 1.13.2
Replace this:
<?php foreach ($this->data['sidebar'] as $bar => $cont) { ?> <div class='portlet' id='p-<?php echo Sanitizer::escapeId($bar) ?>'<?php echo $skin->tooltip('p-'.$bar) ?>> <h5><?php $out = wfMsg( $bar ); if (wfEmptyMsg($bar, $out)) echo $bar; else echo $out; ?></h5> <div class='pBody'> <ul> <?php foreach($cont as $key => $val) { ?> <li id="<?php echo Sanitizer::escapeId($val['id']) ?>"<?php if ( $val['active'] ) { ?> class="active" <?php } ?>><a href="<?php echo htmlspecialchars($val['href']) ?>"<?php echo ... </li> <?php } ?> </ul> </div> </div> <?php } ?>
with this...
<?php global $wgUser,$wgTitle,$wgParser; $side = new Article(Title::newFromText('Sidebar',NS_MEDIAWIKI)); if (is_object($wgParser)) { $psr = $wgParser; $opt = $wgParser->mOptions; } else { $psr = new Parser; $opt = NULL; } if (!is_object($opt)) $opt = ParserOptions::newFromUser($wgUser); $wikitext = "__NOEDITSECTION____NOTOC__\n"; $wikitext .= $side->fetchContent(); $html = $psr->parse($wikitext,$wgTitle,$opt,true,true)->getText(); echo preg_replace("/<li>\\s*<\\/li>/",'',$html); ?>
If php4 on your sys
$html = $psr->parse($wikitext,$wgTitle,$opt,true,true); $html = $psr->mOutput->getText();
[edit] MediaWiki 1.13.2
Replace this:
$sidebar = $this->data['sidebar'];
if ( !isset( $sidebar['SEARCH'] ) ) $sidebar['SEARCH'] = true;
if ( !isset( $sidebar['TOOLBOX'] ) ) $sidebar['TOOLBOX'] = true;
if ( !isset( $sidebar['LANGUAGES'] ) ) $sidebar['LANGUAGES'] = true;
foreach ($sidebar as $boxName => $cont) {
if ( $boxName == 'SEARCH' ) {
$this->searchBox();
} elseif ( $boxName == 'TOOLBOX' ) {
$this->toolbox();
} elseif ( $boxName == 'LANGUAGES' ) {
$this->languageBox();
} else {
$this->customBox( $boxName, $cont );
}
}
with this:
global $wgParser, $wgUser, $wgTitle; if (!is_object($wgParser)) { $wgParser = new Parser; $opt = $wgParser->mOptions; } if (!is_object($opt)) { $opt = ParserOptions::newFromUser($wgUser); } echo $wgParser->parse(wfMsgForContent( 'sidebar' ),$wgTitle,$opt,true,true)->getText(); $this->searchBox(); $this->toolbox(); $this->languageBox();
[edit] Content of MediaWiki:Sidebar
That will allow the MediaWiki:Sidebar article to be proper wikitext. You will need to include the 'pBody' div tag to ensure the portlet is styled correctly, so your MediaWiki:Sidebar article will need to look something like the following example after the change:
<div class="portlet">
<h5>Navigation</h5>
<div class='pBody'>
*[[Main Page]]
*[[Community portal]]
*[{{fullurl:Special:Recentchanges}} Recent changes]
*[[Sandbox]]
*[[Help]]
</div>
</div>
[edit] Add a banner to the sidebar (PHP)
You can add one or more banners to the sidebar by hacking your skins/Monobook.php file (if you're using monobook) to include the following piece of code.
Find (line 188):
?> </div><!-- end of the left (by default at least) column -->
Include:
?>
<!-- begin of banner1 -->
<div class='generated-sidebar portlet'>
<h5><?php $this->msg('sidebar-banner1-headingtext') ?></h5>
<div style="border: 1px solid #B0B0B0; background-color: #FFFFFF;">
<a href="<?php $this->msg('sidebar-banner1-url') ?>">
<img width="100%" title="<?php $this->msg('sidebar-banner1-alttext') ?>"
alt="<?php $this->msg('sidebar-banner1-alttext') ?>"
src="<?php $this->msg('sidebar-banner1-imgsrc') ?>" /></a>
</div></div>
<!-- end of banner1 -->
</div><!-- end of the left (by default at least) column -->
Now in your Wiki, create four System messages: (i.e. articles named MediaWiki:sidebar-banner1-...)
| parameter | value |
|---|---|
| sidebar-banner1-headingtext | The text that will be displayed as the banner heading ("advertisement", "sponsor" etc.) |
| sidebar-banner1-url | The destination URL of this banner |
| sidebar-banner1-alttext | Title for the site. Content of the alt="" parameter of an HTML <img> tag. |
| sidebar-banner1-imgsrc | URL of the banner image. It may be the address of an image uploaded to your Wiki (magic words may be used, e.g. {{filepath:banner1.png}}), or the address of an external image. Content of the src="" parameter of an HTML <img> tag. |
To add more banners, just repeat the process renaming "banner1" to "banner2" etc.