Cleanup in doTableStuff
authorArlo Breault <abreault@wikimedia.org>
Fri, 3 Jul 2015 18:53:06 +0000 (11:53 -0700)
committerTim Starling <tstarling@wikimedia.org>
Thu, 9 Jul 2015 04:57:52 +0000 (04:57 +0000)
Change-Id: I75c0a943b24f96a30c6ee1efc3f0b11388f892b7

includes/parser/Parser.php

index 5506684..7f92590 100644 (file)
@@ -1023,6 +1023,7 @@ class Parser {
                        }
 
                        $first_character = $line[0];
+                       $first_two = substr( $line, 0, 2 );
                        $matches = array();
 
                        if ( preg_match( '/^(:*)\{\|(.*)$/', $line, $matches ) ) {
@@ -1042,7 +1043,7 @@ class Parser {
                                # Don't do any of the following
                                $out .= $outLine . "\n";
                                continue;
-                       } elseif ( substr( $line, 0, 2 ) === '|}' ) {
+                       } elseif ( $first_two === '|}' ) {
                                # We are ending a table
                                $line = '</table>' . substr( $line, 2 );
                                $last_tag = array_pop( $last_tag_history );
@@ -1060,7 +1061,7 @@ class Parser {
                                }
                                array_pop( $tr_attributes );
                                $outLine = $line . str_repeat( '</dd></dl>', $indent_level );
-                       } elseif ( substr( $line, 0, 2 ) === '|-' ) {
+                       } elseif ( $first_two === '|-' ) {
                                # Now we have a table row
                                $line = preg_replace( '#^\|-+#', '', $line );
 
@@ -1089,16 +1090,16 @@ class Parser {
                                array_push( $last_tag_history, '' );
                        } elseif ( $first_character === '|'
                                || $first_character === '!'
-                               || substr( $line, 0, 2 ) === '|+'
+                               || $first_two === '|+'
                        ) {
                                # This might be cell elements, td, th or captions
-                               if ( substr( $line, 0, 2 ) === '|+' ) {
+                               if ( $first_two === '|+' ) {
                                        $first_character = '+';
+                                       $line = substr( $line, 2 );
+                               } else {
                                        $line = substr( $line, 1 );
                                }
 
-                               $line = substr( $line, 1 );
-
                                if ( $first_character === '!' ) {
                                        $line = str_replace( '!!', '||', $line );
                                }