Guard against unset key access in ResourceLoaderImageModule
authorBryan Davis <bd808@wikimedia.org>
Thu, 8 Jan 2015 23:24:50 +0000 (16:24 -0700)
committerUmherirrender <umherirrender_de.wp@web.de>
Fri, 9 Jan 2015 18:58:46 +0000 (18:58 +0000)
Seen in production error logs:
  Undefined index: icon in ResourceLoaderImageModule.php on line 162
  Undefined index: icon in ResourceLoaderImageModule.php on line 185

Change-Id: I44e16563bda2dcc0be3c9694ed2b09d20b3d7468

includes/resourceloader/ResourceLoaderImageModule.php

index 9246df7..67806ff 100644 (file)
@@ -158,10 +158,14 @@ class ResourceLoaderImageModule extends ResourceLoaderModule {
                                                isset( $options['variants'] ) ? $options['variants'] : array(),
                                                $this->getGlobalVariants( $type )
                                        );
-                                       $variantConfig = array_intersect_key(
-                                               $this->variants[$type],
-                                               array_fill_keys( $allowedVariants, true )
-                                       );
+                                       if ( isset( $this->variants[$type] ) ) {
+                                               $variantConfig = array_intersect_key(
+                                                       $this->variants[$type],
+                                                       array_fill_keys( $allowedVariants, true )
+                                               );
+                                       } else {
+                                               $variantConfig = array();
+                                       }
 
                                        $image = new ResourceLoaderImage( $name, $this->getName(), $imageDesc, $this->localBasePath, $variantConfig );
                                        $this->imageObjects[ $image->getName() ] = $image;
@@ -182,9 +186,11 @@ class ResourceLoaderImageModule extends ResourceLoaderModule {
                if ( !isset( $this->globalVariants[$type] ) ) {
                        $this->globalVariants[$type] = array();
 
-                       foreach ( $this->variants[$type] as $name => $config ) {
-                               if ( isset( $config['global'] ) && $config['global'] ) {
-                                       $this->globalVariants[$type][] = $name;
+                       if ( isset( $this->variants[$type] ) ) {
+                               foreach ( $this->variants[$type] as $name => $config ) {
+                                       if ( isset( $config['global'] ) && $config['global'] ) {
+                                               $this->globalVariants[$type][] = $name;
+                                       }
                                }
                        }
                }