3 function wfStreamFile( $fname ) {
5 $stat = stat( $fname );
7 header( 'HTTP/1.0 404 Not Found' );
9 <h1>File not found</h1>
10 <p>Although this PHP script ({$_SERVER['SCRIPT_NAME']}) exists, the file requested for output
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 $sinceTime = strtotime( $_SERVER['HTTP_IF_MODIFIED_SINCE'] );
21 if ( $stat['mtime'] <= $sinceTime ) {
22 header( "HTTP/1.0 304 Not Modified" );
27 $type = wfGetType( $fname );
29 header("Content-type: $type");
31 header('Content-type: application/x-wiki');
36 function wfGetType( $filename ) {
37 # There's probably a better way to do this
38 $types = <<<END_STRING
39 application/andrew-inset ez
40 application/mac-binhex40 hqx
41 application/mac-compactpro cpt
42 application/mathml+xml mathml
43 application/msword doc
44 application/octet-stream bin dms lha lzh exe class so dll
48 application/postscript ai eps ps
49 application/rdf+xml rdf
50 application/smil smi smil
52 application/srgs+xml grxml
53 application/vnd.mif mif
54 application/vnd.ms-excel xls
55 application/vnd.ms-powerpoint ppt
56 application/vnd.wap.wbxml wbxml
57 application/vnd.wap.wmlc wmlc
58 application/vnd.wap.wmlscriptc wmlsc
59 application/voicexml+xml vxml
60 application/x-bcpio bcpio
61 application/x-cdlink vcd
62 application/x-chess-pgn pgn
63 application/x-cpio cpio
65 application/x-director dcr dir dxr
67 application/x-futuresplash spl
68 application/x-gtar gtar
70 application/x-javascript js
71 application/x-koan skp skd skt skm
72 application/x-latex latex
73 application/x-netcdf nc cdf
75 application/x-shar shar
76 application/x-shockwave-flash swf
77 application/x-stuffit sit
78 application/x-sv4cpio sv4cpio
79 application/x-sv4crc sv4crc
83 application/x-texinfo texinfo texi
84 application/x-troff t tr roff
85 application/x-troff-man man
86 application/x-troff-me me
87 application/x-troff-ms ms
88 application/x-ustar ustar
89 application/x-wais-source src
90 application/xhtml+xml xhtml xht
91 application/xslt+xml xslt
92 application/xml xml xsl
93 application/xml-dtd dtd
96 audio/midi mid midi kar
97 audio/mpeg mpga mp2 mp3
98 audio/x-aiff aif aiff aifc
100 audio/x-pn-realaudio ram rm
101 audio/x-pn-realaudio-plugin rpm
110 image/jpeg jpeg jpg jpe
114 image/vnd.djvu djvu djv
115 image/vnd.wap.wbmp wbmp
116 image/x-cmu-raster ras
118 image/x-portable-anymap pnm
119 image/x-portable-bitmap pbm
120 image/x-portable-graymap pgm
121 image/x-portable-pixmap ppm
125 image/x-xwindowdump xwd
127 model/mesh msh mesh silo
129 text/calendar ics ifb
134 text/tab-separated-values tsv
136 text/vnd.wap.wmlscript wmls
138 video/mpeg mpeg mpg mpe
139 video/quicktime qt mov
140 video/vnd.mpegurl mxu
142 video/x-sgi-movie movie
143 x-conference/x-cooltalk ice
145 // Needed for windows servers who use \r\n not \n
148 $types = explode( $endl, $types );
149 if ( !preg_match( "/\.([^.]*?)$/", $filename, $matches ) ) {
153 foreach( $types as $type ) {
154 $extensions = explode( " ", $type );
155 for ( $i=1; $i<count( $extensions ); $i++ ) {
156 if ( $extensions[$i] == $matches[1] ) {
157 return $extensions[0];