hook point for injecting fields into edit form
[mediawiki.git] / includes / StreamFile.php
blobdc653e57bf6e7b1a55b1c08044dcdb6e5cf0d1b1
1 <?php
2 /** */
4 /** */
5 function wfStreamFile( $fname ) {
6 $stat = @stat( $fname );
7 if ( !$stat ) {
8 header( 'HTTP/1.0 404 Not Found' );
9 header( 'Cache-Control: no-cache' );
10 header( 'Content-Type: text/html; charset=utf-8' );
11 $encFile = htmlspecialchars( $fname );
12 $encScript = htmlspecialchars( $_SERVER['SCRIPT_NAME'] );
13 echo "<html><body>
14 <h1>File not found</h1>
15 <p>Although this PHP script ($encScript) exists, the file requested for output
16 ($encFile) does not.</p>
17 </body></html>
19 return;
22 header( 'Last-Modified: ' . gmdate( 'D, d M Y H:i:s', $stat['mtime'] ) . ' GMT' );
24 // Cancel output buffering and gzipping if set
25 wfResetOutputBuffers();
27 $type = wfGetType( $fname );
28 if ( $type and $type!="unknown/unknown") {
29 header("Content-type: $type");
30 } else {
31 header('Content-type: application/x-wiki');
34 if ( !empty( $_SERVER['HTTP_IF_MODIFIED_SINCE'] ) ) {
35 $modsince = preg_replace( '/;.*$/', '', $_SERVER['HTTP_IF_MODIFIED_SINCE'] );
36 $sinceTime = strtotime( $modsince );
37 if ( $stat['mtime'] <= $sinceTime ) {
38 header( "HTTP/1.0 304 Not Modified" );
39 return;
43 header( 'Content-Length: ' . $stat['size'] );
45 readfile( $fname );
48 /** */
49 function wfGetType( $filename ) {
50 global $wgTrivialMimeDetection;
52 # trivial detection by file extension,
53 # used for thumbnails (thumb.php)
54 if ($wgTrivialMimeDetection) {
55 $ext= strtolower(strrchr($filename, '.'));
57 switch ($ext) {
58 case '.gif': return 'image/gif';
59 case '.png': return 'image/png';
60 case '.jpg': return 'image/jpeg';
61 case '.jpeg': return 'image/jpeg';
64 return 'unknown/unknown';
66 else {
67 $magic=& MimeMagic::singleton();
68 return $magic->guessMimeType($filename); //full fancy mime detection