00001 <?php
00005 function wfStreamFile( $fname, $headers = array() ) {
00006 $stat = @stat( $fname );
00007 if ( !$stat ) {
00008 header( 'HTTP/1.0 404 Not Found' );
00009 header( 'Cache-Control: no-cache' );
00010 header( 'Content-Type: text/html; charset=utf-8' );
00011 $encFile = htmlspecialchars( $fname );
00012 $encScript = htmlspecialchars( $_SERVER['SCRIPT_NAME'] );
00013 echo "<html><body>
00014 <h1>File not found</h1>
00015 <p>Although this PHP script ($encScript) exists, the file requested for output
00016 ($encFile) does not.</p>
00017 </body></html>
00018 ";
00019 return;
00020 }
00021
00022 header( 'Last-Modified: ' . gmdate( 'D, d M Y H:i:s', $stat['mtime'] ) . ' GMT' );
00023
00024
00025 wfResetOutputBuffers();
00026
00027 $type = wfGetType( $fname );
00028 if ( $type and $type!="unknown/unknown") {
00029 header("Content-type: $type");
00030 } else {
00031 header('Content-type: application/x-wiki');
00032 }
00033
00034
00035 if ( headers_sent() ) {
00036 echo "Headers already sent, terminating.\n";
00037 return;
00038 }
00039
00040 global $wgContLanguageCode;
00041 header( "Content-Disposition: inline;filename*=utf-8'$wgContLanguageCode'" . urlencode( basename( $fname ) ) );
00042
00043 foreach ( $headers as $header ) {
00044 header( $header );
00045 }
00046
00047 if ( !empty( $_SERVER['HTTP_IF_MODIFIED_SINCE'] ) ) {
00048 $modsince = preg_replace( '/;.*$/', '', $_SERVER['HTTP_IF_MODIFIED_SINCE'] );
00049 $sinceTime = strtotime( $modsince );
00050 if ( $stat['mtime'] <= $sinceTime ) {
00051 ini_set('zlib.output_compression', 0);
00052 header( "HTTP/1.0 304 Not Modified" );
00053 return;
00054 }
00055 }
00056
00057 header( 'Content-Length: ' . $stat['size'] );
00058
00059 readfile( $fname );
00060 }
00061
00063 function wfGetType( $filename, $safe = true ) {
00064 global $wgTrivialMimeDetection;
00065
00066 $ext = strrchr($filename, '.');
00067 $ext = $ext === false ? '' : strtolower( substr( $ext, 1 ) );
00068
00069 # trivial detection by file extension,
00070 # used for thumbnails (thumb.php)
00071 if ($wgTrivialMimeDetection) {
00072 switch ($ext) {
00073 case 'gif': return 'image/gif';
00074 case 'png': return 'image/png';
00075 case 'jpg': return 'image/jpeg';
00076 case 'jpeg': return 'image/jpeg';
00077 }
00078
00079 return 'unknown/unknown';
00080 }
00081
00082 $magic = MimeMagic::singleton();
00083
00084
00085
00086 $type = $magic->guessTypesForExtension( $ext );
00087
00092 if ( $safe ) {
00093 global $wgFileBlacklist, $wgCheckFileExtensions, $wgStrictFileExtensions,
00094 $wgFileExtensions, $wgVerifyMimeType, $wgMimeTypeBlacklist, $wgRequest;
00095 $form = new UploadForm( $wgRequest );
00096 list( $partName, $extList ) = $form->splitExtensions( $filename );
00097 if ( $form->checkFileExtensionList( $extList, $wgFileBlacklist ) ) {
00098 return 'unknown/unknown';
00099 }
00100 if ( $wgCheckFileExtensions && $wgStrictFileExtensions
00101 && !$form->checkFileExtensionList( $extList, $wgFileExtensions ) )
00102 {
00103 return 'unknown/unknown';
00104 }
00105 if ( $wgVerifyMimeType && in_array( strtolower( $type ), $wgMimeTypeBlacklist ) ) {
00106 return 'unknown/unknown';
00107 }
00108 }
00109 return $type;
00110 }