MediaWiki REL1_33
router.php
Go to the documentation of this file.
1<?php
24if ( PHP_SAPI != 'cli-server' ) {
25 die( "This script can only be run by php's cli-server sapi." );
26}
27
28if ( !isset( $_SERVER['SCRIPT_FILENAME'] ) ) {
29 // Let built-in server handle error.
30 return false;
31}
32
33// The SCRIPT_FILENAME can be one of three things:
34// 1. Absolute path to a file in the docroot associated with the
35// path of the current request URL. PHP does this for any file path
36// where it finds a matching file on disk. For both PHP files, and for
37// static files.
38// 2. Relative path to router.php (this file), for any unknown URL path
39// that ends in ".php" or another extension that PHP would execute.
40// 3. Absolute path to {docroot}/index.php, for any other unknown path.
41// Effectively treating it as a 404 handler.
42$file = $_SERVER['SCRIPT_FILENAME'];
43if ( !is_readable( $file ) ) {
44 // Let built-in server handle error.
45 return false;
46}
47
48$ext = pathinfo( $file, PATHINFO_EXTENSION );
49if ( $ext == 'php' ) {
50 // Let built-in server handle script inclusion.
51 return false;
52} else {
53 // Serve static file with appropiate Content-Type headers.
54 // The built-in server for PHP 7.0+ supports most files already
55 // (contrary to PHP 5.2, which was supported when router.php was created).
56 // But it still doesn't support as many MIME types as MediaWiki (e.g. ".json")
57
58 // Fallback
59 $mime = 'text/plain';
60 // Borrow from MimeAnalyzer
61 $lines = explode( "\n", file_get_contents( "includes/libs/mime/mime.types" ) );
62 foreach ( $lines as $line ) {
63 $exts = explode( ' ', $line );
64 $type = array_shift( $exts );
65 if ( in_array( $ext, $exts ) ) {
66 $mime = $type;
67 break;
68 }
69 }
70
71 if ( preg_match( '#^text/#', $mime ) ) {
72 // Text should have a charset=UTF-8 (PHP's webserver does this too)
73 header( "Content-Type: $mime; charset=UTF-8" );
74 } else {
75 header( "Content-Type: $mime" );
76 }
77 header( "Content-Length: " . filesize( $file ) );
78 // Stream that out to the browser
79 $f = fopen( $file, 'rb' );
80 fpassthru( $f );
81
82 return true;
83}
$line
Definition cdb.php:59
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition injection.txt:37
$f
Definition router.php:79
$lines
Definition router.php:61
if(!is_readable( $file)) $ext
Definition router.php:48
if(PHP_SAPI !='cli-server') if(!isset( $_SERVER['SCRIPT_FILENAME'])) $file
Definition router.php:42