From: Bryan Davis Date: Thu, 5 Sep 2013 20:46:38 +0000 (-0600) Subject: Guard against non-object returns from File::getHander() X-Git-Tag: 1.31.0-rc.0~18751^2 X-Git-Url: http://git.cyclocoop.org/%24image?a=commitdiff_plain;h=176e012fe33b042667484754e3fe112d4eca2c1e;p=lhc%2Fweb%2Fwiklou.git Guard against non-object returns from File::getHander() MediaHandler::getHandler() can return false when a handler cannot be determined for the given file's derived mime type. This change adds guards to invocations that I could find that did not properly check for this potential return result. Bug: 53820 Change-Id: I8c0165311cc75f9920ac30ce2b38ccd207439198 --- diff --git a/includes/filerepo/file/File.php b/includes/filerepo/file/File.php index 9060731724..05cb00006f 100644 --- a/includes/filerepo/file/File.php +++ b/includes/filerepo/file/File.php @@ -842,8 +842,9 @@ abstract class File { protected function transformErrorOutput( $thumbPath, $thumbUrl, $params, $flags ) { global $wgIgnoreImageErrors; - if ( $wgIgnoreImageErrors && !( $flags & self::RENDER_NOW ) ) { - return $this->getHandler()->getTransform( $this, $thumbPath, $thumbUrl, $params ); + $handler = $this->getHandler(); + if ( $handler && $wgIgnoreImageErrors && !( $flags & self::RENDER_NOW ) ) { + return $handler->getTransform( $this, $thumbPath, $thumbUrl, $params ); } else { return new MediaTransformError( 'thumbnail_error', $params['width'], 0, wfMessage( 'thumbnail-dest-create' )->text() ); @@ -1000,7 +1001,7 @@ abstract class File { /** * Get a MediaHandler instance for this file * - * @return MediaHandler + * @return MediaHandler|boolean Registered MediaHandler for file's mime type or false if none found */ function getHandler() { if ( !isset( $this->handler ) ) { diff --git a/includes/filerepo/file/LocalFile.php b/includes/filerepo/file/LocalFile.php index 39ef62c6e3..91dacf8a22 100644 --- a/includes/filerepo/file/LocalFile.php +++ b/includes/filerepo/file/LocalFile.php @@ -610,7 +610,11 @@ class LocalFile extends File { $this->load(); if ( $this->isMultipage() ) { - $dim = $this->getHandler()->getPageDimensions( $this, $page ); + $handler = $this->getHandler(); + if ( !$handler ) { + return 0; + } + $dim = $handler->getPageDimensions( $this, $page ); if ( $dim ) { return $dim['width']; } else { @@ -633,7 +637,11 @@ class LocalFile extends File { $this->load(); if ( $this->isMultipage() ) { - $dim = $this->getHandler()->getPageDimensions( $this, $page ); + $handler = $this->getHandler(); + if ( !$handler ) { + return 0; + } + $dim = $handler->getPageDimensions( $this, $page ); if ( $dim ) { return $dim['height']; } else { diff --git a/includes/specials/SpecialUploadStash.php b/includes/specials/SpecialUploadStash.php index e7f36ee57f..002e949be9 100644 --- a/includes/specials/SpecialUploadStash.php +++ b/includes/specials/SpecialUploadStash.php @@ -134,8 +134,13 @@ class SpecialUploadStash extends UnlistedSpecialPage { $paramString = substr( $thumbPart, 0, $srcNamePos - 1 ); $handler = $file->getHandler(); - $params = $handler->parseParamString( $paramString ); - return array( 'file' => $file, 'type' => $type, 'params' => $params ); + if ( $handler ) { + $params = $handler->parseParamString( $paramString ); + return array( 'file' => $file, 'type' => $type, 'params' => $params ); + } else { + throw new UploadStashBadPathException( 'No handler found for ' . + "mime {$file->getMimeType()} of file {$file->getPath()}" ); + } } return array( 'file' => $file, 'type' => $type );