X-Git-Url: https://git.cyclocoop.org/?a=blobdiff_plain;f=includes%2FStreamFile.php;h=0a8309f142c496f1c9e39f96ee17896e1f436a72;hb=957850f0da357337c24291a29d5ea0f08b5050a9;hp=db470ffb44c8778c52fa3b52273c84cd4e1513d4;hpb=1a1e917c86ca9468bd3f0dfece93ba283552c61f;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/StreamFile.php b/includes/StreamFile.php index db470ffb44..0a8309f142 100644 --- a/includes/StreamFile.php +++ b/includes/StreamFile.php @@ -9,24 +9,30 @@ class StreamFile { * Stream a file to the browser, adding all the headings and fun stuff * @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) + * @return bool Success */ - public static function stream( $fname, $headers = array(), $request = null ) { + public static function stream( $fname, $headers = array(), $sendErrors = true ) { + global $wgLanguageCode; + wfSuppressWarnings(); $stat = stat( $fname ); wfRestoreWarnings(); if ( !$stat ) { - header( 'HTTP/1.0 404 Not Found' ); - header( 'Cache-Control: no-cache' ); - header( 'Content-Type: text/html; charset=utf-8' ); - $encFile = htmlspecialchars( $fname ); - $encScript = htmlspecialchars( $_SERVER['SCRIPT_NAME'] ); - echo " -

File not found

-

Although this PHP script ($encScript) exists, the file requested for output - ($encFile) does not.

- - "; - return; + if ( $sendErrors ) { + header( 'HTTP/1.0 404 Not Found' ); + header( 'Cache-Control: no-cache' ); + header( 'Content-Type: text/html; charset=utf-8' ); + $encFile = htmlspecialchars( $fname ); + $encScript = htmlspecialchars( $_SERVER['SCRIPT_NAME'] ); + echo " +

File not found

+

Although this PHP script ($encScript) exists, the file requested for output + ($encFile) does not.

+ + "; + } + return false; } header( 'Last-Modified: ' . gmdate( 'D, d M Y H:i:s', $stat['mtime'] ) . ' GMT' ); @@ -44,29 +50,31 @@ class StreamFile { // Don't stream it out as text/html if there was a PHP error if ( headers_sent() ) { echo "Headers already sent, terminating.\n"; - return; + return false; } - global $wgLanguageCode; - header( "Content-Disposition: inline;filename*=utf-8'$wgLanguageCode'" . urlencode( basename( $fname ) ) ); + header( "Content-Disposition: inline;filename*=utf-8'$wgLanguageCode'" . + urlencode( basename( $fname ) ) ); + // 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'] ); $sinceTime = strtotime( $modsince ); if ( $stat['mtime'] <= $sinceTime ) { ini_set( 'zlib.output_compression', 0 ); header( "HTTP/1.0 304 Not Modified" ); - return; + return true; // ok } } header( 'Content-Length: ' . $stat['size'] ); - readfile( $fname ); + return readfile( $fname ); } /**