====== MediaWiki Sidebar ====== Upgrade for the [[http://www.mediawiki.org/wiki/Extension:CustomNavBlocks|existing extension]]. ===== Installation ===== Simply CustomNavBlocks.php and make the following adjustments to your LocalSettings.php: require_once( "$IP/extensions/trunk/CustomNavBlocks/CustomNavBlocks.php" ); $wgCustomNavBlocksEnable = true; ===== Configuration ===== After the extension is enabled, MediaWiki will look for a page called ''MediaWiki:CustomNavBlocks''. This file defines the blocks used in the sidebar and has the following format: Pagename|title Pagename2|title2 In this example, the first block will be the content of MediaWiki:pagename with the title 'title' and the second block will be the content of MediaWiki:pagename2 with the title 'title2'. Please note that each line must not have more than one pipe ("|"). The default Navigation block is inserted by adding navigation to the ''MediaWiki:CustomNavBlocks'', for example: Pagename|title navigation Pagename2|title2 When Pagename does not exist, a link appears to allow you to create the page. ===== CustomNavBlocks.php ===== 'CustomNavBlocks', 'description' => 'Better customization of your sidebar', 'version' => '2.1.0-1.13.0', 'author' => 'Luuk Peters (2.0.0 by Mathias Ertl)', 'url' => 'http://www.luukpeters.nl/devel_mediawiki/CustomNavBlocks', ); function addCustomNavBlocks( $skin, $tpl ) { global $wgParser, $wgCustomNavBlocksEnable; if ( ! $wgCustomNavBlocksEnable ) return true; $parserOptions = new ParserOptions(); $CustomNavBlocksRaw = $tpl->translator->translate( 'CustomNavBlocks' ); # remove comments $CustomNavBlocksClean = trim( preg_replace( array('//s'), array(''), $CustomNavBlocksRaw ) ); $blocks = explode( "\n", $CustomNavBlocksClean ); $sidebar = array(); foreach ($blocks as $block) { $tmp = explode( '|', $block ); if ( count( $tmp ) == 1 && isset($tpl->data['sidebar'][$block])) { # try to find default sidebar item $sidebar[$block] = $tpl->data['sidebar'][$block]; } else { # break if a line in MediaWiki:CustomNavBlocks has more than one "|" if ( count( $tmp ) != 2 ) { $editBlockTitle = ''; $html = "unknown: " . $block . "" ; } else { # some shortcuts $definition = $tmp[0]; $blockTitle = $tmp[1]; # first, we need a title object: $title = Title::newFromText( $definition, NS_MEDIAWIKI ); # return false if a page defined by MediaWiki:CustomNavBlocks doesn't exist: if (!is_null($title) && ! $title->exists() ) { if(!is_null($title) && $title->quickUserCan('edit')){ $editBlockTitle = '('.$tpl->translator->translate('create').')'; } else { $editBlockTitle = ''; } $html = ''; } else { # get article and content: $content = $tpl->translator->translate( "$definition" ); # parse the mediawiki-syntax into html: $content = $wgParser->preprocess( $content, $title, $parserOptions ); $parserOutput = $wgParser->parse( $content, $title, $parserOptions ); $html = $parserOutput->getText(); if(!is_null($title) && $title->quickUserCan('edit')){ $editBlockTitle = '('.$tpl->translator->translate('edit').')'; } else { $editBlockTitle = ''; } } } # make a sidebar block: $sidebar["$blockTitle $editBlockTitle"] = $html; } } $title = Title::newFromText( "MediaWiki:CustomNavBlocks", NS_MEDIAWIKI ); if($title->quickUserCan('edit')){ $editBlockTitle = '('.''.('sidebar')." ".$tpl->translator->translate('edit').')'; $sidebar[$editBlockTitle] = null; } # set sidebar to new thing: $tpl->set( 'sidebar', $sidebar ); return true; } ?>