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