Merge "Add config for serving main Page from the domain root"
[lhc/web/wiklou.git] / includes / resourceloader / ResourceLoaderFileModule.php
index 017b399..23a9a14 100644 (file)
@@ -1,7 +1,5 @@
 <?php
 /**
- * ResourceLoader module based on local JavaScript/CSS files.
- *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
  * the Free Software Foundation; either version 2 of the License, or
  */
 
 /**
- * ResourceLoader module based on local JavaScript/CSS files.
+ * Module based on local JavaScript/CSS files.
  *
  * The following public methods can query the database:
  *
  * - getDefinitionSummary / … / ResourceLoaderModule::getFileDependencies.
  * - getVersionHash / getDefinitionSummary / … / ResourceLoaderModule::getFileDependencies.
  * - getStyles / ResourceLoaderModule::saveFileDependencies.
+ *
+ * @ingroup ResourceLoader
+ * @since 1.17
  */
 class ResourceLoaderFileModule extends ResourceLoaderModule {
 
@@ -256,11 +257,11 @@ class ResourceLoaderFileModule extends ResourceLoaderModule {
                                case 'debugScripts':
                                case 'styles':
                                case 'packageFiles':
-                                       $this->{$member} = (array)$option;
+                                       $this->{$member} = is_array( $option ) ? $option : [ $option ];
                                        break;
                                case 'templates':
                                        $hasTemplates = true;
-                                       $this->{$member} = (array)$option;
+                                       $this->{$member} = is_array( $option ) ? $option : [ $option ];
                                        break;
                                // Collated lists of file paths
                                case 'languageScripts':
@@ -279,7 +280,7 @@ class ResourceLoaderFileModule extends ResourceLoaderModule {
                                                                "'$key' given, string expected."
                                                        );
                                                }
-                                               $this->{$member}[$key] = (array)$value;
+                                               $this->{$member}[$key] = is_array( $value ) ? $value : [ $value ];
                                        }
                                        break;
                                case 'deprecated':
@@ -315,7 +316,7 @@ class ResourceLoaderFileModule extends ResourceLoaderModule {
                        // Ensure relevant template compiler module gets loaded
                        foreach ( $this->templates as $alias => $templatePath ) {
                                if ( is_int( $alias ) ) {
-                                       $alias = $templatePath;
+                                       $alias = $this->getPath( $templatePath );
                                }
                                $suffix = explode( '.', $alias );
                                $suffix = end( $suffix );
@@ -643,6 +644,18 @@ class ResourceLoaderFileModule extends ResourceLoaderModule {
                return $summary;
        }
 
+       /**
+        * @param string|ResourceLoaderFilePath $path
+        * @return string
+        */
+       protected function getPath( $path ) {
+               if ( $path instanceof ResourceLoaderFilePath ) {
+                       return $path->getPath();
+               }
+
+               return $path;
+       }
+
        /**
         * @param string|ResourceLoaderFilePath $path
         * @return string
@@ -786,9 +799,7 @@ class ResourceLoaderFileModule extends ResourceLoaderModule {
        /**
         * Get a list of file paths for all styles in this module, in order of proper inclusion.
         *
-        * This is considered a private method. Exposed for internal use by WebInstallerOutput.
-        *
-        * @private
+        * @internal Exposed only for use by WebInstallerOutput.
         * @param ResourceLoaderContext $context
         * @return array List of file paths
         */
@@ -992,6 +1003,7 @@ class ResourceLoaderFileModule extends ResourceLoaderModule {
                        || $this->dependencies
                        || $this->messages
                        || $this->skipFunction
+                       || $this->packageFiles
                );
                return $canBeStylesOnly ? self::LOAD_STYLES : self::LOAD_GENERAL;
        }
@@ -1002,7 +1014,7 @@ class ResourceLoaderFileModule extends ResourceLoaderModule {
         * Keeps track of all used files and adds them to localFileRefs.
         *
         * @since 1.22
-        * @since 1.27 Added $context paramter.
+        * @since 1.27 Added $context parameter.
         * @throws Exception If less.php encounters a parse error
         * @param string $fileName File path of LESS source
         * @param ResourceLoaderContext $context Context in which to generate script
@@ -1060,7 +1072,7 @@ class ResourceLoaderFileModule extends ResourceLoaderModule {
                foreach ( $this->templates as $alias => $templatePath ) {
                        // Alias is optional
                        if ( is_int( $alias ) ) {
-                               $alias = $templatePath;
+                               $alias = $this->getPath( $templatePath );
                        }
                        $localPath = $this->getLocalPath( $templatePath );
                        if ( file_exists( $localPath ) ) {
@@ -1147,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' ) {
@@ -1228,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'] );
                        }