X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=thumb.php;h=fed025874b4096461243a007e23f8a929adc8f86;hb=e138fd51ae6e88a579fa98e6333d9defdd2d9850;hp=c699bb19ab1cc87bed4e3a95a05f76b86401a1c5;hpb=aeced6ef8549174e754a90afeaa45f827eadc886;p=lhc%2Fweb%2Fwiklou.git diff --git a/thumb.php b/thumb.php index c699bb19ab..fed025874b 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'; @@ -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', + array( '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, array( 'file' => $thumbName, + 'path' => $thumbPath, 'error' => $status->getWikiText() ) ); } return; } @@ -356,12 +360,13 @@ function wfStreamThumb( array $params ) { } if ( $errorMsg !== false ) { - wfThumbError( $errorCode, $errorMsg ); + wfThumbError( $errorCode, $errorMsg, null, array( '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, array( + 'file' => $thumbName, 'path' => $thumbPath, 'error' => $status->getWikiText() ) ); } } } @@ -420,18 +425,15 @@ function wfGenerateThumbnail( File $file, array $params, $thumbName, $thumbPath 'doWork' => function () use ( $file, $params ) { return $file->transform( $params, File::RENDER_NOW ); }, - 'getCachedWork' => function () use ( $file, $params, $thumbPath ) { + 'doCachedWork' => function () use ( $file, $params, $thumbPath ) { // If the worker that finished made this thumbnail then use it. // Otherwise, it probably made a different thumbnail for this file. return $file->getRepo()->fileExists( $thumbPath ) ? $file->transform( $params, File::RENDER_NOW ) : false; // retry once more in exclusive mode }, - 'fallback' => function () { - return wfMessage( 'generic-pool-error' )->parse(); - }, 'error' => function ( Status $status ) { - return $status->getHTML(); + return wfMessage( 'generic-pool-error' )->parse() . '
' . $status->getHTML(); } ) ); @@ -582,9 +584,12 @@ function wfThumbErrorText( $status, $msgText ) { * * @param int $status * @param string $msgHtml HTML + * @param string $msgText Short error description, for internal logging. Defaults to $msgHtml. + * Only used for HTTP 500 errors. + * @param array $context Error context, for internal logging. Only used for HTTP 500 errors. * @return void */ -function wfThumbError( $status, $msgHtml ) { +function wfThumbError( $status, $msgHtml, $msgText = null, $context = array() ) { global $wgShowHostnames; header( 'Cache-Control: no-cache' ); @@ -595,6 +600,7 @@ function wfThumbError( $status, $msgHtml ) { HttpStatus::header( 403 ); header( 'Vary: Cookie' ); } else { + LoggerFactory::getInstance( 'thumb' )->error( $msgText ?: $msgHtml, $context ); HttpStatus::header( 500 ); } if ( $wgShowHostnames ) {