$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();
// 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 ) {
// 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;
}
}
# 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();