API: added query parameter indexpageids to list the page ids of all returned page...
[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; charset=utf-8' );
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 wfResetOutputBuffers();
26
27 $type = wfGetType( $fname );
28 if ( $type and $type!="unknown/unknown") {
29 header("Content-type: $type");
30 } else {
31 header('Content-type: application/x-wiki');
32 }
33
34 if ( !empty( $_SERVER['HTTP_IF_MODIFIED_SINCE'] ) ) {
35 $modsince = preg_replace( '/;.*$/', '', $_SERVER['HTTP_IF_MODIFIED_SINCE'] );
36 $sinceTime = strtotime( $modsince );
37 if ( $stat['mtime'] <= $sinceTime ) {
38 header( "HTTP/1.0 304 Not Modified" );
39 return;
40 }
41 }
42
43 header( 'Content-Length: ' . $stat['size'] );
44
45 readfile( $fname );
46 }
47
48 /** */
49 function wfGetType( $filename ) {
50 global $wgTrivialMimeDetection;
51
52 # trivial detection by file extension,
53 # used for thumbnails (thumb.php)
54 if ($wgTrivialMimeDetection) {
55 $ext= strtolower(strrchr($filename, '.'));
56
57 switch ($ext) {
58 case '.gif': return 'image/gif';
59 case '.png': return 'image/png';
60 case '.jpg': return 'image/jpeg';
61 case '.jpeg': return 'image/jpeg';
62 }
63
64 return 'unknown/unknown';
65 }
66 else {
67 $magic=& MimeMagic::singleton();
68 return $magic->guessMimeType($filename); //full fancy mime detection
69 }
70 }
71
72 ?>