public $orig;
public $closing;
- public abstract function reverse();
+ abstract public function reverse();
/**
* @return int
* @private
* @ingroup DifferenceEngine
*/
-class DiffOp_Copy extends DiffOp {
+class DiffOpCopy extends DiffOp {
public $type = 'copy';
function __construct( $orig, $closing = false ) {
}
/**
- * @return DiffOp_Copy
+ * @return DiffOpCopy
*/
function reverse() {
- return new DiffOp_Copy( $this->closing, $this->orig );
+ return new DiffOpCopy( $this->closing, $this->orig );
}
}
* @private
* @ingroup DifferenceEngine
*/
-class DiffOp_Delete extends DiffOp {
+class DiffOpDelete extends DiffOp {
public $type = 'delete';
function __construct( $lines ) {
}
/**
- * @return DiffOp_Add
+ * @return DiffOpAdd
*/
function reverse() {
- return new DiffOp_Add( $this->orig );
+ return new DiffOpAdd( $this->orig );
}
}
* @private
* @ingroup DifferenceEngine
*/
-class DiffOp_Add extends DiffOp {
+class DiffOpAdd extends DiffOp {
public $type = 'add';
function __construct( $lines ) {
}
/**
- * @return DiffOp_Delete
+ * @return DiffOpDelete
*/
function reverse() {
- return new DiffOp_Delete( $this->closing );
+ return new DiffOpDelete( $this->closing );
}
}
* @private
* @ingroup DifferenceEngine
*/
-class DiffOp_Change extends DiffOp {
+class DiffOpChange extends DiffOp {
public $type = 'change';
function __construct( $orig, $closing ) {
}
/**
- * @return DiffOp_Change
+ * @return DiffOpChange
*/
function reverse() {
- return new DiffOp_Change( $this->closing, $this->orig );
+ return new DiffOpChange( $this->closing, $this->orig );
}
}
++$yi;
}
if ( $copy ) {
- $edits[] = new DiffOp_Copy( $copy );
+ $edits[] = new DiffOpCopy( $copy );
}
// Find deletes & adds.
}
if ( $delete && $add ) {
- $edits[] = new DiffOp_Change( $delete, $add );
+ $edits[] = new DiffOpChange( $delete, $add );
} elseif ( $delete ) {
- $edits[] = new DiffOp_Delete( $delete );
+ $edits[] = new DiffOpDelete( $delete );
} elseif ( $add ) {
- $edits[] = new DiffOp_Add( $add );
+ $edits[] = new DiffOpAdd( $add );
}
}
wfProfileOut( __METHOD__ );
if ( empty( $ymatches[$line] ) ) {
continue;
}
+
+ $k = 0;
$matches = $ymatches[$line];
reset( $matches );
while ( list( , $y ) = each( $matches ) ) {
break;
}
}
+
while ( list( , $y ) = each( $matches ) ) {
if ( $y > $this->seq[$k - 1] ) {
assert( '$y < $this->seq[$k]' );
function __construct( $from_lines, $to_lines ) {
$eng = new DiffEngine;
$this->edits = $eng->diff( $from_lines, $to_lines );
- // $this->check($from_lines, $to_lines);
}
/**
return $lines;
}
-
- /**
- * Check a Diff for validity.
- *
- * This is here only for debugging purposes.
- * @param $from_lines
- * @param $to_lines
- */
- private 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 );
- }
- if ( serialize( $to_lines ) != serialize( $this->closing() ) ) {
- trigger_error( "Reconstructed closing doesn't match", E_USER_ERROR );
- }
-
- $rev = $this->reverse();
- if ( serialize( $to_lines ) != serialize( $rev->orig() ) ) {
- trigger_error( "Reversed original doesn't match", E_USER_ERROR );
- }
- if ( serialize( $from_lines ) != serialize( $rev->closing() ) ) {
- trigger_error( "Reversed closing 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 );
- }
- $prevtype = $edit->type;
- }
-
- $lcs = $this->lcs();
- trigger_error( 'Diff okay: LCS = ' . $lcs, E_USER_NOTICE );
- wfProfileOut( __METHOD__ );
- }
}
/**
parent::__construct( $mapped_from_lines, $mapped_to_lines );
$xi = $yi = 0;
- for ( $i = 0; $i < count( $this->edits ); $i++ ) {
+ $editCount = count( $this->edits );
+ for ( $i = 0; $i < $editCount; $i++ ) {
$orig = &$this->edits[$i]->orig;
if ( is_array( $orig ) ) {
$orig = array_slice( $from_lines, $xi, count( $orig ) );
* @private
* @ingroup DifferenceEngine
*/
-class HWLDF_WordAccumulator {
+class HWLDFWordAccumulator {
+ public $insClass = ' class="diffchange diffchange-inline"';
+ public $delClass = ' class="diffchange diffchange-inline"';
+
private $lines = array();
private $line = '';
private $group = '';
private function flushGroup( $new_tag ) {
if ( $this->group !== '' ) {
if ( $this->tag == 'ins' ) {
- $this->line .= '<ins class="diffchange diffchange-inline">' .
+ $this->line .= "<ins{$this->insClass}>" .
htmlspecialchars( $this->group ) . '</ins>';
} elseif ( $this->tag == 'del' ) {
- $this->line .= '<del class="diffchange diffchange-inline">' .
+ $this->line .= "<del{$this->delClass}>" .
htmlspecialchars( $this->group ) . '</del>';
} else {
$this->line .= htmlspecialchars( $this->group );
*/
public function orig() {
wfProfileIn( __METHOD__ );
- $orig = new HWLDF_WordAccumulator;
+ $orig = new HWLDFWordAccumulator;
foreach ( $this->edits as $edit ) {
if ( $edit->type == 'copy' ) {
*/
public function closing() {
wfProfileIn( __METHOD__ );
- $closing = new HWLDF_WordAccumulator;
+ $closing = new HWLDFWordAccumulator;
foreach ( $this->edits as $edit ) {
if ( $edit->type == 'copy' ) {