Using the mw alias for mediaWiki in core. Saves bandwidth and makes sense (there...
[lhc/web/wiklou.git] / includes / resourceloader / ResourceLoader.php
index 91fb1ee..354d7f3 100644 (file)
@@ -29,6 +29,7 @@
 class ResourceLoader {
 
        /* Protected Static Members */
+       protected static $filterCacheVersion = 1;
 
        /** Array: List of module name/ResourceLoaderModule object pairs */
        protected $modules = array();
@@ -135,7 +136,7 @@ class ResourceLoader {
 
                // Try for cache hit
                // Use CACHE_ANYTHING since filtering is very slow compared to DB queries
-               $key = wfMemcKey( 'resourceloader', 'filter', $filter, md5( $data ) );
+               $key = wfMemcKey( 'resourceloader', 'filter', $filter, self::$filterCacheVersion, md5( $data ) );
                $cache = wfGetCache( CACHE_ANYTHING );
                $cacheEntry = $cache->get( $key );
                if ( is_string( $cacheEntry ) ) {
@@ -143,6 +144,7 @@ class ResourceLoader {
                        return $cacheEntry;
                }
 
+               $result = '';
                // Run the filter - we've already verified one of these will work
                try {
                        switch ( $filter ) {
@@ -150,9 +152,11 @@ class ResourceLoader {
                                        $result = JavaScriptDistiller::stripWhiteSpace(
                                                $data, $wgResourceLoaderMinifyJSVerticalSpace
                                        );
+                                       $result .= "\n\n/* cache key: $key */\n";
                                        break;
                                case 'minify-css':
                                        $result = CSSMin::minify( $data );
+                                       $result .= "\n\n/* cache key: $key */\n";
                                        break;
                        }
 
@@ -207,6 +211,7 @@ class ResourceLoader {
                        foreach ( $name as $key => $value ) {
                                $this->register( $key, $value );
                        }
+                       wfProfileOut( __METHOD__ );
                        return;
                }
 
@@ -252,7 +257,7 @@ class ResourceLoader {
         * Get the ResourceLoaderModule object for a given module name.
         *
         * @param $name String: Module name
-        * @return Mixed: ResourceLoaderModule if module has been registered, null otherwise
+        * @return ResourceLoaderModule if module has been registered, null otherwise
         */
        public function getModule( $name ) {
                if ( !isset( $this->modules[$name] ) ) {
@@ -379,7 +384,8 @@ class ResourceLoader {
                // Some clients send "timestamp;length=123". Strip the part after the first ';'
                // so we get a valid timestamp.
                $ims = $context->getRequest()->getHeader( 'If-Modified-Since' );
-               if ( $ims !== false ) {
+               // Never send 304s in debug mode
+               if ( $ims !== false && !$context->getDebug() ) {
                        $imsTS = strtok( $ims, ';' );
                        if ( $mtime <= wfTimestamp( TS_UNIX, $imsTS ) ) {
                                // There's another bug in ob_gzhandler (see also the comment at
@@ -442,6 +448,7 @@ class ResourceLoader {
                        return '/* No modules requested. Max made me put this here */';
                }
                
+               wfProfileIn( __METHOD__ );
                // Pre-fetch blobs
                if ( $context->shouldIncludeMessages() ) {
                        try {
@@ -485,7 +492,7 @@ class ResourceLoader {
                                                $out .= self::makeMessageSetScript( new XmlJsCode( $messagesBlob ) );
                                                break;
                                        default:
-                                               // Minify CSS before embedding in mediaWiki.loader.implement call
+                                               // Minify CSS before embedding in mw.loader.implement call
                                                // (unless in debug mode)
                                                if ( !$context->getDebug() ) {
                                                        foreach ( $styles as $media => $style ) {
@@ -522,21 +529,22 @@ class ResourceLoader {
                        }
                }
 
-               if ( $context->getDebug() ) {
-                       return $exceptions . $out;
-               } else {
+               if ( !$context->getDebug() ) {
                        if ( $context->getOnly() === 'styles' ) {
-                               return $exceptions . $this->filter( 'minify-css', $out );
+                               $out = $this->filter( 'minify-css', $out );
                        } else {
-                               return $exceptions . $this->filter( 'minify-js', $out );
+                               $out = $this->filter( 'minify-js', $out );
                        }
                }
+               
+               wfProfileOut( __METHOD__ );
+               return $exceptions . $out;
        }
 
        /* Static Methods */
 
        /**
-        * Returns JS code to call to mediaWiki.loader.implement for a module with 
+        * Returns JS code to call to mw.loader.implement for a module with 
         * given properties.
         *
         * @param $name Module name
@@ -552,7 +560,7 @@ class ResourceLoader {
                        $scripts = implode( $scripts, "\n" );
                }
                return Xml::encodeJsCall( 
-                       'mediaWiki.loader.implement', 
+                       'mw.loader.implement', 
                        array(
                                $name,
                                new XmlJsCode( "function( $, mw ) {{$scripts}}" ),
@@ -568,7 +576,7 @@ class ResourceLoader {
         *     JSON-encoded message blob containing the same data, wrapped in an XmlJsCode object.
         */
        public static function makeMessageSetScript( $messages ) {
-               return Xml::encodeJsCall( 'mediaWiki.messages.set', array( (object)$messages ) );
+               return Xml::encodeJsCall( 'mw.messages.set', array( (object)$messages ) );
        }
 
        /**
@@ -597,7 +605,7 @@ class ResourceLoader {
        }
 
        /**
-        * Returns a JS call to mediaWiki.loader.state, which sets the state of a 
+        * Returns a JS call to mw.loader.state, which sets the state of a 
         * module or modules to a given value. Has two calling conventions:
         *
         *    - ResourceLoader::makeLoaderStateScript( $name, $state ):
@@ -608,9 +616,9 @@ class ResourceLoader {
         */
        public static function makeLoaderStateScript( $name, $state = null ) {
                if ( is_array( $name ) ) {
-                       return Xml::encodeJsCall( 'mediaWiki.loader.state', array( $name ) );
+                       return Xml::encodeJsCall( 'mw.loader.state', array( $name ) );
                } else {
-                       return Xml::encodeJsCall( 'mediaWiki.loader.state', array( $name, $state ) );
+                       return Xml::encodeJsCall( 'mw.loader.state', array( $name, $state ) );
                }
        }
 
@@ -634,7 +642,7 @@ class ResourceLoader {
        }
 
        /**
-        * Returns JS code which calls mediaWiki.loader.register with the given 
+        * Returns JS code which calls mw.loader.register with the given 
         * parameters. Has three calling conventions:
         *
         *   - ResourceLoader::makeLoaderRegisterScript( $name, $version, $dependencies, $group ):
@@ -659,10 +667,10 @@ class ResourceLoader {
                $dependencies = null, $group = null ) 
        {
                if ( is_array( $name ) ) {
-                       return Xml::encodeJsCall( 'mediaWiki.loader.register', array( $name ) );
+                       return Xml::encodeJsCall( 'mw.loader.register', array( $name ) );
                } else {
                        $version = (int) $version > 1 ? (int) $version : 1;
-                       return Xml::encodeJsCall( 'mediaWiki.loader.register', 
+                       return Xml::encodeJsCall( 'mw.loader.register', 
                                array( $name, $version, $dependencies, $group ) );
                }
        }
@@ -685,7 +693,7 @@ class ResourceLoader {
         * @param $configuration Array: List of configuration values keyed by variable name
         */
        public static function makeConfigSetScript( array $configuration ) {
-               return Xml::encodeJsCall( 'mediaWiki.config.set', array( $configuration ) );
+               return Xml::encodeJsCall( 'mw.config.set', array( $configuration ) );
        }
        
        /**