Merge "Remove m prefixes from private variables"
[lhc/web/wiklou.git] / includes / resourceloader / ResourceLoaderModule.php
index 822e73c..11264fc 100644 (file)
@@ -382,14 +382,59 @@ abstract class ResourceLoaderModule {
         * If you want this to happen, you'll need to call getMsgBlobMtime()
         * yourself and take its result into consideration.
         *
-        * @param ResourceLoaderContext $context
-        * @return int: UNIX timestamp
+        * NOTE: The mtime of the module's hash is NOT automatically included.
+        * If your module provides a getModifiedHash() method, you'll need to call getHashMtime()
+        * yourself and take its result into consideration.
+        *
+        * @param ResourceLoaderContext $context Context object
+        * @return integer UNIX timestamp
         */
        public function getModifiedTime( ResourceLoaderContext $context ) {
                // 0 would mean now
                return 1;
        }
 
+       /**
+        * Helper method for calculating when the module's hash (if it has one) changed.
+        *
+        * @param ResourceLoaderContext $context
+        * @return integer: UNIX timestamp or 0 if there is no hash provided
+        */
+       public function getHashMtime( ResourceLoaderContext $context ) {
+               $hash = $this->getModifiedHash( $context );
+               if ( !is_string( $hash ) ) {
+                       return 0;
+               }
+
+               $cache = wfGetCache( CACHE_ANYTHING );
+               $key = wfMemcKey( 'resourceloader', 'modulemodifiedhash', $this->getName() );
+
+               $data = $cache->get( $key );
+               if ( is_array( $data ) && $data['hash'] === $hash ) {
+                       // Hash is still the same, re-use the timestamp of when we first saw this hash.
+                       return $data['timestamp'];
+               }
+
+               $timestamp = wfTimestamp();
+               $cache->set( $key, array(
+                       'hash' => $hash,
+                       'timestamp' => $timestamp,
+               ) );
+
+               return $timestamp;
+       }
+
+       /**
+        * Get the last modification timestamp of the message blob for this
+        * module in a given language.
+        *
+        * @param ResourceLoaderContext $context
+        * @return string|null: Hash
+        */
+       public function getModifiedHash( ResourceLoaderContext $context ) {
+               return null;
+       }
+
        /**
         * Check whether this module is known to be empty. If a child class
         * has an easy and cheap way to determine that this module is
@@ -407,9 +452,6 @@ abstract class ResourceLoaderModule {
        private static $jsParser;
        private static $parseCacheVersion = 1;
 
-       /** @var array Global LESS variables */
-       private static $lessVars;
-
        /**
         * Validate a given script file; if valid returns the original source.
         * If invalid, returns replacement JS source that throws an exception.
@@ -457,40 +499,6 @@ abstract class ResourceLoaderModule {
                return self::$jsParser;
        }
 
-       /**
-        * @since 1.22
-        * @return lessc
-        */
-       protected static function lessCompiler() {
-               global $wgResourceLoaderLESSFunctions, $wgResourceLoaderLESSImportPaths;
-
-               $less = new lessc();
-               $less->setPreserveComments( true );
-               $less->setVariables( self::getLESSVars() );
-               $less->setImportDir( $wgResourceLoaderLESSImportPaths );
-               foreach ( $wgResourceLoaderLESSFunctions as $name => $func ) {
-                       $less->registerFunction( $name, $func );
-               }
-               return $less;
-       }
-
-       /**
-        * Get global LESS variables.
-        *
-        * @since 1.22
-        * @return array: Map of variable names to string CSS values.
-        */
-       protected static function getLESSVars() {
-               global $wgResourceLoaderLESSVars;
-
-               if ( self::$lessVars === null ) {
-                       self::$lessVars = $wgResourceLoaderLESSVars;
-                       // Sort by key to ensure consistent hashing for cache lookups.
-                       ksort( self::$lessVars );
-               }
-               return self::$lessVars;
-       }
-
        /**
         * Safe version of filemtime(), which doesn't throw a PHP warning if the file doesn't exist
         * but returns 1 instead.