Live hack: Skip some work on empty category/link sets
[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 echo "<html><body>
10 <h1>File not found</h1>
11 <p>Although this PHP script ({$_SERVER['SCRIPT_NAME']}) exists, the file requested for output
12 does not.</p>
13 </body></html>";
14 return;
15 }
16
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 /** */
41 function wfGetType( $filename ) {
42 global $wgTrivialMimeDetection;
43
44 # trivial detection by file extension,
45 # used for thumbnails (thumb.php)
46 if ($wgTrivialMimeDetection) {
47 $ext= strtolower(strrchr($filename, '.'));
48
49 switch ($ext) {
50 case '.gif': return 'image/gif';
51 case '.png': return 'image/png';
52 case '.jpg': return 'image/jpeg';
53 case '.jpeg': return 'image/jpeg';
54 }
55
56 return 'unknown/unknown';
57 }
58 else {
59 $magic=& wfGetMimeMagic();
60 return $magic->guessMimeType($filename); //full fancy mime detection
61 }
62 }
63
64 ?>