r71973 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r71972‎ | r71973 | r71974 >
Date:20:28, 30 August 2010
Author:reedy
Status:ok
Tags:
Comment:
Spaces and braces
Modified paths:
  • /trunk/phase3/includes/db/Database.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/db/Database.php
@@ -711,9 +711,15 @@
712712 }
713713 }
714714
715 - if ( isset( $options['GROUP BY'] ) ) $preLimitTail .= " GROUP BY {$options['GROUP BY']}";
716 - if ( isset( $options['HAVING'] ) ) $preLimitTail .= " HAVING {$options['HAVING']}";
717 - if ( isset( $options['ORDER BY'] ) ) $preLimitTail .= " ORDER BY {$options['ORDER BY']}";
 715+ if ( isset( $options['GROUP BY'] ) ) {
 716+ $preLimitTail .= " GROUP BY {$options['GROUP BY']}";
 717+ }
 718+ if ( isset( $options['HAVING'] ) ) {
 719+ $preLimitTail .= " HAVING {$options['HAVING']}";
 720+ }
 721+ if ( isset( $options['ORDER BY'] ) ) {
 722+ $preLimitTail .= " ORDER BY {$options['ORDER BY']}";
 723+ }
718724
719725 //if (isset($options['LIMIT'])) {
720726 // $tailOpts .= $this->limitResult('', $options['LIMIT'],
@@ -721,19 +727,41 @@
722728 // : false);
723729 //}
724730
725 - if ( isset( $noKeyOptions['FOR UPDATE'] ) ) $postLimitTail .= ' FOR UPDATE';
726 - if ( isset( $noKeyOptions['LOCK IN SHARE MODE'] ) ) $postLimitTail .= ' LOCK IN SHARE MODE';
727 - if ( isset( $noKeyOptions['DISTINCT'] ) || isset( $noKeyOptions['DISTINCTROW'] ) ) $startOpts .= 'DISTINCT';
 731+ if ( isset( $noKeyOptions['FOR UPDATE'] ) ) {
 732+ $postLimitTail .= ' FOR UPDATE';
 733+ }
 734+ if ( isset( $noKeyOptions['LOCK IN SHARE MODE'] ) ) {
 735+ $postLimitTail .= ' LOCK IN SHARE MODE';
 736+ }
 737+ if ( isset( $noKeyOptions['DISTINCT'] ) || isset( $noKeyOptions['DISTINCTROW'] ) ) {
 738+ $startOpts .= 'DISTINCT';
 739+ }
728740
729741 # Various MySQL extensions
730 - if ( isset( $noKeyOptions['STRAIGHT_JOIN'] ) ) $startOpts .= ' /*! STRAIGHT_JOIN */';
731 - if ( isset( $noKeyOptions['HIGH_PRIORITY'] ) ) $startOpts .= ' HIGH_PRIORITY';
732 - if ( isset( $noKeyOptions['SQL_BIG_RESULT'] ) ) $startOpts .= ' SQL_BIG_RESULT';
733 - if ( isset( $noKeyOptions['SQL_BUFFER_RESULT'] ) ) $startOpts .= ' SQL_BUFFER_RESULT';
734 - if ( isset( $noKeyOptions['SQL_SMALL_RESULT'] ) ) $startOpts .= ' SQL_SMALL_RESULT';
735 - if ( isset( $noKeyOptions['SQL_CALC_FOUND_ROWS'] ) ) $startOpts .= ' SQL_CALC_FOUND_ROWS';
736 - if ( isset( $noKeyOptions['SQL_CACHE'] ) ) $startOpts .= ' SQL_CACHE';
737 - if ( isset( $noKeyOptions['SQL_NO_CACHE'] ) ) $startOpts .= ' SQL_NO_CACHE';
 742+ if ( isset( $noKeyOptions['STRAIGHT_JOIN'] ) ) {
 743+ $startOpts .= ' /*! STRAIGHT_JOIN */';
 744+ }
 745+ if ( isset( $noKeyOptions['HIGH_PRIORITY'] ) ) {
 746+ $startOpts .= ' HIGH_PRIORITY';
 747+ }
 748+ if ( isset( $noKeyOptions['SQL_BIG_RESULT'] ) ) {
 749+ $startOpts .= ' SQL_BIG_RESULT';
 750+ }
 751+ if ( isset( $noKeyOptions['SQL_BUFFER_RESULT'] ) ) {
 752+ $startOpts .= ' SQL_BUFFER_RESULT';
 753+ }
 754+ if ( isset( $noKeyOptions['SQL_SMALL_RESULT'] ) ) {
 755+ $startOpts .= ' SQL_SMALL_RESULT';
 756+ }
 757+ if ( isset( $noKeyOptions['SQL_CALC_FOUND_ROWS'] ) ) {
 758+ $startOpts .= ' SQL_CALC_FOUND_ROWS';
 759+ }
 760+ if ( isset( $noKeyOptions['SQL_CACHE'] ) ) {
 761+ $startOpts .= ' SQL_CACHE';
 762+ }
 763+ if ( isset( $noKeyOptions['SQL_NO_CACHE'] ) ) {
 764+ $startOpts .= ' SQL_NO_CACHE';
 765+ }
738766
739767 if ( isset( $options['USE INDEX'] ) && ! is_array( $options['USE INDEX'] ) ) {
740768 $useIndex = $this->useIndexClause( $options['USE INDEX'] );
@@ -783,10 +811,11 @@
784812 $options = array( $options );
785813 }
786814 if( is_array( $table ) ) {
787 - if ( !empty($join_conds) || ( isset( $options['USE INDEX'] ) && is_array( @$options['USE INDEX'] ) ) )
 815+ if ( !empty($join_conds) || ( isset( $options['USE INDEX'] ) && is_array( @$options['USE INDEX'] ) ) ) {
788816 $from = ' FROM ' . $this->tableNamesWithUseIndexOrJOIN( $table, @$options['USE INDEX'], $join_conds );
789 - else
 817+ } else {
790818 $from = ' FROM ' . implode( ',', array_map( array( &$this, 'tableName' ), $table ) );
 819+ }
791820 } elseif ($table!='') {
792821 if ($table{0}==' ') {
793822 $from = ' FROM ' . $table;
@@ -840,8 +869,9 @@
841870 function selectRow( $table, $vars, $conds, $fname = 'DatabaseBase::selectRow', $options = array(), $join_conds = array() ) {
842871 $options['LIMIT'] = 1;
843872 $res = $this->select( $table, $vars, $conds, $fname, $options, $join_conds );
844 - if ( $res === false )
 873+ if ( $res === false ) {
845874 return false;
 875+ }
846876 if ( !$this->numRows($res) ) {
847877 return false;
848878 }
@@ -1114,7 +1144,7 @@
11151145 } elseif ( ($mode == LIST_SET) && is_numeric( $field ) ) {
11161146 $list .= "$value";
11171147 } elseif ( ($mode == LIST_AND || $mode == LIST_OR) && is_array($value) ) {
1118 - if( count( $value ) == 0 ) {
 1148+ if ( count( $value ) == 0 ) {
11191149 throw new MWException( __METHOD__.': empty input' );
11201150 } elseif( count( $value ) == 1 ) {
11211151 // Special-case single values, as IN isn't terribly efficient
@@ -1125,7 +1155,7 @@
11261156 } else {
11271157 $list .= $field." IN (".$this->makeList($value).") ";
11281158 }
1129 - } elseif( $value === null ) {
 1159+ } elseif ( $value === null ) {
11301160 if ( $mode == LIST_AND || $mode == LIST_OR ) {
11311161 $list .= "$field IS ";
11321162 } elseif ( $mode == LIST_SET ) {
@@ -1377,7 +1407,7 @@
13781408 'un_user_id' => 'user_id',
13791409 'un_user_ip' => 'user_ip',
13801410 );
1381 - if( isset( $renamed[$index] ) ) {
 1411+ if ( isset( $renamed[$index] ) ) {
13821412 return $renamed[$index];
13831413 } else {
13841414 return $index;
@@ -1614,7 +1644,7 @@
16151645 $selectOptions = array( $selectOptions );
16161646 }
16171647 list( $startOpts, $useIndex, $tailOpts ) = $this->makeSelectOptions( $selectOptions );
1618 - if( is_array( $srcTable ) ) {
 1648+ if ( is_array( $srcTable ) ) {
16191649 $srcTable = implode( ',', array_map( array( &$this, 'tableName' ), $srcTable ) );
16201650 } else {
16211651 $srcTable = $this->tableName( $srcTable );
@@ -1774,7 +1804,7 @@
17751805 $this->reportQueryError( $error, $errno, $sql, $fname );
17761806 }
17771807 }
1778 - } while( $this->wasDeadlock() && --$tries > 0 );
 1808+ } while ( $this->wasDeadlock() && --$tries > 0 );
17791809 $this->ignoreErrors( $oldIgnore );
17801810 if ( $tries <= 0 ) {
17811811 $this->rollback( $myFname );
@@ -1942,7 +1972,7 @@
19431973 * Local database timestamp format or null
19441974 */
19451975 function timestampOrNull( $ts = null ) {
1946 - if( is_null( $ts ) ) {
 1976+ if ( is_null( $ts ) ) {
19471977 return null;
19481978 } else {
19491979 return $this->timestamp( $ts );
@@ -1953,7 +1983,7 @@
19541984 * @todo document
19551985 */
19561986 function resultObject( $result ) {
1957 - if( empty( $result ) ) {
 1987+ if ( empty( $result ) ) {
19581988 return false;
19591989 } elseif ( $result instanceof ResultWrapper ) {
19601990 return $result;
@@ -2095,8 +2125,12 @@
20962126 $line = trim( fgets( $fp, 1024 ) );
20972127 $sl = strlen( $line ) - 1;
20982128
2099 - if ( $sl < 0 ) { continue; }
2100 - if ( '-' == $line{0} && '-' == $line{1} ) { continue; }
 2129+ if ( $sl < 0 ) {
 2130+ continue;
 2131+ }
 2132+ if ( '-' == $line{0} && '-' == $line{1} ) {
 2133+ continue;
 2134+ }
21012135
21022136 ## Allow dollar quoting for function declarations
21032137 if (substr($line,0,4) == '$mw$') {
@@ -2115,7 +2149,9 @@
21162150 }
21172151 }
21182152
2119 - if ( $cmd != '' ) { $cmd .= ' '; }
 2153+ if ( $cmd != '' ) {
 2154+ $cmd .= ' ';
 2155+ }
21202156 $cmd .= "$line\n";
21212157
21222158 if ( $done ) {
@@ -2151,7 +2187,7 @@
21522188
21532189 // Ordinary variables
21542190 foreach ( $varnames as $var ) {
2155 - if( isset( $GLOBALS[$var] ) ) {
 2191+ if ( isset( $GLOBALS[$var] ) ) {
21562192 $val = addslashes( $GLOBALS[$var] ); // FIXME: safety check?
21572193 $ins = str_replace( '{$' . $var . '}', $val, $ins );
21582194 $ins = str_replace( '/*$' . $var . '*/`', '`' . $val, $ins );

Status & tagging log