Last modified: 2010-10-14 01:09:12 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 T8204, the corresponding Phabricator task for complete and up-to-date bug report information.
Bug 6204 - TOC not properly rendered when using $wgMaxTocLevel
TOC not properly rendered when using $wgMaxTocLevel
Status: RESOLVED FIXED
Product: MediaWiki
Classification: Unclassified
Parser (Other open bugs)
1.6.x
All All
: Low minor with 1 vote (vote)
: ---
Assigned To: Nobody - You can work on this!
: parser
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2006-06-05 12:21 UTC by Gourou Lapin
Modified: 2010-10-14 01:09 UTC (History)
3 users (show)

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


Attachments

Description Gourou Lapin 2006-06-05 12:21:08 UTC
How to reproduce this bug:
- I used a clean install of MediaWiki 1.6.6
- I set "$wgMaxTocLevel = 3;" in LocalSettings.php
- I create a test page:
== header 1 ==
== header 2 ==
=== header 2.1 ===
==== header 2.2.1 ====
== header 3 ==
=== header 3.1 ===
=== header 3.2 ===
- I click on Preview, or Save (the result is the same)
- The TOC is not rendered as it should:
Roughly, there are too much "</ul></li>" generated.
It probably comes from improper calls to function tocUnindent()
(includes/Linker.php) from parser (includes/Parser.php).

This was my first bug report, I hope it is accurate.

Thanks for your excellent work,

Best regards.
Comment 1 David 2007-04-30 09:46:54 UTC
The problem is indeed in function formatHeadings in Parser.php
The following line always unindents from the current depth, altough we might did
not reach that depth.

if( $toclevel<$wgMaxTocLevel ) {
    $toc .= $sk->tocUnindent( $prevtoclevel - $toclevel );
}

I fixed it in my code using 
$toc .= $sk->tocUnindent( min($prevtoclevel, $wgMaxTocLevel-1) - $toclevel );

From the svn repository, i think the bug is still present in current versions.
Can anybody confirm or deny this?
Comment 2 Brion Vibber 2007-04-30 19:52:18 UTC
Fixed in r21725 along with a couple related bugs.
Comment 3 Antoine "hashar" Musso (WMF) 2007-05-02 21:53:03 UTC
r21725 fixed the issue with $wgMaxTocLevel = 3 but it caused the same
bug with the default $wgMaxTocLevel = 999 (see bug #9760).

I reverted a small part of r21725 to solve bug #9760, thus reopening this one.
Comment 4 Antoine "hashar" Musso (WMF) 2007-05-02 21:53:39 UTC
I meant bug #9764 instead of bug #9760.
Comment 5 Antoine "hashar" Musso (WMF) 2007-05-03 17:50:10 UTC
Added a parser test in r21833 :

TOC with wgMaxTocLevel=3 (bug 6204)
Comment 6 Antoine "hashar" Musso (WMF) 2007-05-03 19:37:12 UTC
Fixed in r21837.

We unindented line without checking if we did an indent before, that
was not always the case cause $wgMaxTocLevel actually prevent the indenting
of heading above its level.
Comment 7 brandon ooi 2007-12-16 01:36:51 UTC
This is not fixed yet (as of 1.11). This is the corner case.

for example when wgMaxTocLevel = 3

==Section 1==
===Section 1.1==
====Section 1.1.1==== <<-- this is hidden
====Section 1.1.1.1==== <<-- this is hidden
==Section 2==         <<-- this only gets UnIndented ONCE... not twice.

The problem is $prevtoclevel is not kept track of properly. The fix is to track it whenever we indent/unindent. You cannot (should not) track it with toclevel changes because those can fluctuate outside of the $wgMaxTocLevel area.


around line 3561, remove $prevtoclevel set

if( $toclevel ) {
    $prevlevel = $level;
    //$prevtoclevel = $toclevel;  //<<---commented out
}


around line 3605, track $prevtoclevel.

if( $toclevel<$wgMaxTocLevel ) {
    if($prevtoclevel < $wgMaxTocLevel) {
        # Unindent only if the previous toc level was shown :p
        $toc .= $sk->tocUnindent( $prevtoclevel - $toclevel );
        $prevtoclevel = $toclevel; //<<--added.
    } else {
        $toc .= $sk->tocLineEnd();
    }
}

This fixed it for us by tracking $prevtoclevel only with actual indentation/unindentations. Might not be the right fix for everybody though. Thoughts?
Comment 8 Brion Vibber 2007-12-18 00:55:45 UTC
Corrected example text (was missing a =):

==Section 1==
===Section 1.1===
====Section 1.1.1====
====Section 1.1.1.1====
==Section 2==

Should add some parser test cases for this?
Comment 9 Conrad Irwin 2010-09-04 00:04:37 UTC
Fixed (finally) in r72336.
Comment 10 brandon ooi 2010-10-14 01:09:12 UTC
I've long since moved on from this project but it's nice to see you guys still care :P.

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


Navigation
Links