Http::getProxy() method to get proxy configuration
[lhc/web/wiklou.git] / includes / db / Database.php
index 811a4a7..60cf0ec 100644 (file)
@@ -441,6 +441,14 @@ abstract class DatabaseBase implements IDatabase {
                return $this->mDoneWrites ?: false;
        }
 
+       /**
+        * @return bool Whether there is a transaction open with possible write queries
+        * @since 1.27
+        */
+       public function writesPending() {
+               return $this->mTrxLevel && $this->mTrxDoneWrites;
+       }
+
        /**
         * Returns true if there is a transaction open with possible write
         * queries or transaction pre-commit/idle callbacks waiting on it to finish.
@@ -607,8 +615,7 @@ abstract class DatabaseBase implements IDatabase {
        function __construct( array $params ) {
                global $wgDBprefix, $wgDBmwschema, $wgCommandLineMode;
 
-               $this->mTrxAtomicLevels = new SplStack;
-               $this->srvCache = ObjectCache::newAccelerator( 'hash' );
+               $this->srvCache = ObjectCache::getLocalServerInstance( 'hash' );
 
                $server = $params['host'];
                $user = $params['user'];
@@ -927,8 +934,8 @@ abstract class DatabaseBase implements IDatabase {
 
                $isWriteQuery = $this->isWriteQuery( $sql );
                if ( $isWriteQuery ) {
-                       $reason = $this->getLBInfo( 'readOnlyReason' );
-                       if ( is_string( $reason ) ) {
+                       $reason = $this->getReadOnlyReason();
+                       if ( $reason !== false ) {
                                throw new DBReadOnlyError( $this, "Database is read-only: $reason" );
                        }
                        # Set a flag indicating that writes have been done
@@ -1707,19 +1714,21 @@ abstract class DatabaseBase implements IDatabase {
         *
         * Takes the same arguments as DatabaseBase::select().
         *
-        * @param string $table Table name
+        * @since 1.27 Added $join_conds parameter
+        *
+        * @param array|string $tables Table names
         * @param string $vars Unused
         * @param array|string $conds Filters on the table
         * @param string $fname Function name for profiling
         * @param array $options Options for select
+        * @param array $join_conds Join conditions (since 1.27)
         * @return int Row count
-        * @since 1.24
         */
        public function selectRowCount(
-               $table, $vars = '*', $conds = '', $fname = __METHOD__, $options = array()
+               $tables, $vars = '*', $conds = '', $fname = __METHOD__, $options = array(), $join_conds = array()
        ) {
                $rows = 0;
-               $sql = $this->selectSQLText( $table, '1', $conds, $fname, $options );
+               $sql = $this->selectSQLText( $tables, '1', $conds, $fname, $options, $join_conds );
                $res = $this->query( "SELECT COUNT(*) AS rowcount FROM ($sql) tmp_count", $fname );
 
                if ( $res ) {
@@ -3429,7 +3438,7 @@ abstract class DatabaseBase implements IDatabase {
                                $levels = implode( ', ', $this->mTrxAtomicLevels );
                                throw new DBUnexpectedError(
                                        $this,
-                                       "Got explicit BEGIN while atomic sections $levels are still open."
+                                       "Got explicit BEGIN from $fname while atomic section(s) $levels are open."
                                );
                        } elseif ( !$this->mTrxAutomatic ) {
                                // We want to warn about inadvertently nested begin/commit pairs, but not about
@@ -3818,16 +3827,20 @@ abstract class DatabaseBase implements IDatabase {
         *
         * @param IDatabase $db1
         * @param IDatabase ...
-        * @return array ('lag': highest lag, 'since': lowest estimate UNIX timestamp)
+        * @return array Map of values:
+        *   - lag: highest lag of any of the DBs
+        *   - since: oldest UNIX timestamp of any of the DB lag estimates
+        *   - pending: whether any of the DBs have uncommitted changes
         * @since 1.27
         */
        public static function getCacheSetOptions( IDatabase $db1 ) {
-               $res = array( 'lag' => 0, 'since' => INF );
+               $res = array( 'lag' => 0, 'since' => INF, 'pending' => false );
                foreach ( func_get_args() as $db ) {
                        /** @var IDatabase $db */
                        $status = $db->getSessionLagStatus();
                        $res['lag'] = max( $res['lag'], $status['lag'] );
                        $res['since'] = min( $res['since'], $status['since'] );
+                       $res['pending'] = $res['pending'] ?: $db->writesPending();
                }
 
                return $res;
@@ -4284,6 +4297,19 @@ abstract class DatabaseBase implements IDatabase {
                // no-op
        }
 
+       public function isReadOnly() {
+               return ( $this->getReadOnlyReason() !== false );
+       }
+
+       /**
+        * @return string|bool Reason this DB is read-only or false if it is not
+        */
+       protected function getReadOnlyReason() {
+               $reason = $this->getLBInfo( 'readOnlyReason' );
+
+               return is_string( $reason ) ? $reason : false;
+       }
+
        /**
         * @since 1.19
         * @return string