X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=thumb.php;h=dbc07c2150bc31c17d9bae216d414349eeec5d0c;hb=3a24c169ea1474940633bead66fc3911fd740fc8;hp=0183c3fea16db96266e34ba49cdd42be83e5ef5d;hpb=e71e92b67e2eafb47e734de07587279c96430d8b;p=lhc%2Fweb%2Fwiklou.git diff --git a/thumb.php b/thumb.php index 0183c3fea1..dbc07c2150 100644 --- a/thumb.php +++ b/thumb.php @@ -1,79 +1,114 @@ = filemtime( $imagePath ) ) { - wfStreamFile( $thumbPath ); +// Stream the file if it exists already +try { + $img = wfLocalFile( $fileName ); + if ( $img && false != ( $thumbName = $img->thumbName( $params ) ) ) { + $thumbPath = $img->getThumbPath( $thumbName ); + + if ( is_file( $thumbPath ) ) { + wfStreamFile( $thumbPath ); + wfLogProfilingData(); + exit; + } + } +} catch ( MWException $e ) { + thumbInternalError( $e->getHTML() ); + wfLogProfilingData(); exit; } -// OK, no valid thumbnail, time to get out the heavy machinery -require_once( 'Setup.php' ); -wfProfileIn( 'thumb.php' ); - -$img = Image::newFromName( $fileName ); -if ( $img ) { - $thumb = $img->renderThumb( $width, false ); -} else { +wfProfileOut( 'thumb.php-start' ); +wfProfileIn( 'thumb.php-render' ); + +try { + if ( $img ) { + $thumb = $img->transform( $params, File::RENDER_NOW ); + } else { + $thumb = false; + } +} catch( Exception $ex ) { + // Tried to select a page on a non-paged file? $thumb = false; } -if ( $thumb && $thumb->path ) { - wfStreamFile( $thumb->path ); +$errorMsg = false; +if ( !$img ) { + $errorMsg = wfMsg( 'badtitletext' ); +} elseif ( !$thumb ) { + $errorMsg = wfMsgHtml( 'thumbnail_error', 'File::transform() returned false' ); +} elseif ( $thumb->isError() ) { + $errorMsg = $thumb->getHtmlMsg(); +} elseif ( !$thumb->getPath() ) { + $errorMsg = wfMsgHtml( 'thumbnail_error', 'No path supplied in thumbnail object' ); +} elseif ( $thumb->getPath() == $img->getPath() ) { + $errorMsg = wfMsgHtml( 'thumbnail_error', 'Image was not scaled, ' . + 'is the requested width bigger than the source?' ); } else { - $badtitle = wfMsg( 'badtitle' ); - $badtitletext = wfMsg( 'badtitletext' ); - echo " - $badtitle - -

$badtitle

-

$badtitletext

-"; + wfStreamFile( $thumb->getPath() ); +} +if ( $errorMsg !== false ) { + thumbInternalError( $errorMsg ); } +wfProfileOut( 'thumb.php-render' ); wfProfileOut( 'thumb.php' ); +wfLogProfilingData(); + +//-------------------------------------------------------------------------- + +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; +} -?>