Merge "mediawiki.action.edit.preview: Assorted fixes"
[lhc/web/wiklou.git] / thumb.php
index ede30e6..22a5b3d 100644 (file)
--- a/thumb.php
+++ b/thumb.php
  */
 
 define( 'MW_NO_OUTPUT_COMPRESSION', 1 );
-if ( isset( $_SERVER['MW_COMPILED'] ) ) {
-       require( 'core/includes/WebStart.php' );
-} else {
-       require( __DIR__ . '/includes/WebStart.php' );
-}
+require __DIR__ . '/includes/WebStart.php';
 
 // Don't use fancy mime detection, just check the file extension for jpg/gif/png
 $wgTrivialMimeDetection = true;
@@ -66,9 +62,15 @@ function wfThumbHandle404() {
 
        # Set action base paths so that WebRequest::getPathInfo()
        # recognizes the "X" as the 'title' in ../thumb_handler.php/X urls.
-       $wgArticlePath = false; # Don't let a "/*" article path clober our action path
+       # Note: If Custom per-extension repo paths are set, this may break.
+       $repo = RepoGroup::singleton()->getLocalRepo();
+       $oldArticlePath = $wgArticlePath;
+       $wgArticlePath = $repo->getZoneUrl( 'thumb' ) . '/$1';
 
        $matches = WebRequest::getPathInfo();
+
+       $wgArticlePath = $oldArticlePath;
+
        if ( !isset( $matches['title'] ) ) {
                wfThumbError( 404, 'Could not determine the name of the requested thumbnail.' );
                return;
@@ -92,7 +94,7 @@ function wfThumbHandle404() {
 function wfStreamThumb( array $params ) {
        global $wgVaryOnXFP;
 
-       wfProfileIn( __METHOD__ );
+       $section = new ProfileSection( __METHOD__ );
 
        $headers = array(); // HTTP headers to send
 
@@ -126,7 +128,7 @@ function wfStreamThumb( array $params ) {
                $img = new UnregisteredLocalFile( null, $repo,
                        # Temp files are hashed based on the name without the timestamp.
                        # The thumbnails will be hashed based on the entire name however.
-                       # @TODO: fix this convention to actually be reasonable.
+                       # @todo fix this convention to actually be reasonable.
                        $repo->getZonePath( 'public' ) . '/' . $repo->getTempHashPath( $fileName ) . $fileName
                );
        } elseif ( $isOld ) {
@@ -134,13 +136,11 @@ function wfStreamThumb( array $params ) {
                $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 );
@@ -151,7 +151,6 @@ function wfStreamThumb( array $params ) {
        // Check the source file title
        if ( !$img ) {
                wfThumbError( 404, wfMessage( 'badtitletext' )->text() );
-               wfProfileOut( __METHOD__ );
                return;
        }
 
@@ -161,7 +160,6 @@ function wfStreamThumb( array $params ) {
                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';
@@ -171,11 +169,9 @@ function wfStreamThumb( array $params ) {
        // Check the source file storage path
        if ( !$img->exists() ) {
                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;
        }
 
@@ -190,7 +186,6 @@ function wfStreamThumb( array $params ) {
                wfRestoreWarnings();
                if ( wfTimestamp( TS_UNIX, $img->getTimestamp() ) <= $imsUnix ) {
                        header( 'HTTP/1.1 304 Not Modified' );
-                       wfProfileOut( __METHOD__ );
                        return;
                }
        }
@@ -200,13 +195,11 @@ 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;
                }
                $thumbName2 = $img->thumbName( $params, File::THUMB_FULL_NAME ); // b/c; "long" style
        } catch ( MWException $e ) {
                wfThumbError( 500, $e->getHTML() );
-               wfProfileOut( __METHOD__ );
                return;
        }
 
@@ -231,13 +224,11 @@ function wfStreamThumb( array $params ) {
                        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;
                }
        }
@@ -253,7 +244,6 @@ function wfStreamThumb( array $params ) {
        $thumbPath = $img->getThumbPath( $thumbName );
        if ( $img->getRepo()->fileExists( $thumbPath ) ) {
                $img->getRepo()->streamFile( $thumbPath, $headers );
-               wfProfileOut( __METHOD__ );
                return;
        }
 
@@ -285,8 +275,6 @@ function wfStreamThumb( array $params ) {
                // Stream the file if there were no errors
                $thumb->streamFile( $headers );
        }
-
-       wfProfileOut( __METHOD__ );
 }
 
 /**