Remove duplicate files, no point in loading them twice
[lhc/web/wiklou.git] / thumb.php
index c53eb2a..362f304 100644 (file)
--- a/thumb.php
+++ b/thumb.php
@@ -153,6 +153,13 @@ function wfStreamThumb( array $params ) {
                $img = wfLocalFile( $fileName );
        }
 
+       // Check the source file title
+       if ( !$img ) {
+               wfThumbError( 404, wfMessage( 'badtitletext' )->text() );
+               wfProfileOut( __METHOD__ );
+               return;
+       }
+
        // Check permissions if there are read restrictions
        $varyHeader = array();
        if ( !in_array( 'read', User::getGroupPermissions( array( '*' ) ), true ) ) {
@@ -167,11 +174,6 @@ function wfStreamThumb( array $params ) {
        }
 
        // Check the source file storage path
-       if ( !$img ) {
-               wfThumbError( 404, wfMessage( 'badtitletext' )->text() );
-               wfProfileOut( __METHOD__ );
-               return;
-       }
        if ( !$img->exists() ) {
                wfThumbError( 404, 'The source file for the specified thumbnail does not exist.' );
                wfProfileOut( __METHOD__ );
@@ -231,7 +233,9 @@ function wfStreamThumb( array $params ) {
                                if ( $wgVaryOnXFP ) {
                                        $varyHeader[] = 'X-Forwarded-Proto';
                                }
-                               $response->header( 'Vary: ' . implode( ', ', $varyHeader ) );
+                               if ( count( $varyHeader ) ) {
+                                       $response->header( 'Vary: ' . implode( ', ', $varyHeader ) );
+                               }
                                wfProfileOut( __METHOD__ );
                                return;
                        } else {
@@ -242,7 +246,9 @@ function wfStreamThumb( array $params ) {
                }
                $thumbPath = $img->getThumbPath( $thumbName );
                if ( $img->getRepo()->fileExists( $thumbPath ) ) {
-                       $headers[] = 'Vary: ' . implode( ', ', $varyHeader );
+                       if ( count( $varyHeader ) ) {
+                               $headers[] = 'Vary: ' . implode( ', ', $varyHeader );
+                       }
                        $img->getRepo()->streamFile( $thumbPath, $headers );
                        wfProfileOut( __METHOD__ );
                        return;
@@ -252,7 +258,10 @@ function wfStreamThumb( array $params ) {
                wfProfileOut( __METHOD__ );
                return;
        }
-       $headers[] = 'Vary: ' . implode( ', ', $varyHeader );
+
+       if ( count( $varyHeader ) ) {
+               $headers[] = 'Vary: ' . implode( ', ', $varyHeader );
+       }
 
        // Thumbnail isn't already there, so create the new thumbnail...
        try {