X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;ds=sidebyside;f=thumb.php;h=2edc28027a30e4a50b7f075a2c2ca1c67f227d14;hb=304b7a8009624978170be19b1b5f63e9cfcd0916;hp=9cfdae4d3469b907e5d74da9c4d0e090216cc920;hpb=125d6d5feceba4d3d740efb5be0be83058546a20;p=lhc%2Fweb%2Fwiklou.git diff --git a/thumb.php b/thumb.php index 9cfdae4d34..2edc28027a 100644 --- a/thumb.php +++ b/thumb.php @@ -25,7 +25,7 @@ define( 'MW_NO_OUTPUT_COMPRESSION', 1 ); if ( isset( $_SERVER['MW_COMPILED'] ) ) { require( 'core/includes/WebStart.php' ); } else { - require( dirname( __FILE__ ) . '/includes/WebStart.php' ); + require( __DIR__ . '/includes/WebStart.php' ); } // Don't use fancy mime detection, just check the file extension for jpg/gif/png @@ -96,6 +96,7 @@ function wfThumbHandle404() { * @return void */ function wfStreamThumb( array $params ) { + global $wgVaryOnXFP; wfProfileIn( __METHOD__ ); $headers = array(); // HTTP headers to send @@ -129,13 +130,13 @@ function wfStreamThumb( array $params ) { // Format is ! $bits = explode( '!', $fileName, 2 ); if ( count( $bits ) != 2 ) { - wfThumbError( 404, wfMsg( 'badtitletext' ) ); + wfThumbError( 404, wfMessage( 'badtitletext' )->text() ); wfProfileOut( __METHOD__ ); return; } $title = Title::makeTitleSafe( NS_FILE, $bits[1] ); if ( !$title ) { - wfThumbError( 404, wfMsg( 'badtitletext' ) ); + wfThumbError( 404, wfMessage( 'badtitletext' )->text() ); wfProfileOut( __METHOD__ ); return; } @@ -147,7 +148,7 @@ function wfStreamThumb( array $params ) { // Get the name without the timestamp so hash paths are correctly computed $title = Title::makeTitleSafe( NS_FILE, isset( $bits[1] ) ? $bits[1] : $fileName ); if ( !$title ) { - wfThumbError( 404, wfMsg( 'badtitletext' ) ); + wfThumbError( 404, wfMessage( 'badtitletext' )->text() ); wfProfileOut( __METHOD__ ); return; } @@ -159,6 +160,7 @@ function wfStreamThumb( array $params ) { } // Check permissions if there are read restrictions + $varyHeader = array(); if ( !in_array( 'read', User::getGroupPermissions( array( '*' ) ), true ) ) { if ( !$img->getTitle() || !$img->getTitle()->userCan( 'read' ) ) { wfThumbError( 403, 'Access denied. You do not have permission to access ' . @@ -167,12 +169,12 @@ function wfStreamThumb( array $params ) { return; } $headers[] = 'Cache-Control: private'; - $headers[] = 'Vary: Cookie'; + $varyHeader[] = 'Cookie'; } // Check the source file storage path if ( !$img ) { - wfThumbError( 404, wfMsg( 'badtitletext' ) ); + wfThumbError( 404, wfMessage( 'badtitletext' )->text() ); wfProfileOut( __METHOD__ ); return; } @@ -205,33 +207,58 @@ function wfStreamThumb( array $params ) { } } + $thumbName = $img->thumbName( $params ); + if ( !strlen( $thumbName ) ) { // invalid params? + wfThumbError( 400, 'The specified thumbnail parameters are not valid.' ); + wfProfileOut( __METHOD__ ); + return; + } + + $disposition = $img->getThumbDisposition( $thumbName ); + $headers[] = "Content-Disposition: $disposition"; + // Stream the file if it exists already... try { - $thumbName = $img->thumbName( $params ); - if ( strlen( $thumbName ) ) { // valid params? - // For 404 handled thumbnails, we only use the 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). - if ( isset( $params['rel404'] ) // thumbnail was handled via 404 - && urldecode( $params['rel404'] ) !== $img->getThumbRel( $thumbName ) ) - { - wfThumbError( 404, 'The source file for the specified thumbnail does not exist.' ); + $thumbName2 = $img->thumbName( $params, File::THUMB_FULL_NAME ); // b/c; "long" style + // For 404 handled thumbnails, we only use the 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). + if ( isset( $params['rel404'] ) ) { // thumbnail was handled via 404 + if ( urldecode( $params['rel404'] ) === $img->getThumbRel( $thumbName ) ) { + // Request for the canonical thumbnail name + } elseif ( urldecode( $params['rel404'] ) === $img->getThumbRel( $thumbName2 ) ) { + // Request for the "long" thumbnail name; redirect to canonical name + $response = RequestContext::getMain()->getRequest()->response(); + $response->header( "HTTP/1.1 301 " . HttpStatus::getMessage( 301 ) ); + $response->header( 'Location: ' . wfExpandUrl( $img->getThumbUrl( $thumbName ), PROTO_CURRENT ) ); + $response->header( 'Expires: ' . + gmdate( 'D, d M Y H:i:s', time() + 7*86400 ) . ' GMT' ); + if ( $wgVaryOnXFP ) { + $varyHeader[] = 'X-Forwarded-Proto'; + } + $response->header( 'Vary: ' . implode( ', ', $varyHeader ) ); wfProfileOut( __METHOD__ ); return; - } - $thumbPath = $img->getThumbPath( $thumbName ); - if ( $img->getRepo()->fileExists( $thumbPath ) ) { - $img->getRepo()->streamFile( $thumbPath, $headers ); + } else { + wfThumbError( 404, 'The source file for the specified thumbnail does not exist.' ); wfProfileOut( __METHOD__ ); return; } } + $thumbPath = $img->getThumbPath( $thumbName ); + if ( $img->getRepo()->fileExists( $thumbPath ) ) { + $headers[] = 'Vary: ' . implode( ', ', $varyHeader ); + $img->getRepo()->streamFile( $thumbPath, $headers ); + wfProfileOut( __METHOD__ ); + return; + } } catch ( MWException $e ) { wfThumbError( 500, $e->getHTML() ); wfProfileOut( __METHOD__ ); return; } + $headers[] = 'Vary: ' . implode( ', ', $varyHeader ); // Thumbnail isn't already there, so create the new thumbnail... try { @@ -243,15 +270,16 @@ function wfStreamThumb( array $params ) { // Check for thumbnail generation errors... $errorMsg = false; + $msg = wfMessage( 'thumbnail_error' ); if ( !$thumb ) { - $errorMsg = wfMsgHtml( 'thumbnail_error', 'File::transform() returned false' ); + $errorMsg = $msg->rawParams( 'File::transform() returned false' )->escaped(); } elseif ( $thumb->isError() ) { $errorMsg = $thumb->getHtmlMsg(); } elseif ( !$thumb->hasFile() ) { - $errorMsg = wfMsgHtml( 'thumbnail_error', 'No path supplied in thumbnail object' ); + $errorMsg = $msg->rawParams( 'No path supplied in thumbnail object' )->escaped(); } elseif ( $thumb->fileIsSource() ) { - $errorMsg = wfMsgHtml( 'thumbnail_error', - 'Image was not scaled, is the requested width bigger than the source?' ); + $errorMsg = $msg-> + rawParams( 'Image was not scaled, is the requested width bigger than the source?' )->escaped(); } if ( $errorMsg !== false ) {