Index: trunk/phase3/includes/diff/WikiDiff.php |
— | — | @@ -135,6 +135,8 @@ |
136 | 136 | |
137 | 137 | const MAX_XREF_LENGTH = 10000; |
138 | 138 | |
| 139 | + protected $xchanged, $ychanged; |
| 140 | + |
139 | 141 | function diff ( $from_lines, $to_lines ) { |
140 | 142 | wfProfileIn( __METHOD__ ); |
141 | 143 | |
— | — | @@ -162,24 +164,28 @@ |
163 | 165 | $copy[] = $from_lines[$xi++]; |
164 | 166 | ++$yi; |
165 | 167 | } |
166 | | - if ( $copy ) |
167 | | - $edits[] = new _DiffOp_Copy( $copy ); |
| 168 | + if ( $copy ) { |
| 169 | + $edits[] = new _DiffOp_Copy( $copy ); |
| 170 | + } |
168 | 171 | |
169 | 172 | // Find deletes & adds. |
170 | 173 | $delete = array(); |
171 | | - while ( $xi < $n_from && $this->xchanged[$xi] ) |
172 | | - $delete[] = $from_lines[$xi++]; |
| 174 | + while ( $xi < $n_from && $this->xchanged[$xi] ) { |
| 175 | + $delete[] = $from_lines[$xi++]; |
| 176 | + } |
173 | 177 | |
174 | 178 | $add = array(); |
175 | | - while ( $yi < $n_to && $this->ychanged[$yi] ) |
176 | | - $add[] = $to_lines[$yi++]; |
| 179 | + while ( $yi < $n_to && $this->ychanged[$yi] ) { |
| 180 | + $add[] = $to_lines[$yi++]; |
| 181 | + } |
177 | 182 | |
178 | | - if ( $delete && $add ) |
179 | | - $edits[] = new _DiffOp_Change( $delete, $add ); |
180 | | - elseif ( $delete ) |
181 | | - $edits[] = new _DiffOp_Delete( $delete ); |
182 | | - elseif ( $add ) |
183 | | - $edits[] = new _DiffOp_Add( $add ); |
| 183 | + if ( $delete && $add ) { |
| 184 | + $edits[] = new _DiffOp_Change( $delete, $add ); |
| 185 | + } elseif ( $delete ) { |
| 186 | + $edits[] = new _DiffOp_Delete( $delete ); |
| 187 | + } elseif ( $add ) { |
| 188 | + $edits[] = new _DiffOp_Add( $add ); |
| 189 | + } |
184 | 190 | } |
185 | 191 | wfProfileOut( __METHOD__ ); |
186 | 192 | return $edits; |
— | — | @@ -282,16 +288,18 @@ |
283 | 289 | // Things seems faster (I'm not sure I understand why) |
284 | 290 | // when the shortest sequence in X. |
285 | 291 | $flip = true; |
286 | | - list ( $xoff, $xlim, $yoff, $ylim ) |
287 | | - = array( $yoff, $ylim, $xoff, $xlim ); |
| 292 | + list ( $xoff, $xlim, $yoff, $ylim ) = array( $yoff, $ylim, $xoff, $xlim ); |
288 | 293 | } |
289 | 294 | |
290 | | - if ( $flip ) |
291 | | - for ( $i = $ylim - 1; $i >= $yoff; $i-- ) |
292 | | - $ymatches[$this->xv[$i]][] = $i; |
293 | | - else |
294 | | - for ( $i = $ylim - 1; $i >= $yoff; $i-- ) |
295 | | - $ymatches[$this->yv[$i]][] = $i; |
| 295 | + if ( $flip ) { |
| 296 | + for ( $i = $ylim - 1; $i >= $yoff; $i-- ) { |
| 297 | + $ymatches[$this->xv[$i]][] = $i; |
| 298 | + } |
| 299 | + } else { |
| 300 | + for ( $i = $ylim - 1; $i >= $yoff; $i-- ) { |
| 301 | + $ymatches[$this->yv[$i]][] = $i; |
| 302 | + } |
| 303 | + } |
296 | 304 | |
297 | 305 | $this->lcs = 0; |
298 | 306 | $this->seq[0] = $yoff - 1; |
— | — | @@ -301,9 +309,11 @@ |
302 | 310 | $numer = $xlim - $xoff + $nchunks - 1; |
303 | 311 | $x = $xoff; |
304 | 312 | for ( $chunk = 0; $chunk < $nchunks; $chunk++ ) { |
305 | | - if ( $chunk > 0 ) |
306 | | - for ( $i = 0; $i <= $this->lcs; $i++ ) |
307 | | - $ymids[$i][$chunk -1] = $this->seq[$i]; |
| 313 | + if ( $chunk > 0 ) { |
| 314 | + for ( $i = 0; $i <= $this->lcs; $i++ ) { |
| 315 | + $ymids[$i][$chunk -1] = $this->seq[$i]; |
| 316 | + } |
| 317 | + } |
308 | 318 | |
309 | 319 | $x1 = $xoff + (int)( ( $numer + ( $xlim -$xoff ) * $chunk ) / $nchunks ); |
310 | 320 | for ( ; $x < $x1; $x++ ) { |
— | — | @@ -401,9 +411,9 @@ |
402 | 412 | --$ylim; |
403 | 413 | } |
404 | 414 | |
405 | | - if ( $xoff == $xlim || $yoff == $ylim ) |
406 | | - $lcs = 0; |
407 | | - else { |
| 415 | + if ( $xoff == $xlim || $yoff == $ylim ) { |
| 416 | + $lcs = 0; |
| 417 | + } else { |
408 | 418 | // This is ad hoc but seems to work well. |
409 | 419 | // $nchunks = sqrt(min($xlim - $xoff, $ylim - $yoff) / 2.5); |
410 | 420 | // $nchunks = max(2,min(8,(int)$nchunks)); |
— | — | @@ -415,10 +425,12 @@ |
416 | 426 | if ( $lcs == 0 ) { |
417 | 427 | // X and Y sequences have no common subsequence: |
418 | 428 | // mark all changed. |
419 | | - while ( $yoff < $ylim ) |
420 | | - $this->ychanged[$this->yind[$yoff++]] = 1; |
421 | | - while ( $xoff < $xlim ) |
422 | | - $this->xchanged[$this->xind[$xoff++]] = 1; |
| 429 | + while ( $yoff < $ylim ) { |
| 430 | + $this->ychanged[$this->yind[$yoff++]] = 1; |
| 431 | + } |
| 432 | + while ( $xoff < $xlim ) { |
| 433 | + $this->xchanged[$this->xind[$xoff++]] = 1; |
| 434 | + } |
423 | 435 | } else { |
424 | 436 | // Use the partitions to split this problem into subproblems. |
425 | 437 | reset( $seps ); |
— | — | @@ -463,8 +475,9 @@ |
464 | 476 | * Furthermore, $j is always kept so that $j == $other_len or |
465 | 477 | * $other_changed[$j] == false. |
466 | 478 | */ |
467 | | - while ( $j < $other_len && $other_changed[$j] ) |
468 | | - $j++; |
| 479 | + while ( $j < $other_len && $other_changed[$j] ) { |
| 480 | + $j++; |
| 481 | + } |
469 | 482 | |
470 | 483 | while ( $i < $len && ! $changed[$i] ) { |
471 | 484 | assert( '$j < $other_len && ! $other_changed[$j]' ); |
— | — | @@ -473,14 +486,16 @@ |
474 | 487 | $j++; |
475 | 488 | } |
476 | 489 | |
477 | | - if ( $i == $len ) |
478 | | - break; |
| 490 | + if ( $i == $len ) { |
| 491 | + break; |
| 492 | + } |
479 | 493 | |
480 | 494 | $start = $i; |
481 | 495 | |
482 | 496 | // Find the end of this run of changes. |
483 | | - while ( ++$i < $len && $changed[$i] ) |
484 | | - continue; |
| 497 | + while ( ++$i < $len && $changed[$i] ) { |
| 498 | + continue; |
| 499 | + } |
485 | 500 | |
486 | 501 | do { |
487 | 502 | /* |
— | — | @@ -497,11 +512,13 @@ |
498 | 513 | while ( $start > 0 && $lines[$start - 1] == $lines[$i - 1] ) { |
499 | 514 | $changed[--$start] = 1; |
500 | 515 | $changed[--$i] = false; |
501 | | - while ( $start > 0 && $changed[$start - 1] ) |
502 | | - $start--; |
| 516 | + while ( $start > 0 && $changed[$start - 1] ) { |
| 517 | + $start--; |
| 518 | + } |
503 | 519 | assert( '$j > 0' ); |
504 | | - while ( $other_changed[--$j] ) |
505 | | - continue; |
| 520 | + while ( $other_changed[--$j] ) { |
| 521 | + continue; |
| 522 | + } |
506 | 523 | assert( '$j >= 0 && !$other_changed[$j]' ); |
507 | 524 | } |
508 | 525 | |
— | — | @@ -522,15 +539,17 @@ |
523 | 540 | while ( $i < $len && $lines[$start] == $lines[$i] ) { |
524 | 541 | $changed[$start++] = false; |
525 | 542 | $changed[$i++] = 1; |
526 | | - while ( $i < $len && $changed[$i] ) |
527 | | - $i++; |
| 543 | + while ( $i < $len && $changed[$i] ) { |
| 544 | + $i++; |
| 545 | + } |
528 | 546 | |
529 | 547 | assert( '$j < $other_len && ! $other_changed[$j]' ); |
530 | 548 | $j++; |
531 | 549 | if ( $j < $other_len && $other_changed[$j] ) { |
532 | 550 | $corresponding = $i; |
533 | | - while ( $j < $other_len && $other_changed[$j] ) |
534 | | - $j++; |
| 551 | + while ( $j < $other_len && $other_changed[$j] ) { |
| 552 | + $j++; |
| 553 | + } |
535 | 554 | } |
536 | 555 | } |
537 | 556 | } while ( $runlength != $i - $start ); |
— | — | @@ -543,8 +562,9 @@ |
544 | 563 | $changed[--$start] = 1; |
545 | 564 | $changed[--$i] = 0; |
546 | 565 | assert( '$j > 0' ); |
547 | | - while ( $other_changed[--$j] ) |
548 | | - continue; |
| 566 | + while ( $other_changed[--$j] ) { |
| 567 | + continue; |
| 568 | + } |
549 | 569 | assert( '$j >= 0 && !$other_changed[$j]' ); |
550 | 570 | } |
551 | 571 | } |
— | — | @@ -602,8 +622,9 @@ |
603 | 623 | */ |
604 | 624 | function isEmpty () { |
605 | 625 | foreach ( $this->edits as $edit ) { |
606 | | - if ( $edit->type != 'copy' ) |
607 | | - return false; |
| 626 | + if ( $edit->type != 'copy' ) { |
| 627 | + return false; |
| 628 | + } |
608 | 629 | } |
609 | 630 | return true; |
610 | 631 | } |
— | — | @@ -618,8 +639,9 @@ |
619 | 640 | function lcs () { |
620 | 641 | $lcs = 0; |
621 | 642 | foreach ( $this->edits as $edit ) { |
622 | | - if ( $edit->type == 'copy' ) |
623 | | - $lcs += sizeof( $edit->orig ); |
| 643 | + if ( $edit->type == 'copy' ) { |
| 644 | + $lcs += sizeof( $edit->orig ); |
| 645 | + } |
624 | 646 | } |
625 | 647 | return $lcs; |
626 | 648 | } |
— | — | @@ -636,8 +658,9 @@ |
637 | 659 | $lines = array(); |
638 | 660 | |
639 | 661 | foreach ( $this->edits as $edit ) { |
640 | | - if ( $edit->orig ) |
641 | | - array_splice( $lines, sizeof( $lines ), 0, $edit->orig ); |
| 662 | + if ( $edit->orig ) { |
| 663 | + array_splice( $lines, sizeof( $lines ), 0, $edit->orig ); |
| 664 | + } |
642 | 665 | } |
643 | 666 | return $lines; |
644 | 667 | } |
— | — | @@ -654,8 +677,9 @@ |
655 | 678 | $lines = array(); |
656 | 679 | |
657 | 680 | foreach ( $this->edits as $edit ) { |
658 | | - if ( $edit->closing ) |
659 | | - array_splice( $lines, sizeof( $lines ), 0, $edit->closing ); |
| 681 | + if ( $edit->closing ) { |
| 682 | + array_splice( $lines, sizeof( $lines ), 0, $edit->closing ); |
| 683 | + } |
660 | 684 | } |
661 | 685 | return $lines; |
662 | 686 | } |
— | — | @@ -667,22 +691,27 @@ |
668 | 692 | */ |
669 | 693 | function _check ( $from_lines, $to_lines ) { |
670 | 694 | wfProfileIn( __METHOD__ ); |
671 | | - if ( serialize( $from_lines ) != serialize( $this->orig() ) ) |
672 | | - trigger_error( "Reconstructed original doesn't match", E_USER_ERROR ); |
673 | | - if ( serialize( $to_lines ) != serialize( $this->closing() ) ) |
674 | | - trigger_error( "Reconstructed closing doesn't match", E_USER_ERROR ); |
| 695 | + if ( serialize( $from_lines ) != serialize( $this->orig() ) ) { |
| 696 | + trigger_error( "Reconstructed original doesn't match", E_USER_ERROR ); |
| 697 | + } |
| 698 | + if ( serialize( $to_lines ) != serialize( $this->closing() ) ) { |
| 699 | + trigger_error( "Reconstructed closing doesn't match", E_USER_ERROR ); |
| 700 | + } |
675 | 701 | |
676 | 702 | $rev = $this->reverse(); |
677 | | - if ( serialize( $to_lines ) != serialize( $rev->orig() ) ) |
678 | | - trigger_error( "Reversed original doesn't match", E_USER_ERROR ); |
679 | | - if ( serialize( $from_lines ) != serialize( $rev->closing() ) ) |
680 | | - trigger_error( "Reversed closing doesn't match", E_USER_ERROR ); |
| 703 | + if ( serialize( $to_lines ) != serialize( $rev->orig() ) ) { |
| 704 | + trigger_error( "Reversed original doesn't match", E_USER_ERROR ); |
| 705 | + } |
| 706 | + if ( serialize( $from_lines ) != serialize( $rev->closing() ) ) { |
| 707 | + trigger_error( "Reversed closing doesn't match", E_USER_ERROR ); |
| 708 | + } |
681 | 709 | |
682 | 710 | |
683 | 711 | $prevtype = 'none'; |
684 | 712 | foreach ( $this->edits as $edit ) { |
685 | | - if ( $prevtype == $edit->type ) |
686 | | - trigger_error( "Edit sequence is non-optimal", E_USER_ERROR ); |
| 713 | + if ( $prevtype == $edit->type ) { |
| 714 | + trigger_error( "Edit sequence is non-optimal", E_USER_ERROR ); |
| 715 | + } |
687 | 716 | $prevtype = $edit->type; |
688 | 717 | } |
689 | 718 | |
— | — | @@ -723,7 +752,7 @@ |
724 | 753 | * have the same number of elements as $to_lines. |
725 | 754 | */ |
726 | 755 | function __construct( $from_lines, $to_lines, |
727 | | - $mapped_from_lines, $mapped_to_lines ) { |
| 756 | + $mapped_from_lines, $mapped_to_lines ) { |
728 | 757 | wfProfileIn( __METHOD__ ); |
729 | 758 | |
730 | 759 | assert( sizeof( $from_lines ) == sizeof( $mapped_from_lines ) ); |
— | — | @@ -779,7 +808,7 @@ |
780 | 809 | /** |
781 | 810 | * Format a diff. |
782 | 811 | * |
783 | | - * @param $diff object A Diff object. |
| 812 | + * @param $diff Diff A Diff object. |
784 | 813 | * @return string The formatted output. |
785 | 814 | */ |
786 | 815 | function format( $diff ) { |
— | — | @@ -806,8 +835,8 @@ |
807 | 836 | $block[] = new _DiffOp_Copy( $context ); |
808 | 837 | } |
809 | 838 | $this->_block( $x0, $ntrail + $xi - $x0, |
810 | | - $y0, $ntrail + $yi - $y0, |
811 | | - $block ); |
| 839 | + $y0, $ntrail + $yi - $y0, |
| 840 | + $block ); |
812 | 841 | $block = false; |
813 | 842 | } |
814 | 843 | } |
— | — | @@ -819,22 +848,26 @@ |
820 | 849 | $x0 = $xi - sizeof( $context ); |
821 | 850 | $y0 = $yi - sizeof( $context ); |
822 | 851 | $block = array(); |
823 | | - if ( $context ) |
824 | | - $block[] = new _DiffOp_Copy( $context ); |
| 852 | + if ( $context ) { |
| 853 | + $block[] = new _DiffOp_Copy( $context ); |
| 854 | + } |
825 | 855 | } |
826 | 856 | $block[] = $edit; |
827 | 857 | } |
828 | 858 | |
829 | | - if ( $edit->orig ) |
830 | | - $xi += sizeof( $edit->orig ); |
831 | | - if ( $edit->closing ) |
832 | | - $yi += sizeof( $edit->closing ); |
| 859 | + if ( $edit->orig ) { |
| 860 | + $xi += sizeof( $edit->orig ); |
| 861 | + } |
| 862 | + if ( $edit->closing ) { |
| 863 | + $yi += sizeof( $edit->closing ); |
| 864 | + } |
833 | 865 | } |
834 | 866 | |
835 | | - if ( is_array( $block ) ) |
836 | | - $this->_block( $x0, $xi - $x0, |
837 | | - $y0, $yi - $y0, |
838 | | - $block ); |
| 867 | + if ( is_array( $block ) ) { |
| 868 | + $this->_block( $x0, $xi - $x0, |
| 869 | + $y0, $yi - $y0, |
| 870 | + $block ); |
| 871 | + } |
839 | 872 | |
840 | 873 | $end = $this->_end_diff(); |
841 | 874 | wfProfileOut( __METHOD__ ); |
— | — | @@ -845,16 +878,17 @@ |
846 | 879 | wfProfileIn( __METHOD__ ); |
847 | 880 | $this->_start_block( $this->_block_header( $xbeg, $xlen, $ybeg, $ylen ) ); |
848 | 881 | foreach ( $edits as $edit ) { |
849 | | - if ( $edit->type == 'copy' ) |
850 | | - $this->_context( $edit->orig ); |
851 | | - elseif ( $edit->type == 'add' ) |
852 | | - $this->_added( $edit->closing ); |
853 | | - elseif ( $edit->type == 'delete' ) |
854 | | - $this->_deleted( $edit->orig ); |
855 | | - elseif ( $edit->type == 'change' ) |
856 | | - $this->_changed( $edit->orig, $edit->closing ); |
857 | | - else |
858 | | - trigger_error( 'Unknown edit type', E_USER_ERROR ); |
| 882 | + if ( $edit->type == 'copy' ) { |
| 883 | + $this->_context( $edit->orig ); |
| 884 | + } elseif ( $edit->type == 'add' ) { |
| 885 | + $this->_added( $edit->closing ); |
| 886 | + } elseif ( $edit->type == 'delete' ) { |
| 887 | + $this->_deleted( $edit->orig ); |
| 888 | + } elseif ( $edit->type == 'change' ) { |
| 889 | + $this->_changed( $edit->orig, $edit->closing ); |
| 890 | + } else { |
| 891 | + trigger_error( 'Unknown edit type', E_USER_ERROR ); |
| 892 | + } |
859 | 893 | } |
860 | 894 | $this->_end_block(); |
861 | 895 | wfProfileOut( __METHOD__ ); |
— | — | @@ -871,10 +905,12 @@ |
872 | 906 | } |
873 | 907 | |
874 | 908 | function _block_header( $xbeg, $xlen, $ybeg, $ylen ) { |
875 | | - if ( $xlen > 1 ) |
876 | | - $xbeg .= "," . ( $xbeg + $xlen - 1 ); |
877 | | - if ( $ylen > 1 ) |
878 | | - $ybeg .= "," . ( $ybeg + $ylen - 1 ); |
| 909 | + if ( $xlen > 1 ) { |
| 910 | + $xbeg .= "," . ( $xbeg + $xlen - 1 ); |
| 911 | + } |
| 912 | + if ( $ylen > 1 ) { |
| 913 | + $ybeg .= "," . ( $ybeg + $ylen - 1 ); |
| 914 | + } |
879 | 915 | |
880 | 916 | return $xbeg . ( $xlen ? ( $ylen ? 'c' : 'd' ) : 'a' ) . $ybeg; |
881 | 917 | } |
— | — | @@ -887,8 +923,9 @@ |
888 | 924 | } |
889 | 925 | |
890 | 926 | function _lines( $lines, $prefix = ' ' ) { |
891 | | - foreach ( $lines as $line ) |
892 | | - echo "$prefix $line\n"; |
| 927 | + foreach ( $lines as $line ) { |
| 928 | + echo "$prefix $line\n"; |
| 929 | + } |
893 | 930 | } |
894 | 931 | |
895 | 932 | function _context( $lines ) { |
— | — | @@ -942,40 +979,41 @@ |
943 | 980 | $oldline = 1; |
944 | 981 | $newline = 1; |
945 | 982 | $retval = array(); |
946 | | - foreach ( $diff->edits as $edit ) |
947 | | - switch( $edit->type ) { |
948 | | - case 'add': |
949 | | - foreach ( $edit->closing as $l ) { |
950 | | - $retval[] = array( |
951 | | - 'action' => 'add', |
952 | | - 'new' => $l, |
953 | | - 'newline' => $newline++ |
954 | | - ); |
955 | | - } |
956 | | - break; |
957 | | - case 'delete': |
958 | | - foreach ( $edit->orig as $l ) { |
959 | | - $retval[] = array( |
960 | | - 'action' => 'delete', |
961 | | - 'old' => $l, |
962 | | - 'oldline' => $oldline++, |
963 | | - ); |
964 | | - } |
965 | | - break; |
966 | | - case 'change': |
967 | | - foreach ( $edit->orig as $i => $l ) { |
968 | | - $retval[] = array( |
969 | | - 'action' => 'change', |
970 | | - 'old' => $l, |
971 | | - 'new' => @$edit->closing[$i], |
972 | | - 'oldline' => $oldline++, |
973 | | - 'newline' => $newline++, |
974 | | - ); |
975 | | - } |
976 | | - break; |
977 | | - case 'copy': |
978 | | - $oldline += count( $edit->orig ); |
979 | | - $newline += count( $edit->orig ); |
| 983 | + foreach ( $diff->edits as $edit ) { |
| 984 | + switch( $edit->type ) { |
| 985 | + case 'add': |
| 986 | + foreach ( $edit->closing as $l ) { |
| 987 | + $retval[] = array( |
| 988 | + 'action' => 'add', |
| 989 | + 'new' => $l, |
| 990 | + 'newline' => $newline++ |
| 991 | + ); |
| 992 | + } |
| 993 | + break; |
| 994 | + case 'delete': |
| 995 | + foreach ( $edit->orig as $l ) { |
| 996 | + $retval[] = array( |
| 997 | + 'action' => 'delete', |
| 998 | + 'old' => $l, |
| 999 | + 'oldline' => $oldline++, |
| 1000 | + ); |
| 1001 | + } |
| 1002 | + break; |
| 1003 | + case 'change': |
| 1004 | + foreach ( $edit->orig as $i => $l ) { |
| 1005 | + $retval[] = array( |
| 1006 | + 'action' => 'change', |
| 1007 | + 'old' => $l, |
| 1008 | + 'new' => @$edit->closing[$i], |
| 1009 | + 'oldline' => $oldline++, |
| 1010 | + 'newline' => $newline++, |
| 1011 | + ); |
| 1012 | + } |
| 1013 | + break; |
| 1014 | + case 'copy': |
| 1015 | + $oldline += count( $edit->orig ); |
| 1016 | + $newline += count( $edit->orig ); |
| 1017 | + } |
980 | 1018 | } |
981 | 1019 | return $retval; |
982 | 1020 | } |
— | — | @@ -1003,14 +1041,15 @@ |
1004 | 1042 | |
1005 | 1043 | function _flushGroup ( $new_tag ) { |
1006 | 1044 | if ( $this->_group !== '' ) { |
1007 | | - if ( $this->_tag == 'ins' ) |
1008 | | - $this->_line .= '<ins class="diffchange diffchange-inline">' . |
1009 | | - htmlspecialchars ( $this->_group ) . '</ins>'; |
1010 | | - elseif ( $this->_tag == 'del' ) |
1011 | | - $this->_line .= '<del class="diffchange diffchange-inline">' . |
1012 | | - htmlspecialchars ( $this->_group ) . '</del>'; |
1013 | | - else |
1014 | | - $this->_line .= htmlspecialchars ( $this->_group ); |
| 1045 | + if ( $this->_tag == 'ins' ) { |
| 1046 | + $this->_line .= '<ins class="diffchange diffchange-inline">' . |
| 1047 | + htmlspecialchars ( $this->_group ) . '</ins>'; |
| 1048 | + } elseif ( $this->_tag == 'del' ) { |
| 1049 | + $this->_line .= '<del class="diffchange diffchange-inline">' . |
| 1050 | + htmlspecialchars ( $this->_group ) . '</del>'; |
| 1051 | + } else { |
| 1052 | + $this->_line .= htmlspecialchars ( $this->_group ); |
| 1053 | + } |
1015 | 1054 | } |
1016 | 1055 | $this->_group = ''; |
1017 | 1056 | $this->_tag = $new_tag; |
— | — | @@ -1018,22 +1057,25 @@ |
1019 | 1058 | |
1020 | 1059 | function _flushLine ( $new_tag ) { |
1021 | 1060 | $this->_flushGroup( $new_tag ); |
1022 | | - if ( $this->_line != '' ) |
1023 | | - array_push ( $this->_lines, $this->_line ); |
1024 | | - else |
1025 | | - # make empty lines visible by inserting an NBSP |
1026 | | - array_push ( $this->_lines, NBSP ); |
| 1061 | + if ( $this->_line != '' ) { |
| 1062 | + array_push ( $this->_lines, $this->_line ); |
| 1063 | + } else { |
| 1064 | + # make empty lines visible by inserting an NBSP |
| 1065 | + array_push ( $this->_lines, NBSP ); |
| 1066 | + } |
1027 | 1067 | $this->_line = ''; |
1028 | 1068 | } |
1029 | 1069 | |
1030 | 1070 | function addWords ( $words, $tag = '' ) { |
1031 | | - if ( $tag != $this->_tag ) |
1032 | | - $this->_flushGroup( $tag ); |
| 1071 | + if ( $tag != $this->_tag ) { |
| 1072 | + $this->_flushGroup( $tag ); |
| 1073 | + } |
1033 | 1074 | |
1034 | 1075 | foreach ( $words as $word ) { |
1035 | 1076 | // new-line should only come as first char of word. |
1036 | | - if ( $word == '' ) |
1037 | | - continue; |
| 1077 | + if ( $word == '' ) { |
| 1078 | + continue; |
| 1079 | + } |
1038 | 1080 | if ( $word[0] == "\n" ) { |
1039 | 1081 | $this->_flushLine( $tag ); |
1040 | 1082 | $word = substr( $word, 1 ); |
— | — | @@ -1089,7 +1131,7 @@ |
1090 | 1132 | } else { |
1091 | 1133 | $m = array(); |
1092 | 1134 | if ( preg_match_all( '/ ( [^\S\n]+ | [0-9_A-Za-z\x80-\xff]+ | . ) (?: (?!< \n) [^\S\n])? /xs', |
1093 | | - $line, $m ) ) |
| 1135 | + $line, $m ) ) |
1094 | 1136 | { |
1095 | 1137 | $words = array_merge( $words, $m[0] ); |
1096 | 1138 | $stripped = array_merge( $stripped, $m[1] ); |
— | — | @@ -1105,10 +1147,11 @@ |
1106 | 1148 | $orig = new _HWLDF_WordAccumulator; |
1107 | 1149 | |
1108 | 1150 | foreach ( $this->edits as $edit ) { |
1109 | | - if ( $edit->type == 'copy' ) |
1110 | | - $orig->addWords( $edit->orig ); |
1111 | | - elseif ( $edit->orig ) |
1112 | | - $orig->addWords( $edit->orig, 'del' ); |
| 1151 | + if ( $edit->type == 'copy' ) { |
| 1152 | + $orig->addWords( $edit->orig ); |
| 1153 | + } elseif ( $edit->orig ) { |
| 1154 | + $orig->addWords( $edit->orig, 'del' ); |
| 1155 | + } |
1113 | 1156 | } |
1114 | 1157 | $lines = $orig->getLines(); |
1115 | 1158 | wfProfileOut( __METHOD__ ); |
— | — | @@ -1120,10 +1163,11 @@ |
1121 | 1164 | $closing = new _HWLDF_WordAccumulator; |
1122 | 1165 | |
1123 | 1166 | foreach ( $this->edits as $edit ) { |
1124 | | - if ( $edit->type == 'copy' ) |
1125 | | - $closing->addWords( $edit->closing ); |
1126 | | - elseif ( $edit->closing ) |
1127 | | - $closing->addWords( $edit->closing, 'ins' ); |
| 1167 | + if ( $edit->type == 'copy' ) { |
| 1168 | + $closing->addWords( $edit->closing ); |
| 1169 | + } elseif ( $edit->closing ) { |
| 1170 | + $closing->addWords( $edit->closing, 'ins' ); |
| 1171 | + } |
1128 | 1172 | } |
1129 | 1173 | $lines = $closing->getLines(); |
1130 | 1174 | wfProfileOut( __METHOD__ ); |