ResourceLoaderImage: Throw exception if files don't exist
authorBartosz Dziewoński <matma.rex@gmail.com>
Mon, 30 Mar 2015 17:08:55 +0000 (19:08 +0200)
committerBartosz Dziewoński <matma.rex@gmail.com>
Mon, 30 Mar 2015 17:15:37 +0000 (19:15 +0200)
Change-Id: I67eb795f7fc4d35d15feb0717b1b781cbc45f78a

includes/resourceloader/ResourceLoaderImage.php

index d12975a..758ee7c 100644 (file)
@@ -191,6 +191,7 @@ class ResourceLoaderImage {
         * @param string $format Format to get the data for, 'original' or 'rasterized'. Optional, if
         *     given, overrides the data from $context.
         * @return string|false Possibly binary image data, or false on failure
+        * @throws MWException If the image file doesn't exist
         */
        public function getImageData( ResourceLoaderContext $context, $variant = false, $format = false ) {
                if ( $variant === false ) {
@@ -201,6 +202,10 @@ class ResourceLoaderImage {
                }
 
                $path = $this->getPath( $context );
+               if ( !file_exists( $path ) ) {
+                       throw new MWException( "File '$path' does not exist" );
+               }
+
                if ( $this->getExtension() !== 'svg' ) {
                        return file_get_contents( $path );
                }