Merge "Remove taint support"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Wed, 8 May 2013 22:48:33 +0000 (22:48 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Wed, 8 May 2013 22:48:33 +0000 (22:48 +0000)
1  2 
includes/db/Database.php

diff --combined includes/db/Database.php
   * @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
@@@ -158,7 -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
   * @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
         * @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
                        wfDebug( "Query {$this->mDBname} ($cnt) ($master): $sqlx\n" );
                }
  
-               if ( istainted( $sql ) & TC_MYSQL ) {
-                       if ( !Profiler::instance()->isStub() ) {
-                               wfProfileOut( $queryProf );
-                               wfProfileOut( $totalProf );
-                       }
-                       throw new MWException( 'Tainted query found' );
-               }
                $queryId = MWDebug::query( $sql, $fname, $isMaster );
  
                # Do the query and handle errors
         *
         * @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 ) ) {
         *   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 );
  
         * @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 ) ) {
         *
         * @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;
         * @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 );
         * @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;
         *
         * @return bool|null
         */
 -      public function indexExists( $table, $index, $fname = 'DatabaseBase::indexExists' ) {
 +      public function indexExists( $table, $index, $fname = __METHOD__ ) {
                if ( !$this->tableExists( $table ) ) {
                        return null;
                }
         *
         * @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;
         *                   - 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 );
         *    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 ) {
         * @throws DBUnexpectedError
         */
        public function deleteJoin( $delTable, $joinTable, $delVar, $joinVar, $conds,
 -              $fname = 'DatabaseBase::deleteJoin' )
 +              $fname = __METHOD__ )
        {
                if ( !$conds ) {
                        throw new DBUnexpectedError( $this,
         * @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' );
                }
         * @return ResultWrapper
         */
        public function insertSelect( $destTable, $srcTable, $varMap, $conds,
 -              $fname = 'DatabaseBase::insertSelect',
 +              $fname = __METHOD__,
                $insertOptions = array(), $selectOptions = array() )
        {
                $destTable = $this->tableName( $destTable );
                $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];
                        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 );
                                }
         *
         * @param $fname string
         */
 -      final public function begin( $fname = 'DatabaseBase::begin' ) {
 +      final public function begin( $fname = __METHOD__ ) {
                global $wgDebugDBTransactions;
  
                if ( $this->mTrxLevel ) { // implicit commit
         *        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!" );
         *
         * @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!" );
                }
         * @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' );
         * @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' );
        }
  
         * @return bool|string
         */
        public function sourceStream( $fp, $lineCallback = false, $resultCallback = false,
 -              $fname = 'DatabaseBase::sourceStream', $inputCallback = false )
 +              $fname = __METHOD__, $inputCallback = false )
        {
                $cmd = '';
  
         * @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;
                }