X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=thumb.php;h=7c3e757241538809853467ca4a0efa3593ed827c;hb=33eabfd8d6a738ae3ed13e3f52c0bbd7664e581a;hp=04b3e42ac865901b36880722705edfb8b9b423df;hpb=5a4fdb5b4e82fd68e200a887cac9d4e106fed0af;p=lhc%2Fweb%2Fwiklou.git diff --git a/thumb.php b/thumb.php index 04b3e42ac8..7c3e757241 100644 --- a/thumb.php +++ b/thumb.php @@ -22,6 +22,7 @@ */ use MediaWiki\Logger\LoggerFactory; +use MediaWiki\MediaWikiServices; define( 'MW_NO_OUTPUT_COMPRESSION', 1 ); require __DIR__ . '/includes/WebStart.php'; @@ -91,7 +92,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'] : ''; @@ -152,8 +153,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.' ); @@ -265,14 +266,14 @@ function wfStreamThumb( array $params ) { return; } catch ( MWException $e ) { wfThumbError( 500, $e->getHTML(), 'Exception caught while extracting thumb name', - array( 'exception' => $e ) ); + [ 'exception' => $e ] ); return; } // For 404 handled thumbnails, we only use the base name of the URI // for the thumb params and the parent directory for the source file name. // Check that the zone relative path matches up so squid caches won't pick - // up thumbs that would not be purged on source file deletion (bug 34231). + // up thumbs that would not be purged on source file deletion (T36231). if ( $rel404 !== null ) { // thumbnail was handled via 404 if ( rawurldecode( $rel404 ) === $img->getThumbRel( $thumbName ) ) { // Request for the canonical thumbnail name @@ -317,10 +318,12 @@ function wfStreamThumb( array $params ) { $streamtime = microtime( true ) - $starttime; if ( $status->isOK() ) { - RequestContext::getMain()->getStats()->timing( 'media.thumbnail.stream', $streamtime ); + MediaWikiServices::getInstance()->getStatsdDataFactory()->timing( + 'media.thumbnail.stream', $streamtime + ); } else { - wfThumbError( 500, 'Could not stream the file', null, array( 'file' => $thumbName, - 'path' => $thumbPath, 'error' => $status->getWikiText() ) ); + wfThumbError( 500, 'Could not stream the file', null, [ 'file' => $thumbName, + 'path' => $thumbPath, 'error' => $status->getWikiText( false, false, 'en' ) ] ); } return; } @@ -341,6 +344,7 @@ function wfStreamThumb( array $params ) { // Check for thumbnail generation errors... $msg = wfMessage( 'thumbnail_error' ); $errorCode = 500; + if ( !$thumb ) { $errorMsg = $errorMsg ?: $msg->rawParams( 'File::transform() returned false' )->escaped(); if ( $errorMsg instanceof MessageSpecifier && @@ -350,6 +354,7 @@ function wfStreamThumb( array $params ) { } } elseif ( $thumb->isError() ) { $errorMsg = $thumb->getHtmlMsg(); + $errorCode = $thumb->getHttpStatusCode(); } elseif ( !$thumb->hasFile() ) { $errorMsg = $msg->rawParams( 'No path supplied in thumbnail object' )->escaped(); } elseif ( $thumb->fileIsSource() ) { @@ -360,13 +365,14 @@ function wfStreamThumb( array $params ) { } if ( $errorMsg !== false ) { - wfThumbError( $errorCode, $errorMsg, null, array( 'file' => $thumbName, 'path' => $thumbPath ) ); + wfThumbError( $errorCode, $errorMsg, null, [ 'file' => $thumbName, 'path' => $thumbPath ] ); } else { // Stream the file if there were no errors $status = $thumb->streamFileWithStatus( $headers ); if ( !$status->isOK() ) { - wfThumbError( 500, 'Could not stream the file', null, array( - 'file' => $thumbName, 'path' => $thumbPath, 'error' => $status->getWikiText() ) ); + wfThumbError( 500, 'Could not stream the file', null, [ + 'file' => $thumbName, 'path' => $thumbPath, + 'error' => $status->getWikiText( false, false, 'en' ) ] ); } } } @@ -394,7 +400,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; @@ -421,7 +427,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 ); }, @@ -435,7 +441,7 @@ function wfGenerateThumbnail( File $file, array $params, $thumbName, $thumbPath 'error' => function ( Status $status ) { return wfMessage( 'generic-pool-error' )->parse() . '