From: jenkins-bot Date: Thu, 11 Feb 2016 00:31:57 +0000 (+0000) Subject: Merge "DiffFormatter: Don't mess with PHP output buffering" X-Git-Tag: 1.31.0-rc.0~8003 X-Git-Url: http://git.cyclocoop.org/?a=commitdiff_plain;h=7ed96f4de2411d21cce4572e1fac7d3a8d2d0b77;hp=da7f6d0246b150165f2de45fcc1b3d899fe9916f;p=lhc%2Fweb%2Fwiklou.git Merge "DiffFormatter: Don't mess with PHP output buffering" --- diff --git a/includes/diff/DiffFormatter.php b/includes/diff/DiffFormatter.php index 33ca931fdb..23e39ea73b 100644 --- a/includes/diff/DiffFormatter.php +++ b/includes/diff/DiffFormatter.php @@ -49,6 +49,9 @@ abstract class DiffFormatter { */ protected $trailingContextLines = 0; + /** @var string The output buffer; holds the output while it is built. */ + private $result = ''; + /** * Format a diff. * @@ -146,15 +149,24 @@ abstract class DiffFormatter { } protected function startDiff() { - ob_start(); + $this->result = ''; + } + + /** + * Writes a string to the output buffer. + * + * @param string $text + */ + protected function writeOutput( $text ) { + $this->result .= $text; } /** * @return string */ protected function endDiff() { - $val = ob_get_contents(); - ob_end_clean(); + $val = $this->result; + $this->result = ''; return $val; } @@ -185,7 +197,7 @@ abstract class DiffFormatter { * @param string $header */ protected function startBlock( $header ) { - echo $header . "\n"; + $this->writeOutput( $header . "\n" ); } /** @@ -203,7 +215,7 @@ abstract class DiffFormatter { */ protected function lines( $lines, $prefix = ' ' ) { foreach ( $lines as $line ) { - echo "$prefix $line\n"; + $this->writeOutput( "$prefix $line\n" ); } } @@ -236,7 +248,7 @@ abstract class DiffFormatter { */ protected function changed( $orig, $closing ) { $this->deleted( $orig ); - echo "---\n"; + $this->writeOutput( "---\n" ); $this->added( $closing ); } diff --git a/includes/diff/TableDiffFormatter.php b/includes/diff/TableDiffFormatter.php index be38e8759c..f1826edc5e 100644 --- a/includes/diff/TableDiffFormatter.php +++ b/includes/diff/TableDiffFormatter.php @@ -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 '' . $this->emptyLine() . + $this->writeOutput( '' . $this->emptyLine() . $this->addedLine( '' . - htmlspecialchars( $line ) . '' ) . "\n"; + htmlspecialchars( $line ) . '' ) . "\n" ); } } @@ -170,9 +170,9 @@ class TableDiffFormatter extends DiffFormatter { */ protected function deleted( $lines ) { foreach ( $lines as $line ) { - echo '' . $this->deletedLine( '' . + $this->writeOutput( '' . $this->deletedLine( '' . htmlspecialchars( $line ) . '' ) . - $this->emptyLine() . "\n"; + $this->emptyLine() . "\n" ); } } @@ -183,9 +183,9 @@ class TableDiffFormatter extends DiffFormatter { */ protected function context( $lines ) { foreach ( $lines as $line ) { - echo '' . + $this->writeOutput( '' . $this->contextLine( htmlspecialchars( $line ) ) . - $this->contextLine( htmlspecialchars( $line ) ) . "\n"; + $this->contextLine( htmlspecialchars( $line ) ) . "\n" ); } } @@ -207,13 +207,13 @@ class TableDiffFormatter extends DiffFormatter { $line = array_shift( $del ); while ( $line ) { $aline = array_shift( $add ); - echo '' . $this->deletedLine( $line ) . - $this->addedLine( $aline ) . "\n"; + $this->writeOutput( '' . $this->deletedLine( $line ) . + $this->addedLine( $aline ) . "\n" ); $line = array_shift( $del ); } foreach ( $add as $line ) { # If any leftovers - echo '' . $this->emptyLine() . - $this->addedLine( $line ) . "\n"; + $this->writeOutput( '' . $this->emptyLine() . + $this->addedLine( $line ) . "\n" ); } } diff --git a/includes/diff/UnifiedDiffFormatter.php b/includes/diff/UnifiedDiffFormatter.php index 5f3ad3d7bb..72f1a66034 100644 --- a/includes/diff/UnifiedDiffFormatter.php +++ b/includes/diff/UnifiedDiffFormatter.php @@ -42,7 +42,7 @@ class UnifiedDiffFormatter extends DiffFormatter { */ protected function lines( $lines, $prefix = ' ' ) { foreach ( $lines as $line ) { - echo "{$prefix}{$line}\n"; + $this->writeOutput( "{$prefix}{$line}\n" ); } }