ResourceLoaderImage: Correctly ignore 'deprecated' key
authorRoan Kattouw <roan.kattouw@gmail.com>
Wed, 29 Mar 2017 18:44:22 +0000 (14:44 -0400)
committerRoan Kattouw <roan.kattouw@gmail.com>
Wed, 29 Mar 2017 18:44:22 +0000 (14:44 -0400)
It turns out that 'resources/lib/oojs-ui/themes/mediawiki/Moved since v0.20.1, use from the 'interactions' pack instead.'
is not usually an existing file, and doesn't have the extension '.svg'.
Not sure why this didn't break earlier.

Bonus: Add module name to exceptions to make these errors easier
to track down.

Bonus #2: Use the post-expansion, not pre-expansion, definition everywhere
to avoid confusion when debugging.

Change-Id: I0325d4dab5658fd29c3c33fd3e762834b53d1b5d

includes/resourceloader/ResourceLoaderImage.php

index 6a6a3c2..19d5471 100644 (file)
@@ -67,23 +67,27 @@ class ResourceLoaderImage {
                                }
                        }
                }
+               // Remove 'deprecated' key
+               if ( is_array( $this->descriptor ) ) {
+                       unset( $this->descriptor[ 'deprecated' ] );
+               }
 
                // Ensure that all files have common extension.
                $extensions = [];
-               $descriptor = (array)$descriptor;
+               $descriptor = (array)$this->descriptor;
                array_walk_recursive( $descriptor, function ( $path ) use ( &$extensions ) {
                        $extensions[] = pathinfo( $path, PATHINFO_EXTENSION );
                } );
                $extensions = array_unique( $extensions );
                if ( count( $extensions ) !== 1 ) {
                        throw new InvalidArgumentException(
-                               "File type for different image files of '$name' not the same"
+                               "File type for different image files of '$name' not the same in module '$module'"
                        );
                }
                $ext = $extensions[0];
                if ( !isset( self::$fileTypes[$ext] ) ) {
                        throw new InvalidArgumentException(
-                               "Invalid file type for image files of '$name' (valid: svg, png, gif, jpg)"
+                               "Invalid file type for image files of '$name' (valid: svg, png, gif, jpg) in module '$module'"
                        );
                }
                $this->extension = $ext;