For MediaWiki (recent comments | status changes | tags | authors | states | release notes | statistics)
Index: trunk/phase3/includes/Preprocessor_DOM.php =================================================================== --- trunk/phase3/includes/Preprocessor_DOM.php (revision 30369) +++ trunk/phase3/includes/Preprocessor_DOM.php (revision 30370) @@ -955,7 +955,11 @@ # Heading $s = $this->expand( $contextNode->childNodes, $flags ); - if ( $this->parser->ot['html'] ) { + # Insert a heading marker only for <h> children of <root> + # This is to stop extractSections from going over multiple tree levels + if ( $contextNode->parentNode->nodeName == 'root' + && $this->parser->ot['html'] ) + { # Insert heading index marker $headingIndex = $contextNode->getAttribute( 'i' ); $titleText = $this->title->getPrefixedDBkey(); Index: trunk/phase3/includes/Parser.php =================================================================== --- trunk/phase3/includes/Parser.php (revision 30369) +++ trunk/phase3/includes/Parser.php (revision 30370) @@ -4572,7 +4572,6 @@ $this->setTitle( $wgTitle ); // not generally used but removes an ugly failure mode $this->mOptions = new ParserOptions; $this->setOutputType( self::OT_WIKI ); - $curIndex = 0; $outText = ''; $frame = $this->getPreprocessor()->newFrame(); @@ -4597,22 +4596,19 @@ // Section zero doesn't nest, level=big $targetLevel = 1000; } else { - while ( $node ) { - if ( $node->getName() == 'h' ) { - if ( $curIndex + 1 == $sectionIndex ) { + while ( $node ) { + if ( $node->getName() == 'h' ) { + $bits = $node->splitHeading(); + if ( $bits['i'] == $sectionIndex ) { + $targetLevel = $bits['level']; break; } - $curIndex++; } if ( $mode == 'replace' ) { $outText .= $frame->expand( $node, PPFrame::RECOVER_ORIG ); } $node = $node->getNextSibling(); } - if ( $node ) { - $bits = $node->splitHeading(); - $targetLevel = $bits['level']; - } } if ( !$node ) { @@ -4627,10 +4623,9 @@ // Find the end of the section, including nested sections do { if ( $node->getName() == 'h' ) { - $curIndex++; $bits = $node->splitHeading(); $curLevel = $bits['level']; - if ( $curIndex != $sectionIndex && $curLevel <= $targetLevel ) { + if ( $bits['i'] != $sectionIndex && $curLevel <= $targetLevel ) { break; } }