Merge "API: Overhaul ApiResult, make format=xml not throw, and add json formatversion"
[lhc/web/wiklou.git] / includes / resourceloader / ResourceLoaderFileModule.php
index fbca08e..671098e 100644 (file)
@@ -174,7 +174,7 @@ class ResourceLoaderFileModule extends ResourceLoaderModule {
         *     to $wgResourceBasePath
         *
         * Below is a description for the $options array:
-        * @throws MWException
+        * @throws InvalidArgumentException
         * @par Construction options:
         * @code
         *     array(
@@ -255,14 +255,14 @@ class ResourceLoaderFileModule extends ResourceLoaderModule {
                                case 'skinScripts':
                                case 'skinStyles':
                                        if ( !is_array( $option ) ) {
-                                               throw new MWException(
+                                               throw new InvalidArgumentException(
                                                        "Invalid collated file path list error. " .
                                                        "'$option' given, array expected."
                                                );
                                        }
                                        foreach ( $option as $key => $value ) {
                                                if ( !is_string( $key ) ) {
-                                                       throw new MWException(
+                                                       throw new InvalidArgumentException(
                                                                "Invalid collated file path list key error. " .
                                                                "'$key' given, string expected."
                                                        );
@@ -295,6 +295,18 @@ class ResourceLoaderFileModule extends ResourceLoaderModule {
                }
                if ( $hasTemplates ) {
                        $this->dependencies[] = 'mediawiki.template';
+                       // Ensure relevant template compiler module gets loaded
+                       foreach ( $this->templates as $alias => $templatePath ) {
+                               if ( is_int( $alias ) ) {
+                                       $alias = $templatePath;
+                               }
+                               $suffix = explode( '.', $alias );
+                               $suffix = end( $suffix );
+                               $compilerModule = 'mediawiki.template.' . $suffix;
+                               if ( $suffix !== 'html' && !in_array( $compilerModule, $this->dependencies ) ) {
+                                       $this->dependencies[] = $compilerModule;
+                               }
+                       }
                }
        }
 
@@ -561,6 +573,10 @@ class ResourceLoaderFileModule extends ResourceLoaderModule {
                $files = array_map( array( $this, 'getLocalPath' ), $files );
                // File deps need to be treated separately because they're already prefixed
                $files = array_merge( $files, $this->getFileDependencies( $context->getSkin() ) );
+               // Filter out any duplicates from getFileDependencies() and others.
+               // Most commonly introduced by compileLessFile(), which always includes the
+               // entry point Less file we already know about.
+               $files = array_values( array_unique( $files ) );
 
                // If a module is nothing but a list of dependencies, we need to avoid
                // giving max() an empty array
@@ -587,9 +603,7 @@ class ResourceLoaderFileModule extends ResourceLoaderModule {
         * @return array
         */
        public function getDefinitionSummary( ResourceLoaderContext $context ) {
-               $summary = array(
-                       'class' => get_class( $this ),
-               );
+               $summary = parent::getDefinitionSummary( $context );
                foreach ( array(
                        'scripts',
                        'debugScripts',