resourceloader: Unbreak ResourceLoaderImageModule's rasterization
[lhc/web/wiklou.git] / includes / StreamFile.php
index b0e6c12..a7522ea 100644 (file)
@@ -32,14 +32,13 @@ class StreamFile {
         * Headers sent include: Content-type, Content-Length, Last-Modified,
         * and Content-Disposition.
         *
-        * @param $fname string Full name and path of the file to stream
-        * @param $headers array Any additional headers to send
-        * @param $sendErrors bool Send error messages if errors occur (like 404)
+        * @param string $fname Full name and path of the file to stream
+        * @param array $headers Any additional headers to send
+        * @param bool $sendErrors Send error messages if errors occur (like 404)
         * @throws MWException
         * @return bool Success
         */
        public static function stream( $fname, $headers = array(), $sendErrors = true ) {
-               wfProfileIn( __METHOD__ );
 
                if ( FileBackend::isStoragePath( $fname ) ) { // sanity
                        throw new MWException( __FUNCTION__ . " given storage path '$fname'." );
@@ -53,14 +52,11 @@ class StreamFile {
                if ( $res == self::NOT_MODIFIED ) {
                        $ok = true; // use client cache
                } elseif ( $res == self::READY_STREAM ) {
-                       wfProfileIn( __METHOD__ . '-send' );
                        $ok = readfile( $fname );
-                       wfProfileOut( __METHOD__ . '-send' );
                } else {
                        $ok = false; // failed
                }
 
-               wfProfileOut( __METHOD__ );
                return $ok;
        }
 
@@ -71,10 +67,10 @@ class StreamFile {
         * (b) cancels any PHP output buffering and automatic gzipping of output
         * (c) sends Content-Length header based on HTTP_IF_MODIFIED_SINCE check
         *
-        * @param $path string Storage path or file system path
-        * @param $info Array|bool File stat info with 'mtime' and 'size' fields
-        * @param $headers Array Additional headers to send
-        * @param $sendErrors bool Send error messages if errors occur (like 404)
+        * @param string $path Storage path or file system path
+        * @param array|bool $info File stat info with 'mtime' and 'size' fields
+        * @param array $headers Additional headers to send
+        * @param bool $sendErrors Send error messages if errors occur (like 404)
         * @return int|bool READY_STREAM, NOT_MODIFIED, or false on failure
         */
        public static function prepareForStream(
@@ -82,7 +78,7 @@ class StreamFile {
        ) {
                if ( !is_array( $info ) ) {
                        if ( $sendErrors ) {
-                               header( 'HTTP/1.0 404 Not Found' );
+                               HttpStatus::header( 404  );
                                header( 'Cache-Control: no-cache' );
                                header( 'Content-Type: text/html; charset=utf-8' );
                                $encFile = htmlspecialchars( $path );
@@ -130,7 +126,7 @@ class StreamFile {
                        $modsince = preg_replace( '/;.*$/', '', $_SERVER['HTTP_IF_MODIFIED_SINCE'] );
                        if ( wfTimestamp( TS_UNIX, $info['mtime'] ) <= strtotime( $modsince ) ) {
                                ini_set( 'zlib.output_compression', 0 );
-                               header( "HTTP/1.0 304 Not Modified" );
+                               HttpStatus::header( 304 );
                                return self::NOT_MODIFIED; // ok
                        }
                }
@@ -143,8 +139,8 @@ class StreamFile {
        /**
         * Determine the file type of a file based on the path
         *
-        * @param $filename string Storage path or file system path
-        * @param $safe bool Whether to do retroactive upload blacklist checks
+        * @param string $filename Storage path or file system path
+        * @param bool $safe Whether to do retroactive upload blacklist checks
         * @return null|string
         */
        public static function contentTypeFromPath( $filename, $safe = true ) {
@@ -157,10 +153,14 @@ class StreamFile {
                # used for thumbnails (thumb.php)
                if ( $wgTrivialMimeDetection ) {
                        switch ( $ext ) {
-                               case 'gif': return 'image/gif';
-                               case 'png': return 'image/png';
-                               case 'jpg': return 'image/jpeg';
-                               case 'jpeg': return 'image/jpeg';
+                               case 'gif':
+                                       return 'image/gif';
+                               case 'png':
+                                       return 'image/png';
+                               case 'jpg':
+                                       return 'image/jpeg';
+                               case 'jpeg':
+                                       return 'image/jpeg';
                        }
 
                        return 'unknown/unknown';
@@ -184,8 +184,8 @@ class StreamFile {
                                return 'unknown/unknown';
                        }
                        if ( $wgCheckFileExtensions && $wgStrictFileExtensions
-                               && !UploadBase::checkFileExtensionList( $extList, $wgFileExtensions ) )
-                       {
+                               && !UploadBase::checkFileExtensionList( $extList, $wgFileExtensions )
+                       {
                                return 'unknown/unknown';
                        }
                        if ( $wgVerifyMimeType && in_array( strtolower( $type ), $wgMimeTypeBlacklist ) ) {