InfoAction: Use watchlist query group for watchlist queries
[lhc/web/wiklou.git] / thumb.php
index 40f3754..0d0a15e 100644 (file)
--- a/thumb.php
+++ b/thumb.php
@@ -89,7 +89,6 @@ function wfThumbHandle404() {
 function wfStreamThumb( array $params ) {
        global $wgVaryOnXFP;
 
-
        $headers = array(); // HTTP headers to send
 
        $fileName = isset( $params['f'] ) ? $params['f'] : '';
@@ -235,7 +234,7 @@ function wfStreamThumb( array $params ) {
                $imsUnix = strtotime( $imsString );
                MediaWiki\restoreWarnings();
                if ( wfTimestamp( TS_UNIX, $img->getTimestamp() ) <= $imsUnix ) {
-                       HttpStatus::header( 304  );
+                       HttpStatus::header( 304 );
                        return;
                }
        }
@@ -299,12 +298,19 @@ function wfStreamThumb( array $params ) {
                $headers[] = 'Vary: ' . implode( ', ', $varyHeader );
        }
 
+       $stats = RequestContext::getMain()->getStats();
+
        // Stream the file if it exists already...
        $thumbPath = $img->getThumbPath( $thumbName );
        if ( $img->getRepo()->fileExists( $thumbPath ) ) {
+               $starttime = microtime( true );
                $success = $img->getRepo()->streamFile( $thumbPath, $headers );
+               $streamtime = microtime( true ) - $starttime;
+
                if ( !$success ) {
                        wfThumbError( 500, 'Could not stream the file' );
+               } else {
+                       $stats->timing( 'media.thumbnail.stream', $streamtime );
                }
                return;
        }
@@ -319,7 +325,9 @@ function wfStreamThumb( array $params ) {
        }
 
        // Actually generate a new thumbnail
+       $starttime = microtime( true );
        list( $thumb, $errorMsg ) = wfGenerateThumbnail( $img, $params, $thumbName, $thumbPath );
+       $generatetime = microtime( true ) - $starttime;
        /** @var MediaTransformOutput|bool $thumb */
 
        // Check for thumbnail generation errors...
@@ -340,6 +348,8 @@ function wfStreamThumb( array $params ) {
        if ( $errorMsg !== false ) {
                wfThumbError( $errorCode, $errorMsg );
        } else {
+               $stats->timing( 'media.thumbnail.generate', $generatetime );
+
                // Stream the file if there were no errors
                $success = $thumb->streamFile( $headers );
                if ( !$success ) {
@@ -571,7 +581,7 @@ function wfThumbError( $status, $msg ) {
        } else {
                $debug = '';
        }
-       echo <<<EOT
+       $content = <<<EOT
 <!DOCTYPE html>
 <html><head>
 <meta charset="UTF-8" />
@@ -587,4 +597,6 @@ $debug
 </html>
 
 EOT;
+       header( 'Content-Length: ' . strlen( $content ) );
+       echo $content;
 }