X-Git-Url: http://git.cyclocoop.org/?a=blobdiff_plain;f=includes%2Fresourceloader%2FResourceLoaderFileModule.php;h=28488712ddbf7f0d2f95e5068fe59f4266b40590;hb=26e157d31135fd4c74a7e0544722a69face4d6df;hp=0e53e5e731c08350b0d2a52795455e68f8e9b362;hpb=855787ca318e0fa0fabf41c5769af7d4e0d09e7d;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/resourceloader/ResourceLoaderFileModule.php b/includes/resourceloader/ResourceLoaderFileModule.php index 0e53e5e731..28488712dd 100644 --- a/includes/resourceloader/ResourceLoaderFileModule.php +++ b/includes/resourceloader/ResourceLoaderFileModule.php @@ -204,12 +204,11 @@ class ResourceLoaderFileModule extends ResourceLoaderModule { * // If 'packageFiles' is set, 'scripts' cannot also be set * 'packageFiles' => [ * [file path string], // or: - * [file alias] => [file path string], // or: - * [file alias] => [ 'file' => [file path string], 'type' => 'script'|'data' ], // or: - * [file alias] => [ 'content' => [string], 'type' => 'script'|'data' ], // or: - * [file alias] => [ 'callback' => [callable], 'type' => 'script'|'data' ], // or: - * [file alias] => [ 'config' => [ [config var name], ... ], 'type' => 'data' ], // or: - * [file alias] => [ 'config' => [ [JS name] => [PHP name] ], 'type' => 'data' ], + * [ 'name' => [file name], 'file' => [file path], 'type' => 'script'|'data' ], // or: + * [ 'name' => [name], 'content' => [string], 'type' => 'script'|'data' ], // or: + * [ 'name' => [name], 'callback' => [callable], 'type' => 'script'|'data' ], + * [ 'name' => [name], 'config' => [ [config var name], ... ], 'type' => 'data' ], + * [ 'name' => [name], 'config' => [ [JS name] => [PHP name] ], 'type' => 'data' ], * ], * // Modules which must be loaded before this module * 'dependencies' => [module name string or array of module name strings], @@ -878,25 +877,16 @@ class ResourceLoaderFileModule extends ResourceLoaderModule { /** * Get the contents of a list of CSS files. * - * This is considered a private method. Exposed for internal use by WebInstallerOutput. - * - * @private + * @internal This is considered a private method. Exposed for internal use by WebInstallerOutput. * @param array $styles Map of media type to file paths to read, remap, and concatenate * @param bool $flip - * @param ResourceLoaderContext|null $context + * @param ResourceLoaderContext $context * @return array List of concatenated and remapped CSS data from $styles, * keyed by media type * @throws MWException - * @since 1.27 Calling this method without a ResourceLoaderContext instance - * is deprecated. */ - public function readStyleFiles( array $styles, $flip, $context = null ) { - if ( $context === null ) { - wfDeprecated( __METHOD__ . ' without a ResourceLoader context', '1.27' ); - $context = ResourceLoaderContext::newDummyContext(); - } - - if ( empty( $styles ) ) { + public function readStyleFiles( array $styles, $flip, $context ) { + if ( !$styles ) { return []; } foreach ( $styles as $media => $files ) { @@ -1100,25 +1090,20 @@ class ResourceLoaderFileModule extends ResourceLoaderModule { $mainFile = null; foreach ( $this->packageFiles as $alias => $fileInfo ) { - // Alias is optional, but only when specfiying plain file names (strings) - if ( is_int( $alias ) ) { - if ( is_array( $fileInfo ) ) { - $msg = __METHOD__ . ": invalid package file definition for module " . - "\"{$this->getName()}\": key is required when value is not a string"; - wfDebugLog( 'resourceloader', $msg ); - throw new MWException( $msg ); - } - $alias = $fileInfo; - } - if ( !is_array( $fileInfo ) ) { - $fileInfo = [ 'file' => $fileInfo ]; + if ( is_string( $fileInfo ) ) { + $fileInfo = [ 'name' => $fileInfo, 'file' => $fileInfo ]; + } elseif ( !isset( $fileInfo['name'] ) ) { + $msg = __METHOD__ . ": invalid package file definition for module " . + "\"{$this->getName()}\": 'name' key is required when value is not a string"; + wfDebugLog( 'resourceloader', $msg ); + throw new MWException( $msg ); } // Infer type from alias if needed - $type = $fileInfo['type'] ?? self::getPackageFileType( $alias ); + $type = $fileInfo['type'] ?? self::getPackageFileType( $fileInfo['name'] ); $expanded = [ 'type' => $type ]; if ( !empty( $fileInfo['main'] ) ) { - $mainFile = $alias; + $mainFile = $fileInfo['name']; if ( $type !== 'script' ) { $msg = __METHOD__ . ": invalid package file definition for module " . "\"{$this->getName()}\": main file \"$mainFile\" must be of type \"script\", not \"$type\""; @@ -1135,15 +1120,15 @@ class ResourceLoaderFileModule extends ResourceLoaderModule { if ( is_callable( $fileInfo['callback'] ) ) { $expanded['content'] = $fileInfo['callback']( $context ); } else { - $msg = __METHOD__ . ": invalid callback for package file \"$alias\"" . + $msg = __METHOD__ . ": invalid callback for package file \"{$fileInfo['name']}\"" . " in module \"{$this->getName()}\""; wfDebugLog( 'resourceloader', $msg ); throw new MWException( $msg ); } } elseif ( isset( $fileInfo['config'] ) ) { if ( $type !== 'data' ) { - $msg = __METHOD__ . ": invalid use of \"config\" for package file \"$alias\" in module " . - "\"{$this->getName()}\": type must be \"data\" but is \"$type\""; + $msg = __METHOD__ . ": invalid use of \"config\" for package file \"{$fileInfo['name']}\" " . + "in module \"{$this->getName()}\": type must be \"data\" but is \"$type\""; wfDebugLog( 'resourceloader', $msg ); throw new MWException( $msg ); } @@ -1153,16 +1138,17 @@ class ResourceLoaderFileModule extends ResourceLoaderModule { } $expanded['content'] = $expandedConfig; } elseif ( !empty( $fileInfo['main'] ) ) { - // 'foo.js' => [ 'main' => true ] is shorthand - $expanded['filePath'] = $alias; + // [ 'name' => 'foo.js', 'main' => true ] is shorthand + $expanded['filePath'] = $fileInfo['name']; } else { - $msg = __METHOD__ . ": invalid package file definition for \"$alias\" in module " . - "\"{$this->getName()}\": one of \"file\", \"content\", \"callback\" or \"config\" must be set"; + $msg = __METHOD__ . ": invalid package file definition for \"{$fileInfo['name']}\" " . + "in module \"{$this->getName()}\": one of \"file\", \"content\", \"callback\" or \"config\" " . + "must be set"; wfDebugLog( 'resourceloader', $msg ); throw new MWException( $msg ); } - $expandedFiles[$alias] = $expanded; + $expandedFiles[$fileInfo['name']] = $expanded; } if ( $expandedFiles && $mainFile === null ) {