* (bug 2567) Fix HTML escaping on category titles in list
[lhc/web/wiklou.git] / includes / StreamFile.php
1 <?php
2
3 function wfStreamFile( $fname ) {
4 global $wgSquidMaxage;
5 $stat = stat( $fname );
6 if ( !$stat ) {
7 header( 'HTTP/1.0 404 Not Found' );
8 echo "<html><body>
9 <h1>File not found</h1>
10 <p>Although this PHP script ({$_SERVER['SCRIPT_NAME']}) exists, the file requested for output
11 does not.</p>
12 </body></html>";
13 return;
14 }
15
16 header( "Cache-Control: s-maxage=$wgSquidMaxage, must-revalidate, max-age=0" );
17 header( 'Last-Modified: ' . gmdate( 'D, d M Y H:i:s', $stat['mtime'] ) . ' GMT' );
18
19 if ( !empty( $_SERVER['HTTP_IF_MODIFIED_SINCE'] ) ) {
20 $modsince = preg_replace( '/;.*$/', '', $_SERVER['HTTP_IF_MODIFIED_SINCE'] );
21 $sinceTime = strtotime( $modsince );
22 if ( $stat['mtime'] <= $sinceTime ) {
23 header( "HTTP/1.0 304 Not Modified" );
24 return;
25 }
26 }
27
28 header( 'Content-Length: ' . $stat['size'] );
29
30 $type = wfGetType( $fname );
31 if ( $type and $type!="unknown/unknown") {
32 header("Content-type: $type");
33 } else {
34 header('Content-type: application/x-wiki');
35 }
36
37 readfile( $fname );
38 }
39
40 function wfGetType( $filename ) {
41 global $wgTrivialMimeDetection;
42
43 # trivial detection by file extension,
44 # used for thumbnails (thumb.php)
45 if ($wgTrivialMimeDetection) {
46 $ext= strtolower(strrchr($filename, '.'));
47
48 switch ($ext) {
49 case '.gif': return "image/gif";
50 case '.png': return "image/png";
51 case '.jpg': return "image/jpeg";
52 case '.jpeg': return "image/jpeg";
53 }
54
55 return "unknown/unknown";
56 }
57 else {
58 $magic=& wfGetMimeMagic();
59 return $magic->guessMimeType($filename); //full fancy mime detection
60 }
61 }
62
63 ?>