Merge "Allow fragment-only TitleValues"
[lhc/web/wiklou.git] / includes / parser / BlockLevelPass.php
index b2bcc8c..50c7e23 100644 (file)
@@ -199,8 +199,11 @@ class BlockLevelPass {
                $pendingPTag = false;
                $inBlockquote = false;
 
-               $lineCount = count( $textLines );
-               foreach ( $textLines as $i => $inputLine ) {
+               for ( $textLines->rewind(); $textLines->valid(); ) {
+                       $inputLine = $textLines->current();
+                       $textLines->next();
+                       $notLastLine = $textLines->valid();
+
                        # Fix up $lineStart
                        if ( !$this->lineStart ) {
                                $output .= $inputLine;
@@ -377,23 +380,19 @@ class BlockLevelPass {
                                                                $output .= $pendingPTag . '<br />';
                                                                $pendingPTag = false;
                                                                $this->lastParagraph = 'p';
-                                                       } else {
-                                                               if ( $this->lastParagraph !== 'p' ) {
-                                                                       $output .= $this->closeParagraph();
-                                                                       $pendingPTag = '<p>';
-                                                               } else {
-                                                                       $pendingPTag = '</p><p>';
-                                                               }
-                                                       }
-                                               } else {
-                                                       if ( $pendingPTag ) {
-                                                               $output .= $pendingPTag;
-                                                               $pendingPTag = false;
-                                                               $this->lastParagraph = 'p';
                                                        } elseif ( $this->lastParagraph !== 'p' ) {
-                                                               $output .= $this->closeParagraph() . '<p>';
-                                                               $this->lastParagraph = 'p';
+                                                               $output .= $this->closeParagraph();
+                                                               $pendingPTag = '<p>';
+                                                       } else {
+                                                               $pendingPTag = '</p><p>';
                                                        }
+                                               } elseif ( $pendingPTag ) {
+                                                       $output .= $pendingPTag;
+                                                       $pendingPTag = false;
+                                                       $this->lastParagraph = 'p';
+                                               } elseif ( $this->lastParagraph !== 'p' ) {
+                                                       $output .= $this->closeParagraph() . '<p>';
+                                                       $this->lastParagraph = 'p';
                                                }
                                        }
                                }
@@ -407,7 +406,7 @@ class BlockLevelPass {
                                        $output .= $t;
                                        // Add a newline if there's an open paragraph
                                        // or we've yet to reach the last line.
-                                       if ( $i < $lineCount - 1 || $this->hasOpenParagraph() ) {
+                                       if ( $notLastLine || $this->hasOpenParagraph() ) {
                                                $output .= "\n";
                                        }
                                } else {