From cd2eb4e113d9269b4a0200c9ac0618023fa10dcb Mon Sep 17 00:00:00 2001 From: umherirrender Date: Wed, 27 Mar 2013 08:14:01 +0100 Subject: [PATCH] Check return value of dir() in Skin.php This avoids a fatal, when something is wrong with $wgStyleDirectory or the directory referred there. PHP Fatal error: Call to a member function read() on a non-object in Skin.php bug: 42167 Change-Id: I3d63cb984bc2aa0f85ade04607862c639ba51fdb --- includes/Skin.php | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/includes/Skin.php b/includes/Skin.php index a34afb68c5..e5aedd9eed 100644 --- a/includes/Skin.php +++ b/includes/Skin.php @@ -56,17 +56,19 @@ abstract class Skin extends ContextSource { $skinDir = dir( $wgStyleDirectory ); - # while code from www.php.net - while ( false !== ( $file = $skinDir->read() ) ) { - // Skip non-PHP files, hidden files, and '.dep' includes - $matches = array(); - - if ( preg_match( '/^([^.]*)\.php$/', $file, $matches ) ) { - $aSkin = $matches[1]; - $wgValidSkinNames[strtolower( $aSkin )] = $aSkin; + if ( $skinDir !== false && $skinDir !== null ) { + # while code from www.php.net + while ( false !== ( $file = $skinDir->read() ) ) { + // Skip non-PHP files, hidden files, and '.dep' includes + $matches = array(); + + if ( preg_match( '/^([^.]*)\.php$/', $file, $matches ) ) { + $aSkin = $matches[1]; + $wgValidSkinNames[strtolower( $aSkin )] = $aSkin; + } } + $skinDir->close(); } - $skinDir->close(); $skinsInitialised = true; wfProfileOut( __METHOD__ . '-init' ); } -- 2.20.1