X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=thumb.php;h=c699bb19ab1cc87bed4e3a95a05f76b86401a1c5;hb=5669bf329a5f7449d64c39ed17f5d17a16d457da;hp=d39d43bc461916c493886dca455d4a8513ec5feb;hpb=d92845c2295d982c80312880c3fae788450676ea;p=lhc%2Fweb%2Fwiklou.git diff --git a/thumb.php b/thumb.php index d39d43bc46..c699bb19ab 100644 --- a/thumb.php +++ b/thumb.php @@ -38,7 +38,7 @@ if ( defined( 'THUMB_HANDLER' ) ) { $mediawiki = new MediaWiki(); $mediawiki->doPostOutputShutdown( 'fast' ); -//-------------------------------------------------------------------------- +// -------------------------------------------------------------------------- /** * Handle a thumbnail request via thumbnail file URL @@ -250,11 +250,16 @@ function wfStreamThumb( array $params ) { try { $thumbName = $img->thumbName( $params ); if ( !strlen( $thumbName ) ) { // invalid params? - throw new MediaTransformInvalidParametersException( 'Empty return from File::thumbName' ); + throw new MediaTransformInvalidParametersException( + 'Empty return from File::thumbName' + ); } $thumbName2 = $img->thumbName( $params, File::THUMB_FULL_NAME ); // b/c; "long" style } catch ( MediaTransformInvalidParametersException $e ) { - wfThumbError( 400, 'The specified thumbnail parameters are not valid: ' . $e->getMessage() ); + wfThumbError( + 400, + 'The specified thumbnail parameters are not valid: ' . $e->getMessage() + ); return; } catch ( MWException $e ) { wfThumbError( 500, $e->getHTML() ); @@ -294,7 +299,8 @@ function wfStreamThumb( array $params ) { $dispositionType = isset( $params['download'] ) ? 'attachment' : 'inline'; // Suggest a good name for users downloading this thumbnail - $headers[] = "Content-Disposition: {$img->getThumbDisposition( $thumbName, $dispositionType )}"; + $headers[] = + "Content-Disposition: {$img->getThumbDisposition( $thumbName, $dispositionType )}"; if ( count( $varyHeader ) ) { $headers[] = 'Vary: ' . implode( ', ', $varyHeader ); @@ -333,7 +339,9 @@ function wfStreamThumb( array $params ) { $errorCode = 500; if ( !$thumb ) { $errorMsg = $errorMsg ?: $msg->rawParams( 'File::transform() returned false' )->escaped(); - if ( $errorMsg instanceof MessageSpecifier && $errorMsg->getKey() === 'thumbnail_image-failure-limit' ) { + if ( $errorMsg instanceof MessageSpecifier && + $errorMsg->getKey() === 'thumbnail_image-failure-limit' + ) { $errorCode = 429; } } elseif ( $thumb->isError() ) { @@ -341,8 +349,9 @@ function wfStreamThumb( array $params ) { } elseif ( !$thumb->hasFile() ) { $errorMsg = $msg->rawParams( 'No path supplied in thumbnail object' )->escaped(); } elseif ( $thumb->fileIsSource() ) { - $errorMsg = $msg-> - rawParams( 'Image was not scaled, is the requested width bigger than the source?' )->escaped(); + $errorMsg = $msg + ->rawParams( 'Image was not scaled, is the requested width bigger than the source?' ) + ->escaped(); $errorCode = 400; } @@ -367,23 +376,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 ) { + if ( $cache->get( $key ) >= 4 ) { return array( 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 ) ); } } ); @@ -436,7 +450,7 @@ function wfGenerateThumbnail( File $file, array $params, $thumbName, $thumbPath if ( !$thumb || $thumb->isError() ) { // Randomize TTL to reduce stampedes - $wgMemc->incrWithInit( $key, 3600 + mt_rand( 0, 300 ) ); + $cache->incrWithInit( $key, $cache::TTL_HOUR + mt_rand( 0, 300 ) ); } return array( $thumb, $errorHtml ); @@ -585,7 +599,9 @@ function wfThumbError( $status, $msgHtml ) { } if ( $wgShowHostnames ) { header( 'X-MW-Thumbnail-Renderer: ' . wfHostname() ); - $url = htmlspecialchars( isset( $_SERVER['REQUEST_URI'] ) ? $_SERVER['REQUEST_URI'] : '' ); + $url = htmlspecialchars( + isset( $_SERVER['REQUEST_URI'] ) ? $_SERVER['REQUEST_URI'] : '' + ); $hostname = htmlspecialchars( wfHostname() ); $debug = "\n\n"; } else {