Don't try to dl() the wikidiff module if it's already loaded.
[lhc/web/wiklou.git] / includes / DifferenceEngine.php
1 <?php
2 /**
3 * See diff.doc
4 * @package MediaWiki
5 * @subpackage DifferenceEngine
6 */
7
8 /**
9 * @todo document
10 * @access public
11 */
12 class DifferenceEngine {
13 /* private */ var $mOldid, $mNewid;
14 /* private */ var $mOldtitle, $mNewtitle, $mPagetitle;
15 /* private */ var $mOldtext, $mNewtext;
16 /* private */ var $mOldUser, $mNewUser;
17 /* private */ var $mOldComment, $mNewComment;
18 /* private */ var $mOldPage, $mNewPage;
19 /* private */ var $mRcidMarkPatrolled;
20
21 function DifferenceEngine( $old, $new, $rcid = 0 )
22 {
23 global $wgTitle;
24 if ( 'prev' == $new ) {
25 # Show diff between revision $old and the previous one.
26 # Get previous one from DB.
27 #
28 $this->mNewid = intval($old);
29
30 $this->mOldid = $wgTitle->getPreviousRevisionID( $this->mNewid );
31
32 } elseif ( 'next' == $new ) {
33
34 # Show diff between revision $old and the previous one.
35 # Get previous one from DB.
36 #
37 $this->mOldid = intval($old);
38 $this->mNewid = $wgTitle->getNextRevisionID( $this->mOldid );
39 if ( false === $this->mNewid ) {
40 # if no result, NewId points to the newest old revision. The only newer
41 # revision is cur, which is "0".
42 $this->mNewid = 0;
43 }
44
45 } else {
46
47 $this->mOldid = intval($old);
48 $this->mNewid = intval($new);
49 }
50 $this->mRcidMarkPatrolled = intval($rcid); # force it to be an integer
51 }
52
53 function showDiffPage()
54 {
55 global $wgUser, $wgTitle, $wgOut, $wgContLang, $wgOnlySysopsCanPatrol, $wgUseRCPatrol;
56 $fname = 'DifferenceEngine::showDiffPage';
57 wfProfileIn( $fname );
58
59 # mOldid is false if the difference engine is called with a "vague" query for
60 # a diff between a version V and its previous version V' AND the version V
61 # is the first version of that article. In that case, V' does not exist.
62 if ( $this->mOldid === false ) {
63 $this->showFirstRevision();
64 wfProfileOut( $fname );
65 return;
66 }
67
68 $t = $wgTitle->getPrefixedText() . " (Diff: {$this->mOldid}, " .
69 "{$this->mNewid})";
70 $mtext = wfMsg( 'missingarticle', $t );
71
72 $wgOut->setArticleFlag( false );
73 if ( ! $this->loadText() ) {
74 $wgOut->setPagetitle( wfMsg( 'errorpagetitle' ) );
75 $wgOut->addHTML( $mtext );
76 wfProfileOut( $fname );
77 return;
78 }
79 $wgOut->suppressQuickbar();
80
81 $oldTitle = $this->mOldPage->getPrefixedText();
82 $newTitle = $this->mNewPage->getPrefixedText();
83 if( $oldTitle == $newTitle ) {
84 $wgOut->setPageTitle( $newTitle );
85 } else {
86 $wgOut->setPageTitle( $oldTitle . ', ' . $newTitle );
87 }
88 $wgOut->setSubtitle( wfMsg( 'difference' ) );
89 $wgOut->setRobotpolicy( 'noindex,follow' );
90
91 if ( !( $this->mOldPage->userCanRead() && $this->mNewPage->userCanRead() ) ) {
92 $wgOut->loginToUse();
93 $wgOut->output();
94 wfProfileOut( $fname );
95 exit;
96 }
97
98 $sk = $wgUser->getSkin();
99 $talk = $wgContLang->getNsText( NS_TALK );
100 $contribs = wfMsg( 'contribslink' );
101
102 $this->mOldComment = $sk->formatComment($this->mOldComment);
103 $this->mNewComment = $sk->formatComment($this->mNewComment);
104
105 $oldUserLink = $sk->makeLinkObj( Title::makeTitleSafe( NS_USER, $this->mOldUser ), $this->mOldUser );
106 $newUserLink = $sk->makeLinkObj( Title::makeTitleSafe( NS_USER, $this->mNewUser ), $this->mNewUser );
107 $oldUTLink = $sk->makeLinkObj( Title::makeTitleSafe( NS_USER_TALK, $this->mOldUser ), $talk );
108 $newUTLink = $sk->makeLinkObj( Title::makeTitleSafe( NS_USER_TALK, $this->mNewUser ), $talk );
109 $oldContribs = $sk->makeKnownLinkObj( Title::makeTitle( NS_SPECIAL, 'Contributions' ), $contribs,
110 'target=' . urlencode($this->mOldUser) );
111 $newContribs = $sk->makeKnownLinkObj( Title::makeTitle( NS_SPECIAL, 'Contributions' ), $contribs,
112 'target=' . urlencode($this->mNewUser) );
113 if ( !$this->mNewid && $wgUser->isAllowed('rollback') ) {
114 $rollback = '&nbsp;&nbsp;&nbsp;<strong>[' . $sk->makeKnownLinkObj( $wgTitle, wfMsg( 'rollbacklink' ),
115 'action=rollback&from=' . urlencode($this->mNewUser) ) . ']</strong>';
116 } else {
117 $rollback = '';
118 }
119 if ( $wgUseRCPatrol && $this->mRcidMarkPatrolled != 0 && $wgUser->getID() != 0 &&
120 ( $wgUser->isAllowed('rollback') || !$wgOnlySysopsCanPatrol ) )
121 {
122 $patrol = ' [' . $sk->makeKnownLinkObj( $wgTitle, wfMsg( 'markaspatrolleddiff' ),
123 "action=markpatrolled&rcid={$this->mRcidMarkPatrolled}" ) . ']';
124 } else {
125 $patrol = '';
126 }
127
128 $prevlink = $sk->makeKnownLinkObj( $wgTitle, wfMsg( 'previousdiff' ), 'diff=prev&oldid='.$this->mOldid );
129 if ( $this->mNewid == 0 ) {
130 $nextlink = '';
131 } else {
132 $nextlink = $sk->makeKnownLinkObj( $wgTitle, wfMsg( 'nextdiff' ), 'diff=next&oldid='.$this->mNewid );
133 }
134
135 $oldHeader = "<strong>{$this->mOldtitle}</strong><br />$oldUserLink " .
136 "($oldUTLink | $oldContribs)<br />" . $this->mOldComment .
137 '<br />' . $prevlink;
138 $newHeader = "<strong>{$this->mNewtitle}</strong><br />$newUserLink " .
139 "($newUTLink | $newContribs) $rollback<br />" . $this->mNewComment .
140 '<br />' . $nextlink . $patrol;
141
142 DifferenceEngine::showDiff( $this->mOldtext, $this->mNewtext,
143 $oldHeader, $newHeader );
144 $wgOut->addHTML( "<hr /><h2>{$this->mPagetitle}</h2>\n" );
145 $wgOut->addWikiText( $this->mNewtext );
146
147 wfProfileOut( $fname );
148 }
149
150 # Show the first revision of an article. Uses normal diff headers in contrast to normal
151 # "old revision" display style.
152 #
153 function showFirstRevision()
154 {
155 global $wgOut, $wgTitle, $wgUser, $wgLang;
156
157 $fname = 'DifferenceEngine::showFirstRevision';
158 wfProfileIn( $fname );
159
160
161 $this->mOldid = $this->mNewid; # hack to make loadText() work.
162
163 # Get article text from the DB
164 #
165 if ( ! $this->loadText() ) {
166 $t = $wgTitle->getPrefixedText() . " (Diff: {$this->mOldid}, " .
167 "{$this->mNewid})";
168 $mtext = wfMsg( 'missingarticle', $t );
169 $wgOut->setPagetitle( wfMsg( 'errorpagetitle' ) );
170 $wgOut->addHTML( $mtext );
171 wfProfileOut( $fname );
172 return;
173 }
174
175 # Check if user is allowed to look at this page. If not, bail out.
176 #
177 if ( !( $this->mOldPage->userCanRead() ) ) {
178 $wgOut->loginToUse();
179 $wgOut->output();
180 wfProfileOut( $fname );
181 exit;
182 }
183
184 # Prepare the header box
185 #
186 $sk = $wgUser->getSkin();
187
188 $uTLink = $sk->makeLinkObj( Title::makeTitleSafe( NS_USER_TALK, $this->mOldUser ), $wgLang->getNsText( NS_TALK ) );
189 $userLink = $sk->makeLinkObj( Title::makeTitleSafe( NS_USER, $this->mOldUser ), $this->mOldUser );
190 $contribs = $sk->makeKnownLinkObj( Title::makeTitle( NS_SPECIAL, 'Contributions' ), wfMsg( 'contribslink' ),
191 'target=' . urlencode($this->mOldUser) );
192 $nextlink = $sk->makeKnownLinkObj( $wgTitle, wfMsg( 'nextdiff' ), 'diff=next&oldid='.$this->mNewid );
193 $header = "<div class=\"firstrevisionheader\" style=\"text-align: center\"><strong>{$this->mOldtitle}</strong><br />$userLink " .
194 "($uTLink | $contribs)<br />" . $this->mOldComment .
195 '<br />' . $nextlink. "</div>\n";
196
197 $wgOut->addHTML( $header );
198
199 $wgOut->setSubtitle( wfMsg( 'difference' ) );
200 $wgOut->setRobotpolicy( 'noindex,follow' );
201
202
203 # Show current revision
204 #
205 $wgOut->addHTML( "<hr /><h2>{$this->mPagetitle}</h2>\n" );
206 $wgOut->addWikiText( $this->mNewtext );
207
208 wfProfileOut( $fname );
209 }
210
211 function showDiff( $otext, $ntext, $otitle, $ntitle )
212 {
213 global $wgOut;
214 $wgOut->addHTML( DifferenceEngine::getDiff( $otext, $ntext, $otitle, $ntitle ) );
215 }
216
217 function getDiff( $otext, $ntext, $otitle, $ntitle ) {
218 global $wgUseExternalDiffEngine;
219 $out = "
220 <table border='0' width='98%' cellpadding='0' cellspacing='4' class='diff'>
221 <tr>
222 <td colspan='2' width='50%' align='center' class='diff-otitle'>{$otitle}</td>
223 <td colspan='2' width='50%' align='center' class='diff-ntitle'>{$ntitle}</td>
224 </tr>
225 ";
226
227 if ( $wgUseExternalDiffEngine ) {
228 # For historical reasons, external diff engine expects
229 # input text to be HTML-escaped already
230 $otext = str_replace( "\r\n", "\n", htmlspecialchars ( $otext ) );
231 $ntext = str_replace( "\r\n", "\n", htmlspecialchars ( $ntext ) );
232 if( !function_exists( 'wikidiff_do_diff' ) ) {
233 dl('php_wikidiff.so');
234 }
235 $out .= wikidiff_do_diff( $otext, $ntext, 2 );
236 } else {
237 $ota = explode( "\n", str_replace( "\r\n", "\n", $otext ) );
238 $nta = explode( "\n", str_replace( "\r\n", "\n", $ntext ) );
239 $diffs =& new Diff( $ota, $nta );
240 $formatter =& new TableDiffFormatter();
241 $out .= $formatter->format( $diffs );
242 }
243 $out .= "</table>\n";
244 return $out;
245 }
246
247 # Load the text of the articles to compare. If newid is 0, then compare
248 # the old article in oldid to the current article; if oldid is 0, then
249 # compare the current article to the immediately previous one (ignoring
250 # the value of newid).
251 #
252 function loadText()
253 {
254 global $wgTitle, $wgOut, $wgLang;
255 $fname = 'DifferenceEngine::loadText';
256
257 $dbr =& wfGetDB( DB_SLAVE );
258 if ( 0 == $this->mNewid || 0 == $this->mOldid ) {
259 $wgOut->setArticleFlag( true );
260 $newLink = $wgTitle->escapeLocalUrl();
261 $this->mPagetitle = htmlspecialchars( wfMsg( 'currentrev' ) );
262 $this->mNewtitle = "<a href='$newLink'>{$this->mPagetitle}</a>";
263 $id = $wgTitle->getArticleID();
264
265 $s = $dbr->selectRow( 'cur', array( 'cur_text', 'cur_user_text', 'cur_comment' ),
266 array( 'cur_id' => $id ), $fname );
267 if ( $s === false ) {
268 wfDebug( "Unable to load cur_id $id\n" );
269 return false;
270 }
271
272 $this->mNewPage = &$wgTitle;
273 $this->mNewtext = $s->cur_text;
274 $this->mNewUser = $s->cur_user_text;
275 $this->mNewComment = $s->cur_comment;
276 } else {
277 $s = $dbr->selectRow( 'old', array( 'old_namespace','old_title','old_timestamp', 'old_text',
278 'old_flags','old_user_text','old_comment' ), array( 'old_id' => $this->mNewid ), $fname );
279
280 if ( $s === false ) {
281 wfDebug( "Unable to load old_id {$this->mNewid}\n" );
282 return false;
283 }
284
285 $this->mNewtext = Article::getRevisionText( $s );
286
287 $t = $wgLang->timeanddate( $s->old_timestamp, true );
288 $this->mNewPage = Title::MakeTitle( $s->old_namespace, $s->old_title );
289 $newLink = $wgTitle->escapeLocalUrl ('oldid=' . $this->mNewid);
290 $this->mPagetitle = htmlspecialchars( wfMsg( 'revisionasof', $t ) );
291 $this->mNewtitle = "<a href='$newLink'>{$this->mPagetitle}</a>";
292 $this->mNewUser = $s->old_user_text;
293 $this->mNewComment = $s->old_comment;
294 }
295 if ( 0 == $this->mOldid ) {
296 $s = $dbr->selectRow( 'old',
297 array( 'old_namespace','old_title','old_timestamp','old_text', 'old_flags','old_user_text','old_comment' ),
298 array( /* WHERE */
299 'old_namespace' => $this->mNewPage->getNamespace(),
300 'old_title' => $this->mNewPage->getDBkey()
301 ), $fname, array( 'ORDER BY' => 'inverse_timestamp', 'USE INDEX' => 'name_title_timestamp' )
302 );
303 if ( $s === false ) {
304 wfDebug( 'Unable to load ' . $this->mNewPage->getPrefixedDBkey() . " from old\n" );
305 return false;
306 }
307 } else {
308 $s = $dbr->selectRow( 'old',
309 array( 'old_namespace','old_title','old_timestamp','old_text','old_flags','old_user_text','old_comment'),
310 array( 'old_id' => $this->mOldid ),
311 $fname
312 );
313 if ( $s === false ) {
314 wfDebug( "Unable to load old_id {$this->mOldid}\n" );
315 return false;
316 }
317 }
318 $this->mOldPage = Title::MakeTitle( $s->old_namespace, $s->old_title );
319 $this->mOldtext = Article::getRevisionText( $s );
320
321 $t = $wgLang->timeanddate( $s->old_timestamp, true );
322 $oldLink = $this->mOldPage->escapeLocalUrl ('oldid=' . $this->mOldid);
323 $this->mOldtitle = "<a href='$oldLink'>" . htmlspecialchars( wfMsg( 'revisionasof', $t ) ) . '</a>';
324 $this->mOldUser = $s->old_user_text;
325 $this->mOldComment = $s->old_comment;
326
327 return true;
328 }
329 }
330
331 // A PHP diff engine for phpwiki. (Taken from phpwiki-1.3.3)
332 //
333 // Copyright (C) 2000, 2001 Geoffrey T. Dairiki <dairiki@dairiki.org>
334 // You may copy this code freely under the conditions of the GPL.
335 //
336
337 define('USE_ASSERTS', function_exists('assert'));
338
339 /**
340 * @todo document
341 * @access private
342 */
343 class _DiffOp {
344 var $type;
345 var $orig;
346 var $closing;
347
348 function reverse() {
349 trigger_error('pure virtual', E_USER_ERROR);
350 }
351
352 function norig() {
353 return $this->orig ? sizeof($this->orig) : 0;
354 }
355
356 function nclosing() {
357 return $this->closing ? sizeof($this->closing) : 0;
358 }
359 }
360
361 /**
362 * @todo document
363 * @access private
364 */
365 class _DiffOp_Copy extends _DiffOp {
366 var $type = 'copy';
367
368 function _DiffOp_Copy ($orig, $closing = false) {
369 if (!is_array($closing))
370 $closing = $orig;
371 $this->orig = $orig;
372 $this->closing = $closing;
373 }
374
375 function reverse() {
376 return new _DiffOp_Copy($this->closing, $this->orig);
377 }
378 }
379
380 /**
381 * @todo document
382 * @access private
383 */
384 class _DiffOp_Delete extends _DiffOp {
385 var $type = 'delete';
386
387 function _DiffOp_Delete ($lines) {
388 $this->orig = $lines;
389 $this->closing = false;
390 }
391
392 function reverse() {
393 return new _DiffOp_Add($this->orig);
394 }
395 }
396
397 /**
398 * @todo document
399 * @access private
400 */
401 class _DiffOp_Add extends _DiffOp {
402 var $type = 'add';
403
404 function _DiffOp_Add ($lines) {
405 $this->closing = $lines;
406 $this->orig = false;
407 }
408
409 function reverse() {
410 return new _DiffOp_Delete($this->closing);
411 }
412 }
413
414 /**
415 * @todo document
416 * @access private
417 */
418 class _DiffOp_Change extends _DiffOp {
419 var $type = 'change';
420
421 function _DiffOp_Change ($orig, $closing) {
422 $this->orig = $orig;
423 $this->closing = $closing;
424 }
425
426 function reverse() {
427 return new _DiffOp_Change($this->closing, $this->orig);
428 }
429 }
430
431
432 /**
433 * Class used internally by Diff to actually compute the diffs.
434 *
435 * The algorithm used here is mostly lifted from the perl module
436 * Algorithm::Diff (version 1.06) by Ned Konz, which is available at:
437 * http://www.perl.com/CPAN/authors/id/N/NE/NEDKONZ/Algorithm-Diff-1.06.zip
438 *
439 * More ideas are taken from:
440 * http://www.ics.uci.edu/~eppstein/161/960229.html
441 *
442 * Some ideas are (and a bit of code) are from from analyze.c, from GNU
443 * diffutils-2.7, which can be found at:
444 * ftp://gnudist.gnu.org/pub/gnu/diffutils/diffutils-2.7.tar.gz
445 *
446 * closingly, some ideas (subdivision by NCHUNKS > 2, and some optimizations)
447 * are my own.
448 *
449 * @author Geoffrey T. Dairiki
450 * @access private
451 */
452 class _DiffEngine
453 {
454 function diff ($from_lines, $to_lines) {
455 $n_from = sizeof($from_lines);
456 $n_to = sizeof($to_lines);
457
458 $this->xchanged = $this->ychanged = array();
459 $this->xv = $this->yv = array();
460 $this->xind = $this->yind = array();
461 unset($this->seq);
462 unset($this->in_seq);
463 unset($this->lcs);
464
465 // Skip leading common lines.
466 for ($skip = 0; $skip < $n_from && $skip < $n_to; $skip++) {
467 if ($from_lines[$skip] != $to_lines[$skip])
468 break;
469 $this->xchanged[$skip] = $this->ychanged[$skip] = false;
470 }
471 // Skip trailing common lines.
472 $xi = $n_from; $yi = $n_to;
473 for ($endskip = 0; --$xi > $skip && --$yi > $skip; $endskip++) {
474 if ($from_lines[$xi] != $to_lines[$yi])
475 break;
476 $this->xchanged[$xi] = $this->ychanged[$yi] = false;
477 }
478
479 // Ignore lines which do not exist in both files.
480 for ($xi = $skip; $xi < $n_from - $endskip; $xi++)
481 $xhash[$from_lines[$xi]] = 1;
482 for ($yi = $skip; $yi < $n_to - $endskip; $yi++) {
483 $line = $to_lines[$yi];
484 if ( ($this->ychanged[$yi] = empty($xhash[$line])) )
485 continue;
486 $yhash[$line] = 1;
487 $this->yv[] = $line;
488 $this->yind[] = $yi;
489 }
490 for ($xi = $skip; $xi < $n_from - $endskip; $xi++) {
491 $line = $from_lines[$xi];
492 if ( ($this->xchanged[$xi] = empty($yhash[$line])) )
493 continue;
494 $this->xv[] = $line;
495 $this->xind[] = $xi;
496 }
497
498 // Find the LCS.
499 $this->_compareseq(0, sizeof($this->xv), 0, sizeof($this->yv));
500
501 // Merge edits when possible
502 $this->_shift_boundaries($from_lines, $this->xchanged, $this->ychanged);
503 $this->_shift_boundaries($to_lines, $this->ychanged, $this->xchanged);
504
505 // Compute the edit operations.
506 $edits = array();
507 $xi = $yi = 0;
508 while ($xi < $n_from || $yi < $n_to) {
509 USE_ASSERTS && assert($yi < $n_to || $this->xchanged[$xi]);
510 USE_ASSERTS && assert($xi < $n_from || $this->ychanged[$yi]);
511
512 // Skip matching "snake".
513 $copy = array();
514 while ( $xi < $n_from && $yi < $n_to
515 && !$this->xchanged[$xi] && !$this->ychanged[$yi]) {
516 $copy[] = $from_lines[$xi++];
517 ++$yi;
518 }
519 if ($copy)
520 $edits[] = new _DiffOp_Copy($copy);
521
522 // Find deletes & adds.
523 $delete = array();
524 while ($xi < $n_from && $this->xchanged[$xi])
525 $delete[] = $from_lines[$xi++];
526
527 $add = array();
528 while ($yi < $n_to && $this->ychanged[$yi])
529 $add[] = $to_lines[$yi++];
530
531 if ($delete && $add)
532 $edits[] = new _DiffOp_Change($delete, $add);
533 elseif ($delete)
534 $edits[] = new _DiffOp_Delete($delete);
535 elseif ($add)
536 $edits[] = new _DiffOp_Add($add);
537 }
538 return $edits;
539 }
540
541
542 /* Divide the Largest Common Subsequence (LCS) of the sequences
543 * [XOFF, XLIM) and [YOFF, YLIM) into NCHUNKS approximately equally
544 * sized segments.
545 *
546 * Returns (LCS, PTS). LCS is the length of the LCS. PTS is an
547 * array of NCHUNKS+1 (X, Y) indexes giving the diving points between
548 * sub sequences. The first sub-sequence is contained in [X0, X1),
549 * [Y0, Y1), the second in [X1, X2), [Y1, Y2) and so on. Note
550 * that (X0, Y0) == (XOFF, YOFF) and
551 * (X[NCHUNKS], Y[NCHUNKS]) == (XLIM, YLIM).
552 *
553 * This function assumes that the first lines of the specified portions
554 * of the two files do not match, and likewise that the last lines do not
555 * match. The caller must trim matching lines from the beginning and end
556 * of the portions it is going to specify.
557 */
558 function _diag ($xoff, $xlim, $yoff, $ylim, $nchunks) {
559 $flip = false;
560
561 if ($xlim - $xoff > $ylim - $yoff) {
562 // Things seems faster (I'm not sure I understand why)
563 // when the shortest sequence in X.
564 $flip = true;
565 list ($xoff, $xlim, $yoff, $ylim)
566 = array( $yoff, $ylim, $xoff, $xlim);
567 }
568
569 if ($flip)
570 for ($i = $ylim - 1; $i >= $yoff; $i--)
571 $ymatches[$this->xv[$i]][] = $i;
572 else
573 for ($i = $ylim - 1; $i >= $yoff; $i--)
574 $ymatches[$this->yv[$i]][] = $i;
575
576 $this->lcs = 0;
577 $this->seq[0]= $yoff - 1;
578 $this->in_seq = array();
579 $ymids[0] = array();
580
581 $numer = $xlim - $xoff + $nchunks - 1;
582 $x = $xoff;
583 for ($chunk = 0; $chunk < $nchunks; $chunk++) {
584 if ($chunk > 0)
585 for ($i = 0; $i <= $this->lcs; $i++)
586 $ymids[$i][$chunk-1] = $this->seq[$i];
587
588 $x1 = $xoff + (int)(($numer + ($xlim-$xoff)*$chunk) / $nchunks);
589 for ( ; $x < $x1; $x++) {
590 $line = $flip ? $this->yv[$x] : $this->xv[$x];
591 if (empty($ymatches[$line]))
592 continue;
593 $matches = $ymatches[$line];
594 reset($matches);
595 while (list ($junk, $y) = each($matches))
596 if (empty($this->in_seq[$y])) {
597 $k = $this->_lcs_pos($y);
598 USE_ASSERTS && assert($k > 0);
599 $ymids[$k] = $ymids[$k-1];
600 break;
601 }
602 while (list ($junk, $y) = each($matches)) {
603 if ($y > $this->seq[$k-1]) {
604 USE_ASSERTS && assert($y < $this->seq[$k]);
605 // Optimization: this is a common case:
606 // next match is just replacing previous match.
607 $this->in_seq[$this->seq[$k]] = false;
608 $this->seq[$k] = $y;
609 $this->in_seq[$y] = 1;
610 }
611 else if (empty($this->in_seq[$y])) {
612 $k = $this->_lcs_pos($y);
613 USE_ASSERTS && assert($k > 0);
614 $ymids[$k] = $ymids[$k-1];
615 }
616 }
617 }
618 }
619
620 $seps[] = $flip ? array($yoff, $xoff) : array($xoff, $yoff);
621 $ymid = $ymids[$this->lcs];
622 for ($n = 0; $n < $nchunks - 1; $n++) {
623 $x1 = $xoff + (int)(($numer + ($xlim - $xoff) * $n) / $nchunks);
624 $y1 = $ymid[$n] + 1;
625 $seps[] = $flip ? array($y1, $x1) : array($x1, $y1);
626 }
627 $seps[] = $flip ? array($ylim, $xlim) : array($xlim, $ylim);
628
629 return array($this->lcs, $seps);
630 }
631
632 function _lcs_pos ($ypos) {
633 $end = $this->lcs;
634 if ($end == 0 || $ypos > $this->seq[$end]) {
635 $this->seq[++$this->lcs] = $ypos;
636 $this->in_seq[$ypos] = 1;
637 return $this->lcs;
638 }
639
640 $beg = 1;
641 while ($beg < $end) {
642 $mid = (int)(($beg + $end) / 2);
643 if ( $ypos > $this->seq[$mid] )
644 $beg = $mid + 1;
645 else
646 $end = $mid;
647 }
648
649 USE_ASSERTS && assert($ypos != $this->seq[$end]);
650
651 $this->in_seq[$this->seq[$end]] = false;
652 $this->seq[$end] = $ypos;
653 $this->in_seq[$ypos] = 1;
654 return $end;
655 }
656
657 /* Find LCS of two sequences.
658 *
659 * The results are recorded in the vectors $this->{x,y}changed[], by
660 * storing a 1 in the element for each line that is an insertion
661 * or deletion (ie. is not in the LCS).
662 *
663 * The subsequence of file 0 is [XOFF, XLIM) and likewise for file 1.
664 *
665 * Note that XLIM, YLIM are exclusive bounds.
666 * All line numbers are origin-0 and discarded lines are not counted.
667 */
668 function _compareseq ($xoff, $xlim, $yoff, $ylim) {
669 // Slide down the bottom initial diagonal.
670 while ($xoff < $xlim && $yoff < $ylim
671 && $this->xv[$xoff] == $this->yv[$yoff]) {
672 ++$xoff;
673 ++$yoff;
674 }
675
676 // Slide up the top initial diagonal.
677 while ($xlim > $xoff && $ylim > $yoff
678 && $this->xv[$xlim - 1] == $this->yv[$ylim - 1]) {
679 --$xlim;
680 --$ylim;
681 }
682
683 if ($xoff == $xlim || $yoff == $ylim)
684 $lcs = 0;
685 else {
686 // This is ad hoc but seems to work well.
687 //$nchunks = sqrt(min($xlim - $xoff, $ylim - $yoff) / 2.5);
688 //$nchunks = max(2,min(8,(int)$nchunks));
689 $nchunks = min(7, $xlim - $xoff, $ylim - $yoff) + 1;
690 list ($lcs, $seps)
691 = $this->_diag($xoff,$xlim,$yoff, $ylim,$nchunks);
692 }
693
694 if ($lcs == 0) {
695 // X and Y sequences have no common subsequence:
696 // mark all changed.
697 while ($yoff < $ylim)
698 $this->ychanged[$this->yind[$yoff++]] = 1;
699 while ($xoff < $xlim)
700 $this->xchanged[$this->xind[$xoff++]] = 1;
701 }
702 else {
703 // Use the partitions to split this problem into subproblems.
704 reset($seps);
705 $pt1 = $seps[0];
706 while ($pt2 = next($seps)) {
707 $this->_compareseq ($pt1[0], $pt2[0], $pt1[1], $pt2[1]);
708 $pt1 = $pt2;
709 }
710 }
711 }
712
713 /* Adjust inserts/deletes of identical lines to join changes
714 * as much as possible.
715 *
716 * We do something when a run of changed lines include a
717 * line at one end and has an excluded, identical line at the other.
718 * We are free to choose which identical line is included.
719 * `compareseq' usually chooses the one at the beginning,
720 * but usually it is cleaner to consider the following identical line
721 * to be the "change".
722 *
723 * This is extracted verbatim from analyze.c (GNU diffutils-2.7).
724 */
725 function _shift_boundaries ($lines, &$changed, $other_changed) {
726 $i = 0;
727 $j = 0;
728
729 USE_ASSERTS && assert('sizeof($lines) == sizeof($changed)');
730 $len = sizeof($lines);
731 $other_len = sizeof($other_changed);
732
733 while (1) {
734 /*
735 * Scan forwards to find beginning of another run of changes.
736 * Also keep track of the corresponding point in the other file.
737 *
738 * Throughout this code, $i and $j are adjusted together so that
739 * the first $i elements of $changed and the first $j elements
740 * of $other_changed both contain the same number of zeros
741 * (unchanged lines).
742 * Furthermore, $j is always kept so that $j == $other_len or
743 * $other_changed[$j] == false.
744 */
745 while ($j < $other_len && $other_changed[$j])
746 $j++;
747
748 while ($i < $len && ! $changed[$i]) {
749 USE_ASSERTS && assert('$j < $other_len && ! $other_changed[$j]');
750 $i++; $j++;
751 while ($j < $other_len && $other_changed[$j])
752 $j++;
753 }
754
755 if ($i == $len)
756 break;
757
758 $start = $i;
759
760 // Find the end of this run of changes.
761 while (++$i < $len && $changed[$i])
762 continue;
763
764 do {
765 /*
766 * Record the length of this run of changes, so that
767 * we can later determine whether the run has grown.
768 */
769 $runlength = $i - $start;
770
771 /*
772 * Move the changed region back, so long as the
773 * previous unchanged line matches the last changed one.
774 * This merges with previous changed regions.
775 */
776 while ($start > 0 && $lines[$start - 1] == $lines[$i - 1]) {
777 $changed[--$start] = 1;
778 $changed[--$i] = false;
779 while ($start > 0 && $changed[$start - 1])
780 $start--;
781 USE_ASSERTS && assert('$j > 0');
782 while ($other_changed[--$j])
783 continue;
784 USE_ASSERTS && assert('$j >= 0 && !$other_changed[$j]');
785 }
786
787 /*
788 * Set CORRESPONDING to the end of the changed run, at the last
789 * point where it corresponds to a changed run in the other file.
790 * CORRESPONDING == LEN means no such point has been found.
791 */
792 $corresponding = $j < $other_len ? $i : $len;
793
794 /*
795 * Move the changed region forward, so long as the
796 * first changed line matches the following unchanged one.
797 * This merges with following changed regions.
798 * Do this second, so that if there are no merges,
799 * the changed region is moved forward as far as possible.
800 */
801 while ($i < $len && $lines[$start] == $lines[$i]) {
802 $changed[$start++] = false;
803 $changed[$i++] = 1;
804 while ($i < $len && $changed[$i])
805 $i++;
806
807 USE_ASSERTS && assert('$j < $other_len && ! $other_changed[$j]');
808 $j++;
809 if ($j < $other_len && $other_changed[$j]) {
810 $corresponding = $i;
811 while ($j < $other_len && $other_changed[$j])
812 $j++;
813 }
814 }
815 } while ($runlength != $i - $start);
816
817 /*
818 * If possible, move the fully-merged run of changes
819 * back to a corresponding run in the other file.
820 */
821 while ($corresponding < $i) {
822 $changed[--$start] = 1;
823 $changed[--$i] = 0;
824 USE_ASSERTS && assert('$j > 0');
825 while ($other_changed[--$j])
826 continue;
827 USE_ASSERTS && assert('$j >= 0 && !$other_changed[$j]');
828 }
829 }
830 }
831 }
832
833 /**
834 * Class representing a 'diff' between two sequences of strings.
835 * @todo document
836 * @access private
837 */
838 class Diff
839 {
840 var $edits;
841
842 /**
843 * Constructor.
844 * Computes diff between sequences of strings.
845 *
846 * @param $from_lines array An array of strings.
847 * (Typically these are lines from a file.)
848 * @param $to_lines array An array of strings.
849 */
850 function Diff($from_lines, $to_lines) {
851 $eng = new _DiffEngine;
852 $this->edits = $eng->diff($from_lines, $to_lines);
853 //$this->_check($from_lines, $to_lines);
854 }
855
856 /**
857 * Compute reversed Diff.
858 *
859 * SYNOPSIS:
860 *
861 * $diff = new Diff($lines1, $lines2);
862 * $rev = $diff->reverse();
863 * @return object A Diff object representing the inverse of the
864 * original diff.
865 */
866 function reverse () {
867 $rev = $this;
868 $rev->edits = array();
869 foreach ($this->edits as $edit) {
870 $rev->edits[] = $edit->reverse();
871 }
872 return $rev;
873 }
874
875 /**
876 * Check for empty diff.
877 *
878 * @return bool True iff two sequences were identical.
879 */
880 function isEmpty () {
881 foreach ($this->edits as $edit) {
882 if ($edit->type != 'copy')
883 return false;
884 }
885 return true;
886 }
887
888 /**
889 * Compute the length of the Longest Common Subsequence (LCS).
890 *
891 * This is mostly for diagnostic purposed.
892 *
893 * @return int The length of the LCS.
894 */
895 function lcs () {
896 $lcs = 0;
897 foreach ($this->edits as $edit) {
898 if ($edit->type == 'copy')
899 $lcs += sizeof($edit->orig);
900 }
901 return $lcs;
902 }
903
904 /**
905 * Get the original set of lines.
906 *
907 * This reconstructs the $from_lines parameter passed to the
908 * constructor.
909 *
910 * @return array The original sequence of strings.
911 */
912 function orig() {
913 $lines = array();
914
915 foreach ($this->edits as $edit) {
916 if ($edit->orig)
917 array_splice($lines, sizeof($lines), 0, $edit->orig);
918 }
919 return $lines;
920 }
921
922 /**
923 * Get the closing set of lines.
924 *
925 * This reconstructs the $to_lines parameter passed to the
926 * constructor.
927 *
928 * @return array The sequence of strings.
929 */
930 function closing() {
931 $lines = array();
932
933 foreach ($this->edits as $edit) {
934 if ($edit->closing)
935 array_splice($lines, sizeof($lines), 0, $edit->closing);
936 }
937 return $lines;
938 }
939
940 /**
941 * Check a Diff for validity.
942 *
943 * This is here only for debugging purposes.
944 */
945 function _check ($from_lines, $to_lines) {
946 if (serialize($from_lines) != serialize($this->orig()))
947 trigger_error("Reconstructed original doesn't match", E_USER_ERROR);
948 if (serialize($to_lines) != serialize($this->closing()))
949 trigger_error("Reconstructed closing doesn't match", E_USER_ERROR);
950
951 $rev = $this->reverse();
952 if (serialize($to_lines) != serialize($rev->orig()))
953 trigger_error("Reversed original doesn't match", E_USER_ERROR);
954 if (serialize($from_lines) != serialize($rev->closing()))
955 trigger_error("Reversed closing doesn't match", E_USER_ERROR);
956
957
958 $prevtype = 'none';
959 foreach ($this->edits as $edit) {
960 if ( $prevtype == $edit->type )
961 trigger_error("Edit sequence is non-optimal", E_USER_ERROR);
962 $prevtype = $edit->type;
963 }
964
965 $lcs = $this->lcs();
966 trigger_error('Diff okay: LCS = '.$lcs, E_USER_NOTICE);
967 }
968 }
969
970 /**
971 * FIXME: bad name.
972 * @todo document
973 * @access private
974 */
975 class MappedDiff extends Diff
976 {
977 /**
978 * Constructor.
979 *
980 * Computes diff between sequences of strings.
981 *
982 * This can be used to compute things like
983 * case-insensitve diffs, or diffs which ignore
984 * changes in white-space.
985 *
986 * @param $from_lines array An array of strings.
987 * (Typically these are lines from a file.)
988 *
989 * @param $to_lines array An array of strings.
990 *
991 * @param $mapped_from_lines array This array should
992 * have the same size number of elements as $from_lines.
993 * The elements in $mapped_from_lines and
994 * $mapped_to_lines are what is actually compared
995 * when computing the diff.
996 *
997 * @param $mapped_to_lines array This array should
998 * have the same number of elements as $to_lines.
999 */
1000 function MappedDiff($from_lines, $to_lines,
1001 $mapped_from_lines, $mapped_to_lines) {
1002
1003 assert(sizeof($from_lines) == sizeof($mapped_from_lines));
1004 assert(sizeof($to_lines) == sizeof($mapped_to_lines));
1005
1006 $this->Diff($mapped_from_lines, $mapped_to_lines);
1007
1008 $xi = $yi = 0;
1009 for ($i = 0; $i < sizeof($this->edits); $i++) {
1010 $orig = &$this->edits[$i]->orig;
1011 if (is_array($orig)) {
1012 $orig = array_slice($from_lines, $xi, sizeof($orig));
1013 $xi += sizeof($orig);
1014 }
1015
1016 $closing = &$this->edits[$i]->closing;
1017 if (is_array($closing)) {
1018 $closing = array_slice($to_lines, $yi, sizeof($closing));
1019 $yi += sizeof($closing);
1020 }
1021 }
1022 }
1023 }
1024
1025 /**
1026 * A class to format Diffs
1027 *
1028 * This class formats the diff in classic diff format.
1029 * It is intended that this class be customized via inheritance,
1030 * to obtain fancier outputs.
1031 * @todo document
1032 * @access private
1033 */
1034 class DiffFormatter
1035 {
1036 /**
1037 * Number of leading context "lines" to preserve.
1038 *
1039 * This should be left at zero for this class, but subclasses
1040 * may want to set this to other values.
1041 */
1042 var $leading_context_lines = 0;
1043
1044 /**
1045 * Number of trailing context "lines" to preserve.
1046 *
1047 * This should be left at zero for this class, but subclasses
1048 * may want to set this to other values.
1049 */
1050 var $trailing_context_lines = 0;
1051
1052 /**
1053 * Format a diff.
1054 *
1055 * @param $diff object A Diff object.
1056 * @return string The formatted output.
1057 */
1058 function format($diff) {
1059
1060 $xi = $yi = 1;
1061 $block = false;
1062 $context = array();
1063
1064 $nlead = $this->leading_context_lines;
1065 $ntrail = $this->trailing_context_lines;
1066
1067 $this->_start_diff();
1068
1069 foreach ($diff->edits as $edit) {
1070 if ($edit->type == 'copy') {
1071 if (is_array($block)) {
1072 if (sizeof($edit->orig) <= $nlead + $ntrail) {
1073 $block[] = $edit;
1074 }
1075 else{
1076 if ($ntrail) {
1077 $context = array_slice($edit->orig, 0, $ntrail);
1078 $block[] = new _DiffOp_Copy($context);
1079 }
1080 $this->_block($x0, $ntrail + $xi - $x0,
1081 $y0, $ntrail + $yi - $y0,
1082 $block);
1083 $block = false;
1084 }
1085 }
1086 $context = $edit->orig;
1087 }
1088 else {
1089 if (! is_array($block)) {
1090 $context = array_slice($context, sizeof($context) - $nlead);
1091 $x0 = $xi - sizeof($context);
1092 $y0 = $yi - sizeof($context);
1093 $block = array();
1094 if ($context)
1095 $block[] = new _DiffOp_Copy($context);
1096 }
1097 $block[] = $edit;
1098 }
1099
1100 if ($edit->orig)
1101 $xi += sizeof($edit->orig);
1102 if ($edit->closing)
1103 $yi += sizeof($edit->closing);
1104 }
1105
1106 if (is_array($block))
1107 $this->_block($x0, $xi - $x0,
1108 $y0, $yi - $y0,
1109 $block);
1110
1111 return $this->_end_diff();
1112 }
1113
1114 function _block($xbeg, $xlen, $ybeg, $ylen, &$edits) {
1115 $this->_start_block($this->_block_header($xbeg, $xlen, $ybeg, $ylen));
1116 foreach ($edits as $edit) {
1117 if ($edit->type == 'copy')
1118 $this->_context($edit->orig);
1119 elseif ($edit->type == 'add')
1120 $this->_added($edit->closing);
1121 elseif ($edit->type == 'delete')
1122 $this->_deleted($edit->orig);
1123 elseif ($edit->type == 'change')
1124 $this->_changed($edit->orig, $edit->closing);
1125 else
1126 trigger_error('Unknown edit type', E_USER_ERROR);
1127 }
1128 $this->_end_block();
1129 }
1130
1131 function _start_diff() {
1132 ob_start();
1133 }
1134
1135 function _end_diff() {
1136 $val = ob_get_contents();
1137 ob_end_clean();
1138 return $val;
1139 }
1140
1141 function _block_header($xbeg, $xlen, $ybeg, $ylen) {
1142 if ($xlen > 1)
1143 $xbeg .= "," . ($xbeg + $xlen - 1);
1144 if ($ylen > 1)
1145 $ybeg .= "," . ($ybeg + $ylen - 1);
1146
1147 return $xbeg . ($xlen ? ($ylen ? 'c' : 'd') : 'a') . $ybeg;
1148 }
1149
1150 function _start_block($header) {
1151 echo $header;
1152 }
1153
1154 function _end_block() {
1155 }
1156
1157 function _lines($lines, $prefix = ' ') {
1158 foreach ($lines as $line)
1159 echo "$prefix $line\n";
1160 }
1161
1162 function _context($lines) {
1163 $this->_lines($lines);
1164 }
1165
1166 function _added($lines) {
1167 $this->_lines($lines, '>');
1168 }
1169 function _deleted($lines) {
1170 $this->_lines($lines, '<');
1171 }
1172
1173 function _changed($orig, $closing) {
1174 $this->_deleted($orig);
1175 echo "---\n";
1176 $this->_added($closing);
1177 }
1178 }
1179
1180
1181 /**
1182 * Additions by Axel Boldt follow, partly taken from diff.php, phpwiki-1.3.3
1183 *
1184 */
1185
1186 define('NBSP', '&#160;'); // iso-8859-x non-breaking space.
1187
1188 /**
1189 * @todo document
1190 * @access private
1191 */
1192 class _HWLDF_WordAccumulator {
1193 function _HWLDF_WordAccumulator () {
1194 $this->_lines = array();
1195 $this->_line = '';
1196 $this->_group = '';
1197 $this->_tag = '';
1198 }
1199
1200 function _flushGroup ($new_tag) {
1201 if ($this->_group !== '') {
1202 if ($this->_tag == 'mark')
1203 $this->_line .= '<span class="diffchange">' .
1204 htmlspecialchars ( $this->_group ) . '</span>';
1205 else
1206 $this->_line .= htmlspecialchars ( $this->_group );
1207 }
1208 $this->_group = '';
1209 $this->_tag = $new_tag;
1210 }
1211
1212 function _flushLine ($new_tag) {
1213 $this->_flushGroup($new_tag);
1214 if ($this->_line != '')
1215 array_push ( $this->_lines, $this->_line );
1216 else
1217 # make empty lines visible by inserting an NBSP
1218 array_push ( $this->_lines, NBSP );
1219 $this->_line = '';
1220 }
1221
1222 function addWords ($words, $tag = '') {
1223 if ($tag != $this->_tag)
1224 $this->_flushGroup($tag);
1225
1226 foreach ($words as $word) {
1227 // new-line should only come as first char of word.
1228 if ($word == '')
1229 continue;
1230 if ($word[0] == "\n") {
1231 $this->_flushLine($tag);
1232 $word = substr($word, 1);
1233 }
1234 assert(!strstr($word, "\n"));
1235 $this->_group .= $word;
1236 }
1237 }
1238
1239 function getLines() {
1240 $this->_flushLine('~done');
1241 return $this->_lines;
1242 }
1243 }
1244
1245 /**
1246 * @todo document
1247 * @access private
1248 */
1249 class WordLevelDiff extends MappedDiff
1250 {
1251 function WordLevelDiff ($orig_lines, $closing_lines) {
1252 list ($orig_words, $orig_stripped) = $this->_split($orig_lines);
1253 list ($closing_words, $closing_stripped) = $this->_split($closing_lines);
1254
1255
1256 $this->MappedDiff($orig_words, $closing_words,
1257 $orig_stripped, $closing_stripped);
1258 }
1259
1260 function _split($lines) {
1261 if (!preg_match_all('/ ( [^\S\n]+ | [0-9_A-Za-z\x80-\xff]+ | . ) (?: (?!< \n) [^\S\n])? /xs',
1262 implode("\n", $lines),
1263 $m)) {
1264 return array(array(''), array(''));
1265 }
1266 return array($m[0], $m[1]);
1267 }
1268
1269 function orig () {
1270 $orig = new _HWLDF_WordAccumulator;
1271
1272 foreach ($this->edits as $edit) {
1273 if ($edit->type == 'copy')
1274 $orig->addWords($edit->orig);
1275 elseif ($edit->orig)
1276 $orig->addWords($edit->orig, 'mark');
1277 }
1278 return $orig->getLines();
1279 }
1280
1281 function closing () {
1282 $closing = new _HWLDF_WordAccumulator;
1283
1284 foreach ($this->edits as $edit) {
1285 if ($edit->type == 'copy')
1286 $closing->addWords($edit->closing);
1287 elseif ($edit->closing)
1288 $closing->addWords($edit->closing, 'mark');
1289 }
1290 return $closing->getLines();
1291 }
1292 }
1293
1294 /**
1295 * Wikipedia Table style diff formatter.
1296 * @todo document
1297 * @access private
1298 */
1299 class TableDiffFormatter extends DiffFormatter
1300 {
1301 function TableDiffFormatter() {
1302 $this->leading_context_lines = 2;
1303 $this->trailing_context_lines = 2;
1304 }
1305
1306 function _block_header( $xbeg, $xlen, $ybeg, $ylen ) {
1307 $l1 = wfMsg( 'lineno', $xbeg );
1308 $l2 = wfMsg( 'lineno', $ybeg );
1309
1310 $r = '<tr><td colspan="2" align="left"><strong>'.$l1."</strong></td>\n" .
1311 '<td colspan="2" align="left"><strong>'.$l2."</strong></td></tr>\n";
1312 return $r;
1313 }
1314
1315 function _start_block( $header ) {
1316 global $wgOut;
1317 echo $header;
1318 }
1319
1320 function _end_block() {
1321 }
1322
1323 function _lines( $lines, $prefix=' ', $color='white' ) {
1324 }
1325
1326 # HTML-escape parameter before calling this
1327 function addedLine( $line ) {
1328 return "<td>+</td><td class='diff-addedline'>{$line}</td>";
1329 }
1330
1331 # HTML-escape parameter before calling this
1332 function deletedLine( $line ) {
1333 return "<td>-</td><td class='diff-deletedline'>{$line}</td>";
1334 }
1335
1336 # HTML-escape parameter before calling this
1337 function contextLine( $line ) {
1338 return "<td> </td><td class='diff-context'>{$line}</td>";
1339 }
1340
1341 function emptyLine() {
1342 return '<td colspan="2">&nbsp;</td>';
1343 }
1344
1345 function _added( $lines ) {
1346 foreach ($lines as $line) {
1347 echo '<tr>' . $this->emptyLine() .
1348 $this->addedLine( htmlspecialchars ( $line ) ) . "</tr>\n";
1349 }
1350 }
1351
1352 function _deleted($lines) {
1353 foreach ($lines as $line) {
1354 echo '<tr>' . $this->deletedLine( htmlspecialchars ( $line ) ) .
1355 $this->emptyLine() . "</tr>\n";
1356 }
1357 }
1358
1359 function _context( $lines ) {
1360 foreach ($lines as $line) {
1361 echo '<tr>' .
1362 $this->contextLine( htmlspecialchars ( $line ) ) .
1363 $this->contextLine( htmlspecialchars ( $line ) ) . "</tr>\n";
1364 }
1365 }
1366
1367 function _changed( $orig, $closing ) {
1368 $diff = new WordLevelDiff( $orig, $closing );
1369 $del = $diff->orig();
1370 $add = $diff->closing();
1371
1372 # Notice that WordLevelDiff returns HTML-escaped output.
1373 # Hence, we will be calling addedLine/deletedLine without HTML-escaping.
1374
1375 while ( $line = array_shift( $del ) ) {
1376 $aline = array_shift( $add );
1377 echo '<tr>' . $this->deletedLine( $line ) .
1378 $this->addedLine( $aline ) . "</tr>\n";
1379 }
1380 foreach ($add as $line) { # If any leftovers
1381 echo '<tr>' . $this->emptyLine() .
1382 $this->addedLine( $line ) . "</tr>\n";
1383 }
1384 }
1385 }
1386
1387 ?>