Last modified: 2011-03-13 18:06:33 UTC

Wikimedia Bugzilla is closed!

Wikimedia migrated from Bugzilla to Phabricator. Bug reports are handled in Wikimedia Phabricator.
This static website is read-only and for historical purposes. It is not possible to log in and except for displaying bug reports and their history, links might be broken. See T5597, the corresponding Phabricator task for complete and up-to-date bug report information.
Bug 3597 - Allow nested lists in MediaWiki:Sidebar
Allow nested lists in MediaWiki:Sidebar
Status: RESOLVED WONTFIX
Product: MediaWiki
Classification: Unclassified
Parser (Other open bugs)
1.5.x
All All
: Lowest enhancement with 2 votes (vote)
: ---
Assigned To: Nobody - You can work on this!
http://207.175.61.212
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2005-10-04 13:02 UTC by Stefan
Modified: 2011-03-13 18:06 UTC (History)
0 users

See Also:
Web browser: ---
Mobile Platform: ---
Assignee Huggle Beta Tester: ---


Attachments
Nested Submenu Patch(s) (6.91 KB, text/plain)
2005-12-03 08:23 UTC, Ryan Fulcher
Details
1 of 5 Patches for nested Sidebar menus (3.26 KB, patch)
2005-12-07 04:27 UTC, Ryan Fulcher
Details
2 of 5 Patches for nested Sidebar menus (1.86 KB, patch)
2005-12-07 04:28 UTC, Ryan Fulcher
Details
3 of 5 Patches for nested Sidebar menus (1.01 KB, patch)
2005-12-07 04:28 UTC, Ryan Fulcher
Details
4 of 5 Patches for nested Sidebar menus (2.72 KB, patch)
2005-12-07 04:28 UTC, Ryan Fulcher
Details
5 of 5 Patches for nested Sidebar menus (806 bytes, patch)
2005-12-07 04:29 UTC, Ryan Fulcher
Details
1 of 5 Patches for nested Sidebar menus (3.26 KB, patch)
2005-12-07 04:44 UTC, Ryan Fulcher
Details
1 of 5 Patches for nested Sidebar menus (2.90 KB, patch)
2005-12-07 04:59 UTC, Ryan Fulcher
Details
Sidebar class (4.31 KB, text/plain)
2007-08-05 12:36 UTC, Merlijn van Deen (test)
Details
Skin diff for using the Sidebar class (1.56 KB, patch)
2007-08-05 12:37 UTC, Merlijn van Deen (test)
Details

Description Stefan 2005-10-04 13:02:06 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
** ...
** ...
Comment 1 Ryan Fulcher 2005-12-03 08:13:25 UTC
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;
                        }
                        }
                }
 
Comment 2 Ævar Arnfjörð Bjarmason 2005-12-03 08:15:52 UTC
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.
Comment 3 Ryan Fulcher 2005-12-03 08:23:54 UTC
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
Comment 4 Ævar Arnfjörð Bjarmason 2005-12-03 08:27:41 UTC
(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.
Comment 5 Ryan Fulcher 2005-12-03 08:33:34 UTC
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...
Comment 6 Ryan Fulcher 2005-12-07 04:27:29 UTC
Created attachment 1144 [details]
1 of 5 Patches for nested Sidebar menus
Comment 7 Ryan Fulcher 2005-12-07 04:28:02 UTC
Created attachment 1145 [details]
2 of 5 Patches for nested Sidebar menus
Comment 8 Ryan Fulcher 2005-12-07 04:28:40 UTC
Created attachment 1146 [details]
3 of 5 Patches for nested Sidebar menus
Comment 9 Ryan Fulcher 2005-12-07 04:28:59 UTC
Created attachment 1147 [details]
4 of 5 Patches for nested Sidebar menus
Comment 10 Ryan Fulcher 2005-12-07 04:29:15 UTC
Created attachment 1148 [details]
5 of 5 Patches for nested Sidebar menus
Comment 11 Ryan Fulcher 2005-12-07 04:44:35 UTC
Created attachment 1149 [details]
1 of 5 Patches for nested Sidebar menus

Better patch with less/no reversion of other updates within the function.
Comment 12 Ryan Fulcher 2005-12-07 04:55:16 UTC
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
Comment 13 Ryan Fulcher 2005-12-07 04:59:38 UTC
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!
Comment 14 Merlijn van Deen (test) 2007-08-05 12:36:45 UTC
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.
Comment 15 Merlijn van Deen (test) 2007-08-05 12:37:38 UTC
Created attachment 3971 [details]
Skin diff for using the Sidebar class
Comment 16 Brion Vibber 2007-08-08 17:39:19 UTC
Encourages too many links in the sidebar; would not want this.

Note You need to log in before you can comment on or make changes to this bug.


Navigation
Links