MediaWiki  master
WebStart.php
Go to the documentation of this file.
1 <?php
36 # T17461: Make IE8 turn off content sniffing. Everybody else should ignore this
37 # We're adding it here so that it's *always* set, even for alternate entry
38 # points and when $wgOut gets disabled or overridden.
39 header( 'X-Content-Type-Options: nosniff' );
40 
41 # Valid web server entry point, enable includes.
42 # Please don't move this line to includes/Defines.php. This line essentially
43 # defines a valid entry point. If you put it in includes/Defines.php, then
44 # any script that includes it becomes an entry point, thereby defeating
45 # its purpose.
46 define( 'MEDIAWIKI', true );
47 
48 # Full path to the installation directory.
49 $IP = getenv( 'MW_INSTALL_PATH' );
50 if ( $IP === false ) {
51  $IP = dirname( __DIR__ );
52 }
53 
58  # LocalSettings.php is the per-site customization file. If it does not exist
59  # the wiki installer needs to be launched or the generated file uploaded to
60  # the root wiki directory. Give a hint, if it is not readable by the server.
61  global $IP;
62  require_once "$IP/includes/NoLocalSettings.php";
63  die();
64 }
65 
66 // If no LocalSettings file exists, try to display an error page
67 // (use a callback because it depends on TemplateParser)
68 if ( !defined( 'MW_CONFIG_CALLBACK' ) ) {
69  if ( !defined( 'MW_CONFIG_FILE' ) ) {
70  define( 'MW_CONFIG_FILE', "$IP/LocalSettings.php" );
71  }
72  if ( !is_readable( MW_CONFIG_FILE ) ) {
73  define( 'MW_CONFIG_CALLBACK', 'wfWebStartNoLocalSettings' );
74  }
75 }
76 
77 function wfWebStartSetup() {
78  // Initialise output buffering
79  // Check for previously set up buffers, to avoid a mix of gzip and non-gzip output.
80  if ( ob_get_level() == 0 ) {
81  ob_start( 'MediaWiki\\OutputHandler::handle' );
82  }
83 }
84 
85 // Custom setup for WebStart entry point
86 if ( !defined( 'MW_SETUP_CALLBACK' ) ) {
87  define( 'MW_SETUP_CALLBACK', 'wfWebStartSetup' );
88 }
89 
90 require_once "$IP/includes/Setup.php";
91 
92 # Multiple DBs or commits might be used; keep the request as transactional as possible
93 if ( isset( $_SERVER['REQUEST_METHOD'] ) && $_SERVER['REQUEST_METHOD'] === 'POST' ) {
94  ignore_user_abort( true );
95 }
96 
97 if ( !defined( 'MW_API' ) && !defined( 'MW_REST_API' ) &&
98  RequestContext::getMain()->getRequest()->getHeader( 'Promise-Non-Write-API-Action' )
99 ) {
100  header( 'Cache-Control: no-cache' );
101  header( 'Content-Type: text/html; charset=utf-8' );
102  HttpStatus::header( 400 );
103  $errorHtml = wfMessage( 'nonwrite-api-promise-error' )
104  ->useDatabase( false )
105  ->inContentLanguage()
106  ->escaped();
107  $content = <<<HTML
108 <!DOCTYPE html>
109 <html>
110 <head><meta charset="UTF-8" /></head>
111 <body>
112 $errorHtml
113 </body>
114 </html>
115 
116 HTML;
117  header( 'Content-Length: ' . strlen( $content ) );
118  echo $content;
119  die();
120 }
wfMessage
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
Definition: GlobalFunctions.php:1186
$content
$content
Definition: router.php:76
RequestContext\getMain
static getMain()
Get the RequestContext object associated with the main request.
Definition: RequestContext.php:484
HttpStatus\header
static header( $code)
Output an HTTP status code header.
Definition: HttpStatus.php:96
wfWebStartSetup
if(!defined( 'MW_CONFIG_CALLBACK')) wfWebStartSetup()
Definition: WebStart.php:77
$IP
$IP
Definition: WebStart.php:49
wfWebStartNoLocalSettings
if( $IP===false) wfWebStartNoLocalSettings()
Definition: WebStart.php:57