resourceloader: Add Config parameter to packageFiles callbacks
authorRoan Kattouw <roan.kattouw@gmail.com>
Thu, 18 Jul 2019 21:48:42 +0000 (14:48 -0700)
committerRoan Kattouw <roan.kattouw@gmail.com>
Thu, 18 Jul 2019 21:48:42 +0000 (14:48 -0700)
Callbacks used to generate the contents of virtual files in packageFiles
modules only received a ResourceLoaderContext object. They could access
the Config object through ResourceLoaderContext::getConfig(), but that
method is deprecated. Pass the Config object as a second parameter to
these callbacks, so that they don't have to use a deprecated method.

Change-Id: Ia4666914e9b07f298ee5ae30ae8c70a3e83b0910

includes/resourceloader/ResourceLoaderFileModule.php
resources/Resources.php

index fbc59fe..af30313 100644 (file)
@@ -1159,11 +1159,12 @@ class ResourceLoaderFileModule extends ResourceLoaderModule {
                                                throw new MWException( __METHOD__ . ": invalid versionCallback for file" .
                                                        " \"{$fileInfo['name']}\" in module \"{$this->getName()}\"" );
                                        }
-                                       $expanded['definitionSummary'] = ( $fileInfo['versionCallback'] )( $context );
+                                       $expanded['definitionSummary'] =
+                                               ( $fileInfo['versionCallback'] )( $context, $this->getConfig() );
                                        // Don't invoke 'callback' here as it may be expensive (T223260).
                                        $expanded['callback'] = $fileInfo['callback'];
                                } else {
-                                       $expanded['content'] = ( $fileInfo['callback'] )( $context );
+                                       $expanded['content'] = ( $fileInfo['callback'] )( $context, $this->getConfig() );
                                }
                        } elseif ( isset( $fileInfo['config'] ) ) {
                                if ( $type !== 'data' ) {
@@ -1240,7 +1241,7 @@ class ResourceLoaderFileModule extends ResourceLoaderModule {
                                $fileInfo['content'] = $content;
                                unset( $fileInfo['filePath'] );
                        } elseif ( isset( $fileInfo['callback'] ) ) {
-                               $fileInfo['content'] = ( $fileInfo['callback'] )( $context );
+                               $fileInfo['content'] = ( $fileInfo['callback'] )( $context, $this->getConfig() );
                                unset( $fileInfo['callback'] );
                        }
 
index 6298086..9455994 100644 (file)
@@ -1526,7 +1526,9 @@ return [
                'remoteBasePath' => "$wgResourceBasePath/resources/src/mediawiki.jqueryMsg",
                'packageFiles' => [
                        'mediawiki.jqueryMsg.js',
-                       [ 'name' => 'parserDefaults.json', 'callback' => function ( ResourceLoaderContext $context ) {
+                       [ 'name' => 'parserDefaults.json', 'callback' => function (
+                               ResourceLoaderContext $context, Config $config
+                       ) {
                                $tagData = Sanitizer::getRecognizedTagData();
                                $allowedHtmlElements = array_merge(
                                        array_keys( $tagData['htmlpairs'] ),
@@ -1537,7 +1539,7 @@ return [
                                );
 
                                $magicWords = [
-                                       'SITENAME' => $context->getConfig()->get( 'Sitename' ),
+                                       'SITENAME' => $config->get( 'Sitename' ),
                                ];
                                Hooks::run( 'ResourceLoaderJqueryMsgModuleMagicWords', [ $context, &$magicWords ] );