- throw new MWException( __FUNCTION__ . " given storage path '$fname'." );
- }
-
- // Don't stream it out as text/html if there was a PHP error
- if ( ( ( $flags & self::STREAM_HEADLESS ) == 0 || $headers ) && headers_sent() ) {
- echo "Headers already sent, terminating.\n";
- return false;
- }
-
- $headerFunc = ( $flags & self::STREAM_HEADLESS )
- ? function ( $header ) {
- // no-op
- }
- : function ( $header ) {
- is_int( $header ) ? HttpStatus::header( $header ) : header( $header );
- };
-
- MediaWiki\suppressWarnings();
- $info = stat( $fname );
- MediaWiki\restoreWarnings();
-
- if ( !is_array( $info ) ) {
- if ( $sendErrors ) {
- self::send404Message( $fname, $flags );
- }
- return false;
- }
-
- // Send Last-Modified HTTP header for client-side caching
- $headerFunc( 'Last-Modified: ' . wfTimestamp( TS_RFC2822, $info['mtime'] ) );
-
- if ( ( $flags & self::STREAM_ALLOW_OB ) == 0 ) {
- // Cancel output buffering and gzipping if set
- wfResetOutputBuffers();
- }
-
- $type = self::contentTypeFromPath( $fname );
- if ( $type && $type != 'unknown/unknown' ) {
- $headerFunc( "Content-type: $type" );
- } else {
- // Send a content type which is not known to Internet Explorer, to
- // avoid triggering IE's content type detection. Sending a standard
- // unknown content type here essentially gives IE license to apply
- // whatever content type it likes.
- $headerFunc( 'Content-type: application/x-wiki' );