X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=thumb.php;h=25bca879547109821ac2ec2de52916ba9e70f1ec;hb=909e38672a28a06e021fd1d98f74910f0bf90bc6;hp=0d0a15ebcfed1ba1222b8760f63375e884143c2e;hpb=bca2d29cbf2d9a9bbebf546e9df2d80131ae5900;p=lhc%2Fweb%2Fwiklou.git diff --git a/thumb.php b/thumb.php index 0d0a15ebcf..25bca87954 100644 --- a/thumb.php +++ b/thumb.php @@ -163,7 +163,7 @@ function wfStreamThumb( array $params ) { // Check if the file is hidden if ( $img->isDeleted( File::DELETED_FILE ) ) { - wfThumbError( 404, "The source file '$fileName' does not exist." ); + wfThumbErrorText( 404, "The source file '$fileName' does not exist." ); return; } @@ -213,14 +213,15 @@ function wfStreamThumb( array $params ) { if ( count( $varyHeader ) ) { $response->header( 'Vary: ' . implode( ', ', $varyHeader ) ); } + $response->header( 'Content-Length: 0' ); return; } // If its not a redirect that has a target as a local file, give 404. - wfThumbError( 404, "The source file '$fileName' does not exist." ); + wfThumbErrorText( 404, "The source file '$fileName' does not exist." ); return; } elseif ( $img->getPath() === false ) { - wfThumbError( 500, "The source file '$fileName' is not locally accessible." ); + wfThumbErrorText( 500, "The source file '$fileName' is not locally accessible." ); return; } @@ -282,7 +283,7 @@ function wfStreamThumb( array $params ) { } return; } else { - wfThumbError( 404, "The given path of the specified thumbnail is incorrect; + wfThumbErrorText( 404, "The given path of the specified thumbnail is incorrect; expected '" . $img->getThumbRel( $thumbName ) . "' but got '" . rawurldecode( $rel404 ) . "'." ); return; @@ -298,8 +299,6 @@ function wfStreamThumb( array $params ) { $headers[] = 'Vary: ' . implode( ', ', $varyHeader ); } - $stats = RequestContext::getMain()->getStats(); - // Stream the file if it exists already... $thumbPath = $img->getThumbPath( $thumbName ); if ( $img->getRepo()->fileExists( $thumbPath ) ) { @@ -310,7 +309,7 @@ function wfStreamThumb( array $params ) { if ( !$success ) { wfThumbError( 500, 'Could not stream the file' ); } else { - $stats->timing( 'media.thumbnail.stream', $streamtime ); + RequestContext::getMain()->getStats()->timing( 'media.thumbnail.stream', $streamtime ); } return; } @@ -324,10 +323,8 @@ function wfStreamThumb( array $params ) { return; } - // Actually generate a new thumbnail - $starttime = microtime( true ); list( $thumb, $errorMsg ) = wfGenerateThumbnail( $img, $params, $thumbName, $thumbPath ); - $generatetime = microtime( true ) - $starttime; + /** @var MediaTransformOutput|bool $thumb */ // Check for thumbnail generation errors... @@ -348,8 +345,6 @@ function wfStreamThumb( array $params ) { if ( $errorMsg !== false ) { wfThumbError( $errorCode, $errorMsg ); } else { - $stats->timing( 'media.thumbnail.generate', $generatetime ); - // Stream the file if there were no errors $success = $thumb->streamFile( $headers ); if ( !$success ) { @@ -551,14 +546,26 @@ function wfExtractThumbParams( $file, $params ) { return null; } + +/** + * Output a thumbnail generation error message + * + * @param int $status + * @param string $msg Plain text (will be html escaped) + * @return void + */ +function wfThumbErrorText( $status, $msgText ) { + return wfThumbError( $status, htmlspecialchars( $msgText ) ); +} + /** * Output a thumbnail generation error message * * @param int $status - * @param string $msg HTML + * @param string $msgHtml HTML * @return void */ -function wfThumbError( $status, $msg ) { +function wfThumbError( $status, $msgHtml ) { global $wgShowHostnames; header( 'Cache-Control: no-cache' ); @@ -590,7 +597,7 @@ function wfThumbError( $status, $msg ) {

Error generating thumbnail

-$msg +$msgHtml

$debug