/**
* Stream a thumbnail specified by parameters
*
- * @param $params Array List of thumbnailing parameters. In addition to parameters
+ * @param array $params List of thumbnailing parameters. In addition to parameters
* passed to the MediaHandler, this may also includes the keys:
* f (for filename), archived (if archived file), temp (if temp file),
* w (alias for width), p (alias for page), r (ignored; historical),
return;
}
-
// Check the source file storage path
if ( !$img->exists() ) {
$redirectedLocation = false;
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 );
}
}
+ $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 );
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...
}
if ( $errorMsg !== false ) {
+ wfThumbIncrAttemptFailures( $img, $thumbName );
wfThumbError( 500, $errorMsg );
} else {
// Stream the file if there were no errors
}
}
+/**
+ * @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
*
*
* Transform specific parameters are set later via wfExtractThumbParams().
*
- * @param $thumbRel String Thumbnail path relative to the thumb zone
- * @return Array|null associative params array or null
+ * @param string $thumbRel Thumbnail path relative to the thumb zone
+ * @return array|null Associative params array or null
*/
function wfExtractThumbRequestInfo( $thumbRel ) {
$repo = RepoGroup::singleton()->getLocalRepo();
* Convert a thumbnail name (122px-foo.png) to parameters, using
* file handler.
*
- * @param File $file File object for file in question.
- * @param $param Array Array of parameters so far.
- * @return Array parameters array with more parameters.
+ * @param File $file File object for file in question
+ * @param array $param Array of parameters so far
+ * @return array Parameters array with more parameters
*/
function wfExtractThumbParams( $file, $params ) {
if ( !isset( $params['thumbName'] ) ) {
/**
* Output a thumbnail generation error message
*
- * @param $status integer
- * @param $msg string
+ * @param int $status
+ * @param string $msg
* @return void
*/
function wfThumbError( $status, $msg ) {