Resolved bug 26791 by replacing JSMin with a new library called JavaScriptDistiller...
[lhc/web/wiklou.git] / includes / resourceloader / ResourceLoader.php
index 91a5a7c..ba5ae11 100644 (file)
@@ -108,7 +108,7 @@ class ResourceLoader {
         * Runs JavaScript or CSS data through a filter, caching the filtered result for future calls.
         * 
         * Available filters are:
-        *  - minify-js \see JSMin::minify
+        *  - minify-js \see JavaScriptDistiller::stripWhiteSpace
         *  - minify-css \see CSSMin::minify
         * 
         * If $data is empty, only contains whitespace or the filter was unknown, 
@@ -119,6 +119,8 @@ class ResourceLoader {
         * @return String: Filtered data, or a comment containing an error message
         */
        protected function filter( $filter, $data ) {
+               global $wgResourceLoaderMinifyJSVerticalSpace;
+
                wfProfileIn( __METHOD__ );
 
                // For empty/whitespace-only data or for unknown filters, don't perform 
@@ -144,7 +146,9 @@ class ResourceLoader {
                try {
                        switch ( $filter ) {
                                case 'minify-js':
-                                       $result = JSMin::minify( $data );
+                                       $result = JavaScriptDistiller::stripWhiteSpace(
+                                               $data, $wgResourceLoaderMinifyJSVerticalSpace
+                                       );
                                        break;
                                case 'minify-css':
                                        $result = CSSMin::minify( $data );
@@ -329,14 +333,15 @@ class ResourceLoader {
 
                wfProfileIn( __METHOD__.'-getModifiedTime' );
 
+               $private = false;
                // To send Last-Modified and support If-Modified-Since, we need to detect 
                // the last modified time
                $mtime = wfTimestamp( TS_UNIX, $wgCacheEpoch );
                foreach ( $modules as $module ) {
                        try {
-                               // Bypass squid cache if the request includes any private modules
+                               // Bypass Squid and other shared caches if the request includes any private modules
                                if ( $module->getGroup() === 'private' ) {
-                                       $smaxage = 0;
+                                       $private = true;
                                }
                                // Calculate maximum modified time
                                $mtime = max( $mtime, $module->getModifiedTime( $context ) );
@@ -355,10 +360,18 @@ class ResourceLoader {
                }
                header( 'Last-Modified: ' . wfTimestamp( TS_RFC2822, $mtime ) );
                if ( $context->getDebug() ) {
-                       header( 'Cache-Control: must-revalidate' );
+                       // Do not cache debug responses
+                       header( 'Cache-Control: private, no-cache, must-revalidate' );
+                       header( 'Pragma: no-cache' );
                } else {
-                       header( "Cache-Control: public, max-age=$maxage, s-maxage=$smaxage" );
-                       header( 'Expires: ' . wfTimestamp( TS_RFC2822, min( $maxage, $smaxage ) + time() ) );
+                       if ( $private ) {
+                               header( "Cache-Control: private, max-age=$maxage" );
+                               $exp = $maxage;
+                       } else {
+                               header( "Cache-Control: public, max-age=$maxage, s-maxage=$smaxage" );
+                               $exp = min( $maxage, $smaxage );
+                       }
+                       header( 'Expires: ' . wfTimestamp( TS_RFC2822, $exp + time() ) );
                }
 
                // If there's an If-Modified-Since header, respond with a 304 appropriately