Merge "resourceloader: Use "\n" instead of ";" as separator for scripts"
[lhc/web/wiklou.git] / includes / diff / TableDiffFormatter.php
index be38e87..bcae746 100644 (file)
@@ -80,7 +80,7 @@ class TableDiffFormatter extends DiffFormatter {
         * @param string $header
         */
        protected function startBlock( $header ) {
-               echo $header;
+               $this->writeOutput( $header );
        }
 
        protected function endBlock() {
@@ -157,9 +157,9 @@ class TableDiffFormatter extends DiffFormatter {
         */
        protected function added( $lines ) {
                foreach ( $lines as $line ) {
-                       echo '<tr>' . $this->emptyLine() .
+                       $this->writeOutput( '<tr>' . $this->emptyLine() .
                                $this->addedLine( '<ins class="diffchange">' .
-                                       htmlspecialchars( $line ) . '</ins>' ) . "</tr>\n";
+                                       htmlspecialchars( $line ) . '</ins>' ) . "</tr>\n" );
                }
        }
 
@@ -170,9 +170,9 @@ class TableDiffFormatter extends DiffFormatter {
         */
        protected function deleted( $lines ) {
                foreach ( $lines as $line ) {
-                       echo '<tr>' . $this->deletedLine( '<del class="diffchange">' .
+                       $this->writeOutput( '<tr>' . $this->deletedLine( '<del class="diffchange">' .
                                        htmlspecialchars( $line ) . '</del>' ) .
-                               $this->emptyLine() . "</tr>\n";
+                               $this->emptyLine() . "</tr>\n" );
                }
        }
 
@@ -183,9 +183,9 @@ class TableDiffFormatter extends DiffFormatter {
         */
        protected function context( $lines ) {
                foreach ( $lines as $line ) {
-                       echo '<tr>' .
+                       $this->writeOutput( '<tr>' .
                                $this->contextLine( htmlspecialchars( $line ) ) .
-                               $this->contextLine( htmlspecialchars( $line ) ) . "</tr>\n";
+                               $this->contextLine( htmlspecialchars( $line ) ) . "</tr>\n" );
                }
        }
 
@@ -204,16 +204,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 );
-                       echo '<tr>' . $this->deletedLine( $line ) .
-                               $this->addedLine( $aline ) . "</tr>\n";
-                       $line = array_shift( $del );
-               }
-               foreach ( $add as $line ) { # If any leftovers
-                       echo '<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" );
                }
        }