Brian Wolff has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/80135


Change subject: Make thumb.php give http redirects if given a file redirect.
......................................................................

Make thumb.php give http redirects if given a file redirect.

See bug 22390 for some of the background. Basically there's two
reasons why we want this:
* Hotlinkers to commons. We don't want to break their links when
we move a file (Wikimedia blog is a prominent hotlinker)
* Cached entires. On wikis using commons files, a file move doesn't
trigger HTMLCacheUpdate jobs for the downstream wiki (it only
triggers it on commons). This means that these pages will still
use the old version of the html (with img tags that have the old
url) until the next edit or purge action. But these urls won't
work as soon as the file is moved.

I'm pretty confident that redirects will work at this point
in the thumb stack, as the redirects for long file names work
fine (provided no thumb exists in swift with the wrong name).

Change-Id: I40350121cf902f66fcbd3cf788335a988fa7ee33
---
M RELEASE-NOTES-1.22
M thumb.php
2 files changed, 29 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/35/80135/1

diff --git a/RELEASE-NOTES-1.22 b/RELEASE-NOTES-1.22
index 494dcf5..8ba4426 100644
--- a/RELEASE-NOTES-1.22
+++ b/RELEASE-NOTES-1.22
@@ -193,6 +193,7 @@
 * Add a mode parameter to <gallery> tag with potential options of 
"traditional",
   "nolines", "packed", "packed-overlay", or "packed-hover".
 * (bug 47399) A success message is now displayed after changing the password.
+* Make thumb.php give HTTP redirects for file redirects
 
 === Bug fixes in 1.22 ===
 * Disable Special:PasswordReset when $wgEnableEmail is false. Previously one
diff --git a/thumb.php b/thumb.php
index b9826a7..60ad24a 100644
--- a/thumb.php
+++ b/thumb.php
@@ -172,6 +172,34 @@
 
        // Check the source file storage path
        if ( !$img->exists() ) {
+               if ( !$isOld && !$isTemp ) {
+                       // Check for file redirect
+                       $possibleRedirFile = wfFindFile( $fileName );
+                       $redirTarget = $possibleRedirFile->getName();
+                       if ( !is_null( $possibleRedirFile->getRedirected() ) ) {
+                               $targetFile = wfLocalFile( 
Title::makeTitleSafe( NS_FILE, $redirTarget ) );
+                               if ( $targetFile->exists() ) {
+                                       $newThumbName = $targetFile->thumbName( 
$params );
+                                       $newThumbUrl = 
$targetFile->getThumbUrl( $newThumbName );
+
+                                       $response = 
RequestContext::getMain()->getRequest()->response();
+                                       $response->header( "HTTP/1.1 302 " . 
HttpStatus::getMessage( 302 ) );
+                                       $response->header( 'Location: ' . 
wfExpandUrl( $newThumbUrl, PROTO_CURRENT ) );
+                                       $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 ) );
+                                       }
+                                       wfProfileOut( __METHOD__ );
+                                       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;

-- 
To view, visit https://gerrit.wikimedia.org/r/80135
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I40350121cf902f66fcbd3cf788335a988fa7ee33
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Brian Wolff <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to