MediaWiki  master
router.php
Go to the documentation of this file.
1 <?php
24 if ( PHP_SAPI != 'cli-server' ) {
25  die( "This script can only be run by php's cli-server sapi." );
26 }
27 
28 ini_set( 'display_errors', 1 );
29 error_reporting( E_ALL );
30 
31 if ( isset( $_SERVER["SCRIPT_FILENAME"] ) ) {
32  # Known resource, sometimes a script sometimes a file
33  $file = $_SERVER["SCRIPT_FILENAME"];
34 } elseif ( isset( $_SERVER["SCRIPT_NAME"] ) ) {
35  # Usually unknown, document root relative rather than absolute
36  # Happens with some cases like /wiki/File:Image.png
37  if ( is_readable( $_SERVER['DOCUMENT_ROOT'] . $_SERVER["SCRIPT_NAME"] ) ) {
38  # Just in case this actually IS a file, set it here
39  $file = $_SERVER['DOCUMENT_ROOT'] . $_SERVER["SCRIPT_NAME"];
40  } else {
41  # Otherwise let's pretend that this is supposed to go to index.php
42  $file = $_SERVER['DOCUMENT_ROOT'] . '/index.php';
43  }
44 } else {
45  # Meh, we'll just give up
46  return false;
47 }
48 
49 # And now do handling for that $file
50 
51 if ( !is_readable( $file ) ) {
52  # Let the server throw the error if it doesn't exist
53  return false;
54 }
55 $ext = pathinfo( $file, PATHINFO_EXTENSION );
56 if ( $ext == 'php' || $ext == 'php5' ) {
57  # Execute php files
58  # We use require and return true here because when you return false
59  # the php webserver will discard post data and things like login
60  # will not function in the dev environment.
61  require $file;
62 
63  return true;
64 }
65 $mime = false;
66 $lines = explode( "\n", file_get_contents( "includes/mime.types" ) );
67 foreach ( $lines as $line ) {
68  $exts = explode( " ", $line );
69  $mime = array_shift( $exts );
70  if ( in_array( $ext, $exts ) ) {
71  break; # this is the right value for $mime
72  }
73  $mime = false;
74 }
75 if ( !$mime ) {
76  $basename = basename( $file );
77  if ( $basename == strtoupper( $basename ) ) {
78  # IF it's something like README serve it as text
79  $mime = "text/plain";
80  }
81 }
82 if ( $mime ) {
83  # Use custom handling to serve files with a known MIME type
84  # This way we can serve things like .svg files that the built-in
85  # PHP webserver doesn't understand.
86  # ;) Nicely enough we just happen to bundle a mime.types file
87  $f = fopen( $file, 'rb' );
88  if ( preg_match( '#^text/#', $mime ) ) {
89  # Text should have a charset=UTF-8 (php's webserver does this too)
90  header( "Content-Type: $mime; charset=UTF-8" );
91  } else {
92  header( "Content-Type: $mime" );
93  }
94  header( "Content-Length: " . filesize( $file ) );
95  // Stream that out to the browser
96  fpassthru( $f );
97 
98  return true;
99 }
100 
101 # Let the php server handle things on its own otherwise
102 return false;
if($ext== 'php'||$ext== 'php5') $mime
Definition: router.php:65
Some quick notes on the file repository architecture Functionality is
Definition: README:3
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
#define the
$lines
Definition: router.php:66
maintenance dev scripts can help quickly setup a local MediaWiki for development purposes Wikis setup in this way are NOT meant to be publicly available They use a development database not acceptible for use in production Place a sqlite database in an unsafe location a real wiki should never place it in And use predictable default logins for the initial administrator user Running maintenance dev install sh will download and install a local copy of php
Definition: README:5
$ext
Definition: router.php:55