Kill some crappy "failFunction" stuff, marked as old in r14625
authorSam Reed <reedy@users.mediawiki.org>
Wed, 18 Aug 2010 13:38:42 +0000 (13:38 +0000)
committerSam Reed <reedy@users.mediawiki.org>
Wed, 18 Aug 2010 13:38:42 +0000 (13:38 +0000)
includes/db/Database.php
includes/db/DatabaseIbm_db2.php
includes/db/DatabaseMssql.php
includes/db/DatabaseOracle.php
includes/db/DatabasePostgres.php
includes/db/DatabaseSqlite.php
includes/db/LoadBalancer.php
maintenance/tests/SearchUpdateTest.php

index ce676e8..222a962 100644 (file)
@@ -32,7 +32,6 @@ abstract class DatabaseBase {
        protected $mServer, $mUser, $mPassword, $mConn = null, $mDBname;
        protected $mOpened = false;
 
-       protected $mFailFunction;
        protected $mTablePrefix;
        protected $mFlags;
        protected $mTrxLevel = 0;
@@ -46,14 +45,6 @@ abstract class DatabaseBase {
 #------------------------------------------------------------------------------
        # These optionally set a variable and return the previous state
 
-       /**
-        * Fail function, takes a Database as a parameter
-        * Set to false for default, 1 for ignore errors
-        */
-       function failFunction( $function = null ) {
-               return wfSetVar( $this->mFailFunction, $function );
-       }
-
        /**
         * Boolean, controls output of large amounts of debug information
         */
@@ -291,12 +282,11 @@ abstract class DatabaseBase {
         * @param $user String: database user name
         * @param $password String: database user password
         * @param $dbName String: database name
-        * @param $failFunction
         * @param $flags
         * @param $tablePrefix String: database table prefixes. By default use the prefix gave in LocalSettings.php
         */
        function __construct( $server = false, $user = false, $password = false, $dbName = false,
-               $failFunction = false, $flags = 0, $tablePrefix = 'get from global' ) {
+               $flags = 0, $tablePrefix = 'get from global' ) {
 
                global $wgOut, $wgDBprefix, $wgCommandLineMode;
                # Can't get a reference if it hasn't been set yet
@@ -304,7 +294,6 @@ abstract class DatabaseBase {
                        $wgOut = null;
                }
 
-               $this->mFailFunction = $failFunction;
                $this->mFlags = $flags;
 
                if ( $this->mFlags & DBO_DEFAULT ) {
@@ -340,18 +329,16 @@ abstract class DatabaseBase {
         * @param $user String: database user name
         * @param $password String: database user password
         * @param $dbName String: database name
-        * @param failFunction
         * @param $flags
         */
-       static function newFromParams( $server, $user, $password, $dbName, $failFunction = false, $flags = 0 )
+       static function newFromParams( $server, $user, $password, $dbName, $flags = 0 )
        {
                wfDeprecated( __METHOD__ );
-               return new DatabaseMysql( $server, $user, $password, $dbName, $failFunction, $flags );
+               return new DatabaseMysql( $server, $user, $password, $dbName, $flags );
        }
 
        /**
         * Usually aborts on failure
-        * If the failFunction is set to a non-zero integer, returns success
         * @param $server String: database server host
         * @param $user String: database user name
         * @param $password String: database user password
@@ -403,16 +390,7 @@ abstract class DatabaseBase {
                        $error = $myError;
                }
 
-               if ( $this->mFailFunction ) {
-                       # Legacy error handling method
-                       if ( !is_int( $this->mFailFunction ) ) {
-                               $ff = $this->mFailFunction;
-                               $ff( $this, $error );
-                       }
-               } else {
-                       # New method
-                       throw new DBConnectionError( $this, $error );
-               }
+               throw new DBConnectionError( $this, $error );
        }
 
        /**
@@ -2547,7 +2525,7 @@ class DBConnectionError extends DBError {
        }
 
        function getHTML() {
-               global $wgLang, $wgMessageCache, $wgUseFileCache, $wgShowDBErrorBacktrace;
+               global $wgLang, $wgMessageCache, $wgUseFileCache, $wgShowDBErrorBacktrace, $wgContLang;
 
                $sorry = 'Sorry! This site is experiencing technical difficulties.';
                $again = 'Try waiting a few minutes and reloading.';
@@ -2582,6 +2560,13 @@ class DBConnectionError extends DBError {
                                $cache = $this->fileCachedPage();
                                # Cached version on file system?
                                if( $cache !== null ) {
+                                       # Adding support for RTL languages
+                                       if ( $wgContLang !== null ) {                                   
+                                               if ( $wgContLang->isRTL() ) {           
+                                                       $cache = str_replace( '<html>', '<html style="direction:rtl;">', $cache );
+                                               }
+                                       }
+
                                        # Hack: extend the body for error messages
                                        $cache = str_replace( array('</html>','</body>'), '', $cache );
                                        # Add cache notice...
index c91dc86..646f665 100644 (file)
@@ -112,7 +112,6 @@ class DatabaseIbm_db2 extends DatabaseBase {
        protected $mServer, $mUser, $mPassword, $mConn = null, $mDBname;
        protected $mOut, $mOpened = false;
 
-       protected $mFailFunction;
        protected $mTablePrefix;
        protected $mFlags;
        protected $mTrxLevel = 0;
@@ -164,7 +163,6 @@ class DatabaseIbm_db2 extends DatabaseBase {
         * These can be safely inherited
         * 
         * Getter/Setter: (18)
-        * failFunction
         * bufferResults
         * ignoreErrors
         * trxLevel
@@ -405,22 +403,19 @@ class DatabaseIbm_db2 extends DatabaseBase {
         * @param $user String: username
         * @param $password String: password
         * @param $dbName String: database name on the server
-        * @param $failFunction Callback (optional)
         * @param $flags Integer: database behaviour flags (optional, unused)
         * @param $schema String
         */
        public function DatabaseIbm_db2($server = false, $user = false, $password = false,
-                                                       $dbName = false, $failFunction = false, $flags = 0,
+                                                       $dbName = false, $flags = 0,
                                                        $schema = self::USE_GLOBAL )
        {
-
                global $wgOut, $wgDBmwschema;
                # Can't get a reference if it hasn't been set yet
                if ( !isset( $wgOut ) ) {
                        $wgOut = null;
                }
                $this->mOut =& $wgOut;
-               $this->mFailFunction = $failFunction;
                $this->mFlags = DBO_TRX | $flags;
                
                if ( $schema == self::USE_GLOBAL ) {
@@ -579,13 +574,11 @@ class DatabaseIbm_db2 extends DatabaseBase {
         * @param $user String: username
         * @param $password String
         * @param $dbName String: database name on the server
-        * @param $failFunction Callback (optional)
         * @param $flags Integer: database behaviour flags (optional, unused)
         * @return DatabaseIbm_db2 object
         */
-       static function newFromParams( $server, $user, $password, $dbName, $failFunction = false, $flags = 0)
-       {
-               return new DatabaseIbm_db2( $server, $user, $password, $dbName, $failFunction, $flags );
+       static function newFromParams( $server, $user, $password, $dbName, $flags = 0) {
+               return new DatabaseIbm_db2( $server, $user, $password, $dbName, $flags );
        }
        
        /**
index 0c8125f..efe755c 100644 (file)
@@ -18,12 +18,10 @@ class DatabaseMssql extends DatabaseBase {
        var $mAffectedRows = NULL;
 
        function __construct( $server = false, $user = false, $password = false, $dbName = false,
-               $failFunction = false, $flags = 0 )
+               $flags = 0 )
        {
-               $this->mFailFunction = $failFunction;
                $this->mFlags = $flags;
                $this->open( $server, $user, $password, $dbName );
-
        }
 
        function cascadingDeletes() {
@@ -51,14 +49,12 @@ class DatabaseMssql extends DatabaseBase {
                return false;
        }
 
-       static function newFromParams( $server, $user, $password, $dbName, $failFunction = false, $flags = 0 )
-       {
-               return new DatabaseMssql( $server, $user, $password, $dbName, $failFunction, $flags );
+       static function newFromParams( $server, $user, $password, $dbName, $flags = 0 ) {
+               return new DatabaseMssql( $server, $user, $password, $dbName, $flags );
        }
 
        /**
         * Usually aborts on failure
-        * If the failFunction is set to a non-zero integer, returns success
         */
        function open( $server, $user, $password, $dbName ) {
                # Test for driver support, to avoid suppressed fatal error
index eae997c..9296c55 100644 (file)
@@ -185,10 +185,10 @@ class DatabaseOracle extends DatabaseBase {
        var $mFieldInfoCache = array();
 
        function __construct( $server = false, $user = false, $password = false, $dbName = false,
-               $failFunction = false, $flags = 0, $tablePrefix = 'get from global' )
+               $flags = 0, $tablePrefix = 'get from global' )
        {
                $tablePrefix = $tablePrefix == 'get from global' ? $tablePrefix : strtoupper( $tablePrefix );
-               parent::__construct( $server, $user, $password, $dbName, $failFunction, $flags, $tablePrefix );
+               parent::__construct( $server, $user, $password, $dbName, $flags, $tablePrefix );
                wfRunHooks( 'DatabaseOraclePostInit', array( &$this ) );
        }
 
@@ -218,14 +218,12 @@ class DatabaseOracle extends DatabaseBase {
                return true;
        }
 
-       static function newFromParams( $server, $user, $password, $dbName, $failFunction = false, $flags = 0 )
-       {
-               return new DatabaseOracle( $server, $user, $password, $dbName, $failFunction, $flags );
+       static function newFromParams( $server, $user, $password, $dbName, $flags = 0 ){
+               return new DatabaseOracle( $server, $user, $password, $dbName, $flags );
        }
 
        /**
         * Usually aborts on failure
-        * If the failFunction is set to a non-zero integer, returns success
         */
        function open( $server, $user, $password, $dbName ) {
                if ( !function_exists( 'oci_connect' ) ) {
index b956a6b..de01b73 100644 (file)
@@ -97,13 +97,10 @@ class DatabasePostgres extends DatabaseBase {
        var $mAffectedRows = null;
 
        function DatabasePostgres($server = false, $user = false, $password = false, $dbName = false,
-               $failFunction = false, $flags = 0 )
+               $flags = 0 )
        {
-
-               $this->mFailFunction = $failFunction;
                $this->mFlags = $flags;
                $this->open( $server, $user, $password, $dbName);
-
        }
 
        function getType() {
@@ -141,14 +138,12 @@ class DatabasePostgres extends DatabaseBase {
                return $this->numRows($res = $this->doQuery($SQL));
        }
 
-       static function newFromParams( $server, $user, $password, $dbName, $failFunction = false, $flags = 0)
-       {
-               return new DatabasePostgres( $server, $user, $password, $dbName, $failFunction, $flags );
+       static function newFromParams( $server, $user, $password, $dbName, $flags = 0) {
+               return new DatabasePostgres( $server, $user, $password, $dbName, $flags );
        }
 
        /**
         * Usually aborts on failure
-        * If the failFunction is set to a non-zero integer, returns success
         */
        function open( $server, $user, $password, $dbName ) {
                # Test for Postgres support, to avoid suppressed fatal error
@@ -188,11 +183,7 @@ class DatabasePostgres extends DatabaseBase {
                        wfDebug( "DB connection error\n" );
                        wfDebug( "Server: $server, Database: $dbName, User: $user, Password: " . substr( $password, 0, 3 ) . "...\n" );
                        wfDebug( $this->lastError()."\n" );
-                       if ( !$this->mFailFunction ) {
-                               throw new DBConnectionError( $this, $phpError );
-                       } else {
-                               return false;
-                       }
+                       return false;
                }
 
                $this->mOpened = true;
index cee84d6..cc586ce 100644 (file)
@@ -23,9 +23,8 @@ class DatabaseSqlite extends DatabaseBase {
         * Constructor.
         * Parameters $server, $user and $password are not used.
         */
-       function __construct( $server = false, $user = false, $password = false, $dbName = false, $failFunction = false, $flags = 0 ) {
+       function __construct( $server = false, $user = false, $password = false, $dbName = false, $flags = 0 ) {
                global $wgSharedDB;
-               $this->mFailFunction = $failFunction;
                $this->mFlags = $flags;
                $this->mName = $dbName;
 
@@ -53,8 +52,8 @@ class DatabaseSqlite extends DatabaseBase {
         */
        function implicitGroupby()   { return false; }
 
-       static function newFromParams( $server, $user, $password, $dbName, $failFunction = false, $flags = 0 ) {
-               return new DatabaseSqlite( $server, $user, $password, $dbName, $failFunction, $flags );
+       static function newFromParams( $server, $user, $password, $dbName, $flags = 0 ) {
+               return new DatabaseSqlite( $server, $user, $password, $dbName, $flags );
        }
 
        /** Open an SQLite database and return a resource handle to it
@@ -90,12 +89,7 @@ class DatabaseSqlite extends DatabaseBase {
                }
                if ( $this->mConn === false ) {
                        wfDebug( "DB connection error: $err\n" );
-                       if ( !$this->mFailFunction ) {
-                               throw new DBConnectionError( $this, $err );
-                       } else {
-                               return false;
-                       }
-
+                       return false;
                }
                $this->mOpened = !!$this->mConn;
                # set error codes only, don't raise exceptions
index 0040fe9..ebb733a 100644 (file)
@@ -14,7 +14,7 @@
  */
 class LoadBalancer {
        /* private */ var $mServers, $mConns, $mLoads, $mGroupLoads;
-       /* private */ var $mFailFunction, $mErrorConnection;
+       /* private */ var $mErrorConnection;
        /* private */ var $mReadIndex, $mAllowLagged;
        /* private */ var $mWaitForPos, $mWaitTimeout;
        /* private */ var $mLaggedSlaveMode, $mLastError = 'Unknown error';
@@ -24,7 +24,6 @@ class LoadBalancer {
        /**
         * @param $params Array with keys:
         *    servers           Required. Array of server info structures.
-        *    failFunction      Deprecated, use exceptions instead.
         *    masterWaitTimeout Replication lag wait timeout
         *    loadMonitor       Name of a class used to fetch server lag and load.
         */
@@ -35,11 +34,6 @@ class LoadBalancer {
                }
                $this->mServers = $params['servers'];
 
-               if ( isset( $params['failFunction'] ) ) {
-                       $this->mFailFunction = $params['failFunction'];
-               } else {
-                       $this->mFailFunction = false;
-               }
                if ( isset( $params['waitTimeout'] ) ) {
                        $this->mWaitTimeout = $params['waitTimeout'];
                } else {
@@ -73,9 +67,9 @@ class LoadBalancer {
                }
        }
 
-       static function newFromParams( $servers, $failFunction = false, $waitTimeout = 10 )
+       static function newFromParams( $servers, $waitTimeout = 10 )
        {
-               return new LoadBalancer( $servers, $failFunction, $waitTimeout );
+               return new LoadBalancer( $servers, $waitTimeout );
        }
 
        /**
@@ -672,19 +666,11 @@ class LoadBalancer {
                        // No last connection, probably due to all servers being too busy
                        wfLogDBError( "LB failure with no last connection\n" );
                        $conn = new Database;
-                       if ( $this->mFailFunction ) {
-                               $conn->failFunction( $this->mFailFunction );
-                               $conn->reportConnectionError( $this->mLastError );
-                       } else {
-                               // If all servers were busy, mLastError will contain something sensible
-                               throw new DBConnectionError( $conn, $this->mLastError );
-                       }
+
+                       // If all servers were busy, mLastError will contain something sensible
+                       throw new DBConnectionError( $conn, $this->mLastError );
                } else {
-                       if ( $this->mFailFunction ) {
-                               $conn->failFunction( $this->mFailFunction );
-                       } else {
-                               $conn->failFunction( false );
-                       }
+
                        $server = $conn->getProperty( 'mServer' );
                        wfLogDBError( "Connection error: {$this->mLastError} ({$server})\n" );
                        $conn->reportConnectionError( "{$this->mLastError} ({$server})" );
index b4299a8..fc1c0c4 100644 (file)
@@ -2,7 +2,7 @@
 
 class DatabaseMock extends DatabaseBase {
        function __construct( $server = false, $user = false, $password = false, $dbName = false,
-               $failFunction = false, $flags = 0, $tablePrefix = 'get from global' )
+               $flags = 0, $tablePrefix = 'get from global' )
        {
                $this->mConn = true;
                $this->mOpened = true;