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
This commit is contained in:
parent
e7ce589265
commit
176e012fe3
3 changed files with 21 additions and 7 deletions
|
|
@ -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 ) ) {
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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 );
|
||||
|
|
|
|||
Loading…
Reference in a new issue