From 41df695b3637bace808eec1483c8bde4daa1a40e Mon Sep 17 00:00:00 2001 From: Tim Starling Date: Fri, 4 May 2007 15:05:42 +0000 Subject: [PATCH] Output what was asked for. Don't dirty up a clean API like thumb.php with arbitrary defaults when invalid parameters are specified. --- includes/media/Generic.php | 4 +-- thumb.php | 59 ++++++++++++++++++++++---------------- 2 files changed, 37 insertions(+), 26 deletions(-) diff --git a/includes/media/Generic.php b/includes/media/Generic.php index a910bc87bc..d588a7868c 100644 --- a/includes/media/Generic.php +++ b/includes/media/Generic.php @@ -181,10 +181,10 @@ abstract class ImageHandler extends MediaHandler { function makeParamString( $params ) { if ( isset( $params['physicalWidth'] ) ) { $width = $params['physicalWidth']; - } else if ( isset( $params['width'] ) ) { + } elseif ( isset( $params['width'] ) ) { $width = $params['width']; } else { - $width = 180; + throw new MWException( 'No width specified to '.__METHOD__ ); } # Removed for ProofreadPage #$width = intval( $width ); diff --git a/thumb.php b/thumb.php index 4ca24ed77f..b92a6f7ef5 100644 --- a/thumb.php +++ b/thumb.php @@ -41,19 +41,26 @@ unset( $params['r'] ); $fileName = strtr( $fileName, '\\/', '__' ); // Work out paths, carefully avoiding constructing an Image object because that won't work yet -$handler = thumbGetHandler( $fileName ); -if ( $handler ) { - $imagePath = wfImageDir( $fileName ) . '/' . $fileName; - $thumbName = $handler->makeParamString( $params ) . "-$fileName"; - $thumbPath = wfImageThumbDir( $fileName ) . '/' . $thumbName; - - if ( is_file( $thumbPath ) && filemtime( $thumbPath ) >= filemtime( $imagePath ) ) { - wfStreamFile( $thumbPath ); - // Can't log profiling data with no Setup.php - exit; +try { + $handler = thumbGetHandler( $fileName ); + if ( $handler ) { + $imagePath = wfImageDir( $fileName ) . '/' . $fileName; + $thumbName = $handler->makeParamString( $params ) . "-$fileName"; + $thumbPath = wfImageThumbDir( $fileName ) . '/' . $thumbName; + + if ( is_file( $thumbPath ) && filemtime( $thumbPath ) >= filemtime( $imagePath ) ) { + wfStreamFile( $thumbPath ); + // Can't log profiling data with no Setup.php + exit; + } } +} catch ( MWException $e ) { + require_once( './includes/Setup.php' ); + thumbInternalError( $e->getHTML() ); + exit; } + // OK, no valid thumbnail, time to get out the heavy machinery wfProfileOut( 'thumb.php-start' ); require_once( './includes/Setup.php' ); @@ -74,9 +81,6 @@ try { if ( $thumb && $thumb->getPath() && file_exists( $thumb->getPath() ) ) { wfStreamFile( $thumb->getPath() ); } elseif ( $img ) { - header( 'Cache-Control: no-cache' ); - header( 'Content-Type: text/html; charset=utf-8' ); - header( 'HTTP/1.1 500 Internal server error' ); if ( !$thumb ) { $msg = wfMsgHtml( 'thumbnail_error', 'Image::transform() returned false' ); } elseif ( $thumb->isError() ) { @@ -86,17 +90,7 @@ if ( $thumb && $thumb->getPath() && file_exists( $thumb->getPath() ) ) { } else { $msg = wfMsgHtml( 'thumbnail_error', 'Output file missing' ); } - echo <<Error generating thumbnail - -

Error generating thumbnail

-

-$msg -

- - - -EOT; + thumbInternalError( $msg ); } else { $badtitle = wfMsg( 'badtitle' ); $badtitletext = wfMsg( 'badtitletext' ); @@ -129,4 +123,21 @@ function thumbGetHandler( $fileName ) { return MediaHandler::getHandler( $mime ); } +function thumbInternalError( $msg ) { + header( 'Cache-Control: no-cache' ); + header( 'Content-Type: text/html; charset=utf-8' ); + header( 'HTTP/1.1 500 Internal server error' ); + echo <<Error generating thumbnail + +

Error generating thumbnail

+

+$msg +

+ + + +EOT; +} + ?> -- 2.20.1