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 $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" );
28 $type = wfGetType( $fname );
30 header("Content-type: $type");
32 header('Content-type: application/x-wiki');
37 function wfGetType( $filename ) {
38 # There's probably a better way to do this
39 $types = <<<END_STRING
40 application/andrew-inset ez
41 application/mac-binhex40 hqx
42 application/mac-compactpro cpt
43 application/mathml+xml mathml
44 application/msword doc
45 application/octet-stream bin dms lha lzh exe class so dll
49 application/postscript ai eps ps
50 application/rdf+xml rdf
51 application/smil smi smil
53 application/srgs+xml grxml
54 application/vnd.mif mif
55 application/vnd.ms-excel xls
56 application/vnd.ms-powerpoint ppt
57 application/vnd.wap.wbxml wbxml
58 application/vnd.wap.wmlc wmlc
59 application/vnd.wap.wmlscriptc wmlsc
60 application/voicexml+xml vxml
61 application/x-bcpio bcpio
62 application/x-cdlink vcd
63 application/x-chess-pgn pgn
64 application/x-cpio cpio
66 application/x-director dcr dir dxr
68 application/x-futuresplash spl
69 application/x-gtar gtar
71 application/x-javascript js
72 application/x-koan skp skd skt skm
73 application/x-latex latex
74 application/x-netcdf nc cdf
76 application/x-shar shar
77 application/x-shockwave-flash swf
78 application/x-stuffit sit
79 application/x-sv4cpio sv4cpio
80 application/x-sv4crc sv4crc
84 application/x-texinfo texinfo texi
85 application/x-troff t tr roff
86 application/x-troff-man man
87 application/x-troff-me me
88 application/x-troff-ms ms
89 application/x-ustar ustar
90 application/x-wais-source src
91 application/xhtml+xml xhtml xht
92 application/xslt+xml xslt
93 application/xml xml xsl
94 application/xml-dtd dtd
97 audio/midi mid midi kar
98 audio/mpeg mpga mp2 mp3
99 audio/x-aiff aif aiff aifc
101 audio/x-pn-realaudio ram rm
102 audio/x-pn-realaudio-plugin rpm
111 image/jpeg jpeg jpg jpe
115 image/vnd.djvu djvu djv
116 image/vnd.wap.wbmp wbmp
117 image/x-cmu-raster ras
119 image/x-portable-anymap pnm
120 image/x-portable-bitmap pbm
121 image/x-portable-graymap pgm
122 image/x-portable-pixmap ppm
126 image/x-xwindowdump xwd
128 model/mesh msh mesh silo
130 text/calendar ics ifb
135 text/tab-separated-values tsv
137 text/vnd.wap.wmlscript wmls
139 video/mpeg mpeg mpg mpe
140 video/quicktime qt mov
141 video/vnd.mpegurl mxu
143 video/x-sgi-movie movie
144 x-conference/x-cooltalk ice
146 // Needed for windows servers who use \r\n not \n
149 $types = explode( $endl, $types );
150 if ( !preg_match( "/\.([^.]*?)$/", $filename, $matches ) ) {
154 foreach( $types as $type ) {
155 $extensions = explode( " ", $type );
156 for ( $i=1; $i<count( $extensions ); $i++ ) {
157 if ( $extensions[$i] == $matches[1] ) {
158 return $extensions[0];