X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=thumb.php;h=10c2419db1485ea209456614c59fc5b887ea9bb4;hb=8dca366e1135877b86cfacabf0ccb1bb4cd507ab;hp=bd14e417a6f9a16ad8a8b3cd8c1e1bb10e10fda1;hpb=3de7e73bd0f0ddf5d7c38fd46edfae96d1a64e40;p=lhc%2Fweb%2Fwiklou.git diff --git a/thumb.php b/thumb.php index bd14e417a6..10c2419db1 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() ] ); } return; } @@ -356,12 +360,13 @@ 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() ] ); } } } @@ -376,23 +381,28 @@ function wfStreamThumb( array $params ) { * @return array (MediaTransformOutput|bool, string|bool error message HTML) */ function wfGenerateThumbnail( File $file, array $params, $thumbName, $thumbPath ) { - global $wgMemc, $wgAttemptFailureEpoch; + global $wgAttemptFailureEpoch; - $key = wfMemcKey( 'attempt-failures', $wgAttemptFailureEpoch, - $file->getRepo()->getName(), $file->getSha1(), md5( $thumbName ) ); + $cache = ObjectCache::getLocalClusterInstance(); + $key = $cache->makeKey( + 'attempt-failures', + $wgAttemptFailureEpoch, + $file->getRepo()->getName(), + $file->getSha1(), + md5( $thumbName ) + ); // Check if this file keeps failing to render - if ( $wgMemc->get( $key ) >= 4 ) { - return array( false, wfMessage( 'thumbnail_image-failure-limit', 4 ) ); + if ( $cache->get( $key ) >= 4 ) { + return [ false, wfMessage( 'thumbnail_image-failure-limit', 4 ) ]; } $done = false; // Record failures on PHP fatals in addition to caching exceptions - register_shutdown_function( function () use ( &$done, $key ) { + register_shutdown_function( function () use ( $cache, &$done, $key ) { if ( !$done ) { // transform() gave a fatal - global $wgMemc; // Randomize TTL to reduce stampedes - $wgMemc->incrWithInit( $key, 3600 + mt_rand( 0, 300 ) ); + $cache->incrWithInit( $key, $cache::TTL_HOUR + mt_rand( 0, 300 ) ); } } ); @@ -411,24 +421,21 @@ 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 ); }, - '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() . '