User talk:Starbardee

From My Wiki
Jump to navigation Jump to search

Wiki Sidebar

Hi, here's step by step info on how we created our sidebar:

1. Go to your wiki's installation folder (you need access to the server it is hosted on) and inside the Extensions folder create a new folder named "MenuSidebar".

2. Inside this new folder create a new php document (text) named "MenuSidebar.php" and put the code below in it:

<?php
/**
 * Changes in 0.2:
 *  * Use "-" as list item to create a separator
 * Changes in 0.3:
 *  * Added CSS class item# and even/odd to list items to make styling easyer
 * Changes in 0.4:
 *  * Added a small arrow ">" for each menu (with subitems) displayed on the right.
  * Changes in 0.4.1:
 *  * BUGFIX: last </li> was missing  
 */
if ( !defined( 'MEDIAWIKI' ) ) {
	exit( 1 ) ;
}
 
$wgExtensionCredits['other'][] = array(
    'name' => 'MenuSidebar',
	'version' => '0.4.1',
    'author' => 'Wolfgang Stöttinger',
    'description' => 'Sidebar can be displayed as a nested Menu',
	'url'     => 'http://www.mediawiki.org/wiki/Extension:CSS_MenuSidebar',
);
 
$wgHooks['SkinBuildSidebar'][] = 'fnMenuSidebar';
 
/* If this is set to true, each ListItem is parsed by the MediaWiki parser 
 * which allows more flexible inclusion of MediaWiki content e.g links to files. 
 * If set to false, a similar behaviour to the normal SideBar is used.
 * 
 * Be careful when using this!
 */
$wgParseListItems = false;
 
function fnMenuSidebar($skin, &$bar) {
	global $wgParser, $wgUser, $wgTitle, $wgParseListItems;
 
	wfProfileIn( __METHOD__ );
 
	$title = Title::newFromText("MenuSidebar",NS_MEDIAWIKI);	
	/** Use the revision directly to prevent other hooks to be called */
	$rev = Revision::newFromTitle( $title );
 
	if ($rev)
		$lines = explode("\n", $rev->getRawText());
 
	if ($lines && count($lines) > 0) {
 
		$opt = null; 
 
		/* init the parser */
		if ($wgParseListItems) {
			if (!is_object($wgParser)) {
			    $wgParser = new Parser();
			    $opt = $wgParser->mOptions;
			}
			if (!is_object($opt)) {
			    $opt = ParserOptions::newFromUser($wgUser);
			}
		}
 
		for ($i = 0; $i < sizeof($lines); $i++) {
			$line = $lines[$i];
 
			if (strpos($line, '**') === 0 && $i > 0) {// entry in a deeper level:
				$content = '
			<div class="menuSidebar">
				<ul>
					' . fnBuildList($lines,$i,1, $opt) . '
				</ul>
			</div>
			';
				$bar[$title] = $content;
				$i--;
			}
			else { // use Entry as Title:
				$title = trim($line, '* ');
			}	
		}
	}
	return true;
}
 
function fnBuildList($lines,&$i, $level, $opt) {
	global $wgParser, $wgTitle, $wgParseListItems;
 
	$content = "";
	$closeLI = false;
	$itemCount = 0;
	for (;$i < sizeof($lines); $i++) {
		$itemCount++;		
 
  		$class = "item{$itemCount}"; 
  		$class .= ($itemCount % 2 == 0 ? " even" : " odd"); 
 
		$line = $lines[$i];
		$line = substr($line,$level);
 
		if (strpos($line, '**') === 0) {// entry in a deeper level:		
			// inject a > at the end of the line
			$content = rtrim($content); 
			if (strrpos($content,'</a>') === strlen($content) - 4) {
				$content = substr($content,0,-4) . "<em>››</em></a>"; 
			}
 
			$content .= '
				<div><ul>
					' .fnBuildList($lines,$i,$level+1, $opt) . '
				</ul></div>
				';
			$i--;
			$itemCount--;
		}
		else if (strpos($line, '*') === 0) { // entry in this level:
			if ($closeLI) { //workaround to close the last LI 
				$content .= "</li>";
				$closeLI = false;
			}
			if ($wgParseListItems) {
				$text = $wgParser->parse(trim($line, '* '),$wgTitle,$opt,true,true)->getText();
				$text = substr(trim($text),3,-5); // removes <p> and \n</p> that is generated by the parser
 
				if (trim($text) == "-"){
					$class .= " separator";
					$text = "";
				}
				if (strpos($text, '<a') !== 0) 
  					$text = "<a>" . $text . "</a>"; // this is needed to display normal text correctly
 
				$content .= "<li class=\"$class\">$text";
				$closeLI = true;
			}
			else
			{
				if (strpos($line, '|') !== false) {
					$line = array_map('trim', explode( '|' , trim($line, '* '), 2 ) );
					$link = wfMsgForContent( $line[0] );
					if ($link == '-')
						continue;
 
					$text = wfMsgExt($line[1], 'parsemag');
					if (wfEmptyMsg($line[1], $text))
						$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';
						}
					}
					$href = htmlspecialchars($href);
					$text = htmlspecialchars($text);
					$content .= "<li class=\"$class\"><a href=\"$href\">$text</a>";
					$closeLI = true;
				}
				else {
					if (trim($line) == "-") {
						$class = " separator";
						$text = "";
					}
 
					$text = htmlspecialchars( trim($line, '* '));
					$content .= "<li class=\"$class\"><a>$text</a>";
					$closeLI = true;
				}
			}
		}
		else {
			if ($closeLI) { //workaround to close the last LI
				$content .= "</li>";
				$closeLI = false;
			}
			break; 
		}	
	}
	if ($closeLI) { //workaround to close the last LI 
		$content .= "</li>";
		$closeLI = false;
	}
	return $content;
}

3. Inside your live wiki, go to your skin css pages to add some minor adjustments that ensure the menus appear correctly (area overflow issues):

MediaWiki:Monobook.css

/* Allow popup submenus to overflow the sidebar area */
.portlet {
	overflow: visible !important;
}


MediaWiki:Vector.css

/* keep nested list fonts from continually decreasing in size with each nesting */
#mw-panel div.portal div.body ul li {
	font-size: small !important;
}

/* Allow popup submenus to overflow the sidebar area */
#mw-panel div.portal div.body ul li {
	overflow: visible !important;
}

/* minor adjustments to the sidebar area for the Vector skin */
.menuSidebar ul div { 
        top: -1px !important; /* vertical offset of submenus */
}

.menuSidebar ul {
 width: 8em; /* width of main menu */
}

Again these are on *your* wiki. Here are the pages on *this* wiki as an example (if you haven't seen these type of pages before):

4. Creature your menu structure by creating a new page on your wiki named "MediaWiki:MenuSidebar". You can see ours here if you're not sure how to structure things (view the source wiki code): MediaWiki:MenuSidebar.

5. Open your LocalSettings.php file (inside the main wiki installation directory on your host server) and add the following line to the end of the file (if there is a php closing tag at the end of your settings file, "?>", put it on a line before that:

require_once("$IP/extensions/MenuSidebar/MenuSidebar.php");
$wgParseListItems = true;

6. Logged in users should now see the working menu on your wiki. Note that changes to the menu will not cause cached pages to be updated so if you use file caching on your installation you may want to clear that folder after significant changes to your sidebar (the location of these cached pages depends on what the person that set up your installation chose - the location will be noted inside LocalSettings.php).

7. The appearance can be tweaked and adjusted by using the skin files (widths, font sizes, etc).

Hope this helps, let me know if you need anything else or more help getting it set up. This is a slightly modified version of an older extension that can be found here: CSS MenuSidebar.

-- How often to wash makeup brushes? ,<a href=http://cheap-macmakeupor.webs.com/#38275>wholesale mac makeup</a> ,,http://clarisonicmia2us.webs.com/#18392 22:20, 14 June 2011 (EST)