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 
54 // If no LocalSettings file exists, try to display an error page
55 // (use a callback because it depends on TemplateParser)
56 if ( !defined( 'MW_CONFIG_CALLBACK' ) ) {
57  if ( !defined( 'MW_CONFIG_FILE' ) ) {
58  define( 'MW_CONFIG_FILE', "$IP/LocalSettings.php" );
59  }
60  if ( !is_readable( MW_CONFIG_FILE ) ) {
61 
62  function wfWebStartNoLocalSettings() {
63  # LocalSettings.php is the per-site customization file. If it does not exist
64  # the wiki installer needs to be launched or the generated file uploaded to
65  # the root wiki directory. Give a hint, if it is not readable by the server.
66  global $IP;
67  require_once "$IP/includes/NoLocalSettings.php";
68  die();
69  }
70 
71  define( 'MW_CONFIG_CALLBACK', 'wfWebStartNoLocalSettings' );
72  }
73 }
74 
75 // Custom setup for WebStart entry point
76 if ( !defined( 'MW_SETUP_CALLBACK' ) ) {
77 
78  function wfWebStartSetup() {
79  // Initialise output buffering
80  // Check for previously set up buffers, to avoid a mix of gzip and non-gzip output.
81  if ( ob_get_level() == 0 ) {
82  ob_start( 'MediaWiki\\OutputHandler::handle' );
83  }
84  }
85 
86  define( 'MW_SETUP_CALLBACK', 'wfWebStartSetup' );
87 }
88 
89 require_once "$IP/includes/Setup.php";
90 
91 # Multiple DBs or commits might be used; keep the request as transactional as possible
92 if ( isset( $_SERVER['REQUEST_METHOD'] ) && $_SERVER['REQUEST_METHOD'] === 'POST' ) {
93  ignore_user_abort( true );
94 }
95 
96 if ( !defined( 'MW_API' ) &&
97  RequestContext::getMain()->getRequest()->getHeader( 'Promise-Non-Write-API-Action' )
98 ) {
99  header( 'Cache-Control: no-cache' );
100  header( 'Content-Type: text/html; charset=utf-8' );
101  HttpStatus::header( 400 );
102  $errorHtml = wfMessage( 'nonwrite-api-promise-error' )
103  ->useDatabase( false )
104  ->inContentLanguage()
105  ->escaped();
106  $content = <<<HTML
107 <!DOCTYPE html>
108 <html>
109 <head><meta charset="UTF-8" /></head>
110 <body>
111 $errorHtml
112 </body>
113 </html>
114 
115 HTML;
116  header( 'Content-Length: ' . strlen( $content ) );
117  echo $content;
118  die();
119 }
wfMessage
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
Definition: GlobalFunctions.php:1219
$content
$content
Definition: router.php:76
RequestContext\getMain
static getMain()
Get the RequestContext object associated with the main request.
Definition: RequestContext.php:453
HttpStatus\header
static header( $code)
Output an HTTP status code header.
Definition: HttpStatus.php:96
$IP
$IP
Definition: WebStart.php:49