Merge "Convert article delete to use OOUI"
[lhc/web/wiklou.git] / includes / diff / TableDiffFormatter.php
index f1826ed..14307b5 100644 (file)
@@ -196,7 +196,6 @@ class TableDiffFormatter extends DiffFormatter {
         * @param string[] $closing
         */
        protected function changed( $orig, $closing ) {
-
                $diff = new WordLevelDiff( $orig, $closing );
                $del = $diff->orig();
                $add = $diff->closing();
@@ -204,16 +203,13 @@ class TableDiffFormatter extends DiffFormatter {
                # Notice that WordLevelDiff returns HTML-escaped output.
                # Hence, we will be calling addedLine/deletedLine without HTML-escaping.
 
-               $line = array_shift( $del );
-               while ( $line ) {
-                       $aline = array_shift( $add );
-                       $this->writeOutput( '<tr>' . $this->deletedLine( $line ) .
-                               $this->addedLine( $aline ) . "</tr>\n" );
-                       $line = array_shift( $del );
-               }
-               foreach ( $add as $line ) { # If any leftovers
-                       $this->writeOutput( '<tr>' . $this->emptyLine() .
-                               $this->addedLine( $line ) . "</tr>\n" );
+               $ndel = count( $del );
+               $nadd = count( $add );
+               $n = max( $ndel, $nadd );
+               for ( $i = 0; $i < $n; $i++ ) {
+                       $delLine = $i < $ndel ? $this->deletedLine( $del[$i] ) : $this->emptyLine();
+                       $addLine = $i < $nadd ? $this->addedLine( $add[$i] ) : $this->emptyLine();
+                       $this->writeOutput( "<tr>{$delLine}{$addLine}</tr>\n" );
                }
        }