81 public function diff( $from_lines, $to_lines ) {
91 $n_from = count( $from_lines );
92 $n_to = count( $to_lines );
96 while ( $xi < $n_from || $yi < $n_to ) {
97 assert( $yi < $n_to || $this->removed[$xi] );
98 assert( $xi < $n_from || $this->added[$yi] );
102 while ( $xi < $n_from && $yi < $n_to
103 && !$this->removed[$xi] && !$this->added[$yi]
105 $copy[] = $from_lines[$xi++];
114 while ( $xi < $n_from && $this->removed[$xi] ) {
115 $delete[] = $from_lines[$xi++];
119 while ( $yi < $n_to && $this->added[$yi] ) {
120 $add[] = $to_lines[$yi++];
123 if ( $delete && $add ) {
125 } elseif ( $delete ) {
140 $this->bailoutComplexity =
$value;
164 assert( count( $lines ) == count( $changed ) );
165 $len = count( $lines );
166 $other_len = count( $other_changed );
180 while ( $j < $other_len && $other_changed[$j] ) {
184 while ( $i < $len && !$changed[$i] ) {
185 assert( $j < $other_len && ! $other_changed[$j] );
188 while ( $j < $other_len && $other_changed[$j] ) {
200 while ( ++$i < $len && $changed[$i] ) {
209 $runlength = $i - $start;
216 while ( $start > 0 && $lines[$start - 1] == $lines[$i - 1] ) {
217 $changed[--$start] = 1;
218 $changed[--$i] =
false;
219 while ( $start > 0 && $changed[$start - 1] ) {
223 while ( $other_changed[--$j] ) {
226 assert( $j >= 0 && !$other_changed[$j] );
234 $corresponding = $j < $other_len ? $i : $len;
243 while ( $i < $len && $lines[$start] == $lines[$i] ) {
244 $changed[$start++] =
false;
246 while ( $i < $len && $changed[$i] ) {
250 assert( $j < $other_len && ! $other_changed[$j] );
252 if ( $j < $other_len && $other_changed[$j] ) {
254 while ( $j < $other_len && $other_changed[$j] ) {
259 }
while ( $runlength != $i - $start );
265 while ( $corresponding < $i ) {
266 $changed[--$start] = 1;
269 while ( $other_changed[--$j] ) {
272 assert( $j >= 0 && !$other_changed[$j] );
287 $this->heuristicUsed =
false;
291 $added =
$n > 0 ? array_fill( 0,
$n,
true ) : [];
296 while ( $i <
$m && $i <
$n && $from[$i] === $to[$i] ) {
298 unset( $from[$i], $to[$i] );
304 while ( $i + $j <=
$m && $i + $j <=
$n && $from[
$m - $j] === $to[
$n - $j] ) {
306 unset( $from[
$m - $j], $to[
$n - $j] );
310 $this->
from = $newFromIndex = $this->to = $newToIndex = [];
314 foreach ( $from
as $key ) {
315 $shared[$key] =
false;
318 foreach ( $to
as $index => &$el ) {
319 if ( array_key_exists( $el, $shared ) ) {
323 $newToIndex[] = $index;
326 foreach ( $from
as $index => &$el ) {
327 if ( $shared[$el] ) {
330 $newFromIndex[] = $index;
334 unset( $shared, $from, $to );
336 $this->m = count( $this->
from );
337 $this->
n = count( $this->to );
339 if ( $this->bailoutComplexity > 0 && $this->m * $this->
n > $this->bailoutComplexity ) {
343 $this->removed = $this->m > 0 ? array_fill( 0, $this->m,
true ) : [];
344 $this->added = $this->
n > 0 ? array_fill( 0, $this->
n,
true ) : [];
346 if ( $this->m == 0 || $this->
n == 0 ) {
349 $this->maxDifferences = ceil( ( $this->m + $this->
n ) / 2.0 );
350 if ( $this->m * $this->
n > $this->tooLong ) {
352 $this->maxDifferences = floor( pow( $this->maxDifferences, $this->powLimit - 1.0 ) );
353 wfDebug(
"Limiting max number of differences to $this->maxDifferences\n" );
360 $max = min( $this->m, $this->
n );
361 for ( $forwardBound = 0; $forwardBound < $max
362 && $this->
from[$forwardBound] === $this->to[$forwardBound];
365 $this->removed[$forwardBound] = $this->added[$forwardBound] =
false;
368 $backBoundL1 = $this->m - 1;
369 $backBoundL2 = $this->
n - 1;
371 while ( $backBoundL1 >= $forwardBound && $backBoundL2 >= $forwardBound
372 && $this->from[$backBoundL1] === $this->to[$backBoundL2]
374 $this->removed[$backBoundL1--] = $this->added[$backBoundL2--] =
false;
377 $temp = array_fill( 0, $this->m + $this->
n + 1, 0 );
378 $V = [ $temp, $temp ];
379 $snake = [ 0, 0, 0 ];
381 $this->length = $forwardBound + $this->m - $backBoundL1 - 1
395 $this->length += $i + $j - 1;
397 foreach ( $this->removed
as $key => &$removed_elem ) {
398 if ( !$removed_elem ) {
399 $removed[$newFromIndex[$key]] =
false;
402 foreach ( $this->added
as $key => &$added_elem ) {
403 if ( !$added_elem ) {
404 $added[$newToIndex[$key]] =
false;
413 $this->
diff( $from_lines, $to_lines );
414 unset( $from_lines, $to_lines );
418 while ( $xi < $this->m || $yi < $this->
n ) {
420 while ( $xi < $this->m && $yi < $this->n
421 && !$this->removed[$xi]
422 && !$this->added[$yi]
429 while ( $xi < $this->m && $this->removed[$xi] ) {
434 while ( $yi < $this->n && $this->added[$yi] ) {
438 if ( $xi > $xstart || $yi > $ystart ) {
446 private function lcs_rec( $bottoml1, $topl1, $bottoml2, $topl2, &$V, &$snake ) {
448 if ( $bottoml1 > $topl1 || $bottoml2 > $topl2 ) {
453 $topl2, $V, $snake );
462 for ( $i = 0; $i < $len; ++$i ) {
463 $this->removed[$startx + $i] = $this->added[$starty + $i] =
false;
468 + $this->
lcs_rec( $bottoml1, $startx - 1, $bottoml2,
469 $starty - 1, $V, $snake )
470 + $this->
lcs_rec( $startx + $len, $topl1, $starty + $len,
471 $topl2, $V, $snake );
472 } elseif ( $d == 1 ) {
478 $max = min( $startx - $bottoml1, $starty - $bottoml2 );
479 for ( $i = 0; $i < $max; ++$i ) {
480 $this->removed[$bottoml1 + $i] =
481 $this->added[$bottoml2 + $i] =
false;
495 $snake0 = &$snake[0];
496 $snake1 = &$snake[1];
497 $snake2 = &$snake[2];
498 $bottoml1_min_1 = $bottoml1 - 1;
499 $bottoml2_min_1 = $bottoml2 - 1;
500 $N = $topl1 - $bottoml1_min_1;
501 $M = $topl2 - $bottoml2_min_1;
503 $maxabsx = $N + $bottoml1;
504 $maxabsy = $M + $bottoml2;
505 $limit = min( $this->maxDifferences, ceil( ( $N + $M ) / 2 ) );
509 if ( ( $M & 1 ) == 1 ) {
510 $value_to_add_forward = 1;
512 $value_to_add_forward = 0;
515 if ( ( $N & 1 ) == 1 ) {
516 $value_to_add_backward = 1;
518 $value_to_add_backward = 0;
521 $start_forward = -$M;
523 $start_backward = -$N;
526 $limit_min_1 =
$limit - 1;
527 $limit_plus_1 =
$limit + 1;
529 $V0[$limit_plus_1] = 0;
530 $V1[$limit_min_1] = $N;
531 $limit = min( $this->maxDifferences, ceil( ( $N + $M ) / 2 ) );
533 if ( ( $delta & 1 ) == 1 ) {
534 for ( $d = 0; $d <=
$limit; ++$d ) {
535 $start_diag = max( $value_to_add_forward + $start_forward, -$d );
536 $end_diag = min( $end_forward, $d );
537 $value_to_add_forward = 1 - $value_to_add_forward;
540 for ( $k = $start_diag; $k <= $end_diag; $k += 2 ) {
541 if ( $k == -$d || ( $k < $d
542 && $V0[$limit_min_1 + $k] < $V0[$limit_plus_1 + $k] )
544 $x = $V0[$limit_plus_1 + $k];
546 $x = $V0[$limit_min_1 + $k] + 1;
549 $absx = $snake0 = $x + $bottoml1;
550 $absy = $snake1 = $x - $k + $bottoml2;
552 while ( $absx < $maxabsx && $absy < $maxabsy &&
$from[$absx] ===
$to[$absy] ) {
556 $x = $absx - $bottoml1;
558 $snake2 = $absx - $snake0;
560 if ( $k >= $delta - $d + 1 && $k <= $delta + $d - 1
561 && $x >= $V1[
$limit + $k - $delta]
567 if ( $x >= $N && $end_forward > $k - 1 ) {
568 $end_forward = $k - 1;
569 } elseif ( $absy - $bottoml2 >= $M ) {
570 $start_forward = $k + 1;
571 $value_to_add_forward = 0;
575 $start_diag = max( $value_to_add_backward + $start_backward, -$d );
576 $end_diag = min( $end_backward, $d );
577 $value_to_add_backward = 1 - $value_to_add_backward;
580 for ( $k = $start_diag; $k <= $end_diag; $k += 2 ) {
582 || ( $k != -$d && $V1[$limit_min_1 + $k] < $V1[$limit_plus_1 + $k] )
584 $x = $V1[$limit_min_1 + $k];
586 $x = $V1[$limit_plus_1 + $k] - 1;
589 $y = $x - $k - $delta;
592 while ( $x > 0 && $y > 0
593 &&
$from[$x + $bottoml1_min_1] ===
$to[$y + $bottoml2_min_1]
603 $start_backward = $k + 1;
604 $value_to_add_backward = 0;
605 } elseif ( $y <= 0 && $end_backward > $k - 1 ) {
606 $end_backward = $k - 1;
611 for ( $d = 0; $d <=
$limit; ++$d ) {
612 $start_diag = max( $value_to_add_forward + $start_forward, -$d );
613 $end_diag = min( $end_forward, $d );
614 $value_to_add_forward = 1 - $value_to_add_forward;
617 for ( $k = $start_diag; $k <= $end_diag; $k += 2 ) {
619 || ( $k < $d && $V0[$limit_min_1 + $k] < $V0[$limit_plus_1 + $k] )
621 $x = $V0[$limit_plus_1 + $k];
623 $x = $V0[$limit_min_1 + $k] + 1;
626 $absx = $snake0 = $x + $bottoml1;
627 $absy = $snake1 = $x - $k + $bottoml2;
629 while ( $absx < $maxabsx && $absy < $maxabsy &&
$from[$absx] ===
$to[$absy] ) {
633 $x = $absx - $bottoml1;
634 $snake2 = $absx - $snake0;
638 if ( $x >= $N && $end_forward > $k - 1 ) {
639 $end_forward = $k - 1;
640 } elseif ( $absy - $bottoml2 >= $M ) {
641 $start_forward = $k + 1;
642 $value_to_add_forward = 0;
646 $start_diag = max( $value_to_add_backward + $start_backward, -$d );
647 $end_diag = min( $end_backward, $d );
648 $value_to_add_backward = 1 - $value_to_add_backward;
651 for ( $k = $start_diag; $k <= $end_diag; $k += 2 ) {
653 || ( $k != -$d && $V1[$limit_min_1 + $k] < $V1[$limit_plus_1 + $k] )
655 $x = $V1[$limit_min_1 + $k];
657 $x = $V1[$limit_plus_1 + $k] - 1;
660 $y = $x - $k - $delta;
663 while ( $x > 0 && $y > 0
664 &&
$from[$x + $bottoml1_min_1] ===
$to[$y + $bottoml2_min_1]
672 if ( $k >= -$delta - $d && $k <= $d - $delta
673 && $x <= $V0[
$limit + $k + $delta]
675 $snake0 = $bottoml1 + $x;
676 $snake1 = $bottoml2 + $y;
683 $start_backward = $k + 1;
684 $value_to_add_backward = 0;
685 } elseif ( $y <= 0 && $end_backward > $k - 1 ) {
686 $end_backward = $k - 1;
697 $most_progress = self::findMostProgress( $M, $N,
$limit, $V );
699 $snake0 = $bottoml1 + $most_progress[0];
700 $snake1 = $bottoml2 + $most_progress[1];
702 wfDebug(
"Computing the LCS is too expensive. Using a heuristic.\n" );
703 $this->heuristicUsed =
true;
717 if ( ( $M & 1 ) == (
$limit & 1 ) ) {
718 $forward_start_diag = max( -$M, -
$limit );
720 $forward_start_diag = max( 1 - $M, -
$limit );
723 $forward_end_diag = min( $N,
$limit );
725 if ( ( $N & 1 ) == (
$limit & 1 ) ) {
726 $backward_start_diag = max( -$N, -
$limit );
728 $backward_start_diag = max( 1 - $N, -
$limit );
731 $backward_end_diag = -min( $M,
$limit );
735 $max_progress = array_fill( 0, ceil( max( $forward_end_diag - $forward_start_diag,
736 $backward_end_diag - $backward_start_diag ) / 2 ), $temp );
741 for ( $k = $forward_start_diag; $k <= $forward_end_diag; $k += 2 ) {
744 if ( $x > $N || $y > $M ) {
749 if ( $progress > $max_progress[0][2] ) {
751 $max_progress[0][0] = $x;
752 $max_progress[0][1] = $y;
753 $max_progress[0][2] = $progress;
754 } elseif ( $progress == $max_progress[0][2] ) {
756 $max_progress[$num_progress][0] = $x;
757 $max_progress[$num_progress][1] = $y;
758 $max_progress[$num_progress][2] = $progress;
762 $max_progress_forward =
true;
767 for ( $k = $backward_start_diag; $k <= $backward_end_diag; $k += 2 ) {
769 $y = $x - $k - $delta;
770 if ( $x < 0 || $y < 0 ) {
774 $progress = $N - $x + $M - $y;
775 if ( $progress > $max_progress[0][2] ) {
777 $max_progress_forward =
false;
778 $max_progress[0][0] = $x;
779 $max_progress[0][1] = $y;
780 $max_progress[0][2] = $progress;
781 } elseif ( $progress == $max_progress[0][2] && !$max_progress_forward ) {
783 $max_progress[$num_progress][0] = $x;
784 $max_progress[$num_progress][1] = $y;
785 $max_progress[$num_progress][2] = $progress;
790 return $max_progress[(int)floor( $num_progress / 2 )];
797 if ( $this->heuristicUsed && !$this->lcsLengthCorrectedForHeuristic ) {
798 $this->lcsLengthCorrectedForHeuristic =
true;
799 $this->length = $this->m - array_sum( $this->added );
lcs_rec($bottoml1, $topl1, $bottoml2, $topl2, &$V, &$snake)
the array() calling protocol came about after MediaWiki 1.4rc1.
__construct($leftstart, $leftend, $rightstart, $rightend)
Alternative representation of a set of changes, by the index ranges that are changed.
$lcsLengthCorrectedForHeuristic
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for and distribution as defined by Sections through of this document Licensor shall mean the copyright owner or entity authorized by the copyright owner that is granting the License Legal Entity shall mean the union of the acting entity and all other entities that control are controlled by or are under common control with that entity For the purposes of this definition control direct or to cause the direction or management of such whether by contract or including but not limited to software source documentation and configuration files Object form shall mean any form resulting from mechanical transformation or translation of a Source including but not limited to compiled object generated and conversions to other media types Work shall mean the work of whether in Source or Object made available under the as indicated by a copyright notice that is included in or attached to the whether in Source or Object that is based or other modifications as a an original work of authorship For the purposes of this Derivative Works shall not include works that remain separable from
find_middle_snake($bottoml1, $topl1, $bottoml2, $topl2, &$V, &$snake)
diff_range($from_lines, $to_lines)
wfDebug($text, $dest= 'all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
diffInternal(array $from, array $to)
while(($__line=Maintenance::readconsole())!==false) print n
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
This diff implementation is mainly lifted from the LCS algorithm of the Eclipse project which in turn...
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
setBailoutComplexity($value)
Sets the complexity (in comparison operations) that can't be exceeded.
__construct($tooLong=2000000, $powLimit=1.45)
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist e g Watchlist removed from all revisions and log entries to which it was applied This gives extensions a chance to take it off their books as the deletion has already been partly carried out by this point or something similar the user will be unable to create the tag set and then return false from the hook function Ensure you consume the ChangeTagAfterDelete hook to carry out custom deletion actions as context called by AbstractContent::getParserOutput May be used to override the normal model specific rendering of page content as context as context the output can only depend on parameters provided to this hook not on global state indicating whether full HTML should be generated If generation of HTML may be but other information should still be present in the ParserOutput object to manipulate or replace but no entry for that model exists in $wgContentHandlers if desired whether it is OK to use $contentModel on $title Handler functions that modify $ok should generally return false to prevent further hooks from further modifying $ok inclusive $limit
shiftBoundaries(array $lines, array &$changed, array $other_changed)
Adjust inserts/deletes of identical lines to join changes as much as possible.
static findMostProgress($M, $N, $limit, $V)
diff($from_lines, $to_lines)
Performs diff.