Page MenuHomePhabricator

Allow nested lists in MediaWiki:Sidebar
Closed, DeclinedPublic

Assigned To
Authored By
bzimport
Oct 4 2005, 1:02 PM
Referenced Files
F2344: Sidebar.php
Nov 21 2014, 8:51 PM
F2345: Skin.php.diff
Nov 21 2014, 8:51 PM
F2343: includes_Skin.php.Patch
Nov 21 2014, 8:50 PM
F2338: skins_common_cologneblue.css.Patch
Nov 21 2014, 8:50 PM
F2340: skins_MonoBook.php.Patch
Nov 21 2014, 8:50 PM
F2341: skins_monobook_main.css.Patch
Nov 21 2014, 8:50 PM
F2337: skins_CologneBlue.php.Patch
Nov 21 2014, 8:50 PM

Description

Author: wikipedia

Description:
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
    • ...
    • ...

Version: 1.5.x
Severity: enhancement
URL: http://207.175.61.212

Details

Reference
bz3597

Revisions and Commits

Event Timeline

bzimport raised the priority of this task from to Lowest.Nov 21 2014, 8:50 PM
bzimport added a project: MediaWiki-Parser.
bzimport set Reference to bz3597.
bzimport added a subscriber: Unknown Object (MLST).

rjf wrote:

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;

        }
        }
}

avarab wrote:

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.

rjf wrote:

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

attachment Nested_Sidebar ignored as obsolete

avarab wrote:

(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.

rjf wrote:

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...

rjf wrote:

1 of 5 Patches for nested Sidebar menus

attachment includes_Skin.php.Patch ignored as obsolete

rjf wrote:

2 of 5 Patches for nested Sidebar menus

Attached:

rjf wrote:

3 of 5 Patches for nested Sidebar menus

Attached:

rjf wrote:

4 of 5 Patches for nested Sidebar menus

Attached:

rjf wrote:

5 of 5 Patches for nested Sidebar menus

Attached:

rjf wrote:

1 of 5 Patches for nested Sidebar menus

Better patch with less/no reversion of other updates within the function.

attachment includes_Skin.php.Patch ignored as obsolete

rjf wrote:

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

rjf wrote:

1 of 5 Patches for nested Sidebar menus

Better patch with less/no reversion of other updates within the function.
For really this time!

Attached:

Created attachment 3970
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.

Attached:

Created attachment 3971
Skin diff for using the Sidebar class

Attached:

Encourages too many links in the sidebar; would not want this.

epriestley changed the task status from Declined to Resolved by committing Unknown Object (Diffusion Commit).Mar 4 2015, 8:15 AM
epriestley added a commit: Unknown Object (Diffusion Commit).
Aklapper changed the task status from Resolved to Declined.Mar 4 2015, 11:27 AM
Aklapper claimed this task.