Output what was asked for. Don't dirty up a clean API like thumb.php with arbitrary...
authorTim Starling <tstarling@users.mediawiki.org>
Fri, 4 May 2007 15:05:42 +0000 (15:05 +0000)
committerTim Starling <tstarling@users.mediawiki.org>
Fri, 4 May 2007 15:05:42 +0000 (15:05 +0000)
includes/media/Generic.php
thumb.php

index a910bc8..d588a78 100644 (file)
@@ -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 );
index 4ca24ed..b92a6f7 100644 (file)
--- 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 <<<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' );
@@ -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 <<<EOT
+<html><head><title>Error generating thumbnail</title></head>
+<body>
+<h1>Error generating thumbnail</h1>
+<p>
+$msg
+</p>
+</body>
+</html>
+
+EOT;
+}
+
 ?>