r82529 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r82528‎ | r82529 | r82530 >
Date:19:04, 20 February 2011
Author:ashley
Status:ok
Tags:
Comment:
spaces, added some braces to DairikiDiff.php
Modified paths:
  • /trunk/phase3/includes/diff/DairikiDiff.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/diff/DairikiDiff.php
@@ -41,9 +41,10 @@
4242 class _DiffOp_Copy extends _DiffOp {
4343 var $type = 'copy';
4444
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+ }
4849 $this->orig = $orig;
4950 $this->closing = $closing;
5051 }
@@ -61,7 +62,7 @@
6263 class _DiffOp_Delete extends _DiffOp {
6364 var $type = 'delete';
6465
65 - function __construct ( $lines ) {
 66+ function __construct( $lines ) {
6667 $this->orig = $lines;
6768 $this->closing = false;
6869 }
@@ -79,7 +80,7 @@
8081 class _DiffOp_Add extends _DiffOp {
8182 var $type = 'add';
8283
83 - function __construct ( $lines ) {
 84+ function __construct( $lines ) {
8485 $this->closing = $lines;
8586 $this->orig = false;
8687 }
@@ -97,7 +98,7 @@
9899 class _DiffOp_Change extends _DiffOp {
99100 var $type = 'change';
100101
101 - function __construct ( $orig, $closing ) {
 102+ function __construct( $orig, $closing ) {
102103 $this->orig = $orig;
103104 $this->closing = $closing;
104105 }
@@ -222,15 +223,17 @@
223224
224225 // Skip leading common lines.
225226 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+ }
228230 $this->xchanged[$skip] = $this->ychanged[$skip] = false;
229231 }
230232 // Skip trailing common lines.
231233 $xi = $n_from; $yi = $n_to;
232234 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+ }
235238 $this->xchanged[$xi] = $this->ychanged[$yi] = false;
236239 }
237240
@@ -241,16 +244,18 @@
242245
243246 for ( $yi = $skip; $yi < $n_to - $endskip; $yi++ ) {
244247 $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+ }
247251 $yhash[$this->_line_hash( $line )] = 1;
248252 $this->yv[] = $line;
249253 $this->yind[] = $yi;
250254 }
251255 for ( $xi = $skip; $xi < $n_from - $endskip; $xi++ ) {
252256 $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+ }
255260 $this->xv[] = $line;
256261 $this->xind[] = $xi;
257262 }
@@ -272,7 +277,8 @@
273278 }
274279 }
275280
276 - /* Divide the Largest Common Subsequence (LCS) of the sequences
 281+ /**
 282+ * Divide the Largest Common Subsequence (LCS) of the sequences
277283 * [XOFF, XLIM) and [YOFF, YLIM) into NCHUNKS approximately equally
278284 * sized segments.
279285 *
@@ -288,14 +294,14 @@
289295 * match. The caller must trim matching lines from the beginning and end
290296 * of the portions it is going to specify.
291297 */
292 - function _diag ( $xoff, $xlim, $yoff, $ylim, $nchunks ) {
 298+ function _diag( $xoff, $xlim, $yoff, $ylim, $nchunks ) {
293299 $flip = false;
294300
295301 if ( $xlim - $xoff > $ylim - $yoff ) {
296302 // Things seems faster (I'm not sure I understand why)
297303 // when the shortest sequence in X.
298304 $flip = true;
299 - list ( $xoff, $xlim, $yoff, $ylim ) = array( $yoff, $ylim, $xoff, $xlim );
 305+ list( $xoff, $xlim, $yoff, $ylim ) = array( $yoff, $ylim, $xoff, $xlim );
300306 }
301307
302308 if ( $flip ) {
@@ -367,7 +373,7 @@
368374 return array( $this->lcs, $seps );
369375 }
370376
371 - function _lcs_pos ( $ypos ) {
 377+ function _lcs_pos( $ypos ) {
372378 $end = $this->lcs;
373379 if ( $end == 0 || $ypos > $this->seq[$end] ) {
374380 $this->seq[++$this->lcs] = $ypos;
@@ -378,10 +384,11 @@
379385 $beg = 1;
380386 while ( $beg < $end ) {
381387 $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+ }
386393 }
387394
388395 assert( $ypos != $this->seq[$end] );
@@ -392,7 +399,8 @@
393400 return $end;
394401 }
395402
396 - /* Find LCS of two sequences.
 403+ /**
 404+ * Find LCS of two sequences.
397405 *
398406 * The results are recorded in the vectors $this->{x,y}changed[], by
399407 * storing a 1 in the element for each line that is an insertion
@@ -449,7 +457,8 @@
450458 }
451459 }
452460
453 - /* Adjust inserts/deletes of identical lines to join changes
 461+ /**
 462+ * Adjust inserts/deletes of identical lines to join changes
454463 * as much as possible.
455464 *
456465 * We do something when a run of changed lines include a
@@ -461,7 +470,7 @@
462471 *
463472 * This is extracted verbatim from analyze.c (GNU diffutils-2.7).
464473 */
465 - function _shift_boundaries ( $lines, &$changed, $other_changed ) {
 474+ function _shift_boundaries( $lines, &$changed, $other_changed ) {
466475 wfProfileIn( __METHOD__ );
467476 $i = 0;
468477 $j = 0;
@@ -585,8 +594,7 @@
586595 * @private
587596 * @ingroup DifferenceEngine
588597 */
589 -class Diff
590 -{
 598+class Diff {
591599 var $edits;
592600
593601 /**
@@ -613,7 +621,7 @@
614622 * @return object A Diff object representing the inverse of the
615623 * original diff.
616624 */
617 - function reverse () {
 625+ function reverse() {
618626 $rev = $this;
619627 $rev->edits = array();
620628 foreach ( $this->edits as $edit ) {
@@ -627,7 +635,7 @@
628636 *
629637 * @return bool True iff two sequences were identical.
630638 */
631 - function isEmpty () {
 639+ function isEmpty() {
632640 foreach ( $this->edits as $edit ) {
633641 if ( $edit->type != 'copy' ) {
634642 return false;
@@ -643,7 +651,7 @@
644652 *
645653 * @return int The length of the LCS.
646654 */
647 - function lcs () {
 655+ function lcs() {
648656 $lcs = 0;
649657 foreach ( $this->edits as $edit ) {
650658 if ( $edit->type == 'copy' ) {
@@ -696,7 +704,7 @@
697705 *
698706 * This is here only for debugging purposes.
699707 */
700 - function _check ( $from_lines, $to_lines ) {
 708+ function _check( $from_lines, $to_lines ) {
701709 wfProfileIn( __METHOD__ );
702710 if ( serialize( $from_lines ) != serialize( $this->orig() ) ) {
703711 trigger_error( "Reconstructed original doesn't match", E_USER_ERROR );
@@ -717,7 +725,7 @@
718726 $prevtype = 'none';
719727 foreach ( $this->edits as $edit ) {
720728 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 );
722730 }
723731 $prevtype = $edit->type;
724732 }
@@ -733,8 +741,7 @@
734742 * @private
735743 * @ingroup DifferenceEngine
736744 */
737 -class MappedDiff extends Diff
738 -{
 745+class MappedDiff extends Diff {
739746 /**
740747 * Constructor.
741748 *
@@ -835,8 +842,7 @@
836843 if ( is_array( $block ) ) {
837844 if ( sizeof( $edit->orig ) <= $nlead + $ntrail ) {
838845 $block[] = $edit;
839 - }
840 - else {
 846+ } else {
841847 if ( $ntrail ) {
842848 $context = array_slice( $edit->orig, 0, $ntrail );
843849 $block[] = new _DiffOp_Copy( $context );
@@ -849,7 +855,7 @@
850856 }
851857 $context = $edit->orig;
852858 } else {
853 - if ( ! is_array( $block ) ) {
 859+ if ( !is_array( $block ) ) {
854860 $context = array_slice( $context, sizeof( $context ) - $nlead );
855861 $x0 = $xi - sizeof( $context );
856862 $y0 = $yi - sizeof( $context );
@@ -912,10 +918,10 @@
913919
914920 function _block_header( $xbeg, $xlen, $ybeg, $ylen ) {
915921 if ( $xlen > 1 ) {
916 - $xbeg .= "," . ( $xbeg + $xlen - 1 );
 922+ $xbeg .= ',' . ( $xbeg + $xlen - 1 );
917923 }
918924 if ( $ylen > 1 ) {
919 - $ybeg .= "," . ( $ybeg + $ylen - 1 );
 925+ $ybeg .= ',' . ( $ybeg + $ylen - 1 );
920926 }
921927
922928 return $xbeg . ( $xlen ? ( $ylen ? 'c' : 'd' ) : 'a' ) . $ybeg;
@@ -956,7 +962,6 @@
957963 * A formatter that outputs unified diffs
958964 * @ingroup DifferenceEngine
959965 */
960 -
961966 class UnifiedDiffFormatter extends DiffFormatter {
962967 var $leading_context_lines = 2;
963968 var $trailing_context_lines = 2;
@@ -990,29 +995,29 @@
991996 case 'add':
992997 foreach ( $edit->closing as $l ) {
993998 $retval[] = array(
994 - 'action' => 'add',
995 - 'new' => $l,
996 - 'newline' => $newline++
 999+ 'action' => 'add',
 1000+ 'new' => $l,
 1001+ 'newline' => $newline++
9971002 );
9981003 }
9991004 break;
10001005 case 'delete':
10011006 foreach ( $edit->orig as $l ) {
10021007 $retval[] = array(
1003 - 'action' => 'delete',
1004 - 'old' => $l,
1005 - 'oldline' => $oldline++,
 1008+ 'action' => 'delete',
 1009+ 'old' => $l,
 1010+ 'oldline' => $oldline++,
10061011 );
10071012 }
10081013 break;
10091014 case 'change':
10101015 foreach ( $edit->orig as $i => $l ) {
10111016 $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++,
10171022 );
10181023 }
10191024 break;
@@ -1026,8 +1031,7 @@
10271032 }
10281033
10291034 /**
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
10321036 */
10331037
10341038 define( 'NBSP', '&#160;' ); // iso-8859-x non-breaking space.
@@ -1038,36 +1042,36 @@
10391043 * @ingroup DifferenceEngine
10401044 */
10411045 class _HWLDF_WordAccumulator {
1042 - function __construct () {
 1046+ function __construct() {
10431047 $this->_lines = array();
10441048 $this->_line = '';
10451049 $this->_group = '';
10461050 $this->_tag = '';
10471051 }
10481052
1049 - function _flushGroup ( $new_tag ) {
 1053+ function _flushGroup( $new_tag ) {
10501054 if ( $this->_group !== '' ) {
10511055 if ( $this->_tag == 'ins' ) {
10521056 $this->_line .= '<ins class="diffchange diffchange-inline">' .
1053 - htmlspecialchars ( $this->_group ) . '</ins>';
 1057+ htmlspecialchars( $this->_group ) . '</ins>';
10541058 } elseif ( $this->_tag == 'del' ) {
10551059 $this->_line .= '<del class="diffchange diffchange-inline">' .
1056 - htmlspecialchars ( $this->_group ) . '</del>';
 1060+ htmlspecialchars( $this->_group ) . '</del>';
10571061 } else {
1058 - $this->_line .= htmlspecialchars ( $this->_group );
 1062+ $this->_line .= htmlspecialchars( $this->_group );
10591063 }
10601064 }
10611065 $this->_group = '';
10621066 $this->_tag = $new_tag;
10631067 }
10641068
1065 - function _flushLine ( $new_tag ) {
 1069+ function _flushLine( $new_tag ) {
10661070 $this->_flushGroup( $new_tag );
10671071 if ( $this->_line != '' ) {
1068 - array_push ( $this->_lines, $this->_line );
 1072+ array_push( $this->_lines, $this->_line );
10691073 } else {
10701074 # make empty lines visible by inserting an NBSP
1071 - array_push ( $this->_lines, NBSP );
 1075+ array_push( $this->_lines, NBSP );
10721076 }
10731077 $this->_line = '';
10741078 }
@@ -1108,8 +1112,8 @@
11091113 function __construct ( $orig_lines, $closing_lines ) {
11101114 wfProfileIn( __METHOD__ );
11111115
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 );
11141118
11151119 parent::__construct( $orig_words, $closing_words,
11161120 $orig_stripped, $closing_stripped );
@@ -1148,7 +1152,7 @@
11491153 return array( $words, $stripped );
11501154 }
11511155
1152 - function orig () {
 1156+ function orig() {
11531157 wfProfileIn( __METHOD__ );
11541158 $orig = new _HWLDF_WordAccumulator;
11551159
@@ -1164,7 +1168,7 @@
11651169 return $lines;
11661170 }
11671171
1168 - function closing () {
 1172+ function closing() {
11691173 wfProfileIn( __METHOD__ );
11701174 $closing = new _HWLDF_WordAccumulator;
11711175
@@ -1247,14 +1251,14 @@
12481252 foreach ( $lines as $line ) {
12491253 echo '<tr>' . $this->emptyLine() .
12501254 $this->addedLine( '<ins class="diffchange">' .
1251 - htmlspecialchars ( $line ) . '</ins>' ) . "</tr>\n";
 1255+ htmlspecialchars( $line ) . '</ins>' ) . "</tr>\n";
12521256 }
12531257 }
12541258
12551259 function _deleted( $lines ) {
12561260 foreach ( $lines as $line ) {
12571261 echo '<tr>' . $this->deletedLine( '<del class="diffchange">' .
1258 - htmlspecialchars ( $line ) . '</del>' ) .
 1262+ htmlspecialchars( $line ) . '</del>' ) .
12591263 $this->emptyLine() . "</tr>\n";
12601264 }
12611265 }
@@ -1262,8 +1266,8 @@
12631267 function _context( $lines ) {
12641268 foreach ( $lines as $line ) {
12651269 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";
12681272 }
12691273 }
12701274

Status & tagging log