Update suppressWarning()/restoreWarning() calls
[lhc/web/wiklou.git] / includes / cache / CacheDependency.php
index 2d29d86..4ff1004 100644 (file)
@@ -20,6 +20,7 @@
  * @file
  * @ingroup Cache
  */
+use MediaWiki\MediaWikiServices;
 
 /**
  * This class stores an arbitrary value along with its dependencies.
@@ -33,7 +34,6 @@ class DependencyWrapper {
        private $deps;
 
        /**
-        * Create an instance.
         * @param mixed $value The user-supplied value
         * @param CacheDependency|CacheDependency[] $deps A dependency or dependency
         *   array. All dependencies must be objects implementing CacheDependency.
@@ -98,7 +98,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
+        * @param BagOStuff $cache
         * @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
@@ -181,11 +181,11 @@ class FileDependency extends CacheDependency {
 
        function loadDependencyValues() {
                if ( is_null( $this->timestamp ) ) {
-                       MediaWiki\suppressWarnings();
+                       Wikimedia\suppressWarnings();
                        # Dependency on a non-existent file stores "false"
                        # This is a valid concept!
                        $this->timestamp = filemtime( $this->filename );
-                       MediaWiki\restoreWarnings();
+                       Wikimedia\restoreWarnings();
                }
        }
 
@@ -193,9 +193,9 @@ class FileDependency extends CacheDependency {
         * @return bool
         */
        function isExpired() {
-               MediaWiki\suppressWarnings();
+               Wikimedia\suppressWarnings();
                $lastmod = filemtime( $this->filename );
-               MediaWiki\restoreWarnings();
+               Wikimedia\restoreWarnings();
                if ( $lastmod === false ) {
                        if ( $this->timestamp === false ) {
                                # Still nonexistent
@@ -244,6 +244,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
  */