Merge "Convert Special:DeletedContributions to use OOUI."
[lhc/web/wiklou.git] / includes / cache / CacheDependency.php
index 0a45b8e..a59ba97 100644 (file)
@@ -20,6 +20,7 @@
  * @file
  * @ingroup Cache
  */
+use MediaWiki\MediaWikiServices;
 
 /**
  * This class stores an arbitrary value along with its dependencies.
@@ -38,11 +39,11 @@ class DependencyWrapper {
         * @param CacheDependency|CacheDependency[] $deps A dependency or dependency
         *   array. All dependencies must be objects implementing CacheDependency.
         */
-       function __construct( $value = false, $deps = array() ) {
+       function __construct( $value = false, $deps = [] ) {
                $this->value = $value;
 
                if ( !is_array( $deps ) ) {
-                       $deps = array( $deps );
+                       $deps = [ $deps ];
                }
 
                $this->deps = $deps;
@@ -111,7 +112,7 @@ class DependencyWrapper {
         *    callback was defined.
         */
        static function getValueFromCache( $cache, $key, $expiry = 0, $callback = false,
-               $callbackParams = array(), $deps = array()
+               $callbackParams = [], $deps = []
        ) {
                $obj = $cache->get( $key );
 
@@ -176,7 +177,7 @@ class FileDependency extends CacheDependency {
        function __sleep() {
                $this->loadDependencyValues();
 
-               return array( 'filename', 'timestamp' );
+               return [ 'filename', 'timestamp' ];
        }
 
        function loadDependencyValues() {
@@ -244,6 +245,34 @@ class GlobalDependency extends CacheDependency {
        }
 }
 
+/**
+ * @ingroup Cache
+ */
+class MainConfigDependency extends CacheDependency {
+       private $name;
+       private $value;
+
+       function __construct( $name ) {
+               $this->name = $name;
+               $this->value = $this->getConfig()->get( $this->name );
+       }
+
+       private function getConfig() {
+               return MediaWikiServices::getInstance()->getMainConfig();
+       }
+
+       /**
+        * @return bool
+        */
+       function isExpired() {
+               if ( !$this->getConfig()->has( $this->name ) ) {
+                       return true;
+               }
+
+               return $this->getConfig()->get( $this->name ) != $this->value;
+       }
+}
+
 /**
  * @ingroup Cache
  */