Userlevels and grouplevels have been moved out to a 'steward' group. Make
[lhc/web/wiklou.git] / includes / StreamFile.php
1 <?php
2
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;
14 }
15
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' );
18
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;
25 }
26 }
27
28 $type = wfGetType( $fname );
29 if ( $type ) {
30 header("Content-type: $type");
31 } else {
32 header('Content-type: application/x-wiki');
33 }
34 readfile( $fname );
35 }
36
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
46 application/oda oda
47 application/ogg ogg
48 application/pdf pdf
49 application/postscript ai eps ps
50 application/rdf+xml rdf
51 application/smil smi smil
52 application/srgs gram
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
65 application/x-csh csh
66 application/x-director dcr dir dxr
67 application/x-dvi dvi
68 application/x-futuresplash spl
69 application/x-gtar gtar
70 application/x-hdf hdf
71 application/x-javascript js
72 application/x-koan skp skd skt skm
73 application/x-latex latex
74 application/x-netcdf nc cdf
75 application/x-sh sh
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
81 application/x-tar tar
82 application/x-tcl tcl
83 application/x-tex tex
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
95 application/zip zip
96 audio/basic au snd
97 audio/midi mid midi kar
98 audio/mpeg mpga mp2 mp3
99 audio/x-aiff aif aiff aifc
100 audio/x-mpegurl m3u
101 audio/x-pn-realaudio ram rm
102 audio/x-pn-realaudio-plugin rpm
103 audio/x-realaudio ra
104 audio/x-wav wav
105 chemical/x-pdb pdb
106 chemical/x-xyz xyz
107 image/bmp bmp
108 image/cgm cgm
109 image/gif gif
110 image/ief ief
111 image/jpeg jpeg jpg jpe
112 image/png png
113 image/svg+xml svg
114 image/tiff tiff tif
115 image/vnd.djvu djvu djv
116 image/vnd.wap.wbmp wbmp
117 image/x-cmu-raster ras
118 image/x-icon ico
119 image/x-portable-anymap pnm
120 image/x-portable-bitmap pbm
121 image/x-portable-graymap pgm
122 image/x-portable-pixmap ppm
123 image/x-rgb rgb
124 image/x-xbitmap xbm
125 image/x-xpixmap xpm
126 image/x-xwindowdump xwd
127 model/iges igs iges
128 model/mesh msh mesh silo
129 model/vrml wrl vrml
130 text/calendar ics ifb
131 text/css css
132 text/richtext rtx
133 text/rtf rtf
134 text/sgml sgml sgm
135 text/tab-separated-values tsv
136 text/vnd.wap.wml wml
137 text/vnd.wap.wmlscript wmls
138 text/x-setext etx
139 video/mpeg mpeg mpg mpe
140 video/quicktime qt mov
141 video/vnd.mpegurl mxu
142 video/x-msvideo avi
143 video/x-sgi-movie movie
144 x-conference/x-cooltalk ice
145 END_STRING;
146 // Needed for windows servers who use \r\n not \n
147 $endl = "
148 ";
149 $types = explode( $endl, $types );
150 if ( !preg_match( "/\.([^.]*?)$/", $filename, $matches ) ) {
151 return false;
152 }
153
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];
159 }
160 }
161 }
162 return false;
163 }
164
165 ?>