Parser.php calls $sk->tocIndent() and $sk->tocUnindent( $prevtoclevel -
$toclevel ) even if the heading in question is above the $wgMaxTocLevel.
The default for $wgMaxTocLevel is 999, so usually this problem doesn't surface.
But if it is set to something low like 2 or 3, and there are headings on the
page which are greater than this level, the resulting page has an invalid list
in the table of contents. (There are extra <ul> </ul> <li> and </li> tags and
the nesting makes no sense. It doesn't validate as valid xhtml 1.0 transitional.)
I believe a simple fix can be accomplished by adding "if( (
!isset($wgMaxTocLevel) || $toclevel<$wgMaxTocLevel ) )" before "$toc .=
$sk->tocIndent();" and "if( ( !isset($wgMaxTocLevel) ||
$prevtoclevel<$wgMaxTocLevel ) )" before "$toc .= $sk->tocUnindent(
$prevtoclevel - $toclevel );" in Parser.php. This ensures that the tocIndent and
tocUnindent functions are only called if the heading is actually going to appear
in the toc. (these lines only appear once in Parser.php so they should be easy
to find and easy to fix.)