resourceloader: Set value for getVary in server-side
authorFomafix <fomafix@googlemail.com>
Fri, 28 Jun 2019 13:06:42 +0000 (15:06 +0200)
committerKrinkle <krinklemail@gmail.com>
Thu, 4 Jul 2019 16:45:15 +0000 (16:45 +0000)
This change makes ResourceLoaderStorageVersion a private variable.
The JavaScript global variable wgResourceLoaderStorageVersion is now
removed.

This change makes the JavaScript code smaller.

Change-Id: I8e31b95d4c44ba653bedb6be500011a39bc6abd8

includes/resourceloader/ResourceLoaderStartUpModule.php
resources/src/startup/mediawiki.js

index f0de411..41e66ef 100644 (file)
@@ -105,7 +105,6 @@ class ResourceLoaderStartUpModule extends ResourceLoaderModule {
                        'wgCaseSensitiveNamespaces' => $caseSensitiveNamespaces,
                        'wgLegalTitleChars' => Title::convertByteClassToUnicodeClass( Title::legalChars() ),
                        'wgIllegalFileChars' => Title::convertByteClassToUnicodeClass( $illegalFileChars ),
-                       'wgResourceLoaderStorageVersion' => $conf->get( 'ResourceLoaderStorageVersion' ),
                        'wgResourceLoaderStorageEnabled' => $conf->get( 'ResourceLoaderStorageEnabled' ),
                        'wgForeignUploadTargets' => $conf->get( 'ForeignUploadTargets' ),
                        'wgEnableUploads' => $conf->get( 'EnableUploads' ),
@@ -367,6 +366,20 @@ class ResourceLoaderStartUpModule extends ResourceLoaderModule {
                return $baseModules;
        }
 
+       /**
+        * Get the key on which the JavaScript module cache (mw.loader.store) will vary.
+        *
+        * @param ResourceLoaderContext $context
+        * @return string String of concatenated vary conditions
+        */
+       private function getStoreVary( ResourceLoaderContext $context ) {
+               return implode( ':', [
+                       $context->getSkin(),
+                       $this->getConfig()->get( 'ResourceLoaderStorageVersion' ),
+                       $context->getLanguage(),
+               ] );
+       }
+
        /**
         * @param ResourceLoaderContext $context
         * @return string JavaScript code
@@ -399,6 +412,7 @@ class ResourceLoaderStartUpModule extends ResourceLoaderModule {
                        '$VARS.maxQueryLength' => ResourceLoader::encodeJsonForScript(
                                $conf->get( 'ResourceLoaderMaxQueryLength' )
                        ),
+                       '$VARS.storeVary' => ResourceLoader::encodeJsonForScript( $this->getStoreVary( $context ) ),
                ];
                $profilerStubs = [
                        '$CODE.profileExecuteStart();' => 'mw.loader.profiler.onExecuteStart( module );',
index 2976dca..1583445 100644 (file)
                                         * @return {string} String of concatenated vary conditions.
                                         */
                                        getVary: function () {
-                                               return mw.config.get( 'skin' ) + ':' +
-                                                       mw.config.get( 'wgResourceLoaderStorageVersion' ) + ':' +
-                                                       mw.config.get( 'wgUserLanguage' );
+                                               return $VARS.storeVary;
                                        },
 
                                        /**