3 * A PHP diff engine for phpwiki. (Taken from phpwiki-1.3.3)
5 * Copyright © 2000, 2001 Geoffrey T. Dairiki <dairiki@dairiki.org>
6 * You may copy this code freely under the conditions of the GPL.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 * http://www.gnu.org/copyleft/gpl.html
24 * @ingroup DifferenceEngine
25 * @defgroup DifferenceEngine DifferenceEngine
31 * @ingroup DifferenceEngine
33 abstract class DiffOp
{
38 public abstract function reverse();
44 return $this->orig ?
count( $this->orig
) : 0;
51 return $this->closing ?
count( $this->closing
) : 0;
58 * @ingroup DifferenceEngine
60 class DiffOp_Copy
extends DiffOp
{
61 public $type = 'copy';
63 function __construct( $orig, $closing = false ) {
64 if ( !is_array( $closing ) ) {
68 $this->closing
= $closing;
75 return new DiffOp_Copy( $this->closing
, $this->orig
);
82 * @ingroup DifferenceEngine
84 class DiffOp_Delete
extends DiffOp
{
85 public $type = 'delete';
87 function __construct( $lines ) {
89 $this->closing
= false;
96 return new DiffOp_Add( $this->orig
);
103 * @ingroup DifferenceEngine
105 class DiffOp_Add
extends DiffOp
{
106 public $type = 'add';
108 function __construct( $lines ) {
109 $this->closing
= $lines;
114 * @return DiffOp_Delete
117 return new DiffOp_Delete( $this->closing
);
124 * @ingroup DifferenceEngine
126 class DiffOp_Change
extends DiffOp
{
127 public $type = 'change';
129 function __construct( $orig, $closing ) {
131 $this->closing
= $closing;
135 * @return DiffOp_Change
138 return new DiffOp_Change( $this->closing
, $this->orig
);
143 * Class used internally by Diff to actually compute the diffs.
145 * The algorithm used here is mostly lifted from the perl module
146 * Algorithm::Diff (version 1.06) by Ned Konz, which is available at:
147 * http://www.perl.com/CPAN/authors/id/N/NE/NEDKONZ/Algorithm-Diff-1.06.zip
149 * More ideas are taken from:
150 * http://www.ics.uci.edu/~eppstein/161/960229.html
152 * Some ideas are (and a bit of code) are from from analyze.c, from GNU
153 * diffutils-2.7, which can be found at:
154 * ftp://gnudist.gnu.org/pub/gnu/diffutils/diffutils-2.7.tar.gz
156 * closingly, some ideas (subdivision by NCHUNKS > 2, and some optimizations)
159 * Line length limits for robustness added by Tim Starling, 2005-08-31
160 * Alternative implementation added by Guy Van den Broeck, 2008-07-30
162 * @author Geoffrey T. Dairiki, Tim Starling, Guy Van den Broeck
164 * @ingroup DifferenceEngine
168 const MAX_XREF_LENGTH
= 10000;
170 protected $xchanged, $ychanged;
172 protected $xv = array(), $yv = array();
173 protected $xind = array(), $yind = array();
175 protected $seq = array(), $in_seq = array();
184 function diff( $from_lines, $to_lines ) {
185 wfProfileIn( __METHOD__
);
187 // Diff and store locally
188 $this->diffLocal( $from_lines, $to_lines );
190 // Merge edits when possible
191 $this->shiftBoundaries( $from_lines, $this->xchanged
, $this->ychanged
);
192 $this->shiftBoundaries( $to_lines, $this->ychanged
, $this->xchanged
);
194 // Compute the edit operations.
195 $n_from = count( $from_lines );
196 $n_to = count( $to_lines );
200 while ( $xi < $n_from ||
$yi < $n_to ) {
201 assert( '$yi < $n_to || $this->xchanged[$xi]' );
202 assert( '$xi < $n_from || $this->ychanged[$yi]' );
204 // Skip matching "snake".
206 while ( $xi < $n_from && $yi < $n_to
207 && !$this->xchanged
[$xi] && !$this->ychanged
[$yi] ) {
208 $copy[] = $from_lines[$xi++
];
212 $edits[] = new DiffOp_Copy( $copy );
215 // Find deletes & adds.
217 while ( $xi < $n_from && $this->xchanged
[$xi] ) {
218 $delete[] = $from_lines[$xi++
];
222 while ( $yi < $n_to && $this->ychanged
[$yi] ) {
223 $add[] = $to_lines[$yi++
];
226 if ( $delete && $add ) {
227 $edits[] = new DiffOp_Change( $delete, $add );
228 } elseif ( $delete ) {
229 $edits[] = new DiffOp_Delete( $delete );
231 $edits[] = new DiffOp_Add( $add );
234 wfProfileOut( __METHOD__
);
242 private function diffLocal( $from_lines, $to_lines ) {
243 global $wgExternalDiffEngine;
244 wfProfileIn( __METHOD__
);
246 if ( $wgExternalDiffEngine == 'wikidiff3' ) {
248 $wikidiff3 = new WikiDiff3();
249 $wikidiff3->diff( $from_lines, $to_lines );
250 $this->xchanged
= $wikidiff3->removed
;
251 $this->ychanged
= $wikidiff3->added
;
255 $n_from = count( $from_lines );
256 $n_to = count( $to_lines );
257 $this->xchanged
= $this->ychanged
= array();
258 $this->xv
= $this->yv
= array();
259 $this->xind
= $this->yind
= array();
261 unset( $this->in_seq
);
264 // Skip leading common lines.
265 for ( $skip = 0; $skip < $n_from && $skip < $n_to; $skip++
) {
266 if ( $from_lines[$skip] !== $to_lines[$skip] ) {
269 $this->xchanged
[$skip] = $this->ychanged
[$skip] = false;
271 // Skip trailing common lines.
274 for ( $endskip = 0; --$xi > $skip && --$yi > $skip; $endskip++
) {
275 if ( $from_lines[$xi] !== $to_lines[$yi] ) {
278 $this->xchanged
[$xi] = $this->ychanged
[$yi] = false;
281 // Ignore lines which do not exist in both files.
282 for ( $xi = $skip; $xi < $n_from - $endskip; $xi++
) {
283 $xhash[$this->lineHash( $from_lines[$xi] )] = 1;
286 for ( $yi = $skip; $yi < $n_to - $endskip; $yi++
) {
287 $line = $to_lines[$yi];
288 if ( ( $this->ychanged
[$yi] = empty( $xhash[$this->lineHash( $line )] ) ) ) {
291 $yhash[$this->lineHash( $line )] = 1;
295 for ( $xi = $skip; $xi < $n_from - $endskip; $xi++
) {
296 $line = $from_lines[$xi];
297 if ( ( $this->xchanged
[$xi] = empty( $yhash[$this->lineHash( $line )] ) ) ) {
305 $this->compareSeq( 0, count( $this->xv
), 0, count( $this->yv
) );
307 wfProfileOut( __METHOD__
);
311 * Returns the whole line if it's small enough, or the MD5 hash otherwise
312 * @param $line string
315 private function lineHash( $line ) {
316 if ( strlen( $line ) > self
::MAX_XREF_LENGTH
) {
324 * Divide the Largest Common Subsequence (LCS) of the sequences
325 * [XOFF, XLIM) and [YOFF, YLIM) into NCHUNKS approximately equally
328 * Returns (LCS, PTS). LCS is the length of the LCS. PTS is an
329 * array of NCHUNKS+1 (X, Y) indexes giving the diving points between
330 * sub sequences. The first sub-sequence is contained in [X0, X1),
331 * [Y0, Y1), the second in [X1, X2), [Y1, Y2) and so on. Note
332 * that (X0, Y0) == (XOFF, YOFF) and
333 * (X[NCHUNKS], Y[NCHUNKS]) == (XLIM, YLIM).
335 * This function assumes that the first lines of the specified portions
336 * of the two files do not match, and likewise that the last lines do not
337 * match. The caller must trim matching lines from the beginning and end
338 * of the portions it is going to specify.
346 private function diag( $xoff, $xlim, $yoff, $ylim, $nchunks ) {
349 if ( $xlim - $xoff > $ylim - $yoff ) {
350 // Things seems faster (I'm not sure I understand why)
351 // when the shortest sequence in X.
353 list( $xoff, $xlim, $yoff, $ylim ) = array( $yoff, $ylim, $xoff, $xlim );
357 for ( $i = $ylim - 1; $i >= $yoff; $i-- ) {
358 $ymatches[$this->xv
[$i]][] = $i;
361 for ( $i = $ylim - 1; $i >= $yoff; $i-- ) {
362 $ymatches[$this->yv
[$i]][] = $i;
367 $this->seq
[0] = $yoff - 1;
368 $this->in_seq
= array();
371 $numer = $xlim - $xoff +
$nchunks - 1;
373 for ( $chunk = 0; $chunk < $nchunks; $chunk++
) {
375 for ( $i = 0; $i <= $this->lcs
; $i++
) {
376 $ymids[$i][$chunk -1] = $this->seq
[$i];
380 $x1 = $xoff +
(int)( ( $numer +
( $xlim -$xoff ) * $chunk ) / $nchunks );
381 for ( ; $x < $x1; $x++
) {
382 $line = $flip ?
$this->yv
[$x] : $this->xv
[$x];
383 if ( empty( $ymatches[$line] ) ) {
386 $matches = $ymatches[$line];
388 while ( list( , $y ) = each( $matches ) ) {
389 if ( empty( $this->in_seq
[$y] ) ) {
390 $k = $this->lcsPos( $y );
392 $ymids[$k] = $ymids[$k -1];
396 while ( list( , $y ) = each( $matches ) ) {
397 if ( $y > $this->seq
[$k -1] ) {
398 assert( '$y < $this->seq[$k]' );
399 // Optimization: this is a common case:
400 // next match is just replacing previous match.
401 $this->in_seq
[$this->seq
[$k]] = false;
403 $this->in_seq
[$y] = 1;
404 } elseif ( empty( $this->in_seq
[$y] ) ) {
405 $k = $this->lcsPos( $y );
407 $ymids[$k] = $ymids[$k -1];
413 $seps[] = $flip ?
array( $yoff, $xoff ) : array( $xoff, $yoff );
414 $ymid = $ymids[$this->lcs
];
415 for ( $n = 0; $n < $nchunks - 1; $n++
) {
416 $x1 = $xoff +
(int)( ( $numer +
( $xlim - $xoff ) * $n ) / $nchunks );
418 $seps[] = $flip ?
array( $y1, $x1 ) : array( $x1, $y1 );
420 $seps[] = $flip ?
array( $ylim, $xlim ) : array( $xlim, $ylim );
422 return array( $this->lcs
, $seps );
429 private function lcsPos( $ypos ) {
431 if ( $end == 0 ||
$ypos > $this->seq
[$end] ) {
432 $this->seq
[++
$this->lcs
] = $ypos;
433 $this->in_seq
[$ypos] = 1;
438 while ( $beg < $end ) {
439 $mid = (int)( ( $beg +
$end ) / 2 );
440 if ( $ypos > $this->seq
[$mid] ) {
447 assert( '$ypos != $this->seq[$end]' );
449 $this->in_seq
[$this->seq
[$end]] = false;
450 $this->seq
[$end] = $ypos;
451 $this->in_seq
[$ypos] = 1;
456 * Find LCS of two sequences.
458 * The results are recorded in the vectors $this->{x,y}changed[], by
459 * storing a 1 in the element for each line that is an insertion
460 * or deletion (ie. is not in the LCS).
462 * The subsequence of file 0 is [XOFF, XLIM) and likewise for file 1.
464 * Note that XLIM, YLIM are exclusive bounds.
465 * All line numbers are origin-0 and discarded lines are not counted.
471 private function compareSeq( $xoff, $xlim, $yoff, $ylim ) {
472 // Slide down the bottom initial diagonal.
473 while ( $xoff < $xlim && $yoff < $ylim && $this->xv
[$xoff] == $this->yv
[$yoff] ) {
478 // Slide up the top initial diagonal.
479 while ( $xlim > $xoff && $ylim > $yoff
480 && $this->xv
[$xlim - 1] == $this->yv
[$ylim - 1] ) {
485 if ( $xoff == $xlim ||
$yoff == $ylim ) {
488 // This is ad hoc but seems to work well.
489 // $nchunks = sqrt(min($xlim - $xoff, $ylim - $yoff) / 2.5);
490 // $nchunks = max(2,min(8,(int)$nchunks));
491 $nchunks = min( 7, $xlim - $xoff, $ylim - $yoff ) +
1;
492 list( $lcs, $seps ) = $this->diag( $xoff, $xlim, $yoff, $ylim, $nchunks );
496 // X and Y sequences have no common subsequence:
498 while ( $yoff < $ylim ) {
499 $this->ychanged
[$this->yind
[$yoff++
]] = 1;
501 while ( $xoff < $xlim ) {
502 $this->xchanged
[$this->xind
[$xoff++
]] = 1;
505 // Use the partitions to split this problem into subproblems.
508 while ( $pt2 = next( $seps ) ) {
509 $this->compareSeq( $pt1[0], $pt2[0], $pt1[1], $pt2[1] );
516 * Adjust inserts/deletes of identical lines to join changes
517 * as much as possible.
519 * We do something when a run of changed lines include a
520 * line at one end and has an excluded, identical line at the other.
521 * We are free to choose which identical line is included.
522 * `compareseq' usually chooses the one at the beginning,
523 * but usually it is cleaner to consider the following identical line
524 * to be the "change".
526 * This is extracted verbatim from analyze.c (GNU diffutils-2.7).
528 private function shiftBoundaries( $lines, &$changed, $other_changed ) {
529 wfProfileIn( __METHOD__
);
533 assert( 'count($lines) == count($changed)' );
534 $len = count( $lines );
535 $other_len = count( $other_changed );
539 * Scan forwards to find beginning of another run of changes.
540 * Also keep track of the corresponding point in the other file.
542 * Throughout this code, $i and $j are adjusted together so that
543 * the first $i elements of $changed and the first $j elements
544 * of $other_changed both contain the same number of zeros
546 * Furthermore, $j is always kept so that $j == $other_len or
547 * $other_changed[$j] == false.
549 while ( $j < $other_len && $other_changed[$j] ) {
553 while ( $i < $len && ! $changed[$i] ) {
554 assert( '$j < $other_len && ! $other_changed[$j]' );
557 while ( $j < $other_len && $other_changed[$j] ) {
568 // Find the end of this run of changes.
569 while ( ++
$i < $len && $changed[$i] ) {
575 * Record the length of this run of changes, so that
576 * we can later determine whether the run has grown.
578 $runlength = $i - $start;
581 * Move the changed region back, so long as the
582 * previous unchanged line matches the last changed one.
583 * This merges with previous changed regions.
585 while ( $start > 0 && $lines[$start - 1] == $lines[$i - 1] ) {
586 $changed[--$start] = 1;
587 $changed[--$i] = false;
588 while ( $start > 0 && $changed[$start - 1] ) {
592 while ( $other_changed[--$j] ) {
595 assert( '$j >= 0 && !$other_changed[$j]' );
599 * Set CORRESPONDING to the end of the changed run, at the last
600 * point where it corresponds to a changed run in the other file.
601 * CORRESPONDING == LEN means no such point has been found.
603 $corresponding = $j < $other_len ?
$i : $len;
606 * Move the changed region forward, so long as the
607 * first changed line matches the following unchanged one.
608 * This merges with following changed regions.
609 * Do this second, so that if there are no merges,
610 * the changed region is moved forward as far as possible.
612 while ( $i < $len && $lines[$start] == $lines[$i] ) {
613 $changed[$start++
] = false;
615 while ( $i < $len && $changed[$i] ) {
619 assert( '$j < $other_len && ! $other_changed[$j]' );
621 if ( $j < $other_len && $other_changed[$j] ) {
623 while ( $j < $other_len && $other_changed[$j] ) {
628 } while ( $runlength != $i - $start );
631 * If possible, move the fully-merged run of changes
632 * back to a corresponding run in the other file.
634 while ( $corresponding < $i ) {
635 $changed[--$start] = 1;
638 while ( $other_changed[--$j] ) {
641 assert( '$j >= 0 && !$other_changed[$j]' );
644 wfProfileOut( __METHOD__
);
649 * Class representing a 'diff' between two sequences of strings.
652 * @ingroup DifferenceEngine
659 * Computes diff between sequences of strings.
661 * @param $from_lines array An array of strings.
662 * (Typically these are lines from a file.)
663 * @param $to_lines array An array of strings.
665 function __construct( $from_lines, $to_lines ) {
666 $eng = new DiffEngine
;
667 $this->edits
= $eng->diff( $from_lines, $to_lines );
668 // $this->check($from_lines, $to_lines);
672 * Compute reversed Diff.
676 * $diff = new Diff($lines1, $lines2);
677 * $rev = $diff->reverse();
678 * @return Object A Diff object representing the inverse of the
683 $rev->edits
= array();
684 /** @var DiffOp $edit */
685 foreach ( $this->edits
as $edit ) {
686 $rev->edits
[] = $edit->reverse();
692 * Check for empty diff.
694 * @return bool True if two sequences were identical.
697 foreach ( $this->edits
as $edit ) {
698 if ( $edit->type
!= 'copy' ) {
706 * Compute the length of the Longest Common Subsequence (LCS).
708 * This is mostly for diagnostic purposed.
710 * @return int The length of the LCS.
714 foreach ( $this->edits
as $edit ) {
715 if ( $edit->type
== 'copy' ) {
716 $lcs +
= count( $edit->orig
);
723 * Get the original set of lines.
725 * This reconstructs the $from_lines parameter passed to the
728 * @return array The original sequence of strings.
733 foreach ( $this->edits
as $edit ) {
735 array_splice( $lines, count( $lines ), 0, $edit->orig
);
742 * Get the closing set of lines.
744 * This reconstructs the $to_lines parameter passed to the
747 * @return array The sequence of strings.
752 foreach ( $this->edits
as $edit ) {
753 if ( $edit->closing
) {
754 array_splice( $lines, count( $lines ), 0, $edit->closing
);
761 * Check a Diff for validity.
763 * This is here only for debugging purposes.
767 private function check( $from_lines, $to_lines ) {
768 wfProfileIn( __METHOD__
);
769 if ( serialize( $from_lines ) != serialize( $this->orig() ) ) {
770 trigger_error( "Reconstructed original doesn't match", E_USER_ERROR
);
772 if ( serialize( $to_lines ) != serialize( $this->closing() ) ) {
773 trigger_error( "Reconstructed closing doesn't match", E_USER_ERROR
);
776 $rev = $this->reverse();
777 if ( serialize( $to_lines ) != serialize( $rev->orig() ) ) {
778 trigger_error( "Reversed original doesn't match", E_USER_ERROR
);
780 if ( serialize( $from_lines ) != serialize( $rev->closing() ) ) {
781 trigger_error( "Reversed closing doesn't match", E_USER_ERROR
);
785 foreach ( $this->edits
as $edit ) {
786 if ( $prevtype == $edit->type
) {
787 trigger_error( 'Edit sequence is non-optimal', E_USER_ERROR
);
789 $prevtype = $edit->type
;
793 trigger_error( 'Diff okay: LCS = ' . $lcs, E_USER_NOTICE
);
794 wfProfileOut( __METHOD__
);
799 * @todo document, bad name.
801 * @ingroup DifferenceEngine
803 class MappedDiff
extends Diff
{
807 * Computes diff between sequences of strings.
809 * This can be used to compute things like
810 * case-insensitve diffs, or diffs which ignore
811 * changes in white-space.
813 * @param $from_lines array An array of strings.
814 * (Typically these are lines from a file.)
816 * @param $to_lines array An array of strings.
818 * @param $mapped_from_lines array This array should
819 * have the same size number of elements as $from_lines.
820 * The elements in $mapped_from_lines and
821 * $mapped_to_lines are what is actually compared
822 * when computing the diff.
824 * @param $mapped_to_lines array This array should
825 * have the same number of elements as $to_lines.
827 function __construct( $from_lines, $to_lines,
828 $mapped_from_lines, $mapped_to_lines ) {
829 wfProfileIn( __METHOD__
);
831 assert( 'count( $from_lines ) == count( $mapped_from_lines )' );
832 assert( 'count( $to_lines ) == count( $mapped_to_lines )' );
834 parent
::__construct( $mapped_from_lines, $mapped_to_lines );
837 for ( $i = 0; $i < count( $this->edits
); $i++
) {
838 $orig = &$this->edits
[$i]->orig
;
839 if ( is_array( $orig ) ) {
840 $orig = array_slice( $from_lines, $xi, count( $orig ) );
841 $xi +
= count( $orig );
844 $closing = &$this->edits
[$i]->closing
;
845 if ( is_array( $closing ) ) {
846 $closing = array_slice( $to_lines, $yi, count( $closing ) );
847 $yi +
= count( $closing );
850 wfProfileOut( __METHOD__
);
855 * Additions by Axel Boldt follow, partly taken from diff.php, phpwiki-1.3.3
861 * @ingroup DifferenceEngine
863 class HWLDF_WordAccumulator
{
864 private $lines = array();
872 private function flushGroup( $new_tag ) {
873 if ( $this->group
!== '' ) {
874 if ( $this->tag
== 'ins' ) {
875 $this->line
.= '<ins class="diffchange diffchange-inline">' .
876 htmlspecialchars( $this->group
) . '</ins>';
877 } elseif ( $this->tag
== 'del' ) {
878 $this->line
.= '<del class="diffchange diffchange-inline">' .
879 htmlspecialchars( $this->group
) . '</del>';
881 $this->line
.= htmlspecialchars( $this->group
);
885 $this->tag
= $new_tag;
891 private function flushLine( $new_tag ) {
892 $this->flushGroup( $new_tag );
893 if ( $this->line
!= '' ) {
894 array_push( $this->lines
, $this->line
);
896 # make empty lines visible by inserting an NBSP
897 array_push( $this->lines
, ' ' );
906 public function addWords( $words, $tag = '' ) {
907 if ( $tag != $this->tag
) {
908 $this->flushGroup( $tag );
911 foreach ( $words as $word ) {
912 // new-line should only come as first char of word.
916 if ( $word[0] == "\n" ) {
917 $this->flushLine( $tag );
918 $word = substr( $word, 1 );
920 assert( '!strstr( $word, "\n" )' );
921 $this->group
.= $word;
928 public function getLines() {
929 $this->flushLine( '~done' );
937 * @ingroup DifferenceEngine
939 class WordLevelDiff
extends MappedDiff
{
940 const MAX_LINE_LENGTH
= 10000;
944 * @param $closing_lines
946 function __construct( $orig_lines, $closing_lines ) {
947 wfProfileIn( __METHOD__
);
949 list( $orig_words, $orig_stripped ) = $this->split( $orig_lines );
950 list( $closing_words, $closing_stripped ) = $this->split( $closing_lines );
952 parent
::__construct( $orig_words, $closing_words,
953 $orig_stripped, $closing_stripped );
954 wfProfileOut( __METHOD__
);
961 private function split( $lines ) {
962 wfProfileIn( __METHOD__
);
967 foreach ( $lines as $line ) {
968 # If the line is too long, just pretend the entire line is one big word
969 # This prevents resource exhaustion problems
976 if ( strlen( $line ) > self
::MAX_LINE_LENGTH
) {
981 if ( preg_match_all( '/ ( [^\S\n]+ | [0-9_A-Za-z\x80-\xff]+ | . ) (?: (?!< \n) [^\S\n])? /xs',
984 foreach ( $m[0] as $word ) {
987 foreach ( $m[1] as $stripped_word ) {
988 $stripped[] = $stripped_word;
993 wfProfileOut( __METHOD__
);
994 return array( $words, $stripped );
1000 public function orig() {
1001 wfProfileIn( __METHOD__
);
1002 $orig = new HWLDF_WordAccumulator
;
1004 foreach ( $this->edits
as $edit ) {
1005 if ( $edit->type
== 'copy' ) {
1006 $orig->addWords( $edit->orig
);
1007 } elseif ( $edit->orig
) {
1008 $orig->addWords( $edit->orig
, 'del' );
1011 $lines = $orig->getLines();
1012 wfProfileOut( __METHOD__
);
1019 public function closing() {
1020 wfProfileIn( __METHOD__
);
1021 $closing = new HWLDF_WordAccumulator
;
1023 foreach ( $this->edits
as $edit ) {
1024 if ( $edit->type
== 'copy' ) {
1025 $closing->addWords( $edit->closing
);
1026 } elseif ( $edit->closing
) {
1027 $closing->addWords( $edit->closing
, 'ins' );
1030 $lines = $closing->getLines();
1031 wfProfileOut( __METHOD__
);