2005-04-16 04:33:34 +00:00
|
|
|
<?php
|
2005-07-05 21:22:25 +00:00
|
|
|
/** */
|
2005-04-16 04:33:34 +00:00
|
|
|
|
2005-07-05 21:22:25 +00:00
|
|
|
/** */
|
2005-04-16 04:33:34 +00:00
|
|
|
function wfStreamFile( $fname ) {
|
2005-08-13 07:53:16 +00:00
|
|
|
$stat = @stat( $fname );
|
2005-04-16 04:33:34 +00:00
|
|
|
if ( !$stat ) {
|
|
|
|
|
header( 'HTTP/1.0 404 Not Found' );
|
2006-11-01 11:21:09 +00:00
|
|
|
header( 'Cache-Control: no-cache' );
|
2007-02-21 01:02:47 +00:00
|
|
|
header( 'Content-Type: text/html; charset=utf-8' );
|
2006-10-02 17:04:13 +00:00
|
|
|
$encFile = htmlspecialchars( $fname );
|
|
|
|
|
$encScript = htmlspecialchars( $_SERVER['SCRIPT_NAME'] );
|
2005-04-16 04:33:34 +00:00
|
|
|
echo "<html><body>
|
|
|
|
|
<h1>File not found</h1>
|
2006-10-02 17:04:13 +00:00
|
|
|
<p>Although this PHP script ($encScript) exists, the file requested for output
|
|
|
|
|
($encFile) does not.</p>
|
2006-11-12 10:44:48 +00:00
|
|
|
</body></html>
|
|
|
|
|
";
|
2005-04-16 04:33:34 +00:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2005-04-16 05:48:21 +00:00
|
|
|
header( 'Last-Modified: ' . gmdate( 'D, d M Y H:i:s', $stat['mtime'] ) . ' GMT' );
|
|
|
|
|
|
2006-06-13 20:22:08 +00:00
|
|
|
// Cancel output buffering and gzipping if set
|
2006-12-11 01:51:21 +00:00
|
|
|
wfResetOutputBuffers();
|
2006-06-13 20:22:08 +00:00
|
|
|
|
2006-06-13 23:54:08 +00:00
|
|
|
$type = wfGetType( $fname );
|
|
|
|
|
if ( $type and $type!="unknown/unknown") {
|
|
|
|
|
header("Content-type: $type");
|
|
|
|
|
} else {
|
|
|
|
|
header('Content-type: application/x-wiki');
|
|
|
|
|
}
|
|
|
|
|
|
2005-04-16 05:48:21 +00:00
|
|
|
if ( !empty( $_SERVER['HTTP_IF_MODIFIED_SINCE'] ) ) {
|
2005-04-16 11:05:41 +00:00
|
|
|
$modsince = preg_replace( '/;.*$/', '', $_SERVER['HTTP_IF_MODIFIED_SINCE'] );
|
|
|
|
|
$sinceTime = strtotime( $modsince );
|
2005-04-16 05:48:21 +00:00
|
|
|
if ( $stat['mtime'] <= $sinceTime ) {
|
|
|
|
|
header( "HTTP/1.0 304 Not Modified" );
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
2006-01-07 13:31:29 +00:00
|
|
|
|
2005-05-21 07:46:17 +00:00
|
|
|
header( 'Content-Length: ' . $stat['size'] );
|
2006-01-07 13:31:29 +00:00
|
|
|
|
2005-04-16 04:33:34 +00:00
|
|
|
readfile( $fname );
|
|
|
|
|
}
|
|
|
|
|
|
2005-07-05 21:22:25 +00:00
|
|
|
/** */
|
2005-04-16 04:33:34 +00:00
|
|
|
function wfGetType( $filename ) {
|
2005-05-21 07:46:17 +00:00
|
|
|
global $wgTrivialMimeDetection;
|
2005-04-16 04:33:34 +00:00
|
|
|
|
2005-05-21 07:46:17 +00:00
|
|
|
# trivial detection by file extension,
|
|
|
|
|
# used for thumbnails (thumb.php)
|
|
|
|
|
if ($wgTrivialMimeDetection) {
|
|
|
|
|
$ext= strtolower(strrchr($filename, '.'));
|
2006-01-07 13:31:29 +00:00
|
|
|
|
2005-05-21 07:46:17 +00:00
|
|
|
switch ($ext) {
|
2005-07-05 21:22:25 +00:00
|
|
|
case '.gif': return 'image/gif';
|
|
|
|
|
case '.png': return 'image/png';
|
|
|
|
|
case '.jpg': return 'image/jpeg';
|
|
|
|
|
case '.jpeg': return 'image/jpeg';
|
2005-04-16 04:33:34 +00:00
|
|
|
}
|
2006-01-07 13:31:29 +00:00
|
|
|
|
2005-07-05 21:22:25 +00:00
|
|
|
return 'unknown/unknown';
|
2005-05-21 07:46:17 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2006-10-03 13:00:52 +00:00
|
|
|
$magic=& MimeMagic::singleton();
|
2005-05-21 07:46:17 +00:00
|
|
|
return $magic->guessMimeType($filename); //full fancy mime detection
|
2005-04-16 04:33:34 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
?>
|