resourceloader: Hard deprecate ResourceLoader::getLessVars
[lhc/web/wiklou.git] / includes / resourceloader / ResourceLoader.php
index 3e55dfd..54ab6a1 100644 (file)
@@ -689,24 +689,29 @@ class ResourceLoader implements LoggerAwareInterface {
         *
         * @since 1.28
         * @param ResourceLoaderContext $context
+        * @param string[]|null $modules
         * @return string Hash
         */
-       public function makeVersionQuery( ResourceLoaderContext $context ) {
+       public function makeVersionQuery( ResourceLoaderContext $context, array $modules = null ) {
+               if ( $modules === null ) {
+                       wfDeprecated( __METHOD__ . ' without $modules', '1.34' );
+                       $modules = $context->getModules();
+               }
                // As of MediaWiki 1.28, the server and client use the same algorithm for combining
                // version hashes. There is no technical reason for this to be same, and for years the
                // implementations differed. If getCombinedVersion in PHP (used for StartupModule and
                // E-Tag headers) differs in the future from getCombinedVersion in JS (used for 'version'
                // query parameter), then this method must continue to match the JS one.
-               $moduleNames = [];
-               foreach ( $context->getModules() as $name ) {
+               $filtered = [];
+               foreach ( $modules as $name ) {
                        if ( !$this->getModule( $name ) ) {
                                // If a versioned request contains a missing module, the version is a mismatch
                                // as the client considered a module (and version) we don't have.
                                return '';
                        }
-                       $moduleNames[] = $name;
+                       $filtered[] = $name;
                }
-               return $this->getCombinedVersion( $context, $moduleNames );
+               return $this->getCombinedVersion( $context, $filtered );
        }
 
        /**
@@ -863,7 +868,7 @@ class ResourceLoader implements LoggerAwareInterface {
                // - Version mismatch (T117587, T47877)
                if ( is_null( $context->getVersion() )
                        || $errors
-                       || $context->getVersion() !== $this->makeVersionQuery( $context )
+                       || $context->getVersion() !== $this->makeVersionQuery( $context, $context->getModules() )
                ) {
                        $maxage = $rlMaxage['unversioned']['client'];
                        $smaxage = $rlMaxage['unversioned']['server'];
@@ -1361,27 +1366,20 @@ MESSAGE;
        }
 
        /**
-        * Returns a JS call to mw.loader.state, which sets the state of one
-        * ore more modules to a given value. Has two calling conventions:
-        *
-        *    - ResourceLoader::makeLoaderStateScript( $context, $name, $state ):
-        *         Set the state of a single module called $name to $state
+        * Returns a JS call to mw.loader.state, which sets the state of modules
+        * to a given value:
         *
         *    - ResourceLoader::makeLoaderStateScript( $context, [ $name => $state, ... ] ):
         *         Set the state of modules with the given names to the given states
         *
         * @internal
         * @param ResourceLoaderContext $context
-        * @param array|string $states
-        * @param string|null $state
+        * @param array $states
         * @return string JavaScript code
         */
        public static function makeLoaderStateScript(
-               ResourceLoaderContext $context, $states, $state = null
+               ResourceLoaderContext $context, array $states
        ) {
-               if ( !is_array( $states ) ) {
-                       $states = [ $states => $state ];
-               }
                return 'mw.loader.state('
                        . $context->encodeJson( $states )
                        . ');';
@@ -1477,10 +1475,7 @@ MESSAGE;
 
        /**
         * Returns JS code which calls mw.loader.addSource() with the given
-        * parameters. Has two calling conventions:
-        *
-        *   - ResourceLoader::makeLoaderSourcesScript( $context, $id, $properties ):
-        *       Register a single source
+        * parameters.
         *
         *   - ResourceLoader::makeLoaderSourcesScript( $context,
         *         [ $id1 => $loadUrl, $id2 => $loadUrl, ... ]
@@ -1489,16 +1484,12 @@ MESSAGE;
         *
         * @internal For use by ResourceLoaderStartUpModule only
         * @param ResourceLoaderContext $context
-        * @param string|array $sources Source ID
-        * @param string|null $loadUrl load.php url
+        * @param array $sources
         * @return string JavaScript code
         */
        public static function makeLoaderSourcesScript(
-               ResourceLoaderContext $context, $sources, $loadUrl = null
+               ResourceLoaderContext $context, array $sources
        ) {
-               if ( !is_array( $sources ) ) {
-                       $sources = [ $sources => $loadUrl ];
-               }
                return 'mw.loader.addSource('
                        . $context->encodeJson( $sources )
                        . ');';
@@ -1826,10 +1817,11 @@ MESSAGE;
         * Get global LESS variables.
         *
         * @since 1.27
-        * @deprecated since 1.32 Use ResourceLoderModule::getLessVars() instead.
+        * @deprecated since 1.32 Use ResourceLoaderModule::getLessVars() instead.
         * @return array Map of variable names to string CSS values.
         */
        public function getLessVars() {
+               wfDeprecated( __METHOD__, '1.32' );
                return [];
        }
 }