jenkins-bot has submitted this change and it was merged.
Change subject: DiffFormatter: Don't mess with PHP output buffering
......................................................................
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
---
M includes/diff/DiffFormatter.php
M includes/diff/TableDiffFormatter.php
M includes/diff/UnifiedDiffFormatter.php
3 files changed, 30 insertions(+), 18 deletions(-)
Approvals:
MaxSem: Looks good to me, approved
Jdlrobson: Looks good to me, but someone else must approve
jenkins-bot: Verified
diff --git a/includes/diff/DiffFormatter.php b/includes/diff/DiffFormatter.php
index 33ca931..23e39ea 100644
--- a/includes/diff/DiffFormatter.php
+++ b/includes/diff/DiffFormatter.php
@@ -49,6 +49,9 @@
*/
protected $trailingContextLines = 0;
+ /** @var string The output buffer; holds the output while it is built.
*/
+ private $result = '';
+
/**
* Format a diff.
*
@@ -146,15 +149,24 @@
}
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 @@
* @param string $header
*/
protected function startBlock( $header ) {
- echo $header . "\n";
+ $this->writeOutput( $header . "\n" );
}
/**
@@ -203,7 +215,7 @@
*/
protected function lines( $lines, $prefix = ' ' ) {
foreach ( $lines as $line ) {
- echo "$prefix $line\n";
+ $this->writeOutput( "$prefix $line\n" );
}
}
@@ -236,7 +248,7 @@
*/
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 be38e87..f1826ed 100644
--- a/includes/diff/TableDiffFormatter.php
+++ b/includes/diff/TableDiffFormatter.php
@@ -80,7 +80,7 @@
* @param string $header
*/
protected function startBlock( $header ) {
- echo $header;
+ $this->writeOutput( $header );
}
protected function endBlock() {
@@ -157,9 +157,9 @@
*/
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 @@
*/
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 @@
*/
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" );
}
}
@@ -207,13 +207,13 @@
$line = array_shift( $del );
while ( $line ) {
$aline = array_shift( $add );
- echo '<tr>' . $this->deletedLine( $line ) .
- $this->addedLine( $aline ) . "</tr>\n";
+ $this->writeOutput( '<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";
+ $this->writeOutput( '<tr>' . $this->emptyLine() .
+ $this->addedLine( $line ) . "</tr>\n" );
}
}
diff --git a/includes/diff/UnifiedDiffFormatter.php
b/includes/diff/UnifiedDiffFormatter.php
index 5f3ad3d..72f1a66 100644
--- a/includes/diff/UnifiedDiffFormatter.php
+++ b/includes/diff/UnifiedDiffFormatter.php
@@ -42,7 +42,7 @@
*/
protected function lines( $lines, $prefix = ' ' ) {
foreach ( $lines as $line ) {
- echo "{$prefix}{$line}\n";
+ $this->writeOutput( "{$prefix}{$line}\n" );
}
}
--
To view, visit https://gerrit.wikimedia.org/r/244632
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Idf2a6c593b81a152edec923d4db6272ca1f3f545
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: PleaseStand <[email protected]>
Gerrit-Reviewer: Jdlrobson <[email protected]>
Gerrit-Reviewer: Legoktm <[email protected]>
Gerrit-Reviewer: MaxSem <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits