Last modified: 2011-03-13 18:06:33 UTC
It would be nice, if the sidebar could deal with lists that are nested more than once. So that something like the following works: * Blockheading ** mainpage|mainpage ** artikel-url|Artikel *** sub-artikel-url|Sub-Artikel *** sub-artikel-url|Sub-Artikel ** next-listpoint-url|next-listpoint * Next-Block-Heading ** ... ** ...
Here goes, this appears to work but has some bugs, like it doesn't deal with special characters very well, and could probebly be improved quite a bit... It expands the entire sub-branch for menus like: Main Menu Main Item2+ -Sub_Item --Sub Sub Item -Sub Item2 Main Item3 Main Item4 Uses "-" characters to "indent" items to their depth Uses "+" characters to indicate where you are currently sitting. In includes/Skin.php Replace existing buildSidebar function with this one function buildSidebar() { global $wgOut; // new required by next line $whereami = htmlspecialchars( $wgOut->getPageTitle() ); // new determine what article I am // Notice: Article names in menus with "_" instead of " " won't match later! // Bug: Other special characters in acticle names will cause broken links! $fname = 'SkinTemplate::buildSidebar'; wfProfileIn( $fname ); $bar = array(); $lines = explode( "\n", wfMsgForContent( 'sidebar' ) ); $majorlevel = -1; // new foreach ($lines as $line) { // This might be better as a case statement $minorlevel = 0; // new reinit minorlevel each time arround if (strpos($line, '*') !== 0) continue; // compressed this line if (strpos($line, '********') !== 0) $minorlevel = 6; // new if (strpos($line, '*******') !== 0) $minorlevel = 5; // new if (strpos($line, '******') !== 0) $minorlevel = 4; // new if (strpos($line, '*****') !== 0) $minorlevel = 3; // new if (strpos($line, '****') !== 0) $minorlevel = 2; // new if (strpos($line, '***') !== 0) { $minorlevel = 1; $majorlevel++; } // new 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 (wfNoMsg($line[1], $text = wfMsg($line[1]))) $text = $line[1]; if (wfNoMsg($line[0], $link)) $link = $line[0]; if ( $whereami == $link ) $text = "+" . $text . "+"; // new modify whereami's link text if ( $whereami == $link ) $mymajorlevel=$majorlevel; // new set mymajorlevel for export $bar[$heading][] = array( 'text' => $text, 'majorlevel' => $majorlevel, // new 'minorlevel' => $minorlevel, // new 'mymajorlevel' => $mymajorlevel, // new 'href' => $this->makeInternalOrExternalUrl( $link ), 'id' => 'n-' . strtr($line[1], ' ', '-'), ); } else { continue; } } } wfProfileOut( $fname ); return $bar; } In skins/MonoBook.php Change line ?132-134 <?php foreach($cont as $key => $val) { ?> <li id="<?php echo htmlspecialchars($val['id']) ?>"><a href="<?php echo htmlspecialchars($val['href']) ?>"><?php echo htmlspecialchars($val['text'])?></a></li> <?php } ?> To <!-- begin nesting menu code --> <!-- run through the array and determine what mymajorlevel is --> <?php foreach($cont as $key => $val) { ?><?php $mymajorlevel = $val['mymajorlevel'] ?><?php } ?> <?php foreach($cont as $key => $val) { ?> <!-- set indentation character based on minorlevel --> <!-- you can add an extra - to each level if you like --> <?php if($val['minorlevel'] == "1" ) {?><?php $text = "" . htmlspecialchars($val['text']) ?><?php } ?> <?php if($val['minorlevel'] == "2" ) {?><?php $text = "-" . htmlspecialchars($val['text']) ?><?php } ?> <?php if($val['minorlevel'] == "3" ) {?><?php $text = "--" . htmlspecialchars($val['text']) ?><?php } ?> <?php if($val['minorlevel'] == "4" ) {?><?php $text = "---" . htmlspecialchars($val['text']) ?><?php } ?> <?php if($val['minorlevel'] == "5" ) {?><?php $text = "----" . htmlspecialchars($val['text']) ?><?php } ?> <?php if($val['minorlevel'] == "6" ) {?><?php $text = "-----" . htmlspecialchars($val['text']) ?><?php } ?> <!-- if within mymajorlevel OR minorlevel is 1 output menu item --> <?php if($mymajorlevel == $val['majorlevel'] || $val['minorlevel'] == "1") {?> <li id="<?php echo htmlspecialchars($val['id']) ?>"><a href="<?php echo htmlspecialchars($val['href']) ?>"><?php echo htmlspecialchars($text)?></a></li> <?php } ?> <?php } ?> <!-- end nesting menu code --> In skins/CologneBlue.php Change line ?205- foreach ( $browseLinks as $link ) { if ( $link['text'] != '-' ) { $s .= "<a href=\"{$link['href']}\">" . htmlspecialchars( $link['text'] ) . '</a>' . $sep; } } To foreach ( $browseLinks as $link ) { $mymajorlevel = $link['mymajorlevel']; } foreach ( $browseLinks as $link ) { if ( $link['minorlevel'] == 1 ) { $link['text'] = "" . $link['text']; } if ( $link['minorlevel'] == 2 ) { $link['text'] = "-" . $link['text']; } if ( $link['minorlevel'] == 3 ) { $link['text'] = "--" . $link['text']; } if ( $link['minorlevel'] == 4 ) { $link['text'] = "---" . $link['text']; } if ( $link['minorlevel'] == 5 ) { $link['text'] = "----" . $link['text']; } if ( $link['minorlevel'] == 6 ) { $link['text'] = "-----" . $link['text']; } if ( $mymajorlevel == $link['majorlevel'] || $link['minorlevel'] == 1) { if ( $link['text'] != '-' ) { $s .= "<a href=\"{$link['href']}\">" . htmlspecialchars( $link['text'] ) . '</a>' . $sep; } } }
First of all AAA, submit a patch as an attachment and don't put it in the comment, second, we have code for parsing lists of arbitary depth in Licences.php, you might want to refactor that so it can be used for both of them.
Created attachment 1131 [details] Nested Submenu Patch(s) An attachment of the post I just made, which mangled formatting. In regards to http://bugzilla.wikimedia.org/show_bug.cgi?id=3597 In use (for the moment) at http://207.175.61.212 Remaining Bugs: * Special characters in article names, Such as "&" or " " produce broken links. * Intentation by renaming the link text is sloppy. * Expansion of entire branch is not ideal. L8r Ryan
(In reply to comment #3) > Created an attachment (id=1131) [edit] > Nested Submenu Patch(s) That's not a patch, see http://meta.wikimedia.org/wiki/MediaWiki_localization#Create_a_patch for how to make one.
first time Bugzilla-er, ThanX for the help, I guess it would have paid to read up first... I was just trying to get outa here for the night, guess that didn't work. Regarding posting the patch, sorry, I noticed that didn't work well. And the patch(s) I did post are also probably not attached correctly? ( which was just confirmed, I'll try again tomorrow ) I don't see a Licenses.php in my wiki tree, guess it's an aftermarket addon. I'll have to look into it...
Created attachment 1144 [details] 1 of 5 Patches for nested Sidebar menus
Created attachment 1145 [details] 2 of 5 Patches for nested Sidebar menus
Created attachment 1146 [details] 3 of 5 Patches for nested Sidebar menus
Created attachment 1147 [details] 4 of 5 Patches for nested Sidebar menus
Created attachment 1148 [details] 5 of 5 Patches for nested Sidebar menus
Created attachment 1149 [details] 1 of 5 Patches for nested Sidebar menus Better patch with less/no reversion of other updates within the function.
OK, hope these are valid patches as opposed to the junk I submitted earlier... I followed the checkout instructions here http://meta.wikimedia.org/wiki/MediaWiki_localization#Create_a_patch Not sure if I've set the Version and other attributes correctly here within bugzilla? These are somewhat better than the previous anyhow. Branches are expanded nicely up to three sub-levels deep, afterwhich the entire sub-branch is fully expanded. ... Who would want more then three levels of depth anyway? ;( Sub-branches are now indented at 5px steps up to 9 deep. This appears to work with both MonoBook and CologneBlue based skins. I'm sure that this could be written more elegantly, such as to not be limited by the depth of the menu. I don't know PHP yet and this is the best I could do. It's in use here, at the moment: http://207.175.61.212 L8r Ryan
Created attachment 1150 [details] 1 of 5 Patches for nested Sidebar menus Better patch with less/no reversion of other updates within the function. For really this time!
Created attachment 3970 [details] Sidebar class Sidebar class with several improvements over both the original implementation and the patch proposed herein: * Allows nesting arbitrarily deep * Checks to ensure unique id's are outputted * Allows non-links * Class \o/ I will upload a patch for Skin.php and MonoBook.php in a minute.
Created attachment 3971 [details] Skin diff for using the Sidebar class
Encourages too many links in the sidebar; would not want this.