Revert r78000 (removing PHP version from environment checks), never got a chance...
[lhc/web/wiklou.git] / includes / BagOStuff.php
index d2c95fe..7f40001 100644 (file)
@@ -130,14 +130,18 @@ abstract class BagOStuff {
                }
        }
 
+       /**
+        * @param $key String: Key to increase
+        * @param $value Integer: Value to add to $key (Default 1)
+        * @return null if lock is not possible else $key value increased by $value
+        */
        public function incr( $key, $value = 1 ) {
                if ( !$this->lock( $key ) ) {
-                       return false;
+                       return null;
                }
 
                $value = intval( $value );
 
-               $n = false;
                if ( ( $n = $this->get( $key ) ) !== false ) {
                        $n += $value;
                        $this->set( $key, $n ); // exptime?
@@ -236,14 +240,12 @@ class SqlBagOStuff extends BagOStuff {
        var $lastExpireAll = 0;
 
        protected function getDB() {
-               global $wgDBtype;
-
                if ( !isset( $this->db ) ) {
                        /* We must keep a separate connection to MySQL in order to avoid deadlocks
                         * However, SQLite has an opposite behaviour.
                         * @todo Investigate behaviour for other databases
                         */
-                       if ( $wgDBtype == 'sqlite' ) {
+                       if ( wfGetDB( DB_MASTER )->getType() == 'sqlite' ) {
                                $this->db = wfGetDB( DB_MASTER );
                        } else {
                                $this->lb = wfGetLBFactory()->newMainLB();
@@ -861,9 +863,11 @@ class WinCacheBagOStuff extends BagOStuff {
         * @return bool
         */
        public function set( $key, $value, $expire = 0 ) {
-               wincache_ucache_set( $key, serialize( $value ), $expire );
+               $result = wincache_ucache_set( $key, serialize( $value ), $expire );
 
-               return true;
+               /* wincache_ucache_set returns an empty array on success if $value
+                  was an array, bool otherwise */
+               return ( is_array( $result ) && $result === array() ) || $result;
        }
 
        /**
@@ -884,6 +888,10 @@ class WinCacheBagOStuff extends BagOStuff {
                $list = $info['ucache_entries'];
                $keys = array();
 
+               if ( is_null( $list ) ) {
+                       return array();
+               }
+
                foreach ( $list as $entry ) {
                        $keys[] = $entry['key_name'];
                }