Merge "Update namespace names for Sanskrit"
[lhc/web/wiklou.git] / includes / resourceloader / ResourceLoader.php
index fa131bd..cecb6a2 100644 (file)
@@ -25,6 +25,7 @@
 use Psr\Log\LoggerAwareInterface;
 use Psr\Log\LoggerInterface;
 use Psr\Log\NullLogger;
+use WrappedString\WrappedString;
 
 /**
  * Dynamic JavaScript and CSS resource loading system.
@@ -180,7 +181,7 @@ class ResourceLoader implements LoggerAwareInterface {
         * @param string $data Text to filter, such as JavaScript or CSS text
         * @param array $options For back-compat, can also be the boolean value for "cacheReport". Keys:
         *  - (bool) cache: Whether to allow caching this data. Default: true.
-        *  - (bool) cacheReport: Whether to include the "cache key" report comment. Default: true.
+        *  - (bool) cacheReport: Whether to include the "cache key" report comment. Default: false.
         * @return string Filtered data, or a comment containing an error message
         */
        public function filter( $filter, $data, $options = array() ) {
@@ -189,7 +190,7 @@ class ResourceLoader implements LoggerAwareInterface {
                        $options = array( 'cacheReport' => $options );
                }
                // Defaults
-               $options += array( 'cache' => true, 'cacheReport' => true );
+               $options += array( 'cache' => true, 'cacheReport' => false );
 
                // Don't filter empty content
                if ( trim( $data ) === '' ) {
@@ -220,7 +221,8 @@ class ResourceLoader implements LoggerAwareInterface {
 
                                $result = self::applyFilter( $filter, $data, $this->config );
 
-                               $stats->timing( "resourceloader_cache.$filter.miss", microtime( true ) - $statStart );
+                               $statTiming = microtime( true ) - $statStart;
+                               $stats->timing( "resourceloader_cache.$filter.miss", 1000 * $statTiming );
                                if ( $options['cacheReport'] ) {
                                        $result .= "\n/* cache key: $key */";
                                }
@@ -810,7 +812,7 @@ class ResourceLoader implements LoggerAwareInterface {
                        header( 'Cache-Control: private, no-cache, must-revalidate' );
                        header( 'Pragma: no-cache' );
                } else {
-                       header( "Cache-Control: public, must-revalidate, max-age=$maxage, s-maxage=$smaxage" );
+                       header( "Cache-Control: public, max-age=$maxage, s-maxage=$smaxage" );
                        $exp = min( $maxage, $smaxage );
                        header( 'Expires: ' . wfTimestamp( TS_RFC2822, $exp + time() ) );
                }
@@ -1379,7 +1381,7 @@ MESSAGE;
         * @return string
         */
        public static function makeLoaderConditionalScript( $script ) {
-               return "var RLQ = RLQ || []; RLQ.push( function () {\n" . trim( $script ) . "\n} );";
+               return "window.RLQ = window.RLQ || []; window.RLQ.push( function () {\n" . trim( $script ) . "\n} );";
        }
 
        /**
@@ -1389,11 +1391,15 @@ MESSAGE;
         * only if the client has adequate support for MediaWiki JavaScript code.
         *
         * @param string $script JavaScript code
-        * @return string HTML
+        * @return WrappedString HTML
         */
        public static function makeInlineScript( $script ) {
                $js = self::makeLoaderConditionalScript( $script );
-               return Html::inlineScript( $js );
+               return new WrappedString(
+                       Html::inlineScript( $js ),
+                       "<script>window.RLQ = window.RLQ || []; window.RLQ.push( function () {\n",
+                       "\n} );</script>"
+               );
        }
 
        /**
@@ -1404,11 +1410,13 @@ MESSAGE;
         * @return string
         */
        public static function makeConfigSetScript( array $configuration ) {
-               return Xml::encodeJsCall(
-                       'mw.config.set',
-                       array( $configuration ),
-                       ResourceLoader::inDebugMode()
-               );
+               if ( ResourceLoader::inDebugMode() ) {
+                       return Xml::encodeJsCall( 'mw.config.set', array( $configuration ), true );
+               }
+
+               $config = RequestContext::getMain()->getConfig();
+               $js = Xml::encodeJsCall( 'mw.config.set', array( $configuration ), false );
+               return self::applyFilter( 'minify-js', $js, $config );
        }
 
        /**
@@ -1470,7 +1478,7 @@ MESSAGE;
         * @param string $source Name of the ResourceLoader source
         * @param ResourceLoaderContext $context
         * @param array $extraQuery
-        * @return string URL to load.php. May be protocol-relative (if $wgLoadScript is procol-relative)
+        * @return string URL to load.php. May be protocol-relative if $wgLoadScript is, too.
         */
        public function createLoaderURL( $source, ResourceLoaderContext $context,
                $extraQuery = array()
@@ -1496,7 +1504,7 @@ MESSAGE;
         * @param bool $printable Printable mode
         * @param bool $handheld Handheld mode
         * @param array $extraQuery Extra query parameters to add
-        * @return string URL to load.php. May be protocol-relative (if $wgLoadScript is procol-relative)
+        * @return string URL to load.php. May be protocol-relative if $wgLoadScript is, too.
         */
        public static function makeLoaderURL( $modules, $lang, $skin, $user = null,
                $version = null, $debug = false, $only = null, $printable = false,