class _DiffOp_Copy extends _DiffOp {
var $type = 'copy';
- function __construct ( $orig, $closing = false ) {
- if ( !is_array( $closing ) )
- $closing = $orig;
+ function __construct( $orig, $closing = false ) {
+ if ( !is_array( $closing ) ) {
+ $closing = $orig;
+ }
$this->orig = $orig;
$this->closing = $closing;
}
class _DiffOp_Delete extends _DiffOp {
var $type = 'delete';
- function __construct ( $lines ) {
+ function __construct( $lines ) {
$this->orig = $lines;
$this->closing = false;
}
class _DiffOp_Add extends _DiffOp {
var $type = 'add';
- function __construct ( $lines ) {
+ function __construct( $lines ) {
$this->closing = $lines;
$this->orig = false;
}
class _DiffOp_Change extends _DiffOp {
var $type = 'change';
- function __construct ( $orig, $closing ) {
+ function __construct( $orig, $closing ) {
$this->orig = $orig;
$this->closing = $closing;
}
// Skip leading common lines.
for ( $skip = 0; $skip < $n_from && $skip < $n_to; $skip++ ) {
- if ( $from_lines[$skip] !== $to_lines[$skip] )
- break;
+ if ( $from_lines[$skip] !== $to_lines[$skip] ) {
+ break;
+ }
$this->xchanged[$skip] = $this->ychanged[$skip] = false;
}
// Skip trailing common lines.
$xi = $n_from; $yi = $n_to;
for ( $endskip = 0; --$xi > $skip && --$yi > $skip; $endskip++ ) {
- if ( $from_lines[$xi] !== $to_lines[$yi] )
- break;
+ if ( $from_lines[$xi] !== $to_lines[$yi] ) {
+ break;
+ }
$this->xchanged[$xi] = $this->ychanged[$yi] = false;
}
for ( $yi = $skip; $yi < $n_to - $endskip; $yi++ ) {
$line = $to_lines[$yi];
- if ( ( $this->ychanged[$yi] = empty( $xhash[$this->_line_hash( $line )] ) ) )
- continue;
+ if ( ( $this->ychanged[$yi] = empty( $xhash[$this->_line_hash( $line )] ) ) ) {
+ continue;
+ }
$yhash[$this->_line_hash( $line )] = 1;
$this->yv[] = $line;
$this->yind[] = $yi;
}
for ( $xi = $skip; $xi < $n_from - $endskip; $xi++ ) {
$line = $from_lines[$xi];
- if ( ( $this->xchanged[$xi] = empty( $yhash[$this->_line_hash( $line )] ) ) )
- continue;
+ if ( ( $this->xchanged[$xi] = empty( $yhash[$this->_line_hash( $line )] ) ) ) {
+ continue;
+ }
$this->xv[] = $line;
$this->xind[] = $xi;
}
}
}
- /* Divide the Largest Common Subsequence (LCS) of the sequences
+ /**
+ * Divide the Largest Common Subsequence (LCS) of the sequences
* [XOFF, XLIM) and [YOFF, YLIM) into NCHUNKS approximately equally
* sized segments.
*
* match. The caller must trim matching lines from the beginning and end
* of the portions it is going to specify.
*/
- function _diag ( $xoff, $xlim, $yoff, $ylim, $nchunks ) {
+ function _diag( $xoff, $xlim, $yoff, $ylim, $nchunks ) {
$flip = false;
if ( $xlim - $xoff > $ylim - $yoff ) {
// Things seems faster (I'm not sure I understand why)
// when the shortest sequence in X.
$flip = true;
- list ( $xoff, $xlim, $yoff, $ylim ) = array( $yoff, $ylim, $xoff, $xlim );
+ list( $xoff, $xlim, $yoff, $ylim ) = array( $yoff, $ylim, $xoff, $xlim );
}
if ( $flip ) {
return array( $this->lcs, $seps );
}
- function _lcs_pos ( $ypos ) {
+ function _lcs_pos( $ypos ) {
$end = $this->lcs;
if ( $end == 0 || $ypos > $this->seq[$end] ) {
$this->seq[++$this->lcs] = $ypos;
$beg = 1;
while ( $beg < $end ) {
$mid = (int)( ( $beg + $end ) / 2 );
- if ( $ypos > $this->seq[$mid] )
- $beg = $mid + 1;
- else
- $end = $mid;
+ if ( $ypos > $this->seq[$mid] ) {
+ $beg = $mid + 1;
+ } else {
+ $end = $mid;
+ }
}
assert( $ypos != $this->seq[$end] );
return $end;
}
- /* Find LCS of two sequences.
+ /**
+ * Find LCS of two sequences.
*
* The results are recorded in the vectors $this->{x,y}changed[], by
* storing a 1 in the element for each line that is an insertion
}
}
- /* Adjust inserts/deletes of identical lines to join changes
+ /**
+ * Adjust inserts/deletes of identical lines to join changes
* as much as possible.
*
* We do something when a run of changed lines include a
*
* This is extracted verbatim from analyze.c (GNU diffutils-2.7).
*/
- function _shift_boundaries ( $lines, &$changed, $other_changed ) {
+ function _shift_boundaries( $lines, &$changed, $other_changed ) {
wfProfileIn( __METHOD__ );
$i = 0;
$j = 0;
* @private
* @ingroup DifferenceEngine
*/
-class Diff
-{
+class Diff {
var $edits;
/**
* @return object A Diff object representing the inverse of the
* original diff.
*/
- function reverse () {
+ function reverse() {
$rev = $this;
$rev->edits = array();
foreach ( $this->edits as $edit ) {
*
* @return bool True iff two sequences were identical.
*/
- function isEmpty () {
+ function isEmpty() {
foreach ( $this->edits as $edit ) {
if ( $edit->type != 'copy' ) {
return false;
*
* @return int The length of the LCS.
*/
- function lcs () {
+ function lcs() {
$lcs = 0;
foreach ( $this->edits as $edit ) {
if ( $edit->type == 'copy' ) {
*
* This is here only for debugging purposes.
*/
- function _check ( $from_lines, $to_lines ) {
+ function _check( $from_lines, $to_lines ) {
wfProfileIn( __METHOD__ );
if ( serialize( $from_lines ) != serialize( $this->orig() ) ) {
trigger_error( "Reconstructed original doesn't match", E_USER_ERROR );
$prevtype = 'none';
foreach ( $this->edits as $edit ) {
if ( $prevtype == $edit->type ) {
- trigger_error( "Edit sequence is non-optimal", E_USER_ERROR );
+ trigger_error( 'Edit sequence is non-optimal', E_USER_ERROR );
}
$prevtype = $edit->type;
}
* @private
* @ingroup DifferenceEngine
*/
-class MappedDiff extends Diff
-{
+class MappedDiff extends Diff {
/**
* Constructor.
*
if ( is_array( $block ) ) {
if ( sizeof( $edit->orig ) <= $nlead + $ntrail ) {
$block[] = $edit;
- }
- else {
+ } else {
if ( $ntrail ) {
$context = array_slice( $edit->orig, 0, $ntrail );
$block[] = new _DiffOp_Copy( $context );
}
$context = $edit->orig;
} else {
- if ( ! is_array( $block ) ) {
+ if ( !is_array( $block ) ) {
$context = array_slice( $context, sizeof( $context ) - $nlead );
$x0 = $xi - sizeof( $context );
$y0 = $yi - sizeof( $context );
function _block_header( $xbeg, $xlen, $ybeg, $ylen ) {
if ( $xlen > 1 ) {
- $xbeg .= "," . ( $xbeg + $xlen - 1 );
+ $xbeg .= ',' . ( $xbeg + $xlen - 1 );
}
if ( $ylen > 1 ) {
- $ybeg .= "," . ( $ybeg + $ylen - 1 );
+ $ybeg .= ',' . ( $ybeg + $ylen - 1 );
}
return $xbeg . ( $xlen ? ( $ylen ? 'c' : 'd' ) : 'a' ) . $ybeg;
* A formatter that outputs unified diffs
* @ingroup DifferenceEngine
*/
-
class UnifiedDiffFormatter extends DiffFormatter {
var $leading_context_lines = 2;
var $trailing_context_lines = 2;
case 'add':
foreach ( $edit->closing as $l ) {
$retval[] = array(
- 'action' => 'add',
- 'new' => $l,
- 'newline' => $newline++
+ 'action' => 'add',
+ 'new' => $l,
+ 'newline' => $newline++
);
}
break;
case 'delete':
foreach ( $edit->orig as $l ) {
$retval[] = array(
- 'action' => 'delete',
- 'old' => $l,
- 'oldline' => $oldline++,
+ 'action' => 'delete',
+ 'old' => $l,
+ 'oldline' => $oldline++,
);
}
break;
case 'change':
foreach ( $edit->orig as $i => $l ) {
$retval[] = array(
- 'action' => 'change',
- 'old' => $l,
- 'new' => @$edit->closing[$i],
- 'oldline' => $oldline++,
- 'newline' => $newline++,
+ 'action' => 'change',
+ 'old' => $l,
+ 'new' => @$edit->closing[$i],
+ 'oldline' => $oldline++,
+ 'newline' => $newline++,
);
}
break;
}
/**
- * Additions by Axel Boldt follow, partly taken from diff.php, phpwiki-1.3.3
- *
+ * Additions by Axel Boldt follow, partly taken from diff.php, phpwiki-1.3.3
*/
define( 'NBSP', ' ' ); // iso-8859-x non-breaking space.
* @ingroup DifferenceEngine
*/
class _HWLDF_WordAccumulator {
- function __construct () {
+ function __construct() {
$this->_lines = array();
$this->_line = '';
$this->_group = '';
$this->_tag = '';
}
- function _flushGroup ( $new_tag ) {
+ function _flushGroup( $new_tag ) {
if ( $this->_group !== '' ) {
if ( $this->_tag == 'ins' ) {
$this->_line .= '<ins class="diffchange diffchange-inline">' .
- htmlspecialchars ( $this->_group ) . '</ins>';
+ htmlspecialchars( $this->_group ) . '</ins>';
} elseif ( $this->_tag == 'del' ) {
$this->_line .= '<del class="diffchange diffchange-inline">' .
- htmlspecialchars ( $this->_group ) . '</del>';
+ htmlspecialchars( $this->_group ) . '</del>';
} else {
- $this->_line .= htmlspecialchars ( $this->_group );
+ $this->_line .= htmlspecialchars( $this->_group );
}
}
$this->_group = '';
$this->_tag = $new_tag;
}
- function _flushLine ( $new_tag ) {
+ function _flushLine( $new_tag ) {
$this->_flushGroup( $new_tag );
if ( $this->_line != '' ) {
- array_push ( $this->_lines, $this->_line );
+ array_push( $this->_lines, $this->_line );
} else {
# make empty lines visible by inserting an NBSP
- array_push ( $this->_lines, NBSP );
+ array_push( $this->_lines, NBSP );
}
$this->_line = '';
}
function __construct ( $orig_lines, $closing_lines ) {
wfProfileIn( __METHOD__ );
- list ( $orig_words, $orig_stripped ) = $this->_split( $orig_lines );
- list ( $closing_words, $closing_stripped ) = $this->_split( $closing_lines );
+ list( $orig_words, $orig_stripped ) = $this->_split( $orig_lines );
+ list( $closing_words, $closing_stripped ) = $this->_split( $closing_lines );
parent::__construct( $orig_words, $closing_words,
$orig_stripped, $closing_stripped );
return array( $words, $stripped );
}
- function orig () {
+ function orig() {
wfProfileIn( __METHOD__ );
$orig = new _HWLDF_WordAccumulator;
return $lines;
}
- function closing () {
+ function closing() {
wfProfileIn( __METHOD__ );
$closing = new _HWLDF_WordAccumulator;
foreach ( $lines as $line ) {
echo '<tr>' . $this->emptyLine() .
$this->addedLine( '<ins class="diffchange">' .
- htmlspecialchars ( $line ) . '</ins>' ) . "</tr>\n";
+ htmlspecialchars( $line ) . '</ins>' ) . "</tr>\n";
}
}
function _deleted( $lines ) {
foreach ( $lines as $line ) {
echo '<tr>' . $this->deletedLine( '<del class="diffchange">' .
- htmlspecialchars ( $line ) . '</del>' ) .
+ htmlspecialchars( $line ) . '</del>' ) .
$this->emptyLine() . "</tr>\n";
}
}
function _context( $lines ) {
foreach ( $lines as $line ) {
echo '<tr>' .
- $this->contextLine( htmlspecialchars ( $line ) ) .
- $this->contextLine( htmlspecialchars ( $line ) ) . "</tr>\n";
+ $this->contextLine( htmlspecialchars( $line ) ) .
+ $this->contextLine( htmlspecialchars( $line ) ) . "</tr>\n";
}
}