- public static function prepareForStream(
- $path, $info, $headers = [], $sendErrors = true
- ) {
- if ( !is_array( $info ) ) {
- if ( $sendErrors ) {
- HttpStatus::header( 404 );
- header( 'Cache-Control: no-cache' );
- header( 'Content-Type: text/html; charset=utf-8' );
- $encFile = htmlspecialchars( $path );
- $encScript = htmlspecialchars( $_SERVER['SCRIPT_NAME'] );
- echo "<html><body>
- <h1>File not found</h1>
- <p>Although this PHP script ($encScript) exists, the file requested for output
- ($encFile) does not.</p>
- </body></html>
- ";
- }
- return false;
- }
-
- // Sent Last-Modified HTTP header for client-side caching
- header( 'Last-Modified: ' . wfTimestamp( TS_RFC2822, $info['mtime'] ) );
-
- // Cancel output buffering and gzipping if set
- wfResetOutputBuffers();
-
- $type = self::contentTypeFromPath( $path );
- if ( $type && $type != 'unknown/unknown' ) {
- header( "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.
- header( 'Content-type: application/x-wiki' );
- }
-
- // Don't stream it out as text/html if there was a PHP error
- if ( headers_sent() ) {
- echo "Headers already sent, terminating.\n";
- return false;
- }
-
- // Send additional headers
- foreach ( $headers as $header ) {
- header( $header );
- }
-
- // Don't send if client has up to date cache
- if ( !empty( $_SERVER['HTTP_IF_MODIFIED_SINCE'] ) ) {
- $modsince = preg_replace( '/;.*$/', '', $_SERVER['HTTP_IF_MODIFIED_SINCE'] );
- if ( wfTimestamp( TS_UNIX, $info['mtime'] ) <= strtotime( $modsince ) ) {
- ini_set( 'zlib.output_compression', 0 );
- HttpStatus::header( 304 );
- return self::NOT_MODIFIED; // ok
- }
- }
-
- header( 'Content-Length: ' . $info['size'] );