function wfStreamThumb( array $params ) {
global $wgVaryOnXFP;
- wfProfileIn( __METHOD__ );
+ $section = new ProfileSection( __METHOD__ );
$headers = array(); // HTTP headers to send
$bits = explode( '!', $fileName, 2 );
if ( count( $bits ) != 2 ) {
wfThumbError( 404, wfMessage( 'badtitletext' )->text() );
- wfProfileOut( __METHOD__ );
return;
}
$title = Title::makeTitleSafe( NS_FILE, $bits[1] );
if ( !$title ) {
wfThumbError( 404, wfMessage( 'badtitletext' )->text() );
- wfProfileOut( __METHOD__ );
return;
}
$img = RepoGroup::singleton()->getLocalRepo()->newFromArchiveName( $title, $fileName );
// Check the source file title
if ( !$img ) {
wfThumbError( 404, wfMessage( 'badtitletext' )->text() );
- wfProfileOut( __METHOD__ );
return;
}
if ( !$img->getTitle() || !$img->getTitle()->userCan( 'read' ) ) {
wfThumbError( 403, 'Access denied. You do not have permission to access ' .
'the source file.' );
- wfProfileOut( __METHOD__ );
return;
}
$headers[] = 'Cache-Control: private';
// Check the source file storage path
if ( !$img->exists() ) {
+ $redirectedLocation = false;
+ if ( !$isTemp ) {
+ // Check for file redirect
+ if ( $isOld ) {
+ // Since redirects are associated with pages, not versions of files,
+ // we look for the most current version to see if its a redirect.
+ $possibleRedirFile = RepoGroup::singleton()->getLocalRepo()->findFile( $img->getName() );
+ } else {
+ $possibleRedirFile = RepoGroup::singleton()->getLocalRepo()->findFile( $fileName );
+ }
+ if ( $possibleRedirFile && !is_null( $possibleRedirFile->getRedirected() ) ) {
+ $redirTarget = $possibleRedirFile->getName();
+ $targetFile = wfLocalFile( Title::makeTitleSafe( NS_FILE, $redirTarget ) );
+ if ( $targetFile->exists() ) {
+ $newThumbName = $targetFile->thumbName( $params );
+ if ( $isOld ) {
+ $newThumbUrl = $targetFile->getArchiveThumbUrl( $bits[0] . '!' . $targetFile->getName(), $newThumbName );
+ } else {
+ $newThumbUrl = $targetFile->getThumbUrl( $newThumbName );
+ }
+ $redirectedLocation = wfExpandUrl( $newThumbUrl, PROTO_CURRENT );
+ }
+ }
+ }
+
+ if ( $redirectedLocation ) {
+ // File has been moved. Give redirect.
+ $response = RequestContext::getMain()->getRequest()->response();
+ $response->header( "HTTP/1.1 302 " . HttpStatus::getMessage( 302 ) );
+ $response->header( 'Location: ' . $redirectedLocation );
+ $response->header( 'Expires: ' .
+ gmdate( 'D, d M Y H:i:s', time() + 12 * 3600 ) . ' GMT' );
+ if ( $wgVaryOnXFP ) {
+ $varyHeader[] = 'X-Forwarded-Proto';
+ }
+ if ( count( $varyHeader ) ) {
+ $response->header( 'Vary: ' . implode( ', ', $varyHeader ) );
+ }
+ return;
+ }
+
+ // If its not a redirect that has a target as a local file, give 404.
wfThumbError( 404, "The source file '$fileName' does not exist." );
- wfProfileOut( __METHOD__ );
return;
} elseif ( $img->getPath() === false ) {
wfThumbError( 500, "The source file '$fileName' is not locally accessible." );
- wfProfileOut( __METHOD__ );
return;
}
wfRestoreWarnings();
if ( wfTimestamp( TS_UNIX, $img->getTimestamp() ) <= $imsUnix ) {
header( 'HTTP/1.1 304 Not Modified' );
- wfProfileOut( __METHOD__ );
return;
}
}
$thumbName = $img->thumbName( $params );
if ( !strlen( $thumbName ) ) { // invalid params?
wfThumbError( 400, 'The specified thumbnail parameters are not valid.' );
- wfProfileOut( __METHOD__ );
return;
}
$thumbName2 = $img->thumbName( $params, File::THUMB_FULL_NAME ); // b/c; "long" style
} catch ( MWException $e ) {
wfThumbError( 500, $e->getHTML() );
- wfProfileOut( __METHOD__ );
return;
}
if ( count( $varyHeader ) ) {
$response->header( 'Vary: ' . implode( ', ', $varyHeader ) );
}
- wfProfileOut( __METHOD__ );
return;
} else {
wfThumbError( 404, "The given path of the specified thumbnail is incorrect;
expected '" . $img->getThumbRel( $thumbName ) . "' but got '" .
rawurldecode( $params['rel404'] ) . "'." );
- wfProfileOut( __METHOD__ );
return;
}
}
$thumbPath = $img->getThumbPath( $thumbName );
if ( $img->getRepo()->fileExists( $thumbPath ) ) {
$img->getRepo()->streamFile( $thumbPath, $headers );
- wfProfileOut( __METHOD__ );
return;
}
// Stream the file if there were no errors
$thumb->streamFile( $headers );
}
-
- wfProfileOut( __METHOD__ );
}
/**