* @ingroup DifferenceEngine
*/
class ArrayDiffFormatter extends DiffFormatter {
-
/**
* @param $diff
* @return array
$newline += count( $edit->orig );
}
}
+
return $retval;
}
}
*
* The algorithm used here is mostly lifted from the perl module
* Algorithm::Diff (version 1.06) by Ned Konz, which is available at:
- * http://www.perl.com/CPAN/authors/id/N/NE/NEDKONZ/Algorithm-Diff-1.06.zip
+ * http://www.perl.com/CPAN/authors/id/N/NE/NEDKONZ/Algorithm-Diff-1.06.zip
*
* More ideas are taken from:
- * http://www.ics.uci.edu/~eppstein/161/960229.html
+ * http://www.ics.uci.edu/~eppstein/161/960229.html
*
* Some ideas are (and a bit of code) are from from analyze.c, from GNU
* diffutils-2.7, which can be found at:
- * ftp://gnudist.gnu.org/pub/gnu/diffutils/diffutils-2.7.tar.gz
+ * ftp://gnudist.gnu.org/pub/gnu/diffutils/diffutils-2.7.tar.gz
*
* closingly, some ideas (subdivision by NCHUNKS > 2, and some optimizations)
* are my own.
* @ingroup DifferenceEngine
*/
class DiffEngine {
-
const MAX_XREF_LENGTH = 10000;
protected $xchanged, $ychanged;
// Skip matching "snake".
$copy = array();
while ( $xi < $n_from && $yi < $n_to
- && !$this->xchanged[$xi] && !$this->ychanged[$yi] ) {
+ && !$this->xchanged[$xi] && !$this->ychanged[$yi]
+ ) {
$copy[] = $from_lines[$xi++];
++$yi;
}
}
}
wfProfileOut( __METHOD__ );
+
return $edits;
}
for ( $chunk = 0; $chunk < $nchunks; $chunk++ ) {
if ( $chunk > 0 ) {
for ( $i = 0; $i <= $this->lcs; $i++ ) {
- $ymids[$i][$chunk -1] = $this->seq[$i];
+ $ymids[$i][$chunk - 1] = $this->seq[$i];
}
}
- $x1 = $xoff + (int)( ( $numer + ( $xlim -$xoff ) * $chunk ) / $nchunks );
+ $x1 = $xoff + (int)( ( $numer + ( $xlim - $xoff ) * $chunk ) / $nchunks );
for ( ; $x < $x1; $x++ ) {
$line = $flip ? $this->yv[$x] : $this->xv[$x];
if ( empty( $ymatches[$line] ) ) {
if ( empty( $this->in_seq[$y] ) ) {
$k = $this->lcsPos( $y );
assert( '$k > 0' );
- $ymids[$k] = $ymids[$k -1];
+ $ymids[$k] = $ymids[$k - 1];
break;
}
}
while ( list( , $y ) = each( $matches ) ) {
- if ( $y > $this->seq[$k -1] ) {
+ if ( $y > $this->seq[$k - 1] ) {
assert( '$y < $this->seq[$k]' );
// Optimization: this is a common case:
// next match is just replacing previous match.
} elseif ( empty( $this->in_seq[$y] ) ) {
$k = $this->lcsPos( $y );
assert( '$k > 0' );
- $ymids[$k] = $ymids[$k -1];
+ $ymids[$k] = $ymids[$k - 1];
}
}
}
if ( $end == 0 || $ypos > $this->seq[$end] ) {
$this->seq[++$this->lcs] = $ypos;
$this->in_seq[$ypos] = 1;
+
return $this->lcs;
}
$this->in_seq[$this->seq[$end]] = false;
$this->seq[$end] = $ypos;
$this->in_seq[$ypos] = 1;
+
return $end;
}
// Slide up the top initial diagonal.
while ( $xlim > $xoff && $ylim > $yoff
- && $this->xv[$xlim - 1] == $this->yv[$ylim - 1] ) {
+ && $this->xv[$xlim - 1] == $this->yv[$ylim - 1]
+ ) {
--$xlim;
--$ylim;
}
$j++;
}
- while ( $i < $len && ! $changed[$i] ) {
+ while ( $i < $len && !$changed[$i] ) {
assert( '$j < $other_len && ! $other_changed[$j]' );
$i++;
$j++;
* Computes diff between sequences of strings.
*
* @param $from_lines array An array of strings.
- * (Typically these are lines from a file.)
+ * Typically these are lines from a file.
* @param $to_lines array An array of strings.
*/
function __construct( $from_lines, $to_lines ) {
*
* SYNOPSIS:
*
- * $diff = new Diff($lines1, $lines2);
- * $rev = $diff->reverse();
+ * $diff = new Diff($lines1, $lines2);
+ * $rev = $diff->reverse();
* @return Object A Diff object representing the inverse of the
- * original diff.
+ * original diff.
*/
function reverse() {
$rev = $this;
foreach ( $this->edits as $edit ) {
$rev->edits[] = $edit->reverse();
}
+
return $rev;
}
return false;
}
}
+
return true;
}
$lcs += count( $edit->orig );
}
}
+
return $lcs;
}
array_splice( $lines, count( $lines ), 0, $edit->orig );
}
}
+
return $lines;
}
array_splice( $lines, count( $lines ), 0, $edit->closing );
}
}
+
return $lines;
}
* changes in white-space.
*
* @param $from_lines array An array of strings.
- * (Typically these are lines from a file.)
+ * Typically these are lines from a file.
*
* @param $to_lines array An array of strings.
*
* @param $mapped_from_lines array This array should
- * have the same size number of elements as $from_lines.
- * The elements in $mapped_from_lines and
- * $mapped_to_lines are what is actually compared
- * when computing the diff.
+ * have the same size number of elements as $from_lines.
+ * The elements in $mapped_from_lines and
+ * $mapped_to_lines are what is actually compared
+ * when computing the diff.
*
* @param $mapped_to_lines array This array should
- * have the same number of elements as $to_lines.
+ * have the same number of elements as $to_lines.
*/
function __construct( $from_lines, $to_lines,
$mapped_from_lines, $mapped_to_lines ) {
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 );
}
*/
public function getLines() {
$this->flushLine( '~done' );
+
return $this->lines;
}
}
list( $closing_words, $closing_stripped ) = $this->split( $closing_lines );
parent::__construct( $orig_words, $closing_words,
- $orig_stripped, $closing_stripped );
+ $orig_stripped, $closing_stripped );
wfProfileOut( __METHOD__ );
}
} else {
$m = array();
if ( preg_match_all( '/ ( [^\S\n]+ | [0-9_A-Za-z\x80-\xff]+ | . ) (?: (?!< \n) [^\S\n])? /xs',
- $line, $m ) )
- {
+ $line, $m )
+ ) {
foreach ( $m[0] as $word ) {
$words[] = $word;
}
}
}
wfProfileOut( __METHOD__ );
+
return array( $words, $stripped );
}
}
$lines = $orig->getLines();
wfProfileOut( __METHOD__ );
+
return $lines;
}
}
$lines = $closing->getLines();
wfProfileOut( __METHOD__ );
+
return $lines;
}
}
* @ingroup DifferenceEngine
*/
abstract class DiffFormatter {
- /**
- * Number of leading context "lines" to preserve.
+ /** @var int Number of leading context "lines" to preserve.
*
* This should be left at zero for this class, but subclasses
* may want to set this to other values.
*/
protected $leadingContextLines = 0;
- /**
- * Number of trailing context "lines" to preserve.
+ /** @var int Number of trailing context "lines" to preserve.
*
* This should be left at zero for this class, but subclasses
* may want to set this to other values.
$end = $this->endDiff();
wfProfileOut( __METHOD__ );
+
return $end;
}
protected function endDiff() {
$val = ob_get_contents();
ob_end_clean();
+
return $val;
}
* @ingroup DifferenceEngine
*/
class DifferenceEngine extends ContextSource {
+ /** @var int */
public $mOldid;
+
+ /** @var int */
public $mNewid;
+
private $mOldTags;
private $mNewTags;
- /**
- * @var Content
- */
+ /** @var Content */
public $mOldContent;
+
+ /** @var Content */
public $mNewContent;
+
+ /** @var Language */
protected $mDiffLang;
- /**
- * @var Title
- */
+ /** @var Title */
public $mOldPage;
+
+ /** @var Title */
public $mNewPage;
- /**
- * @var Revision
- */
+ /** @var Revision */
public $mOldRev;
+
+ /** @var Revision */
public $mNewRev;
- private $mRevisionsIdsLoaded = false; // Have the revisions IDs been loaded
- public $mRevisionsLoaded = false; // Have the revisions been loaded
- public $mTextLoaded = 0; // How many text blobs have been loaded, 0, 1 or 2?
- public $mCacheHit = false; // Was the diff fetched from cache?
+
+ /** @var bool Have the revisions IDs been loaded */
+ private $mRevisionsIdsLoaded = false;
+
+ /** @var bool Have the revisions been loaded */
+ public $mRevisionsLoaded = false;
+
+ /** @var int How many text blobs have been loaded, 0, 1 or 2? */
+ public $mTextLoaded = 0;
+
+ /** @var bool Was the diff fetched from cache? */
+ public $mCacheHit = false;
/**
* Set this to true to add debug info to the HTML output.
*/
public $enableDebugComment = false;
- // If true, line X is not displayed when X is 1, for example to increase
- // readability and conserve space with many small diffs.
+ /** @var bool If true, line X is not displayed when X is 1, for example
+ * to increase readability and conserve space with many small diffs.
+ */
protected $mReducedLineNumbers = false;
- // Link to action=markpatrolled
+ /** @var string Link to action=markpatrolled */
protected $mMarkPatrolledLink = null;
- protected $unhide = false; # show rev_deleted content if allowed
+ /** @var bool Show rev_deleted content if allowed */
+ protected $unhide = false;
/**#@-*/
/**
# Default language in which the diff text is written.
$this->mDiffLang = $this->getTitle()->getPageLanguage();
}
+
return $this->mDiffLang;
}
*/
function getOldid() {
$this->loadRevisionIds();
+
return $this->mOldid;
}
*/
function getNewid() {
$this->loadRevisionIds();
+
return $this->mNewid;
}
if ( $row ) {
$rev = Revision::newFromArchiveRow( $row );
$title = Title::makeTitleSafe( $row->ar_namespace, $row->ar_title );
+
return SpecialPage::getTitleFor( 'Undelete' )->getFullURL( array(
'target' => $title->getPrefixedText(),
'timestamp' => $rev->getTimestamp()
- ));
+ ) );
}
}
+
return false;
}
if ( !$this->loadRevisionData() ) {
$this->showMissingRevision();
wfProfileOut( __METHOD__ );
+
return;
}
'href' => $this->mNewPage->getLocalURL( array(
'action' => 'edit',
'undoafter' => $this->mOldid,
- 'undo' => $this->mNewid ) ),
+ 'undo' => $this->mNewid
+ ) ),
'title' => Linker::titleAttrib( 'undo' )
),
$this->msg( 'editundo' )->text()
$oldHeader = '<div id="mw-diff-otitle1"><strong>' . $oldRevisionHeader . '</strong></div>' .
'<div id="mw-diff-otitle2">' .
- Linker::revUserTools( $this->mOldRev, !$this->unhide ) . '</div>' .
+ Linker::revUserTools( $this->mOldRev, !$this->unhide ) . '</div>' .
'<div id="mw-diff-otitle3">' . $oldminor .
- Linker::revComment( $this->mOldRev, !$diffOnly, !$this->unhide ) . $ldel . '</div>' .
+ Linker::revComment( $this->mOldRev, !$diffOnly, !$this->unhide ) . $ldel . '</div>' .
'<div id="mw-diff-otitle5">' . $oldChangeTags[0] . '</div>' .
'<div id="mw-diff-otitle4">' . $prevlink . '</div>';
$newHeader = '<div id="mw-diff-ntitle1"><strong>' . $newRevisionHeader . '</strong></div>' .
'<div id="mw-diff-ntitle2">' . Linker::revUserTools( $this->mNewRev, !$this->unhide ) .
- " $rollback</div>" .
+ " $rollback</div>" .
'<div id="mw-diff-ntitle3">' . $newminor .
- Linker::revComment( $this->mNewRev, !$diffOnly, !$this->unhide ) . $rdel . '</div>' .
+ Linker::revComment( $this->mNewRev, !$diffOnly, !$this->unhide ) . $rdel . '</div>' .
'<div id="mw-diff-ntitle5">' . $newChangeTags[0] . '</div>' .
'<div id="mw-diff-ntitle4">' . $nextlink . $this->markPatrolledLink() . '</div>';
if ( $link !== '' ) {
$link = '   ' . $link . ' ';
}
+
return $link;
}
}
$parserOutput = $page->getParserOutput( $parserOptions, $rev->getId() );
+
return $parserOutput;
}
$diff = $this->getDiff( $otitle, $ntitle, $notice );
if ( $diff === false ) {
$this->showMissingRevision();
+
return false;
} else {
$this->showDiffStyle();
$this->getOutput()->addHTML( $diff );
+
return true;
}
}
// Check if the diff should be hidden from this user
if ( !$this->loadRevisionData() ) {
wfProfileOut( __METHOD__ );
+
return false;
} elseif ( $this->mOldRev &&
!$this->mOldRev->userCan( Revision::DELETED_TEXT, $this->getUser() )
) {
wfProfileOut( __METHOD__ );
+
return false;
} elseif ( $this->mNewRev &&
!$this->mNewRev->userCan( Revision::DELETED_TEXT, $this->getUser() )
) {
wfProfileOut( __METHOD__ );
+
return false;
}
// Short-circuit
if ( $this->mOldRev === false || ( $this->mOldRev && $this->mNewRev
- && $this->mOldRev->getID() == $this->mNewRev->getID() ) )
- {
+ && $this->mOldRev->getID() == $this->mNewRev->getID() )
+ ) {
wfProfileOut( __METHOD__ );
+
return '';
}
// Cacheable?
$difftext = $this->localiseLineNumbers( $difftext );
$difftext .= "\n<!-- diff cache key $key -->\n";
wfProfileOut( __METHOD__ );
+
return $difftext;
}
} // don't try to load but save the result
// Loadtext is permission safe, this just clears out the diff
if ( !$this->loadText() ) {
wfProfileOut( __METHOD__ );
+
return false;
}
$difftext = $this->localiseLineNumbers( $difftext );
}
wfProfileOut( __METHOD__ );
+
return $difftext;
}
*/
function generateContentDiffBody( Content $old, Content $new ) {
if ( !( $old instanceof TextContent ) ) {
- throw new MWException( "Diff not implemented for " . get_class( $old ) . "; "
- . "override generateContentDiffBody to fix this." );
+ throw new MWException( "Diff not implemented for " . get_class( $old ) . "; " .
+ "override generateContentDiffBody to fix this." );
}
if ( !( $new instanceof TextContent ) ) {
if ( $wgExternalDiffEngine == 'wikidiff' && function_exists( 'wikidiff_do_diff' ) ) {
# For historical reasons, external diff engine expects
# input text to be HTML-escaped already
- $otext = htmlspecialchars ( $wgContLang->segmentForDiff( $otext ) );
- $ntext = htmlspecialchars ( $wgContLang->segmentForDiff( $ntext ) );
+ $otext = htmlspecialchars( $wgContLang->segmentForDiff( $otext ) );
+ $ntext = htmlspecialchars( $wgContLang->segmentForDiff( $ntext ) );
wfProfileOut( __METHOD__ );
+
return $wgContLang->unsegmentForDiff( wikidiff_do_diff( $otext, $ntext, 2 ) ) .
$this->debug( 'wikidiff1' );
}
$text .= $this->debug( 'wikidiff2' );
wfProfileOut( 'wikidiff2_do_diff' );
wfProfileOut( __METHOD__ );
+
return $text;
}
if ( $wgExternalDiffEngine != 'wikidiff3' && $wgExternalDiffEngine !== false ) {
$tempFile1 = fopen( $tempName1, "w" );
if ( !$tempFile1 ) {
wfProfileOut( __METHOD__ );
+
return false;
}
$tempFile2 = fopen( $tempName2, "w" );
if ( !$tempFile2 ) {
wfProfileOut( __METHOD__ );
+
return false;
}
fwrite( $tempFile1, $otext );
unlink( $tempName1 );
unlink( $tempName2 );
wfProfileOut( __METHOD__ );
+
return $difftext;
}
$diffs = new Diff( $ota, $nta );
$formatter = new TableDiffFormatter();
$difftext = $wgContLang->unsegmentForDiff( $formatter->format( $diffs ) ) .
- wfProfileOut( __METHOD__ );
+ wfProfileOut( __METHOD__ );
+
return $difftext;
}
* Generate a debug comment indicating diff generating time,
* server node, and generator backend.
*
- * @param String $generator: What diff engine was used
+ * @param String $generator : What diff engine was used
*
* @return string
*/
$data[] = wfHostname();
}
$data[] = wfTimestamp( TS_DB );
- return "<!-- diff generator: "
- . implode( " ",
- array_map(
- "htmlspecialchars",
- $data )
- )
- . " -->\n";
+
+ return "<!-- diff generator: " .
+ implode( " ", array_map( "htmlspecialchars", $data ) ) .
+ " -->\n";
}
/**
* @return mixed
*/
function localiseLineNumbers( $text ) {
- return preg_replace_callback( '/<!--LINE (\d+)-->/',
- array( &$this, 'localiseLineNumbersCb' ), $text );
+ return preg_replace_callback(
+ '/<!--LINE (\d+)-->/',
+ array( &$this, 'localiseLineNumbersCb' ),
+ $text
+ );
}
function localiseLineNumbersCb( $matches ) {
if ( $matches[1] === '1' && $this->mReducedLineNumbers ) {
return '';
}
+
return $this->msg( 'lineno' )->numParams( $matches[1] )->escaped();
}
if ( $nEdits > 0 ) {
$limit = 100; // use diff-multi-manyusers if too many users
$numUsers = $this->mNewPage->countAuthorsBetween( $oldRev, $newRev, $limit );
+
return self::intermediateEditsMsg( $nEdits, $numUsers, $limit );
}
+
return ''; // nothing
}
} else {
$msg = 'diff-multi';
}
+
return wfMessage( $msg )->numParams( $numEdits, $numUsers )->parse();
}
/**
* Add the header to a diff body
*
- * @param String $diff: Diff body
- * @param String $otitle: Old revision header
- * @param String $ntitle: New revision header
- * @param String $multi: Notice telling user that there are intermediate revisions between the ones being compared
- * @param String $notice: Other notices, e.g. that user is viewing deleted content
+ * @param string $diff Diff body
+ * @param string $otitle Old revision header
+ * @param string $ntitle New revision header
+ * @param string $multi Notice telling user that there are intermediate revisions between the ones being compared
+ * @param string $notice Other notices, e.g. that user is viewing deleted content
*
* @return string
*/
$msg = preg_replace( '/^ /m', '  ', $msg );
$msg = preg_replace( '/ $/m', '  ', $msg );
$msg = preg_replace( '/ /', '  ', $msg );
+
return $msg;
}
protected function blockHeader( $xbeg, $xlen, $ybeg, $ylen ) {
$r = '<tr><td colspan="2" class="diff-lineno"><!--LINE ' . $xbeg . "--></td>\n" .
'<td colspan="2" class="diff-lineno"><!--LINE ' . $ybeg . "--></td></tr>\n";
+
return $r;
}
// The <div> wrapper is needed for 'overflow: auto' style to scroll properly
$line = Xml::tags( 'div', null, $this->escapeWhiteSpace( $line ) );
}
+
return "<td class='diff-marker'>$marker</td><td class='$class'>$line</td>";
}
echo '<tr>' . $this->deletedLine( $line ) .
$this->addedLine( $aline ) . "</tr>\n";
}
- foreach ( $add as $line ) { # If any leftovers
+ foreach ( $add as $line ) { # If any leftovers
echo '<tr>' . $this->emptyLine() .
$this->addedLine( $line ) . "</tr>\n";
}
* @ingroup DifferenceEngine
*/
class UnifiedDiffFormatter extends DiffFormatter {
+ /** @var int */
protected $leadingContextLines = 2;
+
+ /** @var int */
protected $trailingContextLines = 2;
/**
*/
$max = min( $this->m, $this->n );
for ( $forwardBound = 0; $forwardBound < $max
- && $this->from[$forwardBound] === $this->to[$forwardBound];
- ++$forwardBound ) {
+ && $this->from[$forwardBound] === $this->to[$forwardBound];
+ ++$forwardBound
+ ) {
$this->removed[$forwardBound] = $this->added[$forwardBound] = false;
}
$backBoundL2 = $this->n - 1;
while ( $backBoundL1 >= $forwardBound && $backBoundL2 >= $forwardBound
- && $this->from[$backBoundL1] === $this->to[$backBoundL2] ) {
+ && $this->from[$backBoundL1] === $this->to[$backBoundL2]
+ ) {
$this->removed[$backBoundL1--] = $this->added[$backBoundL2--] = false;
}
$snake = array( 0, 0, 0 );
$this->length = $forwardBound + $this->m - $backBoundL1 - 1
- + $this->lcs_rec( $forwardBound, $backBoundL1,
- $forwardBound, $backBoundL2, $V, $snake );
+ + $this->lcs_rec(
+ $forwardBound,
+ $backBoundL1,
+ $forwardBound,
+ $backBoundL2,
+ $V,
+ $snake
+ );
}
$this->m = $m;
while ( $xi < $this->m || $yi < $this->n ) {
// Matching "snake".
while ( $xi < $this->m && $yi < $this->n
- && !$this->removed[$xi]
- && !$this->added[$yi] ) {
+ && !$this->removed[$xi]
+ && !$this->added[$yi]
+ ) {
++$xi;
++$yi;
}
}
if ( $xi > $xstart || $yi > $ystart ) {
- $ranges[] = new RangeDifference( $xstart, $xi,
- $ystart, $yi );
+ $ranges[] = new RangeDifference( $xstart, $xi, $ystart, $yi );
}
}
+
return $ranges;
}
}
$d = $this->find_middle_snake( $bottoml1, $topl1, $bottoml2,
- $topl2, $V, $snake );
+ $topl2, $V, $snake );
// need to store these so we don't lose them when they're
// overwritten by the recursion
if ( $d > 1 ) {
return $len
+ $this->lcs_rec( $bottoml1, $startx - 1, $bottoml2,
- $starty - 1, $V, $snake )
+ $starty - 1, $V, $snake )
+ $this->lcs_rec( $startx + $len, $topl1, $starty + $len,
- $topl2, $V, $snake );
+ $topl2, $V, $snake );
} elseif ( $d == 1 ) {
/*
* In this case the sequences differ by exactly 1 line. We have
$this->removed[$bottoml1 + $i] =
$this->added[$bottoml2 + $i] = false;
}
+
return $max + $len;
}
+
return $len;
}
$snake0 = &$snake[0];
$snake1 = &$snake[1];
$snake2 = &$snake[2];
- $bottoml1_min_1 = $bottoml1 -1;
- $bottoml2_min_1 = $bottoml2 -1;
+ $bottoml1_min_1 = $bottoml1 - 1;
+ $bottoml2_min_1 = $bottoml2 - 1;
$N = $topl1 - $bottoml1_min_1;
$M = $topl2 - $bottoml2_min_1;
$delta = $N - $M;
// compute forward furthest reaching paths
for ( $k = $start_diag; $k <= $end_diag; $k += 2 ) {
if ( $k == -$d || ( $k < $d
- && $V0[$limit_min_1 + $k] < $V0[$limit_plus_1 + $k] ) ) {
+ && $V0[$limit_min_1 + $k] < $V0[$limit_plus_1 + $k] )
+ ) {
$x = $V0[$limit_plus_1 + $k];
} else {
$x = $V0[$limit_min_1 + $k] + 1;
++$absx;
++$absy;
}
- $x = $absx -$bottoml1;
+ $x = $absx - $bottoml1;
- $snake2 = $absx -$snake0;
+ $snake2 = $absx - $snake0;
$V0[$limit + $k] = $x;
if ( $k >= $delta - $d + 1 && $k <= $delta + $d - 1
- && $x >= $V1[$limit + $k - $delta] ) {
+ && $x >= $V1[$limit + $k - $delta]
+ ) {
return 2 * $d - 1;
}
// compute backward furthest reaching paths
for ( $k = $start_diag; $k <= $end_diag; $k += 2 ) {
if ( $k == $d
- || ( $k != -$d && $V1[$limit_min_1 + $k] < $V1[$limit_plus_1 + $k] ) ) {
+ || ( $k != -$d && $V1[$limit_min_1 + $k] < $V1[$limit_plus_1 + $k] )
+ ) {
$x = $V1[$limit_min_1 + $k];
} else {
$x = $V1[$limit_plus_1 + $k] - 1;
$snake2 = 0;
while ( $x > 0 && $y > 0
- && $from[$x + $bottoml1_min_1] === $to[$y + $bottoml2_min_1] ) {
+ && $from[$x + $bottoml1_min_1] === $to[$y + $bottoml2_min_1]
+ ) {
--$x;
--$y;
++$snake2;
// compute forward furthest reaching paths
for ( $k = $start_diag; $k <= $end_diag; $k += 2 ) {
if ( $k == -$d
- || ( $k < $d && $V0[$limit_min_1 + $k] < $V0[$limit_plus_1 + $k] ) ) {
+ || ( $k < $d && $V0[$limit_min_1 + $k] < $V0[$limit_plus_1 + $k] )
+ ) {
$x = $V0[$limit_plus_1 + $k];
} else {
$x = $V0[$limit_min_1 + $k] + 1;
++$absx;
++$absy;
}
- $x = $absx -$bottoml1;
- $snake2 = $absx -$snake0;
+ $x = $absx - $bottoml1;
+ $snake2 = $absx - $snake0;
$V0[$limit + $k] = $x;
// check to see if we can cut down the diagonal range
if ( $x >= $N && $end_forward > $k - 1 ) {
$end_forward = $k - 1;
- } elseif ( $absy -$bottoml2 >= $M ) {
+ } elseif ( $absy - $bottoml2 >= $M ) {
$start_forward = $k + 1;
$value_to_add_forward = 0;
}
// compute backward furthest reaching paths
for ( $k = $start_diag; $k <= $end_diag; $k += 2 ) {
if ( $k == $d
- || ( $k != -$d && $V1[$limit_min_1 + $k] < $V1[$limit_plus_1 + $k] ) ) {
+ || ( $k != -$d && $V1[$limit_min_1 + $k] < $V1[$limit_plus_1 + $k] )
+ ) {
$x = $V1[$limit_min_1 + $k];
} else {
$x = $V1[$limit_plus_1 + $k] - 1;
$snake2 = 0;
while ( $x > 0 && $y > 0
- && $from[$x + $bottoml1_min_1] === $to[$y + $bottoml2_min_1] ) {
+ && $from[$x + $bottoml1_min_1] === $to[$y + $bottoml2_min_1]
+ ) {
--$x;
--$y;
++$snake2;
$V1[$limit + $k] = $x;
if ( $k >= -$delta - $d && $k <= $d - $delta
- && $x <= $V0[$limit + $k + $delta] ) {
+ && $x <= $V0[$limit + $k + $delta]
+ ) {
$snake0 = $bottoml1 + $x;
$snake1 = $bottoml2 + $y;
+
return 2 * $d;
}
$snake2 = 0;
wfDebug( "Computing the LCS is too expensive. Using a heuristic.\n" );
$this->heuristicUsed = true;
+
return 5; /*
* HACK: since we didn't really finish the LCS computation
* we don't really know the length of the SES. We don't do
public function getLcsLength() {
if ( $this->heuristicUsed && !$this->lcsLengthCorrectedForHeuristic ) {
$this->lcsLengthCorrectedForHeuristic = true;
- $this->length = $this->m -array_sum( $this->added );
+ $this->length = $this->m - array_sum( $this->added );
}
+
return $this->length;
}
-
}
/**
* @ingroup DifferenceEngine
*/
class RangeDifference {
-
+ /** @var int */
public $leftstart;
+
+ /** @var int */
public $leftend;
+
+ /** @var int */
public $leftlength;
+ /** @var int */
public $rightstart;
+
+ /** @var int */
public $rightend;
+
+ /** @var int */
public $rightlength;
function __construct( $leftstart, $leftend, $rightstart, $rightend ) {