X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=thumb.php;h=b0d9f10eddc6c89dfde1b6987f81efca71cccf49;hb=4f0eb20c113f03fbd60057fd8040f68e71655073;hp=35ab9f27e622ba6499ae2dfc2ecd9d19ce96909f;hpb=83beb3e5631957695a243f8abdc10ab4d03b035b;p=lhc%2Fweb%2Fwiklou.git diff --git a/thumb.php b/thumb.php index 35ab9f27e6..b0d9f10edd 100644 --- a/thumb.php +++ b/thumb.php @@ -180,7 +180,6 @@ function wfStreamThumb( array $params ) { return; } - // Check the source file storage path if ( !$img->exists() ) { $redirectedLocation = false; @@ -247,7 +246,6 @@ function wfStreamThumb( array $params ) { unset( $params['r'] ); // ignore 'r' because we unconditionally pass File::RENDER unset( $params['f'] ); // We're done with 'f' parameter. - // Get the normalized thumbnail name from the parameters... try { $thumbName = $img->thumbName( $params ); @@ -291,8 +289,10 @@ 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 )}"; + $headers[] = "Content-Disposition: {$img->getThumbDisposition( $thumbName, $dispositionType )}"; if ( count( $varyHeader ) ) { $headers[] = 'Vary: ' . implode( ', ', $varyHeader ); @@ -309,6 +309,9 @@ function wfStreamThumb( array $params ) { if ( $user->pingLimiter( 'renderfile' ) ) { wfThumbError( 500, wfMessage( 'actionthrottledtext' ) ); return; + } elseif ( wfThumbIsAttemptThrottled( $img, $thumbName, 5 ) ) { + wfThumbError( 500, wfMessage( 'thumbnail_image-failure-limit', 5 ) ); + return; } // Thumbnail isn't already there, so create the new thumbnail... @@ -334,6 +337,7 @@ function wfStreamThumb( array $params ) { } if ( $errorMsg !== false ) { + wfThumbIncrAttemptFailures( $img, $thumbName ); wfThumbError( 500, $errorMsg ); } else { // Stream the file if there were no errors @@ -341,6 +345,45 @@ function wfStreamThumb( array $params ) { } } +/** + * @param File $img + * @param string $thumbName + * @param int $limit + * @return int|bool + */ +function wfThumbIsAttemptThrottled( File $img, $thumbName, $limit ) { + global $wgMemc; + + return ( $wgMemc->get( wfThumbAttemptKey( $img, $thumbName ) ) >= $limit ); +} + +/** + * @param File $img + * @param string $thumbName + */ +function wfThumbIncrAttemptFailures( File $img, $thumbName ) { + global $wgMemc; + + $key = wfThumbAttemptKey( $img, $thumbName ); + if ( !$wgMemc->incr( $key, 1 ) ) { + if ( !$wgMemc->add( $key, 1, 3600 ) ) { + $wgMemc->incr( $key, 1 ); + } + } +} + +/** + * @param File $img + * @param string $thumbName + * @return string + */ +function wfThumbAttemptKey( File $img, $thumbName ) { + global $wgAttemptFailureEpoch; + + return wfMemcKey( 'attempt-failures', $wgAttemptFailureEpoch, + $img->getRepo()->getName(), md5( $img->getName() ), md5( $thumbName ) ); +} + /** * Convert pathinfo type parameter, into normal request parameters *