From 1157312f1e5fe2641784f5c6d0d5ad93dca24f38 Mon Sep 17 00:00:00 2001 From: Bryan Davis Date: Thu, 8 Jan 2015 16:24:50 -0700 Subject: [PATCH] Guard against unset key access in ResourceLoaderImageModule 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 --- .../ResourceLoaderImageModule.php | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/includes/resourceloader/ResourceLoaderImageModule.php b/includes/resourceloader/ResourceLoaderImageModule.php index 9246df729b..67806fffb7 100644 --- a/includes/resourceloader/ResourceLoaderImageModule.php +++ b/includes/resourceloader/ResourceLoaderImageModule.php @@ -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; + } } } } -- 2.20.1