Merge "Document WAN cache FLD_* constants"
[lhc/web/wiklou.git] / includes / objectcache / ObjectCache.php
index 90a9f7c..24846e6 100644 (file)
@@ -22,6 +22,7 @@
  */
 
 use MediaWiki\Logger\LoggerFactory;
+use MediaWiki\MediaWikiServices;
 
 /**
  * Functions to get cache objects
@@ -78,9 +79,9 @@ use MediaWiki\Logger\LoggerFactory;
  */
 class ObjectCache {
        /** @var BagOStuff[] Map of (id => BagOStuff) */
-       public static $instances = array();
+       public static $instances = [];
        /** @var WANObjectCache[] Map of (id => WANObjectCache) */
-       public static $wanInstances = array();
+       public static $wanInstances = [];
 
        /**
         * Get a cached instance of the specified type of cache object.
@@ -174,11 +175,13 @@ class ObjectCache {
                } elseif ( isset( $params['class'] ) ) {
                        $class = $params['class'];
                        // Automatically set the 'async' update handler
-                       if ( $class === 'MultiWriteBagOStuff' ) {
-                               $params['asyncHandler'] = isset( $params['asyncHandler'] )
-                                       ? $params['asyncHandler']
-                                       : 'DeferredUpdates::addCallableUpdate';
-                       }
+                       $params['asyncHandler'] = isset( $params['asyncHandler'] )
+                               ? $params['asyncHandler']
+                               : 'DeferredUpdates::addCallableUpdate';
+                       // Enable reportDupes by default
+                       $params['reportDupes'] = isset( $params['reportDupes'] )
+                               ? $params['reportDupes']
+                               : true;
                        // Do b/c logic for MemcachedBagOStuff
                        if ( is_subclass_of( $class, 'MemcachedBagOStuff' ) ) {
                                if ( !isset( $params['servers'] ) ) {
@@ -217,7 +220,7 @@ class ObjectCache {
         */
        public static function newAnything( $params ) {
                global $wgMainCacheType, $wgMessageCacheType, $wgParserCacheType;
-               $candidates = array( $wgMainCacheType, $wgMessageCacheType, $wgParserCacheType );
+               $candidates = [ $wgMainCacheType, $wgMessageCacheType, $wgParserCacheType ];
                foreach ( $candidates as $candidate ) {
                        if ( $candidate !== CACHE_NONE && $candidate !== CACHE_ANYTHING ) {
                                return self::getInstance( $candidate );
@@ -267,10 +270,8 @@ class ObjectCache {
         * @return BagOStuff
         * @deprecated 1.27
         */
-       public static function newAccelerator( $params = array(), $fallback = null ) {
+       public static function newAccelerator( $params = [], $fallback = null ) {
                if ( $fallback === null ) {
-                       // The is_array check here is needed because in PHP 5.3:
-                       // $a = 'hash'; isset( $params['fallback'] ); yields true
                        if ( is_array( $params ) && isset( $params['fallback'] ) ) {
                                $fallback = $params['fallback'];
                        } elseif ( !is_array( $params ) ) {
@@ -298,8 +299,11 @@ class ObjectCache {
                }
 
                $params = $wgWANObjectCaches[$id];
-               $class = $params['relayerConfig']['class'];
-               $params['relayer'] = new $class( $params['relayerConfig'] );
+               foreach ( $params['channels'] as $action => $channel ) {
+                       $params['relayers'][$action] = MediaWikiServices::getInstance()->getEventRelayerGroup()
+                               ->getRelayer( $channel );
+                       $params['channels'][$action] = $channel;
+               }
                $params['cache'] = self::newFromId( $params['cacheId'] );
                if ( isset( $params['loggroup'] ) ) {
                        $params['logger'] = LoggerFactory::getInstance( $params['loggroup'] );
@@ -363,7 +367,7 @@ class ObjectCache {
         * Clear all the cached instances.
         */
        public static function clear() {
-               self::$instances = array();
-               self::$wanInstances = array();
+               self::$instances = [];
+               self::$wanInstances = [];
        }
 }