Break long lines and formatting updates for includes/db/
[lhc/web/wiklou.git] / includes / db / Database.php
index e2c59ed..9ba1851 100644 (file)
@@ -208,7 +208,8 @@ interface DatabaseType {
  * Interface for classes that implement or wrap DatabaseBase
  * @ingroup Database
  */
-interface IDatabase {}
+interface IDatabase {
+}
 
 /**
  * Database abstraction object
@@ -626,7 +627,7 @@ abstract class DatabaseBase implements IDatabase, DatabaseType {
        /**
         * Clear a flag for this connection
         *
-        * @param $flag: same as setFlag()'s $flag param
+        * @param $flag : same as setFlag()'s $flag param
         */
        public function clearFlag( $flag ) {
                global $wgDebugDBTransactions;
@@ -639,7 +640,7 @@ abstract class DatabaseBase implements IDatabase, DatabaseType {
        /**
         * Returns a boolean whether the flag $flag is set for this connection
         *
-        * @param $flag: same as setFlag()'s $flag param
+        * @param $flag : same as setFlag()'s $flag param
         * @return Boolean
         */
        public function getFlag( $flag ) {
@@ -758,13 +759,14 @@ abstract class DatabaseBase implements IDatabase, DatabaseType {
         * not restored on unserialize.
         */
        public function __sleep() {
-               throw new MWException( 'Database serialization may cause problems, since the connection is not restored on wakeup.' );
+               throw new MWException( 'Database serialization may cause problems, since ' .
+                       'the connection is not restored on wakeup.' );
        }
 
        /**
         * Given a DB type, construct the name of the appropriate child class of
         * DatabaseBase. This is designed to replace all of the manual stuff like:
-        *      $class = 'Database' . ucfirst( strtolower( $dbType ) );
+        *    $class = 'Database' . ucfirst( strtolower( $dbType ) );
         * as well as validate against the canonical list of DB types we have
         *
         * This factory function is mostly useful for when you need to connect to a
@@ -784,11 +786,11 @@ abstract class DatabaseBase implements IDatabase, DatabaseType {
         */
        final public static function factory( $dbType, $p = array() ) {
                $canonicalDBTypes = array(
-                       'mysql'    => array( 'mysqli', 'mysql' ),
+                       'mysql' => array( 'mysqli', 'mysql' ),
                        'postgres' => array(),
-                       'sqlite'   => array(),
-                       'oracle'   => array(),
-                       'mssql'    => array(),
+                       'sqlite' => array(),
+                       'oracle' => array(),
+                       'mssql' => array(),
                );
 
                $driver = false;
@@ -829,6 +831,7 @@ abstract class DatabaseBase implements IDatabase, DatabaseType {
                                'tablePrefix' => isset( $p['tablePrefix'] ) ? $p['tablePrefix'] : 'get from global',
                                'foreign' => isset( $p['foreign'] ) ? $p['foreign'] : false
                        );
+
                        return new $class( $params );
                } else {
                        return null;
@@ -852,6 +855,7 @@ abstract class DatabaseBase implements IDatabase, DatabaseType {
                if ( $this->mPHPError ) {
                        $error = preg_replace( '!\[<a.*</a>\]!', '', $this->mPHPError );
                        $error = preg_replace( '!^.*?:\s?(.*)$!', '$1', $error );
+
                        return $error;
                } else {
                        return false;
@@ -891,6 +895,7 @@ abstract class DatabaseBase implements IDatabase, DatabaseType {
 
                        $ret = $this->closeConnection();
                        $this->mConn = false;
+
                        return $ret;
                } else {
                        return true;
@@ -987,8 +992,8 @@ abstract class DatabaseBase implements IDatabase, DatabaseType {
 
                # If DBO_TRX is set, start a transaction
                if ( ( $this->mFlags & DBO_TRX ) && !$this->mTrxLevel &&
-                       $sql != 'BEGIN' && $sql != 'COMMIT' && $sql != 'ROLLBACK' )
-               {
+                       $sql != 'BEGIN' && $sql != 'COMMIT' && $sql != 'ROLLBACK'
+               {
                        # Avoid establishing transactions for SHOW and SET statements too -
                        # that would delay transaction initializations to once connection
                        # is really used by application
@@ -1198,9 +1203,15 @@ abstract class DatabaseBase implements IDatabase, DatabaseType {
                                return $arg;
                        case '&':
                                # return $this->addQuotes( file_get_contents( $arg ) );
-                               throw new DBUnexpectedError( $this, '& mode is not implemented. If it\'s really needed, uncomment the line above.' );
+                               throw new DBUnexpectedError(
+                                       $this,
+                                       '& mode is not implemented. If it\'s really needed, uncomment the line above.'
+                               );
                        default:
-                               throw new DBUnexpectedError( $this, 'Received invalid match. This should never happen!' );
+                               throw new DBUnexpectedError(
+                                       $this,
+                                       'Received invalid match. This should never happen!'
+                               );
                }
        }
 
@@ -1362,6 +1373,7 @@ abstract class DatabaseBase implements IDatabase, DatabaseType {
                                : $options['HAVING'];
                        $sql .= ' HAVING ' . $having;
                }
+
                return $sql;
        }
 
@@ -1378,8 +1390,10 @@ abstract class DatabaseBase implements IDatabase, DatabaseType {
                        $ob = is_array( $options['ORDER BY'] )
                                ? implode( ',', $options['ORDER BY'] )
                                : $options['ORDER BY'];
+
                        return ' ORDER BY ' . $ob;
                }
+
                return '';
        }
 
@@ -1546,8 +1560,8 @@ abstract class DatabaseBase implements IDatabase, DatabaseType {
         * @see DatabaseBase::select()
         */
        public function selectSQLText( $table, $vars, $conds = '', $fname = __METHOD__,
-               $options = array(), $join_conds = array() )
-       {
+               $options = array(), $join_conds = array()
+       {
                if ( is_array( $vars ) ) {
                        $vars = implode( ',', $this->fieldNamesWithAlias( $vars ) );
                }
@@ -1611,8 +1625,8 @@ abstract class DatabaseBase implements IDatabase, DatabaseType {
         * @return object|bool
         */
        public function selectRow( $table, $vars, $conds, $fname = __METHOD__,
-               $options = array(), $join_conds = array() )
-       {
+               $options = array(), $join_conds = array()
+       {
                $options = (array)$options;
                $options['LIMIT'] = 1;
                $res = $this->select( $table, $vars, $conds, $fname, $options, $join_conds );
@@ -1651,8 +1665,8 @@ abstract class DatabaseBase implements IDatabase, DatabaseType {
         * @return Integer: row count
         */
        public function estimateRowCount( $table, $vars = '*', $conds = '',
-               $fname = __METHOD__, $options = array() )
-       {
+               $fname = __METHOD__, $options = array()
+       {
                $rows = 0;
                $res = $this->select( $table, array( 'rowcount' => 'COUNT(*)' ), $conds, $fname, $options );
 
@@ -1905,7 +1919,7 @@ abstract class DatabaseBase implements IDatabase, DatabaseType {
         * @param $table  String name of the table to UPDATE. This will be passed through
         *                DatabaseBase::tableName().
         *
-        * @param array $values  An array of values to SET. For each array element,
+        * @param array $values An array of values to SET. For each array element,
         *                the key gives the field name, and the value gives the data
         *                to set that field to. The data will be quoted by
         *                DatabaseBase::addQuotes().
@@ -2099,6 +2113,7 @@ abstract class DatabaseBase implements IDatabase, DatabaseType {
                $delim, $table, $field, $conds = '', $join_conds = array()
        ) {
                $fld = "GROUP_CONCAT($field SEPARATOR " . $this->addQuotes( $delim ) . ')';
+
                return '(' . $this->selectSQLText( $table, $fld, $conds, null, array(), $join_conds ) . ')';
        }
 
@@ -2116,6 +2131,7 @@ abstract class DatabaseBase implements IDatabase, DatabaseType {
                # if your database engine supports a concept similar to MySQL's
                # databases you may as well.
                $this->mDBname = $db;
+
                return true;
        }
 
@@ -2183,7 +2199,7 @@ abstract class DatabaseBase implements IDatabase, DatabaseType {
                        list( $table ) = $dbDetails;
                        if ( $wgSharedDB !== null # We have a shared database
                                && $this->mForeign == false # We're not working on a foreign database
-                               && !$this->isQuotedIdentifier( $table ) # Paranoia check to prevent shared tables listing '`table`'
+                               && !$this->isQuotedIdentifier( $table ) # Prevent shared tables listing '`table`'
                                && in_array( $table, $wgSharedTables ) # A shared table is selected
                        ) {
                                $database = $wgSharedDB;
@@ -2285,6 +2301,7 @@ abstract class DatabaseBase implements IDatabase, DatabaseType {
                        }
                        $retval[] = $this->tableNameWithAlias( $table, $alias );
                }
+
                return $retval;
        }
 
@@ -2318,6 +2335,7 @@ abstract class DatabaseBase implements IDatabase, DatabaseType {
                        }
                        $retval[] = $this->fieldNameWithAlias( $field, $alias );
                }
+
                return $retval;
        }
 
@@ -2462,13 +2480,17 @@ abstract class DatabaseBase implements IDatabase, DatabaseType {
        }
 
        /**
-        * LIKE statement wrapper, receives a variable-length argument list with parts of pattern to match
-        * containing either string literals that will be escaped or tokens returned by anyChar() or anyString().
-        * Alternatively, the function could be provided with an array of aforementioned parameters.
+        * LIKE statement wrapper, receives a variable-length argument list with
+        * parts of pattern to match containing either string literals that will be
+        * escaped or tokens returned by anyChar() or anyString(). Alternatively,
+        * the function could be provided with an array of aforementioned
+        * parameters.
         *
-        * Example: $dbr->buildLike( 'My_page_title/', $dbr->anyString() ) returns a LIKE clause that searches
-        * for subpages of 'My page title'.
-        * Alternatively: $pattern = array( 'My_page_title/', $dbr->anyString() ); $query .= $dbr->buildLike( $pattern );
+        * Example: $dbr->buildLike( 'My_page_title/', $dbr->anyString() ) returns
+        * a LIKE clause that searches for subpages of 'My page title'.
+        * Alternatively:
+        *   $pattern = array( 'My_page_title/', $dbr->anyString() );
+        *   $query .= $dbr->buildLike( $pattern );
         *
         * @since 1.16
         * @return String: fully built LIKE statement
@@ -2751,8 +2773,8 @@ abstract class DatabaseBase implements IDatabase, DatabaseType {
         * @throws DBUnexpectedError
         */
        public function deleteJoin( $delTable, $joinTable, $delVar, $joinVar, $conds,
-               $fname = __METHOD__ )
-       {
+               $fname = __METHOD__
+       {
                if ( !$conds ) {
                        throw new DBUnexpectedError( $this,
                                'DatabaseBase::deleteJoin() called with empty $conds' );
@@ -2863,8 +2885,8 @@ abstract class DatabaseBase implements IDatabase, DatabaseType {
         */
        public function insertSelect( $destTable, $srcTable, $varMap, $conds,
                $fname = __METHOD__,
-               $insertOptions = array(), $selectOptions = array() )
-       {
+               $insertOptions = array(), $selectOptions = array()
+       {
                $destTable = $this->tableName( $destTable );
 
                if ( is_array( $insertOptions ) ) {
@@ -2923,6 +2945,7 @@ abstract class DatabaseBase implements IDatabase, DatabaseType {
                if ( !is_numeric( $limit ) ) {
                        throw new DBUnexpectedError( $this, "Invalid non-numeric limit passed to limitResult()\n" );
                }
+
                return "$sql LIMIT "
                        . ( ( is_numeric( $offset ) && $offset != 0 ) ? "{$offset}," : "" )
                        . "{$limit} ";
@@ -2947,6 +2970,7 @@ abstract class DatabaseBase implements IDatabase, DatabaseType {
         */
        public function unionQueries( $sqls, $all ) {
                $glue = $all ? ') UNION ALL (' : ') UNION (';
+
                return '(' . implode( $glue, $sqls ) . ')';
        }
 
@@ -2963,6 +2987,7 @@ abstract class DatabaseBase implements IDatabase, DatabaseType {
                if ( is_array( $cond ) ) {
                        $cond = $this->makeList( $cond, LIST_AND );
                }
+
                return " (CASE WHEN $cond THEN $trueVal ELSE $falseVal END) ";
        }
 
@@ -3083,9 +3108,11 @@ abstract class DatabaseBase implements IDatabase, DatabaseType {
                if ( $tries <= 0 ) {
                        $this->rollback( __METHOD__ );
                        $this->reportQueryError( $error, $errno, $sql, $fname );
+
                        return false;
                } else {
                        $this->commit( __METHOD__ );
+
                        return $retVal;
                }
        }
@@ -3110,15 +3137,18 @@ abstract class DatabaseBase implements IDatabase, DatabaseType {
                        if ( $wait > $timeout * 1e6 ) {
                                wfDebug( "Fake slave timed out waiting for $pos ($wait us)\n" );
                                wfProfileOut( __METHOD__ );
+
                                return -1;
                        } elseif ( $wait > 0 ) {
                                wfDebug( "Fake slave waiting $wait us\n" );
                                usleep( $wait );
                                wfProfileOut( __METHOD__ );
+
                                return 1;
                        } else {
                                wfDebug( "Fake slave up to date ($wait us)\n" );
                                wfProfileOut( __METHOD__ );
+
                                return 0;
                        }
                }
@@ -3138,6 +3168,7 @@ abstract class DatabaseBase implements IDatabase, DatabaseType {
                if ( !is_null( $this->mFakeSlaveLag ) ) {
                        $pos = new MySQLMasterPos( 'fake', microtime( true ) - $this->mFakeSlaveLag );
                        wfDebug( __METHOD__ . ": fake slave pos = $pos\n" );
+
                        return $pos;
                } else {
                        # Stub
@@ -3216,7 +3247,8 @@ abstract class DatabaseBase implements IDatabase, DatabaseType {
                                        $this->clearFlag( DBO_TRX ); // make each query its own transaction
                                        call_user_func( $phpCallback );
                                        $this->setFlag( $autoTrx ? DBO_TRX : 0 ); // restore automatic begin()
-                               } catch ( Exception $e ) {}
+                               } catch ( Exception $e ) {
+                               }
                        }
                } while ( count( $this->mTrxIdleCallbacks ) );
 
@@ -3239,7 +3271,8 @@ abstract class DatabaseBase implements IDatabase, DatabaseType {
                                try {
                                        list( $phpCallback ) = $callback;
                                        call_user_func( $phpCallback );
-                               } catch ( Exception $e ) {}
+                               } catch ( Exception $e ) {
+                               }
                        }
                } while ( count( $this->mTrxPreCommitCallbacks ) );
 
@@ -3309,14 +3342,16 @@ abstract class DatabaseBase implements IDatabase, DatabaseType {
        }
 
        /**
-        * Begin a transaction. If a transaction is already in progress, that transaction will be committed before the
-        * new transaction is started.
+        * Begin a transaction. If a transaction is already in progress,
+        * that transaction will be committed before the new transaction is started.
         *
-        * Note that when the DBO_TRX flag is set (which is usually the case for web requests, but not for maintenance scripts),
-        * any previous database query will have started a transaction automatically.
+        * Note that when the DBO_TRX flag is set (which is usually the case for web
+        * requests, but not for maintenance scripts), any previous database query
+        * will have started a transaction automatically.
         *
-        * Nesting of transactions is not supported. Attempts to nest transactions will cause a warning, unless the current
-        * transaction was started automatically because of the DBO_TRX flag.
+        * Nesting of transactions is not supported. Attempts to nest transactions
+        * will cause a warning, unless the current transaction was started
+        * automatically because of the DBO_TRX flag.
         *
         * @param $fname string
         * @throws DBError
@@ -3384,15 +3419,19 @@ abstract class DatabaseBase implements IDatabase, DatabaseType {
         * Nesting of transactions is not supported.
         *
         * @param $fname string
-        * @param string $flush Flush flag, set to 'flush' to disable warnings about explicitly committing implicit
-        *        transactions, or calling commit when no transaction is in progress.
-        *        This will silently break any ongoing explicit transaction. Only set the flush flag if you are sure
-        *        that it is safe to ignore these warnings in your context.
+        * @param string $flush Flush flag, set to 'flush' to disable warnings about
+        *   explicitly committing implicit transactions, or calling commit when no
+        *   transaction is in progress. This will silently break any ongoing
+        *   explicit transaction. Only set the flush flag if you are sure that it
+        *   is safe to ignore these warnings in your context.
         */
        final public function commit( $fname = __METHOD__, $flush = '' ) {
                if ( !$this->mTrxAtomicLevels->isEmpty() ) {
                        // There are still atomic sections open. This cannot be ignored
-                       throw new DBUnexpectedError( $this, "Attempted to commit transaction while atomic sections are still open" );
+                       throw new DBUnexpectedError(
+                               $this,
+                               "Attempted to commit transaction while atomic sections are still open"
+                       );
                }
 
                if ( $flush != 'flush' ) {
@@ -3511,8 +3550,8 @@ abstract class DatabaseBase implements IDatabase, DatabaseType {
         * For caching purposes the list of all views should be stored in
         * $this->allViews. The process cache can be cleared with clearViewsCache()
         *
-        * @param string $prefix   Only show VIEWs with this prefix, eg. unit_test_
-        * @param string $fname    Name of calling function
+        * @param string $prefix Only show VIEWs with this prefix, eg. unit_test_
+        * @param string $fname Name of calling function
         * @throws MWException
         * @since 1.22
         */
@@ -3673,8 +3712,9 @@ abstract class DatabaseBase implements IDatabase, DatabaseType {
         * @param bool|callable $lineCallback Optional function called before reading each line
         * @param bool|callable $resultCallback Optional function called for each MySQL result
         * @param bool|string $fname Calling function name or false if name should be
-        *      generated dynamically using $filename
-        * @param bool|callable $inputCallback Callback: Optional function called for each complete line sent
+        *   generated dynamically using $filename
+        * @param bool|callable $inputCallback Callback: Optional function called
+        *   for each complete line sent
         * @throws MWException
         * @throws Exception|MWException
         * @return bool|string
@@ -3696,8 +3736,7 @@ abstract class DatabaseBase implements IDatabase, DatabaseType {
 
                try {
                        $error = $this->sourceStream( $fp, $lineCallback, $resultCallback, $fname, $inputCallback );
-               }
-               catch ( MWException $e ) {
+               } catch ( MWException $e ) {
                        fclose( $fp );
                        throw $e;
                }
@@ -3751,8 +3790,8 @@ abstract class DatabaseBase implements IDatabase, DatabaseType {
         * @return bool|string
         */
        public function sourceStream( $fp, $lineCallback = false, $resultCallback = false,
-               $fname = __METHOD__, $inputCallback = false )
-       {
+               $fname = __METHOD__, $inputCallback = false
+       {
                $cmd = '';
 
                while ( !feof( $fp ) ) {
@@ -3790,6 +3829,7 @@ abstract class DatabaseBase implements IDatabase, DatabaseType {
 
                                        if ( false === $res ) {
                                                $err = $this->lastError();
+
                                                return "Query \"{$cmd}\" failed with error code \"$err\".\n";
                                        }
                                }
@@ -3815,6 +3855,7 @@ abstract class DatabaseBase implements IDatabase, DatabaseType {
                                return true;
                        }
                }
+
                return false;
        }
 
@@ -3845,6 +3886,7 @@ abstract class DatabaseBase implements IDatabase, DatabaseType {
                        // replace /*$var*/
                        $ins = str_replace( '/*$' . $var . '*/', $this->strencode( $value ), $ins );
                }
+
                return $ins;
        }
 
@@ -3998,6 +4040,7 @@ abstract class DatabaseBase implements IDatabase, DatabaseType {
                if ( $this->cascadingDeletes() ) {
                        $sql .= " CASCADE";
                }
+
                return $this->query( $sql, $fName );
        }
 
@@ -4078,7 +4121,6 @@ abstract class DatabaseBase implements IDatabase, DatabaseType {
                        $callers = array();
                        foreach ( $this->mTrxIdleCallbacks as $callbackInfo ) {
                                $callers[] = $callbackInfo[1];
-
                        }
                        $callers = implode( ', ', $callers );
                        trigger_error( "DB transaction callbacks still pending (from $callers)." );