From: Brion Vibber Date: Sat, 9 Oct 2004 02:53:11 +0000 (+0000) Subject: Reduce dependence on $wgOut global in the difference formatter; just buffer up the... X-Git-Tag: 1.5.0alpha1~1625 X-Git-Url: http://git.cyclocoop.org/%28?a=commitdiff_plain;h=8a70a3f4d357d73a00b70cc004eb18f6b467ca78;p=lhc%2Fweb%2Fwiklou.git Reduce dependence on $wgOut global in the difference formatter; just buffer up the output and give it to $wgOut in a lump. Also added DifferenceEngine::getDiff() so you can get a diff without sending it to $wgOut. --- diff --git a/includes/DifferenceEngine.php b/includes/DifferenceEngine.php index ae4eef2be5..c5d3e90aca 100644 --- a/includes/DifferenceEngine.php +++ b/includes/DifferenceEngine.php @@ -209,15 +209,19 @@ class DifferenceEngine { function showDiff( $otext, $ntext, $otitle, $ntitle ) { - global $wgOut, $wgUseExternalDiffEngine; - - $wgOut->addHTML( " + global $wgOut; + $wgOut->addHTML( DifferenceEngine::getDiff( $otext, $ntext, $otitle, $ntitle ) ); + } + + function getDiff( $otext, $ntext, $otitle, $ntitle ) { + global $wgUseExternalDiffEngine; + $out = " - " ); + "; if ( $wgUseExternalDiffEngine ) { # For historical reasons, external diff engine expects @@ -225,15 +229,16 @@ class DifferenceEngine { $otext = str_replace( "\r\n", "\n", htmlspecialchars ( $otext ) ); $ntext = str_replace( "\r\n", "\n", htmlspecialchars ( $ntext ) ); dl('php_wikidiff.so'); - $wgOut->addHTML( wikidiff_do_diff( $otext, $ntext, 2) ); + $out .= wikidiff_do_diff( $otext, $ntext, 2 ); } else { $ota = explode( "\n", str_replace( "\r\n", "\n", $otext ) ); $nta = explode( "\n", str_replace( "\r\n", "\n", $ntext ) ); - $diffs = new Diff( $ota, $nta ); - $formatter = new TableDiffFormatter(); - $formatter->format( $diffs ); + $diffs =& new Diff( $ota, $nta ); + $formatter =& new TableDiffFormatter(); + $out .= $formatter->format( $diffs ); } - $wgOut->addHTML( "
{$otitle} {$ntitle}
\n" ); + $out .= "\n"; + return $out; } # Load the text of the articles to compare. If newid is 0, then compare @@ -293,7 +298,7 @@ class DifferenceEngine { ), $fname, array( 'ORDER BY' => 'inverse_timestamp', 'USE INDEX' => 'name_title_timestamp' ) ); if ( $s === false ) { - wfDebug( 'Unable to load ' . $this->mNewPage->getPrefixedDBkey . " from old\n" ); + wfDebug( 'Unable to load ' . $this->mNewPage->getPrefixedDBkey() . " from old\n" ); return false; } } else { @@ -1307,7 +1312,7 @@ class TableDiffFormatter extends DiffFormatter function _start_block( $header ) { global $wgOut; - $wgOut->addHTML( $header ); + echo $header; } function _end_block() { @@ -1336,32 +1341,28 @@ class TableDiffFormatter extends DiffFormatter } function _added( $lines ) { - global $wgOut; foreach ($lines as $line) { - $wgOut->addHTML( '' . $this->emptyLine() . - $this->addedLine( htmlspecialchars ( $line ) ) . "\n" ); + echo '' . $this->emptyLine() . + $this->addedLine( htmlspecialchars ( $line ) ) . "\n"; } } function _deleted($lines) { - global $wgOut; foreach ($lines as $line) { - $wgOut->addHTML( '' . $this->deletedLine( htmlspecialchars ( $line ) ) . - $this->emptyLine() . "\n" ); + echo '' . $this->deletedLine( htmlspecialchars ( $line ) ) . + $this->emptyLine() . "\n"; } } function _context( $lines ) { - global $wgOut; foreach ($lines as $line) { - $wgOut->addHTML( '' . + echo '' . $this->contextLine( htmlspecialchars ( $line ) ) . - $this->contextLine( htmlspecialchars ( $line ) ) . "\n" ); + $this->contextLine( htmlspecialchars ( $line ) ) . "\n"; } } function _changed( $orig, $closing ) { - global $wgOut; $diff = new WordLevelDiff( $orig, $closing ); $del = $diff->orig(); $add = $diff->closing(); @@ -1371,12 +1372,12 @@ class TableDiffFormatter extends DiffFormatter while ( $line = array_shift( $del ) ) { $aline = array_shift( $add ); - $wgOut->addHTML( '' . $this->deletedLine( $line ) . - $this->addedLine( $aline ) . "\n" ); + echo '' . $this->deletedLine( $line ) . + $this->addedLine( $aline ) . "\n"; } foreach ($add as $line) { # If any leftovers - $wgOut->addHTML( '' . $this->emptyLine() . - $this->addedLine( $line ) . "\n" ); + echo '' . $this->emptyLine() . + $this->addedLine( $line ) . "\n"; } } }