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 );
$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' );
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() ) {
} else {
$msg = wfMsgHtml( 'thumbnail_error', 'Output file missing' );
}
- echo <<<EOT
-<html><head><title>Error generating thumbnail</title></head>
-<body>
-<h1>Error generating thumbnail</h1>
-<p>
-$msg
-</p>
-</body>
-</html>
-
-EOT;
+ thumbInternalError( $msg );
} else {
$badtitle = wfMsg( 'badtitle' );
$badtitletext = wfMsg( 'badtitletext' );
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 <<<EOT
+<html><head><title>Error generating thumbnail</title></head>
+<body>
+<h1>Error generating thumbnail</h1>
+<p>
+$msg
+</p>
+</body>
+</html>
+
+EOT;
+}
+
?>