X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=thumb.php;h=fca25c55d28b51145c3da147aea3f73593f1e649;hb=84ca06799fe71d6b60d319fde335adfe637963e7;hp=34f641d1ea91ca773314d8e0ce13a24c8e4daea6;hpb=7eebfa63264a4d1408d5fab98bb1bd4bd431c215;p=lhc%2Fweb%2Fwiklou.git diff --git a/thumb.php b/thumb.php index 34f641d1ea..fca25c55d2 100644 --- a/thumb.php +++ b/thumb.php @@ -21,6 +21,8 @@ * @ingroup Media */ +use MediaWiki\Logger\LoggerFactory; + define( 'MW_NO_OUTPUT_COMPRESSION', 1 ); require __DIR__ . '/includes/WebStart.php'; @@ -89,7 +91,7 @@ function wfThumbHandle404() { function wfStreamThumb( array $params ) { global $wgVaryOnXFP; - $headers = array(); // HTTP headers to send + $headers = []; // HTTP headers to send $fileName = isset( $params['f'] ) ? $params['f'] : ''; @@ -150,8 +152,8 @@ function wfStreamThumb( array $params ) { } // Check permissions if there are read restrictions - $varyHeader = array(); - if ( !in_array( 'read', User::getGroupPermissions( array( '*' ) ), true ) ) { + $varyHeader = []; + if ( !in_array( 'read', User::getGroupPermissions( [ '*' ] ), true ) ) { if ( !$img->getTitle() || !$img->getTitle()->userCan( 'read' ) ) { wfThumbError( 403, 'Access denied. You do not have permission to access ' . 'the source file.' ); @@ -262,7 +264,8 @@ function wfStreamThumb( array $params ) { ); return; } catch ( MWException $e ) { - wfThumbError( 500, $e->getHTML() ); + wfThumbError( 500, $e->getHTML(), 'Exception caught while extracting thumb name', + [ 'exception' => $e ] ); return; } @@ -310,13 +313,14 @@ function wfStreamThumb( array $params ) { $thumbPath = $img->getThumbPath( $thumbName ); if ( $img->getRepo()->fileExists( $thumbPath ) ) { $starttime = microtime( true ); - $success = $img->getRepo()->streamFile( $thumbPath, $headers ); + $status = $img->getRepo()->streamFileWithStatus( $thumbPath, $headers ); $streamtime = microtime( true ) - $starttime; - if ( !$success ) { - wfThumbError( 500, 'Could not stream the file' ); - } else { + if ( $status->isOK() ) { RequestContext::getMain()->getStats()->timing( 'media.thumbnail.stream', $streamtime ); + } else { + wfThumbError( 500, 'Could not stream the file', null, [ 'file' => $thumbName, + 'path' => $thumbPath, 'error' => $status->getWikiText( false, false, 'en' ) ] ); } return; } @@ -356,12 +360,14 @@ function wfStreamThumb( array $params ) { } if ( $errorMsg !== false ) { - wfThumbError( $errorCode, $errorMsg ); + wfThumbError( $errorCode, $errorMsg, null, [ 'file' => $thumbName, 'path' => $thumbPath ] ); } else { // Stream the file if there were no errors - $success = $thumb->streamFile( $headers ); - if ( !$success ) { - wfThumbError( 500, 'Could not stream the file' ); + $status = $thumb->streamFileWithStatus( $headers ); + if ( !$status->isOK() ) { + wfThumbError( 500, 'Could not stream the file', null, [ + 'file' => $thumbName, 'path' => $thumbPath, + 'error' => $status->getWikiText( false, false, 'en' ) ] ); } } } @@ -389,7 +395,7 @@ function wfGenerateThumbnail( File $file, array $params, $thumbName, $thumbPath // Check if this file keeps failing to render if ( $cache->get( $key ) >= 4 ) { - return array( false, wfMessage( 'thumbnail_image-failure-limit', 4 ) ); + return [ false, wfMessage( 'thumbnail_image-failure-limit', 4 ) ]; } $done = false; @@ -416,7 +422,7 @@ function wfGenerateThumbnail( File $file, array $params, $thumbName, $thumbPath // Thumbnail isn't already there, so create the new thumbnail... try { $work = new PoolCounterWorkViaCallback( $poolCounterType, sha1( $file->getName() ), - array( + [ 'doWork' => function () use ( $file, $params ) { return $file->transform( $params, File::RENDER_NOW ); }, @@ -430,7 +436,7 @@ function wfGenerateThumbnail( File $file, array $params, $thumbName, $thumbPath 'error' => function ( Status $status ) { return wfMessage( 'generic-pool-error' )->parse() . '