+ $img = wfLocalFile( $fileName );
+ }
+
+ if ( !$img ) {
+ wfThumbError( 404, wfMsg( 'badtitletext' ) );
+ return;
+ }
+ if ( !$img->exists() ) {
+ wfThumbError( 404, 'The source file for the specified thumbnail does not exist.' );
+ return;
+ }
+ $sourcePath = $img->getPath();
+ if ( $sourcePath === false ) {
+ wfThumbError( 500, 'The source file is not locally accessible.' );
+ return;
+ }
+
+ // Check IMS against the source file
+ // This means that clients can keep a cached copy even after it has been deleted on the server
+ if ( !empty( $_SERVER['HTTP_IF_MODIFIED_SINCE'] ) ) {
+ // Fix IE brokenness
+ $imsString = preg_replace( '/;.*$/', '', $_SERVER["HTTP_IF_MODIFIED_SINCE"] );
+ // Calculate time
+ wfSuppressWarnings();
+ $imsUnix = strtotime( $imsString );
+ wfRestoreWarnings();
+ $stat = @stat( $sourcePath );
+ if ( $stat['mtime'] <= $imsUnix ) {
+ header( 'HTTP/1.1 304 Not Modified' );
+ return;
+ }
+ }
+
+ // Stream the file if it exists already
+ try {
+ if ( false != ( $thumbName = $img->thumbName( $params ) ) ) {
+ $thumbPath = $img->getThumbPath( $thumbName );
+
+ if ( is_file( $thumbPath ) ) {
+ wfStreamFile( $thumbPath );
+ return;
+ }
+ }
+ } catch ( MWException $e ) {
+ wfThumbError( 500, $e->getHTML() );
+ return;
+ }
+
+ try {
+ $thumb = $img->transform( $params, File::RENDER_NOW );
+ } catch( Exception $ex ) {
+ // Tried to select a page on a non-paged file?