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