Index: trunk/phase3/includes/diff/DairikiDiff.php |
— | — | @@ -41,9 +41,10 @@ |
42 | 42 | class _DiffOp_Copy extends _DiffOp { |
43 | 43 | var $type = 'copy'; |
44 | 44 | |
45 | | - function __construct ( $orig, $closing = false ) { |
46 | | - if ( !is_array( $closing ) ) |
47 | | - $closing = $orig; |
| 45 | + function __construct( $orig, $closing = false ) { |
| 46 | + if ( !is_array( $closing ) ) { |
| 47 | + $closing = $orig; |
| 48 | + } |
48 | 49 | $this->orig = $orig; |
49 | 50 | $this->closing = $closing; |
50 | 51 | } |
— | — | @@ -61,7 +62,7 @@ |
62 | 63 | class _DiffOp_Delete extends _DiffOp { |
63 | 64 | var $type = 'delete'; |
64 | 65 | |
65 | | - function __construct ( $lines ) { |
| 66 | + function __construct( $lines ) { |
66 | 67 | $this->orig = $lines; |
67 | 68 | $this->closing = false; |
68 | 69 | } |
— | — | @@ -79,7 +80,7 @@ |
80 | 81 | class _DiffOp_Add extends _DiffOp { |
81 | 82 | var $type = 'add'; |
82 | 83 | |
83 | | - function __construct ( $lines ) { |
| 84 | + function __construct( $lines ) { |
84 | 85 | $this->closing = $lines; |
85 | 86 | $this->orig = false; |
86 | 87 | } |
— | — | @@ -97,7 +98,7 @@ |
98 | 99 | class _DiffOp_Change extends _DiffOp { |
99 | 100 | var $type = 'change'; |
100 | 101 | |
101 | | - function __construct ( $orig, $closing ) { |
| 102 | + function __construct( $orig, $closing ) { |
102 | 103 | $this->orig = $orig; |
103 | 104 | $this->closing = $closing; |
104 | 105 | } |
— | — | @@ -222,15 +223,17 @@ |
223 | 224 | |
224 | 225 | // Skip leading common lines. |
225 | 226 | for ( $skip = 0; $skip < $n_from && $skip < $n_to; $skip++ ) { |
226 | | - if ( $from_lines[$skip] !== $to_lines[$skip] ) |
227 | | - break; |
| 227 | + if ( $from_lines[$skip] !== $to_lines[$skip] ) { |
| 228 | + break; |
| 229 | + } |
228 | 230 | $this->xchanged[$skip] = $this->ychanged[$skip] = false; |
229 | 231 | } |
230 | 232 | // Skip trailing common lines. |
231 | 233 | $xi = $n_from; $yi = $n_to; |
232 | 234 | for ( $endskip = 0; --$xi > $skip && --$yi > $skip; $endskip++ ) { |
233 | | - if ( $from_lines[$xi] !== $to_lines[$yi] ) |
234 | | - break; |
| 235 | + if ( $from_lines[$xi] !== $to_lines[$yi] ) { |
| 236 | + break; |
| 237 | + } |
235 | 238 | $this->xchanged[$xi] = $this->ychanged[$yi] = false; |
236 | 239 | } |
237 | 240 | |
— | — | @@ -241,16 +244,18 @@ |
242 | 245 | |
243 | 246 | for ( $yi = $skip; $yi < $n_to - $endskip; $yi++ ) { |
244 | 247 | $line = $to_lines[$yi]; |
245 | | - if ( ( $this->ychanged[$yi] = empty( $xhash[$this->_line_hash( $line )] ) ) ) |
246 | | - continue; |
| 248 | + if ( ( $this->ychanged[$yi] = empty( $xhash[$this->_line_hash( $line )] ) ) ) { |
| 249 | + continue; |
| 250 | + } |
247 | 251 | $yhash[$this->_line_hash( $line )] = 1; |
248 | 252 | $this->yv[] = $line; |
249 | 253 | $this->yind[] = $yi; |
250 | 254 | } |
251 | 255 | for ( $xi = $skip; $xi < $n_from - $endskip; $xi++ ) { |
252 | 256 | $line = $from_lines[$xi]; |
253 | | - if ( ( $this->xchanged[$xi] = empty( $yhash[$this->_line_hash( $line )] ) ) ) |
254 | | - continue; |
| 257 | + if ( ( $this->xchanged[$xi] = empty( $yhash[$this->_line_hash( $line )] ) ) ) { |
| 258 | + continue; |
| 259 | + } |
255 | 260 | $this->xv[] = $line; |
256 | 261 | $this->xind[] = $xi; |
257 | 262 | } |
— | — | @@ -272,7 +277,8 @@ |
273 | 278 | } |
274 | 279 | } |
275 | 280 | |
276 | | - /* Divide the Largest Common Subsequence (LCS) of the sequences |
| 281 | + /** |
| 282 | + * Divide the Largest Common Subsequence (LCS) of the sequences |
277 | 283 | * [XOFF, XLIM) and [YOFF, YLIM) into NCHUNKS approximately equally |
278 | 284 | * sized segments. |
279 | 285 | * |
— | — | @@ -288,14 +294,14 @@ |
289 | 295 | * match. The caller must trim matching lines from the beginning and end |
290 | 296 | * of the portions it is going to specify. |
291 | 297 | */ |
292 | | - function _diag ( $xoff, $xlim, $yoff, $ylim, $nchunks ) { |
| 298 | + function _diag( $xoff, $xlim, $yoff, $ylim, $nchunks ) { |
293 | 299 | $flip = false; |
294 | 300 | |
295 | 301 | if ( $xlim - $xoff > $ylim - $yoff ) { |
296 | 302 | // Things seems faster (I'm not sure I understand why) |
297 | 303 | // when the shortest sequence in X. |
298 | 304 | $flip = true; |
299 | | - list ( $xoff, $xlim, $yoff, $ylim ) = array( $yoff, $ylim, $xoff, $xlim ); |
| 305 | + list( $xoff, $xlim, $yoff, $ylim ) = array( $yoff, $ylim, $xoff, $xlim ); |
300 | 306 | } |
301 | 307 | |
302 | 308 | if ( $flip ) { |
— | — | @@ -367,7 +373,7 @@ |
368 | 374 | return array( $this->lcs, $seps ); |
369 | 375 | } |
370 | 376 | |
371 | | - function _lcs_pos ( $ypos ) { |
| 377 | + function _lcs_pos( $ypos ) { |
372 | 378 | $end = $this->lcs; |
373 | 379 | if ( $end == 0 || $ypos > $this->seq[$end] ) { |
374 | 380 | $this->seq[++$this->lcs] = $ypos; |
— | — | @@ -378,10 +384,11 @@ |
379 | 385 | $beg = 1; |
380 | 386 | while ( $beg < $end ) { |
381 | 387 | $mid = (int)( ( $beg + $end ) / 2 ); |
382 | | - if ( $ypos > $this->seq[$mid] ) |
383 | | - $beg = $mid + 1; |
384 | | - else |
385 | | - $end = $mid; |
| 388 | + if ( $ypos > $this->seq[$mid] ) { |
| 389 | + $beg = $mid + 1; |
| 390 | + } else { |
| 391 | + $end = $mid; |
| 392 | + } |
386 | 393 | } |
387 | 394 | |
388 | 395 | assert( $ypos != $this->seq[$end] ); |
— | — | @@ -392,7 +399,8 @@ |
393 | 400 | return $end; |
394 | 401 | } |
395 | 402 | |
396 | | - /* Find LCS of two sequences. |
| 403 | + /** |
| 404 | + * Find LCS of two sequences. |
397 | 405 | * |
398 | 406 | * The results are recorded in the vectors $this->{x,y}changed[], by |
399 | 407 | * storing a 1 in the element for each line that is an insertion |
— | — | @@ -449,7 +457,8 @@ |
450 | 458 | } |
451 | 459 | } |
452 | 460 | |
453 | | - /* Adjust inserts/deletes of identical lines to join changes |
| 461 | + /** |
| 462 | + * Adjust inserts/deletes of identical lines to join changes |
454 | 463 | * as much as possible. |
455 | 464 | * |
456 | 465 | * We do something when a run of changed lines include a |
— | — | @@ -461,7 +470,7 @@ |
462 | 471 | * |
463 | 472 | * This is extracted verbatim from analyze.c (GNU diffutils-2.7). |
464 | 473 | */ |
465 | | - function _shift_boundaries ( $lines, &$changed, $other_changed ) { |
| 474 | + function _shift_boundaries( $lines, &$changed, $other_changed ) { |
466 | 475 | wfProfileIn( __METHOD__ ); |
467 | 476 | $i = 0; |
468 | 477 | $j = 0; |
— | — | @@ -585,8 +594,7 @@ |
586 | 595 | * @private |
587 | 596 | * @ingroup DifferenceEngine |
588 | 597 | */ |
589 | | -class Diff |
590 | | -{ |
| 598 | +class Diff { |
591 | 599 | var $edits; |
592 | 600 | |
593 | 601 | /** |
— | — | @@ -613,7 +621,7 @@ |
614 | 622 | * @return object A Diff object representing the inverse of the |
615 | 623 | * original diff. |
616 | 624 | */ |
617 | | - function reverse () { |
| 625 | + function reverse() { |
618 | 626 | $rev = $this; |
619 | 627 | $rev->edits = array(); |
620 | 628 | foreach ( $this->edits as $edit ) { |
— | — | @@ -627,7 +635,7 @@ |
628 | 636 | * |
629 | 637 | * @return bool True iff two sequences were identical. |
630 | 638 | */ |
631 | | - function isEmpty () { |
| 639 | + function isEmpty() { |
632 | 640 | foreach ( $this->edits as $edit ) { |
633 | 641 | if ( $edit->type != 'copy' ) { |
634 | 642 | return false; |
— | — | @@ -643,7 +651,7 @@ |
644 | 652 | * |
645 | 653 | * @return int The length of the LCS. |
646 | 654 | */ |
647 | | - function lcs () { |
| 655 | + function lcs() { |
648 | 656 | $lcs = 0; |
649 | 657 | foreach ( $this->edits as $edit ) { |
650 | 658 | if ( $edit->type == 'copy' ) { |
— | — | @@ -696,7 +704,7 @@ |
697 | 705 | * |
698 | 706 | * This is here only for debugging purposes. |
699 | 707 | */ |
700 | | - function _check ( $from_lines, $to_lines ) { |
| 708 | + function _check( $from_lines, $to_lines ) { |
701 | 709 | wfProfileIn( __METHOD__ ); |
702 | 710 | if ( serialize( $from_lines ) != serialize( $this->orig() ) ) { |
703 | 711 | trigger_error( "Reconstructed original doesn't match", E_USER_ERROR ); |
— | — | @@ -717,7 +725,7 @@ |
718 | 726 | $prevtype = 'none'; |
719 | 727 | foreach ( $this->edits as $edit ) { |
720 | 728 | if ( $prevtype == $edit->type ) { |
721 | | - trigger_error( "Edit sequence is non-optimal", E_USER_ERROR ); |
| 729 | + trigger_error( 'Edit sequence is non-optimal', E_USER_ERROR ); |
722 | 730 | } |
723 | 731 | $prevtype = $edit->type; |
724 | 732 | } |
— | — | @@ -733,8 +741,7 @@ |
734 | 742 | * @private |
735 | 743 | * @ingroup DifferenceEngine |
736 | 744 | */ |
737 | | -class MappedDiff extends Diff |
738 | | -{ |
| 745 | +class MappedDiff extends Diff { |
739 | 746 | /** |
740 | 747 | * Constructor. |
741 | 748 | * |
— | — | @@ -835,8 +842,7 @@ |
836 | 843 | if ( is_array( $block ) ) { |
837 | 844 | if ( sizeof( $edit->orig ) <= $nlead + $ntrail ) { |
838 | 845 | $block[] = $edit; |
839 | | - } |
840 | | - else { |
| 846 | + } else { |
841 | 847 | if ( $ntrail ) { |
842 | 848 | $context = array_slice( $edit->orig, 0, $ntrail ); |
843 | 849 | $block[] = new _DiffOp_Copy( $context ); |
— | — | @@ -849,7 +855,7 @@ |
850 | 856 | } |
851 | 857 | $context = $edit->orig; |
852 | 858 | } else { |
853 | | - if ( ! is_array( $block ) ) { |
| 859 | + if ( !is_array( $block ) ) { |
854 | 860 | $context = array_slice( $context, sizeof( $context ) - $nlead ); |
855 | 861 | $x0 = $xi - sizeof( $context ); |
856 | 862 | $y0 = $yi - sizeof( $context ); |
— | — | @@ -912,10 +918,10 @@ |
913 | 919 | |
914 | 920 | function _block_header( $xbeg, $xlen, $ybeg, $ylen ) { |
915 | 921 | if ( $xlen > 1 ) { |
916 | | - $xbeg .= "," . ( $xbeg + $xlen - 1 ); |
| 922 | + $xbeg .= ',' . ( $xbeg + $xlen - 1 ); |
917 | 923 | } |
918 | 924 | if ( $ylen > 1 ) { |
919 | | - $ybeg .= "," . ( $ybeg + $ylen - 1 ); |
| 925 | + $ybeg .= ',' . ( $ybeg + $ylen - 1 ); |
920 | 926 | } |
921 | 927 | |
922 | 928 | return $xbeg . ( $xlen ? ( $ylen ? 'c' : 'd' ) : 'a' ) . $ybeg; |
— | — | @@ -956,7 +962,6 @@ |
957 | 963 | * A formatter that outputs unified diffs |
958 | 964 | * @ingroup DifferenceEngine |
959 | 965 | */ |
960 | | - |
961 | 966 | class UnifiedDiffFormatter extends DiffFormatter { |
962 | 967 | var $leading_context_lines = 2; |
963 | 968 | var $trailing_context_lines = 2; |
— | — | @@ -990,29 +995,29 @@ |
991 | 996 | case 'add': |
992 | 997 | foreach ( $edit->closing as $l ) { |
993 | 998 | $retval[] = array( |
994 | | - 'action' => 'add', |
995 | | - 'new' => $l, |
996 | | - 'newline' => $newline++ |
| 999 | + 'action' => 'add', |
| 1000 | + 'new' => $l, |
| 1001 | + 'newline' => $newline++ |
997 | 1002 | ); |
998 | 1003 | } |
999 | 1004 | break; |
1000 | 1005 | case 'delete': |
1001 | 1006 | foreach ( $edit->orig as $l ) { |
1002 | 1007 | $retval[] = array( |
1003 | | - 'action' => 'delete', |
1004 | | - 'old' => $l, |
1005 | | - 'oldline' => $oldline++, |
| 1008 | + 'action' => 'delete', |
| 1009 | + 'old' => $l, |
| 1010 | + 'oldline' => $oldline++, |
1006 | 1011 | ); |
1007 | 1012 | } |
1008 | 1013 | break; |
1009 | 1014 | case 'change': |
1010 | 1015 | foreach ( $edit->orig as $i => $l ) { |
1011 | 1016 | $retval[] = array( |
1012 | | - 'action' => 'change', |
1013 | | - 'old' => $l, |
1014 | | - 'new' => @$edit->closing[$i], |
1015 | | - 'oldline' => $oldline++, |
1016 | | - 'newline' => $newline++, |
| 1017 | + 'action' => 'change', |
| 1018 | + 'old' => $l, |
| 1019 | + 'new' => @$edit->closing[$i], |
| 1020 | + 'oldline' => $oldline++, |
| 1021 | + 'newline' => $newline++, |
1017 | 1022 | ); |
1018 | 1023 | } |
1019 | 1024 | break; |
— | — | @@ -1026,8 +1031,7 @@ |
1027 | 1032 | } |
1028 | 1033 | |
1029 | 1034 | /** |
1030 | | - * Additions by Axel Boldt follow, partly taken from diff.php, phpwiki-1.3.3 |
1031 | | - * |
| 1035 | + * Additions by Axel Boldt follow, partly taken from diff.php, phpwiki-1.3.3 |
1032 | 1036 | */ |
1033 | 1037 | |
1034 | 1038 | define( 'NBSP', ' ' ); // iso-8859-x non-breaking space. |
— | — | @@ -1038,36 +1042,36 @@ |
1039 | 1043 | * @ingroup DifferenceEngine |
1040 | 1044 | */ |
1041 | 1045 | class _HWLDF_WordAccumulator { |
1042 | | - function __construct () { |
| 1046 | + function __construct() { |
1043 | 1047 | $this->_lines = array(); |
1044 | 1048 | $this->_line = ''; |
1045 | 1049 | $this->_group = ''; |
1046 | 1050 | $this->_tag = ''; |
1047 | 1051 | } |
1048 | 1052 | |
1049 | | - function _flushGroup ( $new_tag ) { |
| 1053 | + function _flushGroup( $new_tag ) { |
1050 | 1054 | if ( $this->_group !== '' ) { |
1051 | 1055 | if ( $this->_tag == 'ins' ) { |
1052 | 1056 | $this->_line .= '<ins class="diffchange diffchange-inline">' . |
1053 | | - htmlspecialchars ( $this->_group ) . '</ins>'; |
| 1057 | + htmlspecialchars( $this->_group ) . '</ins>'; |
1054 | 1058 | } elseif ( $this->_tag == 'del' ) { |
1055 | 1059 | $this->_line .= '<del class="diffchange diffchange-inline">' . |
1056 | | - htmlspecialchars ( $this->_group ) . '</del>'; |
| 1060 | + htmlspecialchars( $this->_group ) . '</del>'; |
1057 | 1061 | } else { |
1058 | | - $this->_line .= htmlspecialchars ( $this->_group ); |
| 1062 | + $this->_line .= htmlspecialchars( $this->_group ); |
1059 | 1063 | } |
1060 | 1064 | } |
1061 | 1065 | $this->_group = ''; |
1062 | 1066 | $this->_tag = $new_tag; |
1063 | 1067 | } |
1064 | 1068 | |
1065 | | - function _flushLine ( $new_tag ) { |
| 1069 | + function _flushLine( $new_tag ) { |
1066 | 1070 | $this->_flushGroup( $new_tag ); |
1067 | 1071 | if ( $this->_line != '' ) { |
1068 | | - array_push ( $this->_lines, $this->_line ); |
| 1072 | + array_push( $this->_lines, $this->_line ); |
1069 | 1073 | } else { |
1070 | 1074 | # make empty lines visible by inserting an NBSP |
1071 | | - array_push ( $this->_lines, NBSP ); |
| 1075 | + array_push( $this->_lines, NBSP ); |
1072 | 1076 | } |
1073 | 1077 | $this->_line = ''; |
1074 | 1078 | } |
— | — | @@ -1108,8 +1112,8 @@ |
1109 | 1113 | function __construct ( $orig_lines, $closing_lines ) { |
1110 | 1114 | wfProfileIn( __METHOD__ ); |
1111 | 1115 | |
1112 | | - list ( $orig_words, $orig_stripped ) = $this->_split( $orig_lines ); |
1113 | | - list ( $closing_words, $closing_stripped ) = $this->_split( $closing_lines ); |
| 1116 | + list( $orig_words, $orig_stripped ) = $this->_split( $orig_lines ); |
| 1117 | + list( $closing_words, $closing_stripped ) = $this->_split( $closing_lines ); |
1114 | 1118 | |
1115 | 1119 | parent::__construct( $orig_words, $closing_words, |
1116 | 1120 | $orig_stripped, $closing_stripped ); |
— | — | @@ -1148,7 +1152,7 @@ |
1149 | 1153 | return array( $words, $stripped ); |
1150 | 1154 | } |
1151 | 1155 | |
1152 | | - function orig () { |
| 1156 | + function orig() { |
1153 | 1157 | wfProfileIn( __METHOD__ ); |
1154 | 1158 | $orig = new _HWLDF_WordAccumulator; |
1155 | 1159 | |
— | — | @@ -1164,7 +1168,7 @@ |
1165 | 1169 | return $lines; |
1166 | 1170 | } |
1167 | 1171 | |
1168 | | - function closing () { |
| 1172 | + function closing() { |
1169 | 1173 | wfProfileIn( __METHOD__ ); |
1170 | 1174 | $closing = new _HWLDF_WordAccumulator; |
1171 | 1175 | |
— | — | @@ -1247,14 +1251,14 @@ |
1248 | 1252 | foreach ( $lines as $line ) { |
1249 | 1253 | echo '<tr>' . $this->emptyLine() . |
1250 | 1254 | $this->addedLine( '<ins class="diffchange">' . |
1251 | | - htmlspecialchars ( $line ) . '</ins>' ) . "</tr>\n"; |
| 1255 | + htmlspecialchars( $line ) . '</ins>' ) . "</tr>\n"; |
1252 | 1256 | } |
1253 | 1257 | } |
1254 | 1258 | |
1255 | 1259 | function _deleted( $lines ) { |
1256 | 1260 | foreach ( $lines as $line ) { |
1257 | 1261 | echo '<tr>' . $this->deletedLine( '<del class="diffchange">' . |
1258 | | - htmlspecialchars ( $line ) . '</del>' ) . |
| 1262 | + htmlspecialchars( $line ) . '</del>' ) . |
1259 | 1263 | $this->emptyLine() . "</tr>\n"; |
1260 | 1264 | } |
1261 | 1265 | } |
— | — | @@ -1262,8 +1266,8 @@ |
1263 | 1267 | function _context( $lines ) { |
1264 | 1268 | foreach ( $lines as $line ) { |
1265 | 1269 | echo '<tr>' . |
1266 | | - $this->contextLine( htmlspecialchars ( $line ) ) . |
1267 | | - $this->contextLine( htmlspecialchars ( $line ) ) . "</tr>\n"; |
| 1270 | + $this->contextLine( htmlspecialchars( $line ) ) . |
| 1271 | + $this->contextLine( htmlspecialchars( $line ) ) . "</tr>\n"; |
1268 | 1272 | } |
1269 | 1273 | } |
1270 | 1274 | |