Fix broken contribution listings with postgres by adding a new variable
[lhc/web/wiklou.git] / includes / StreamFile.php
1 <?php
2 /** */
3
4 /** */
5 function wfStreamFile( $fname ) {
6 $stat = @stat( $fname );
7 if ( !$stat ) {
8 header( 'HTTP/1.0 404 Not Found' );
9 header( 'Cache-Control: no-cache' );
10 header( 'Content-Type: text/html' );
11 $encFile = htmlspecialchars( $fname );
12 $encScript = htmlspecialchars( $_SERVER['SCRIPT_NAME'] );
13 echo "<html><body>
14 <h1>File not found</h1>
15 <p>Although this PHP script ($encScript) exists, the file requested for output
16 ($encFile) does not.</p>
17 </body></html>
18 ";
19 return;
20 }
21
22 header( 'Last-Modified: ' . gmdate( 'D, d M Y H:i:s', $stat['mtime'] ) . ' GMT' );
23
24 // Cancel output buffering and gzipping if set
25 while( $status = ob_get_status() ) {
26 ob_end_clean();
27 if( $status['name'] == 'ob_gzhandler' ) {
28 header( 'Content-Encoding:' );
29 }
30 }
31
32 $type = wfGetType( $fname );
33 if ( $type and $type!="unknown/unknown") {
34 header("Content-type: $type");
35 } else {
36 header('Content-type: application/x-wiki');
37 }
38
39 if ( !empty( $_SERVER['HTTP_IF_MODIFIED_SINCE'] ) ) {
40 $modsince = preg_replace( '/;.*$/', '', $_SERVER['HTTP_IF_MODIFIED_SINCE'] );
41 $sinceTime = strtotime( $modsince );
42 if ( $stat['mtime'] <= $sinceTime ) {
43 header( "HTTP/1.0 304 Not Modified" );
44 return;
45 }
46 }
47
48 header( 'Content-Length: ' . $stat['size'] );
49
50 readfile( $fname );
51 }
52
53 /** */
54 function wfGetType( $filename ) {
55 global $wgTrivialMimeDetection;
56
57 # trivial detection by file extension,
58 # used for thumbnails (thumb.php)
59 if ($wgTrivialMimeDetection) {
60 $ext= strtolower(strrchr($filename, '.'));
61
62 switch ($ext) {
63 case '.gif': return 'image/gif';
64 case '.png': return 'image/png';
65 case '.jpg': return 'image/jpeg';
66 case '.jpeg': return 'image/jpeg';
67 }
68
69 return 'unknown/unknown';
70 }
71 else {
72 $magic=& MimeMagic::singleton();
73 return $magic->guessMimeType($filename); //full fancy mime detection
74 }
75 }
76
77 ?>