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