diff options
author | Kevin Israel <pleasestand@live.com> | 2015-10-08 23:17:50 -0400 |
---|---|---|
committer | Kevin Israel <pleasestand@live.com> | 2016-01-27 19:31:17 -0500 |
commit | 2476589b267c65d30176cfe23414e0178774e255 (patch) | |
tree | 2bcc20d4b46a204b070115dea3158c5ba66f0667 /includes/diff/DiffFormatter.php | |
parent | 5346065e0222004cd4293ad33ae331280ce86e2b (diff) | |
download | mediawikicore-2476589b267c65d30176cfe23414e0178774e255.tar.gz mediawikicore-2476589b267c65d30176cfe23414e0178774e255.zip |
DiffFormatter: Don't mess with PHP output buffering
This is a line-by-line conversion to append to a string property rather
than print into a PHP output buffer.
The changes to the base class break subclasses such as MobileFrontend's
InlineDiffFormatter, which is updated in I81dd01cb.
Depends-On: I81dd01cbb9ce11b87115fb1fed511027aee436a1
Change-Id: Idf2a6c593b81a152edec923d4db6272ca1f3f545
Diffstat (limited to 'includes/diff/DiffFormatter.php')
-rw-r--r-- | includes/diff/DiffFormatter.php | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/includes/diff/DiffFormatter.php b/includes/diff/DiffFormatter.php index 33ca931fdb58..23e39ea73bd3 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 ); } |