(bugs 2633, 2672) Fix Estonian, Portuguese and Finnish numeric formatting
[mediawiki.git] / includes / StreamFile.php
blobe154d6a20250d3f31bbdda23cf4eceeda953bb67
1 <?php
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;
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' );
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;
28 header( 'Content-Length: ' . $stat['size'] );
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');
37 readfile( $fname );
40 function wfGetType( $filename ) {
41 global $wgTrivialMimeDetection;
43 # trivial detection by file extension,
44 # used for thumbnails (thumb.php)
45 if ($wgTrivialMimeDetection) {
46 $ext= strtolower(strrchr($filename, '.'));
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";
55 return "unknown/unknown";
57 else {
58 $magic=& wfGetMimeMagic();
59 return $magic->guessMimeType($filename); //full fancy mime detection