Merge "Remove taint support"
[lhc/web/wiklou.git] / includes / db / Database.php
index f9d5407..85c459e 100644 (file)
  * @ingroup Database
  */
 
-/** Number of times to re-try an operation in case of deadlock */
-define( 'DEADLOCK_TRIES', 4 );
-/** Minimum time to wait before retry, in microseconds */
-define( 'DEADLOCK_DELAY_MIN', 500000 );
-/** Maximum time to wait before retry */
-define( 'DEADLOCK_DELAY_MAX', 1500000 );
-
 /**
  * Base interface for all DBMS-specific code. At a bare minimum, all of the
  * following must be implemented to support MediaWiki
@@ -165,7 +158,7 @@ interface DatabaseType {
         * @param string $fname Calling function name
         * @return Mixed: Database-specific index description class or false if the index does not exist
         */
-       function indexInfo( $table, $index, $fname = 'Database::indexInfo' );
+       function indexInfo( $table, $index, $fname = __METHOD__ );
 
        /**
         * Get the number of rows affected by the last write query
@@ -216,6 +209,12 @@ interface DatabaseType {
  * @ingroup Database
  */
 abstract class DatabaseBase implements DatabaseType {
+       /** Number of times to re-try an operation in case of deadlock */
+       const DEADLOCK_TRIES = 4;
+       /** Minimum time to wait before retry, in microseconds */
+       const DEADLOCK_DELAY_MIN = 500000;
+       /** Maximum time to wait before retry */
+       const DEADLOCK_DELAY_MAX = 1500000;
 
 # ------------------------------------------------------------------------------
 # Variables
@@ -871,7 +870,7 @@ abstract class DatabaseBase implements DatabaseType {
         * @return boolean|ResultWrapper. true for a successful write query, ResultWrapper object
         *     for a successful read query, or false on failure if $tempIgnore set
         */
-       public function query( $sql, $fname = '', $tempIgnore = false ) {
+       public function query( $sql, $fname = __METHOD__, $tempIgnore = false ) {
                $isMaster = !is_null( $this->getLBInfo( 'master' ) );
                if ( !Profiler::instance()->isStub() ) {
                        # generalizeSQL will probably cut down the query to reasonable
@@ -1140,7 +1139,7 @@ abstract class DatabaseBase implements DatabaseType {
         *
         * @return bool|mixed The value from the field, or false on failure.
         */
-       public function selectField( $table, $var, $cond = '', $fname = 'DatabaseBase::selectField',
+       public function selectField( $table, $var, $cond = '', $fname = __METHOD__,
                $options = array()
        ) {
                if ( !is_array( $options ) ) {
@@ -1431,7 +1430,7 @@ abstract class DatabaseBase implements DatabaseType {
         *   DBQueryError exception will be thrown, except if the "ignore errors"
         *   option was set, in which case false will be returned.
         */
-       public function select( $table, $vars, $conds = '', $fname = 'DatabaseBase::select',
+       public function select( $table, $vars, $conds = '', $fname = __METHOD__,
                $options = array(), $join_conds = array() ) {
                $sql = $this->selectSQLText( $table, $vars, $conds, $fname, $options, $join_conds );
 
@@ -1454,7 +1453,7 @@ abstract class DatabaseBase implements DatabaseType {
         * @return string SQL query string.
         * @see DatabaseBase::select()
         */
-       public function selectSQLText( $table, $vars, $conds = '', $fname = 'DatabaseBase::select',
+       public function selectSQLText( $table, $vars, $conds = '', $fname = __METHOD__,
                $options = array(), $join_conds = array() )
        {
                if ( is_array( $vars ) ) {
@@ -1521,7 +1520,7 @@ abstract class DatabaseBase implements DatabaseType {
         *
         * @return object|bool
         */
-       public function selectRow( $table, $vars, $conds, $fname = 'DatabaseBase::selectRow',
+       public function selectRow( $table, $vars, $conds, $fname = __METHOD__,
                $options = array(), $join_conds = array() )
        {
                $options = (array)$options;
@@ -1562,7 +1561,7 @@ abstract class DatabaseBase implements DatabaseType {
         * @return Integer: row count
         */
        public function estimateRowCount( $table, $vars = '*', $conds = '',
-               $fname = 'DatabaseBase::estimateRowCount', $options = array() )
+               $fname = __METHOD__, $options = array() )
        {
                $rows = 0;
                $res = $this->select( $table, array( 'rowcount' => 'COUNT(*)' ), $conds, $fname, $options );
@@ -1611,7 +1610,7 @@ abstract class DatabaseBase implements DatabaseType {
         * @param string $fname calling function name (optional)
         * @return Boolean: whether $table has filed $field
         */
-       public function fieldExists( $table, $field, $fname = 'DatabaseBase::fieldExists' ) {
+       public function fieldExists( $table, $field, $fname = __METHOD__ ) {
                $info = $this->fieldInfo( $table, $field );
 
                return (bool)$info;
@@ -1628,7 +1627,7 @@ abstract class DatabaseBase implements DatabaseType {
         *
         * @return bool|null
         */
-       public function indexExists( $table, $index, $fname = 'DatabaseBase::indexExists' ) {
+       public function indexExists( $table, $index, $fname = __METHOD__ ) {
                if ( !$this->tableExists( $table ) ) {
                        return null;
                }
@@ -1733,7 +1732,7 @@ abstract class DatabaseBase implements DatabaseType {
         *
         * @return bool
         */
-       public function insert( $table, $a, $fname = 'DatabaseBase::insert', $options = array() ) {
+       public function insert( $table, $a, $fname = __METHOD__, $options = array() ) {
                # No rows to insert, easy just return now
                if ( !count( $a ) ) {
                        return true;
@@ -1832,7 +1831,7 @@ abstract class DatabaseBase implements DatabaseType {
         *                   - LOW_PRIORITY: MySQL-specific, see MySQL manual.
         * @return Boolean
         */
-       function update( $table, $values, $conds, $fname = 'DatabaseBase::update', $options = array() ) {
+       function update( $table, $values, $conds, $fname = __METHOD__, $options = array() ) {
                $table = $this->tableName( $table );
                $opts = $this->makeUpdateOptions( $options );
                $sql = "UPDATE $opts $table SET " . $this->makeList( $values, LIST_SET );
@@ -2449,7 +2448,7 @@ abstract class DatabaseBase implements DatabaseType {
         *    a field name or an array of field names
         * @param string $fname Calling function name (use __METHOD__) for logs/profiling
         */
-       public function replace( $table, $uniqueIndexes, $rows, $fname = 'DatabaseBase::replace' ) {
+       public function replace( $table, $uniqueIndexes, $rows, $fname = __METHOD__ ) {
                $quotedTable = $this->tableName( $table );
 
                if ( count( $rows ) == 0 ) {
@@ -2552,7 +2551,7 @@ abstract class DatabaseBase implements DatabaseType {
         * @throws DBUnexpectedError
         */
        public function deleteJoin( $delTable, $joinTable, $delVar, $joinVar, $conds,
-               $fname = 'DatabaseBase::deleteJoin' )
+               $fname = __METHOD__ )
        {
                if ( !$conds ) {
                        throw new DBUnexpectedError( $this,
@@ -2618,7 +2617,7 @@ abstract class DatabaseBase implements DatabaseType {
         * @throws DBUnexpectedError
         * @return bool|ResultWrapper
         */
-       public function delete( $table, $conds, $fname = 'DatabaseBase::delete' ) {
+       public function delete( $table, $conds, $fname = __METHOD__ ) {
                if ( !$conds ) {
                        throw new DBUnexpectedError( $this, 'DatabaseBase::delete() called with no conditions' );
                }
@@ -2660,7 +2659,7 @@ abstract class DatabaseBase implements DatabaseType {
         * @return ResultWrapper
         */
        public function insertSelect( $destTable, $srcTable, $varMap, $conds,
-               $fname = 'DatabaseBase::insertSelect',
+               $fname = __METHOD__,
                $insertOptions = array(), $selectOptions = array() )
        {
                $destTable = $this->tableName( $destTable );
@@ -2852,7 +2851,7 @@ abstract class DatabaseBase implements DatabaseType {
                $args = func_get_args();
                $function = array_shift( $args );
                $oldIgnore = $this->ignoreErrors( true );
-               $tries = DEADLOCK_TRIES;
+               $tries = self::DEADLOCK_TRIES;
 
                if ( is_array( $function ) ) {
                        $fname = $function[0];
@@ -2869,7 +2868,7 @@ abstract class DatabaseBase implements DatabaseType {
                        if ( $errno ) {
                                if ( $this->wasDeadlock() ) {
                                        # Retry
-                                       usleep( mt_rand( DEADLOCK_DELAY_MIN, DEADLOCK_DELAY_MAX ) );
+                                       usleep( mt_rand( self::DEADLOCK_DELAY_MIN, self::DEADLOCK_DELAY_MAX ) );
                                } else {
                                        $this->reportQueryError( $error, $errno, $sql, $fname );
                                }
@@ -3057,7 +3056,7 @@ abstract class DatabaseBase implements DatabaseType {
         *
         * @param $fname string
         */
-       final public function begin( $fname = 'DatabaseBase::begin' ) {
+       final public function begin( $fname = __METHOD__ ) {
                global $wgDebugDBTransactions;
 
                if ( $this->mTrxLevel ) { // implicit commit
@@ -3112,7 +3111,7 @@ abstract class DatabaseBase implements DatabaseType {
         *        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 = 'DatabaseBase::commit', $flush = '' ) {
+       final public function commit( $fname = __METHOD__, $flush = '' ) {
                if ( $flush != 'flush' ) {
                        if ( !$this->mTrxLevel ) {
                                wfWarn( "$fname: No transaction to commit, something got out of sync!" );
@@ -3153,7 +3152,7 @@ abstract class DatabaseBase implements DatabaseType {
         *
         * @param $fname string
         */
-       final public function rollback( $fname = 'DatabaseBase::rollback' ) {
+       final public function rollback( $fname = __METHOD__ ) {
                if ( !$this->mTrxLevel ) {
                        wfWarn( "$fname: No transaction to rollback, something got out of sync!" );
                }
@@ -3191,7 +3190,7 @@ abstract class DatabaseBase implements DatabaseType {
         * @return Boolean: true if operation was successful
         */
        public function duplicateTableStructure( $oldName, $newName, $temporary = false,
-               $fname = 'DatabaseBase::duplicateTableStructure'
+               $fname = __METHOD__
        ) {
                throw new MWException(
                        'DatabaseBase::duplicateTableStructure is not implemented in descendant class' );
@@ -3204,7 +3203,7 @@ abstract class DatabaseBase implements DatabaseType {
         * @param string $fname calling function name
         * @throws MWException
         */
-       function listTables( $prefix = null, $fname = 'DatabaseBase::listTables' ) {
+       function listTables( $prefix = null, $fname = __METHOD__ ) {
                throw new MWException( 'DatabaseBase::listTables is not implemented in descendant class' );
        }
 
@@ -3428,7 +3427,7 @@ abstract class DatabaseBase implements DatabaseType {
         * @return bool|string
         */
        public function sourceStream( $fp, $lineCallback = false, $resultCallback = false,
-               $fname = 'DatabaseBase::sourceStream', $inputCallback = false )
+               $fname = __METHOD__, $inputCallback = false )
        {
                $cmd = '';
 
@@ -3667,7 +3666,7 @@ abstract class DatabaseBase implements DatabaseType {
         * @return bool|ResultWrapper
         * @since 1.18
         */
-       public function dropTable( $tableName, $fName = 'DatabaseBase::dropTable' ) {
+       public function dropTable( $tableName, $fName = __METHOD__ ) {
                if ( !$this->tableExists( $tableName, $fName ) ) {
                        return false;
                }