MediaWiki r30370 - Code Review

Jump to: navigation, search
Repository:MediaWiki
Revision:r30369‎ | r30370 (on ViewVC)‎ | r30371 >
Date:01:35, 1 February 2008
Author:tstarling
Status:old
Tags:
Comment:
Fix a regression of bug 4899 due to HHPv2: <h> tags now appear on tree depth levels other than the first. The 4899 aspect is easily fixed by having extractSections() look at the i attribute instead of just counting.

The implications in general are that headings inside properly-closed double braces will not have section edit links, even where the braces are broken by invalid title characters and expanded literally to recover the heading. Respecting such headings as section breaks would run into the same problems as those discussed w.r.t. LST on wikitech-l -- there's no way to recover the text for a section that starts on one tree level and finishes on a different one. The fact that higher level <h> nodes appear in the XML is just due to a shortcut in preprocessToObj(): headings are put into the stack in case the braces turn out to be unclosed, in which case the heading will be at level 1 of the tree.
Modified paths:

Diff [purge]

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;
 				}
 			}

Status & tagging log

  • 15:24, 12 September 2011 Meno25 (Talk | contribs) changed the status of r30370 [removed: ok added: old]
Personal tools
Namespaces
Variants
Views
Actions
Site
Support
Download
Development
Communication
Toolbox