Note that jquery.json will be removed in 1.25
[lhc/web/wiklou.git] / includes / WebStart.php
1 <?php
2 /**
3 * This does the initial set up for a web request.
4 * It does some security checks, starts the profiler and loads the
5 * configuration, and optionally loads Setup.php depending on whether
6 * MW_NO_SETUP is defined.
7 *
8 * Setup.php (if loaded) then sets up GlobalFunctions, the AutoLoader,
9 * and the configuration globals (though not $wgTitle).
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License along
22 * with this program; if not, write to the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24 * http://www.gnu.org/copyleft/gpl.html
25 *
26 * @file
27 */
28
29 # Die if register_globals is enabled (PHP <=5.3)
30 # This must be done before any globals are set by the code
31 if ( ini_get( 'register_globals' ) ) {
32 die( 'MediaWiki does not support installations where register_globals is enabled. '
33 . 'Please see <a href="https://www.mediawiki.org/wiki/register_globals">mediawiki.org</a> '
34 . 'for help on how to disable it.' );
35 }
36
37 # bug 15461: Make IE8 turn off content sniffing. Everybody else should ignore this
38 # We're adding it here so that it's *always* set, even for alternate entry
39 # points and when $wgOut gets disabled or overridden.
40 header( 'X-Content-Type-Options: nosniff' );
41
42 $wgRequestTime = microtime( true );
43 # getrusage() does not exist on the Microsoft Windows platforms, catching this
44 if ( function_exists ( 'getrusage' ) ) {
45 $wgRUstart = getrusage();
46 } else {
47 $wgRUstart = array();
48 }
49 unset( $IP );
50
51 # Valid web server entry point, enable includes.
52 # Please don't move this line to includes/Defines.php. This line essentially
53 # defines a valid entry point. If you put it in includes/Defines.php, then
54 # any script that includes it becomes an entry point, thereby defeating
55 # its purpose.
56 define( 'MEDIAWIKI', true );
57
58 # Full path to working directory.
59 # Makes it possible to for example to have effective exclude path in apc.
60 # __DIR__ breaks symlinked includes, but realpath() returns false
61 # if we don't have permissions on parent directories.
62 $IP = getenv( 'MW_INSTALL_PATH' );
63 if ( $IP === false ) {
64 if ( realpath( '.' ) ) {
65 $IP = realpath( '.' );
66 } else {
67 $IP = dirname( __DIR__ );
68 }
69 }
70
71 # Start the autoloader, so that extensions can derive classes from core files
72 require_once "$IP/includes/AutoLoader.php";
73
74 # Load the profiler
75 require_once "$IP/includes/profiler/Profiler.php";
76
77 # Load up some global defines.
78 require_once "$IP/includes/Defines.php";
79
80 # Start the profiler
81 $wgProfiler = array();
82 if ( file_exists( "$IP/StartProfiler.php" ) ) {
83 require "$IP/StartProfiler.php";
84 }
85
86 wfProfileIn( 'WebStart.php-conf' );
87
88 # Load default settings
89 require_once "$IP/includes/DefaultSettings.php";
90
91 # Load composer's autoloader if present
92 if ( is_readable( "$IP/vendor/autoload.php" ) ) {
93 require_once "$IP/vendor/autoload.php";
94 }
95
96 if ( defined( 'MW_CONFIG_CALLBACK' ) ) {
97 # Use a callback function to configure MediaWiki
98 call_user_func( MW_CONFIG_CALLBACK );
99 } else {
100 if ( !defined( 'MW_CONFIG_FILE' ) ) {
101 define( 'MW_CONFIG_FILE', "$IP/LocalSettings.php" );
102 }
103
104 # LocalSettings.php is the per site customization file. If it does not exist
105 # the wiki installer needs to be launched or the generated file uploaded to
106 # the root wiki directory. Give a hint, if it is not readable by the server.
107 if ( !is_readable( MW_CONFIG_FILE ) ) {
108 require_once "$IP/includes/templates/NoLocalSettings.php";
109 die();
110 }
111
112 # Include site settings. $IP may be changed (hopefully before the AutoLoader is invoked)
113 require_once MW_CONFIG_FILE;
114 }
115
116 wfProfileOut( 'WebStart.php-conf' );
117
118 wfProfileIn( 'WebStart.php-ob_start' );
119 # Initialise output buffering
120 # Check that there is no previous output or previously set up buffers, because
121 # that would cause us to potentially mix gzip and non-gzip output, creating a
122 # big mess.
123 if ( !defined( 'MW_NO_OUTPUT_BUFFER' ) && ob_get_level() == 0 ) {
124 require_once "$IP/includes/OutputHandler.php";
125 ob_start( 'wfOutputHandler' );
126 }
127 wfProfileOut( 'WebStart.php-ob_start' );
128
129 if ( !defined( 'MW_NO_SETUP' ) ) {
130 require_once "$IP/includes/Setup.php";
131 }