76 if ( array_key_exists( $i, $this->closing ) ) {
77 return $this->closing[$i];
82 abstract public function reverse();
88 return $this->orig ? count( $this->orig ) : 0;
95 return $this->closing ? count( $this->closing ) : 0;
121 return new DiffOpCopy( $this->closing, $this->orig );
137 $this->closing =
false;
236 public function diff( $from_lines, $to_lines ) {
239 $this->
diffLocal( $from_lines, $to_lines );
242 $this->
shiftBoundaries( $from_lines, $this->xchanged, $this->ychanged );
246 $n_from = count( $from_lines );
247 $n_to = count( $to_lines );
251 while ( $xi < $n_from || $yi < $n_to ) {
252 assert( $yi < $n_to || $this->xchanged[$xi] );
253 assert( $xi < $n_from || $this->ychanged[$yi] );
257 while ( $xi < $n_from && $yi < $n_to
258 && !$this->xchanged[$xi] && !$this->ychanged[$yi]
260 $copy[] = $from_lines[$xi++];
269 while ( $xi < $n_from && $this->xchanged[$xi] ) {
270 $delete[] = $from_lines[$xi++];
274 while ( $yi < $n_to && $this->ychanged[$yi] ) {
275 $add[] = $to_lines[$yi++];
278 if ( $delete && $add ) {
280 } elseif ( $delete ) {
296 $wikidiff3->diff( $from_lines, $to_lines );
297 $this->xchanged = $wikidiff3->removed;
298 $this->ychanged = $wikidiff3->added;
318 assert( count(
$lines ) == count( $changed ) );
320 $other_len = count( $other_changed );
334 while ( $j < $other_len && $other_changed[$j] ) {
338 while ( $i < $len && !$changed[$i] ) {
339 assert( $j < $other_len && ! $other_changed[$j] );
342 while ( $j < $other_len && $other_changed[$j] ) {
354 while ( ++$i < $len && $changed[$i] ) {
363 $runlength = $i - $start;
370 while ( $start > 0 &&
$lines[$start - 1] ==
$lines[$i - 1] ) {
371 $changed[--$start] = 1;
372 $changed[--$i] =
false;
373 while ( $start > 0 && $changed[$start - 1] ) {
377 while ( $other_changed[--$j] ) {
380 assert( $j >= 0 && !$other_changed[$j] );
388 $corresponding = $j < $other_len ? $i : $len;
398 $changed[$start++] =
false;
400 while ( $i < $len && $changed[$i] ) {
404 assert( $j < $other_len && ! $other_changed[$j] );
406 if ( $j < $other_len && $other_changed[$j] ) {
408 while ( $j < $other_len && $other_changed[$j] ) {
413 }
while ( $runlength != $i - $start );
419 while ( $corresponding < $i ) {
420 $changed[--$start] = 1;
423 while ( $other_changed[--$j] ) {
426 assert( $j >= 0 && !$other_changed[$j] );
455 $this->
edits = $eng->diff( $from_lines, $to_lines );
480 foreach ( $this->
edits as $edit ) {
481 $rev->edits[] = $edit->reverse();
493 foreach ( $this->
edits as $edit ) {
494 if ( $edit->type !=
'copy' ) {
511 foreach ( $this->
edits as $edit ) {
512 if ( $edit->type ==
'copy' ) {
513 $lcs += count( $edit->orig );
531 foreach ( $this->
edits as $edit ) {
533 array_splice(
$lines, count(
$lines ), 0, $edit->orig );
551 foreach ( $this->
edits as $edit ) {
552 if ( $edit->closing ) {
553 array_splice(
$lines, count(
$lines ), 0, $edit->closing );
588 $mapped_from_lines, $mapped_to_lines ) {
590 assert( count( $from_lines ) == count( $mapped_from_lines ) );
591 assert( count( $to_lines ) == count( $mapped_to_lines ) );
593 parent::__construct( $mapped_from_lines, $mapped_to_lines );
596 $editCount = count( $this->
edits );
597 for ( $i = 0; $i < $editCount; $i++ ) {
598 $orig = &$this->
edits[$i]->orig;
599 if ( is_array( $orig ) ) {
600 $orig = array_slice( $from_lines, $xi, count( $orig ) );
601 $xi += count( $orig );
604 $closing = &$this->
edits[$i]->closing;
605 if ( is_array( $closing ) ) {
606 $closing = array_slice( $to_lines, $yi, count( $closing ) );
607 $yi += count( $closing );
623 public $insClass =
' class="diffchange diffchange-inline"';
624 public $delClass =
' class="diffchange diffchange-inline"';
635 if ( $this->group !==
'' ) {
636 if ( $this->tag ==
'ins' ) {
637 $this->
line .=
"<ins{$this->insClass}>" .
638 htmlspecialchars( $this->group ) .
'</ins>';
639 } elseif ( $this->tag ==
'del' ) {
640 $this->
line .=
"<del{$this->delClass}>" .
641 htmlspecialchars( $this->group ) .
'</del>';
643 $this->
line .= htmlspecialchars( $this->group );
647 $this->tag = $new_tag;
655 if ( $this->
line !=
'' ) {
656 array_push( $this->lines, $this->
line );
658 # make empty lines visible by inserting an NBSP
659 array_push( $this->lines,
' ' );
669 if (
$tag != $this->tag ) {
673 foreach ( $words
as $word ) {
678 if ( $word[0] ==
"\n" ) {
680 $word = substr( $word, 1 );
682 assert( !strstr( $word,
"\n" ) );
683 $this->group .= $word;
711 list( $orig_words, $orig_stripped ) = $this->
split( $orig_lines );
712 list( $closing_words, $closing_stripped ) = $this->
split( $closing_lines );
714 parent::__construct( $orig_words, $closing_words,
715 $orig_stripped, $closing_stripped );
729 # If the line is too long, just pretend the entire line is one big word
730 # This prevents resource exhaustion problems
737 if ( strlen( $line ) > self::MAX_LINE_LENGTH ) {
742 if ( preg_match_all(
'/ ( [^\S\n]+ | [0-9_A-Za-z\x80-\xff]+ | . ) (?: (?!< \n) [^\S\n])? /xs',
745 foreach ( $m[0]
as $word ) {
748 foreach ( $m[1]
as $stripped_word ) {
749 $stripped[] = $stripped_word;
755 return [ $words, $stripped ];
764 foreach ( $this->
edits as $edit ) {
765 if ( $edit->type ==
'copy' ) {
767 } elseif ( $edit->orig ) {
768 $orig->addWords( $edit->orig,
'del' );
771 $lines = $orig->getLines();
782 foreach ( $this->
edits as $edit ) {
783 if ( $edit->type ==
'copy' ) {
784 $closing->
addWords( $edit->closing );
785 } elseif ( $edit->closing ) {
786 $closing->addWords( $edit->closing,
'ins' );
789 $lines = $closing->getLines();
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these but it might have such a feature in the future We handle these by creating a deferred update object and putting those objects on a global list
shiftBoundaries($lines, &$changed, $other_changed)
Adjust inserts/deletes of identical lines to join changes as much as possible.
__construct($from_lines, $to_lines, $mapped_from_lines, $mapped_to_lines)
Constructor.
closing()
Get the closing set of lines.
The base class for all other DiffOp classes.
__construct($from_lines, $to_lines)
Constructor.
This diff implementation is mainly lifted from the LCS algorithm of the Eclipse project which in turn...
reverse()
Compute reversed Diff.
lcs()
Compute the length of the Longest Common Subsequence (LCS).
__construct($orig, $closing)
orig()
Get the original set of lines.
isEmpty()
Check for empty diff.
Class representing a 'diff' between two sequences of strings.
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these but it might have such a feature in the future We handle these by creating a deferred update object and putting those objects on a global then executing the whole list after the page is displayed We don t do anything smart like collating updates to the same table or such because the list is almost always going to have just one item on if so it s not worth the trouble Since there is a job queue in the jobs which is used to update link tables of transcluding pages after edits
presenting them properly to the user as errors is done by the caller return true use this to change the list i e etc $rev
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
Class used internally by Diff to actually compute the diffs.
Additions by Axel Boldt follow, partly taken from diff.php, phpwiki-1.3.3.
__construct($orig_lines, $closing_lines)
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
addWords($words, $tag= '')
diffLocal($from_lines, $to_lines)
__construct($orig, $closing=false)
I won t presume to tell you how to I m just describing the methods I chose to use for myself If you do choose to follow these it will probably be easier for you to collaborate with others on the but if you want to contribute without by all means do which work well I also use K &R brace matching style I know that s a religious issue for so if you want to use a style that puts opening braces on the next line
diff($from_lines, $to_lines)