Merge "LinkFilter: Fix return types in phpdoc"
[lhc/web/wiklou.git] / includes / cache / CacheDependency.php
index 517f379..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;
@@ -98,7 +99,7 @@ class DependencyWrapper {
         * it will be generated with the callback function (if present), and the newly
         * calculated value will be stored to the cache in a wrapper.
         *
-        * @param BagOStuff $cache A cache object such as $wgMemc
+        * @param BagOStuff $cache A cache object
         * @param string $key The cache key
         * @param int $expiry The expiry timestamp or interval in seconds
         * @param bool|callable $callback The callback for generating the value, or false
@@ -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,16 +177,16 @@ class FileDependency extends CacheDependency {
        function __sleep() {
                $this->loadDependencyValues();
 
-               return array( 'filename', 'timestamp' );
+               return [ 'filename', 'timestamp' ];
        }
 
        function loadDependencyValues() {
                if ( is_null( $this->timestamp ) ) {
-                       wfSuppressWarnings();
+                       MediaWiki\suppressWarnings();
                        # Dependency on a non-existent file stores "false"
                        # This is a valid concept!
                        $this->timestamp = filemtime( $this->filename );
-                       wfRestoreWarnings();
+                       MediaWiki\restoreWarnings();
                }
        }
 
@@ -193,9 +194,9 @@ class FileDependency extends CacheDependency {
         * @return bool
         */
        function isExpired() {
-               wfSuppressWarnings();
+               MediaWiki\suppressWarnings();
                $lastmod = filemtime( $this->filename );
-               wfRestoreWarnings();
+               MediaWiki\restoreWarnings();
                if ( $lastmod === false ) {
                        if ( $this->timestamp === false ) {
                                # Still nonexistent
@@ -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
  */