Optional thumbnail generation by client request, using thumb.php. This removes any...
[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
17 $type = wfGetType( $fname );
18 if ( $type ) {
19 header("Content-type: $type");
20 } else {
21 header('Content-type: application/x-wiki');
22 }
23 header( 'Last-Modified: ' . gmdate( 'D, d M Y H:i:s', $stat['mtime'] ) );
24 header( "Cache-Control: s-maxage=$wgSquidMaxage, must-revalidate, max-age=0" );
25 readfile( $fname );
26 exit;
27 }
28
29 function wfGetType( $filename ) {
30 # There's probably a better way to do this
31 $types = <<<END_STRING
32 application/andrew-inset ez
33 application/mac-binhex40 hqx
34 application/mac-compactpro cpt
35 application/mathml+xml mathml
36 application/msword doc
37 application/octet-stream bin dms lha lzh exe class so dll
38 application/oda oda
39 application/ogg ogg
40 application/pdf pdf
41 application/postscript ai eps ps
42 application/rdf+xml rdf
43 application/smil smi smil
44 application/srgs gram
45 application/srgs+xml grxml
46 application/vnd.mif mif
47 application/vnd.ms-excel xls
48 application/vnd.ms-powerpoint ppt
49 application/vnd.wap.wbxml wbxml
50 application/vnd.wap.wmlc wmlc
51 application/vnd.wap.wmlscriptc wmlsc
52 application/voicexml+xml vxml
53 application/x-bcpio bcpio
54 application/x-cdlink vcd
55 application/x-chess-pgn pgn
56 application/x-cpio cpio
57 application/x-csh csh
58 application/x-director dcr dir dxr
59 application/x-dvi dvi
60 application/x-futuresplash spl
61 application/x-gtar gtar
62 application/x-hdf hdf
63 application/x-javascript js
64 application/x-koan skp skd skt skm
65 application/x-latex latex
66 application/x-netcdf nc cdf
67 application/x-sh sh
68 application/x-shar shar
69 application/x-shockwave-flash swf
70 application/x-stuffit sit
71 application/x-sv4cpio sv4cpio
72 application/x-sv4crc sv4crc
73 application/x-tar tar
74 application/x-tcl tcl
75 application/x-tex tex
76 application/x-texinfo texinfo texi
77 application/x-troff t tr roff
78 application/x-troff-man man
79 application/x-troff-me me
80 application/x-troff-ms ms
81 application/x-ustar ustar
82 application/x-wais-source src
83 application/xhtml+xml xhtml xht
84 application/xslt+xml xslt
85 application/xml xml xsl
86 application/xml-dtd dtd
87 application/zip zip
88 audio/basic au snd
89 audio/midi mid midi kar
90 audio/mpeg mpga mp2 mp3
91 audio/x-aiff aif aiff aifc
92 audio/x-mpegurl m3u
93 audio/x-pn-realaudio ram rm
94 audio/x-pn-realaudio-plugin rpm
95 audio/x-realaudio ra
96 audio/x-wav wav
97 chemical/x-pdb pdb
98 chemical/x-xyz xyz
99 image/bmp bmp
100 image/cgm cgm
101 image/gif gif
102 image/ief ief
103 image/jpeg jpeg jpg jpe
104 image/png png
105 image/svg+xml svg
106 image/tiff tiff tif
107 image/vnd.djvu djvu djv
108 image/vnd.wap.wbmp wbmp
109 image/x-cmu-raster ras
110 image/x-icon ico
111 image/x-portable-anymap pnm
112 image/x-portable-bitmap pbm
113 image/x-portable-graymap pgm
114 image/x-portable-pixmap ppm
115 image/x-rgb rgb
116 image/x-xbitmap xbm
117 image/x-xpixmap xpm
118 image/x-xwindowdump xwd
119 model/iges igs iges
120 model/mesh msh mesh silo
121 model/vrml wrl vrml
122 text/calendar ics ifb
123 text/css css
124 text/richtext rtx
125 text/rtf rtf
126 text/sgml sgml sgm
127 text/tab-separated-values tsv
128 text/vnd.wap.wml wml
129 text/vnd.wap.wmlscript wmls
130 text/x-setext etx
131 video/mpeg mpeg mpg mpe
132 video/quicktime qt mov
133 video/vnd.mpegurl mxu
134 video/x-msvideo avi
135 video/x-sgi-movie movie
136 x-conference/x-cooltalk ice
137 END_STRING;
138 // Needed for windows servers who use \r\n not \n
139 $endl = "
140 ";
141 $types = explode( $endl, $types );
142 if ( !preg_match( "/\.([^.]*?)$/", $filename, $matches ) ) {
143 return false;
144 }
145
146 foreach( $types as $type ) {
147 $extensions = explode( " ", $type );
148 for ( $i=1; $i<count( $extensions ); $i++ ) {
149 if ( $extensions[$i] == $matches[1] ) {
150 return $extensions[0];
151 }
152 }
153 }
154 return false;
155 }
156
157 ?>