Modify maintenance/dev/ router code to fix the bug where post data gets discarded...
[lhc/web/wiklou.git] / maintenance / dev / router.php
1 <?php
2
3 ini_set('display_errors', 1);
4 error_reporting(E_ALL);
5
6 if ( isset( $_SERVER["SCRIPT_FILENAME"] ) ) {
7 $file = $_SERVER["SCRIPT_FILENAME"];
8 if ( !is_readable( $file ) ) {
9 // Let the server throw the error
10 return false;
11 }
12 $ext = pathinfo( $file, PATHINFO_EXTENSION );
13 if ( $ext == 'php' || $ext == 'php5' ) {
14 # Execute php files
15 # We use require and return true here because when you return false
16 # the php webserver will discard post data and things like login
17 # will not function in the dev environment.
18 require $file;
19 return true;
20 }
21 $mime = false;
22 $lines = explode( "\n", file_get_contents( "includes/mime.types" ) );
23 foreach ( $lines as $line ) {
24 $exts = explode( " ", $line );
25 $mime = array_shift( $exts );
26 if ( in_array( $ext, $exts ) ) {
27 break; # this is the right value for $mime
28 }
29 $mime = false;
30 }
31 if ( !$mime ) {
32 $basename = basename( $file );
33 if ( $basename == strtoupper( $basename ) ) {
34 # IF it's something like README serve it as text
35 $mime = "text/plain";
36 }
37 }
38 if ( $mime ) {
39 # Use custom handling to serve files with a known mime type
40 # This way we can serve things like .svg files that the built-in
41 # PHP webserver doesn't understand.
42 # ;) Nicely enough we just happen to bundle a mime.types file
43 $f = fopen($file, 'rb');
44 if ( preg_match( '^text/', $mime ) ) {
45 # Text should have a charset=UTF-8 (php's webserver does this too)
46 header("Content-Type: $mime; charset=UTF-8");
47 } else {
48 header("Content-Type: $mime");
49 }
50 header("Content-Length: " . filesize($file));
51 // Stream that out to the browser
52 fpassthru($f);
53 return true;
54 }
55 }
56
57 # Let the php server handle things on it's own otherwise
58 return false;
59