MediaWiki REL1_32
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
28ini_set( 'display_errors', 1 );
29error_reporting( E_ALL );
30
31if ( 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
51if ( !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 );
56if ( $ext == 'php' || $ext == 'php5' ) {
57 return false;
58}
59$mime = false;
60// Borrow mime type file from MimeAnalyzer
61$lines = explode( "\n", file_get_contents( "includes/libs/mime/mime.types" ) );
62foreach ( $lines as $line ) {
63 $exts = explode( " ", $line );
64 $mime = array_shift( $exts );
65 if ( in_array( $ext, $exts ) ) {
66 break; # this is the right value for $mime
67 }
68 $mime = false;
69}
70if ( !$mime ) {
71 $basename = basename( $file );
72 if ( $basename == strtoupper( $basename ) ) {
73 # IF it's something like README serve it as text
74 $mime = "text/plain";
75 }
76}
77if ( $mime ) {
78 # Use custom handling to serve files with a known MIME type
79 # This way we can serve things like .svg files that the built-in
80 # PHP webserver doesn't understand.
81 # ;) Nicely enough we just happen to bundle a mime.types file
82 $f = fopen( $file, 'rb' );
83 if ( preg_match( '#^text/#', $mime ) ) {
84 # Text should have a charset=UTF-8 (php's webserver does this too)
85 header( "Content-Type: $mime; charset=UTF-8" );
86 } else {
87 header( "Content-Type: $mime" );
88 }
89 header( "Content-Length: " . filesize( $file ) );
90 // Stream that out to the browser
91 fpassthru( $f );
92
93 return true;
94}
95
96# Let the php server handle things on its own otherwise
97return false;
$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
This document provides an overview of the usage of PageUpdater and that is
if( $ext=='php'|| $ext=='php5') $mime
Definition router.php:59
$lines
Definition router.php:61
if(!is_readable( $file)) $ext
Definition router.php:55