MagicWord initialisation deferred.
[lhc/web/wiklou.git] / includes / Setup.php
1 <?php
2 /**
3 * Include most things that's need to customize the site
4 * @package MediaWiki
5 */
6
7 /**
8 * This file is not a valid entry point, perform no further processing unless
9 * MEDIAWIKI is defined
10 */
11 if( !defined( 'MEDIAWIKI' ) ) {
12 echo "This file is part of MediaWiki, it is not a valid entry point.\n";
13 exit( 1 );
14 }
15
16 # The main wiki script and things like database
17 # conversion and maintenance scripts all share a
18 # common setup of including lots of classes and
19 # setting up a few globals.
20 #
21
22 $fname = 'Setup.php';
23 wfProfileIn( $fname );
24
25 // Check to see if we are at the file scope
26 if ( !isset( $wgVersion ) ) {
27 echo "Error, Setup.php must be included from the file scope, after DefaultSettings.php\n";
28 die( 1 );
29 }
30
31 require_once( "$IP/includes/AutoLoader.php" );
32
33 wfProfileIn( $fname.'-exception' );
34 require_once( "$IP/includes/Exception.php" );
35 wfInstallExceptionHandler();
36 wfProfileOut( $fname.'-exception' );
37
38 wfProfileIn( $fname.'-includes' );
39
40 require_once( "$IP/includes/GlobalFunctions.php" );
41 require_once( "$IP/includes/Hooks.php" );
42 require_once( "$IP/includes/Namespace.php" );
43 require_once( "$IP/includes/User.php" );
44 require_once( "$IP/includes/OutputPage.php" );
45 require_once( "$IP/includes/MessageCache.php" );
46 require_once( "$IP/includes/Parser.php" );
47 require_once( "$IP/includes/LoadBalancer.php" );
48 require_once( "$IP/includes/IP.php" );
49 require_once( "$IP/includes/ProxyTools.php" );
50 require_once( "$IP/includes/ObjectCache.php" );
51 require_once( "$IP/includes/ImageFunctions.php" );
52
53 if ( $wgUseDynamicDates ) {
54 require_once( "$IP/includes/DateFormatter.php" );
55 }
56
57 wfProfileOut( $fname.'-includes' );
58 wfProfileIn( $fname.'-misc1' );
59
60 $wgIP = false; # Load on demand
61 $wgRequest = new WebRequest();
62 if ( function_exists( 'posix_uname' ) ) {
63 $wguname = posix_uname();
64 $wgNodeName = $wguname['nodename'];
65 } else {
66 $wgNodeName = '';
67 }
68
69 # Useful debug output
70 if ( $wgCommandLineMode ) {
71 # wfDebug( '"' . implode( '" "', $argv ) . '"' );
72 } elseif ( function_exists( 'getallheaders' ) ) {
73 wfDebug( "\n\nStart request\n" );
74 wfDebug( $_SERVER['REQUEST_METHOD'] . ' ' . $_SERVER['REQUEST_URI'] . "\n" );
75 $headers = getallheaders();
76 foreach ($headers as $name => $value) {
77 wfDebug( "$name: $value\n" );
78 }
79 wfDebug( "\n" );
80 } elseif( isset( $_SERVER['REQUEST_URI'] ) ) {
81 wfDebug( $_SERVER['REQUEST_METHOD'] . ' ' . $_SERVER['REQUEST_URI'] . "\n" );
82 }
83
84 if ( $wgSkipSkin ) {
85 $wgSkipSkins[] = $wgSkipSkin;
86 }
87
88 $wgUseEnotif = $wgEnotifUserTalk || $wgEnotifWatchlist;
89
90 wfProfileOut( $fname.'-misc1' );
91 wfProfileIn( $fname.'-memcached' );
92
93 $wgMemc =& wfGetMainCache();
94 $messageMemc =& wfGetMessageCacheStorage();
95 $parserMemc =& wfGetParserCacheStorage();
96
97 wfDebug( 'Main cache: ' . get_class( $wgMemc ) .
98 "\nMessage cache: " . get_class( $messageMemc ) .
99 "\nParser cache: " . get_class( $parserMemc ) . "\n" );
100
101 wfProfileOut( $fname.'-memcached' );
102 wfProfileIn( $fname.'-SetupSession' );
103
104 if ( $wgDBprefix ) {
105 $wgCookiePrefix = $wgDBname . '_' . $wgDBprefix;
106 } elseif ( $wgSharedDB ) {
107 $wgCookiePrefix = $wgSharedDB;
108 } else {
109 $wgCookiePrefix = $wgDBname;
110 }
111
112 # If session.auto_start is there, we can't touch session name
113 #
114 if( !ini_get( 'session.auto_start' ) )
115 session_name( $wgSessionName ? $wgSessionName : $wgCookiePrefix . '_session' );
116
117 if( !$wgCommandLineMode && ( isset( $_COOKIE[session_name()] ) || isset( $_COOKIE[$wgCookiePrefix.'Token'] ) ) ) {
118 wfIncrStats( 'request_with_session' );
119 User::SetupSession();
120 $wgSessionStarted = true;
121 } else {
122 wfIncrStats( 'request_without_session' );
123 $wgSessionStarted = false;
124 }
125
126 wfProfileOut( $fname.'-SetupSession' );
127 wfProfileIn( $fname.'-database' );
128
129 if ( !$wgDBservers ) {
130 $wgDBservers = array(array(
131 'host' => $wgDBserver,
132 'user' => $wgDBuser,
133 'password' => $wgDBpassword,
134 'dbname' => $wgDBname,
135 'type' => $wgDBtype,
136 'load' => 1,
137 'flags' => ($wgDebugDumpSql ? DBO_DEBUG : 0) | DBO_DEFAULT
138 ));
139 }
140 $wgLoadBalancer = LoadBalancer::newFromParams( $wgDBservers, false, $wgMasterWaitTimeout );
141 $wgLoadBalancer->loadMasterPos();
142
143 wfProfileOut( $fname.'-database' );
144 wfProfileIn( $fname.'-language1' );
145
146 require_once( "$IP/languages/Language.php" );
147
148 function setupLangObj($langclass) {
149 global $IP;
150
151 if( ! class_exists( $langclass ) ) {
152 # Default to English/UTF-8
153 $baseclass = 'LanguageUtf8';
154 require_once( "$IP/languages/$baseclass.php" );
155 $lc = strtolower(substr($langclass, 8));
156 $snip = "
157 class $langclass extends $baseclass {
158 function getVariants() {
159 return array(\"$lc\");
160 }
161
162 }";
163 eval($snip);
164 }
165
166 $lang = new $langclass();
167
168 return $lang;
169 }
170
171 # $wgLanguageCode may be changed later to fit with user preference.
172 # The content language will remain fixed as per the configuration,
173 # so let's keep it.
174 $wgContLanguageCode = $wgLanguageCode;
175 $wgContLangClass = 'Language' . str_replace( '-', '_', ucfirst( $wgContLanguageCode ) );
176
177 $wgContLang = setupLangObj( $wgContLangClass );
178 $wgContLang->initEncoding();
179
180 wfProfileOut( $fname.'-language1' );
181 wfProfileIn( $fname.'-User' );
182
183 # Skin setup functions
184 # Entries can be added to this variable during the inclusion
185 # of the extension file. Skins can then perform any necessary initialisation.
186 #
187 foreach ( $wgSkinExtensionFunctions as $func ) {
188 call_user_func( $func );
189 }
190
191 if( !is_object( $wgAuth ) ) {
192 require_once( 'AuthPlugin.php' );
193 $wgAuth = new AuthPlugin();
194 }
195
196 if( $wgCommandLineMode ) {
197 # Used for some maintenance scripts; user session cookies can screw things up
198 # when the database is in an in-between state.
199 $wgUser = new User();
200 # Prevent loading User settings from the DB.
201 $wgUser->setLoaded( true );
202 } else {
203 $wgUser = null;
204 wfRunHooks('AutoAuthenticate',array(&$wgUser));
205 if ($wgUser === null) {
206 $wgUser = User::loadFromSession();
207 }
208 }
209
210 wfProfileOut( $fname.'-User' );
211 wfProfileIn( $fname.'-language2' );
212
213 // wgLanguageCode now specifically means the UI language
214 $wgLanguageCode = $wgRequest->getText('uselang', '');
215 if ($wgLanguageCode == '')
216 $wgLanguageCode = $wgUser->getOption('language');
217 # Validate $wgLanguageCode, which will soon be sent to an eval()
218 if( empty( $wgLanguageCode ) || !preg_match( '/^[a-z]+(-[a-z]+)?$/', $wgLanguageCode ) ) {
219 $wgLanguageCode = $wgContLanguageCode;
220 }
221
222 $wgLangClass = 'Language'. str_replace( '-', '_', ucfirst( $wgLanguageCode ) );
223
224 if( $wgLangClass == $wgContLangClass ) {
225 $wgLang = &$wgContLang;
226 } else {
227 wfSuppressWarnings();
228 // Preload base classes to work around APC/PHP5 bug
229 include_once("$IP/languages/$wgLangClass.deps.php");
230 include_once("$IP/languages/$wgLangClass.php");
231 wfRestoreWarnings();
232
233 $wgLang = setupLangObj( $wgLangClass );
234 }
235
236 wfProfileOut( $fname.'-language2' );
237 wfProfileIn( $fname.'-MessageCache' );
238
239 $wgMessageCache = new MessageCache( $parserMemc, $wgUseDatabaseMessages, $wgMsgCacheExpiry, $wgDBname);
240
241 wfProfileOut( $fname.'-MessageCache' );
242
243 #
244 # I guess the warning about UI switching might still apply...
245 #
246 # FIXME: THE ABOVE MIGHT BREAK NAMESPACES, VARIABLES,
247 # SEARCH INDEX UPDATES, AND MANY MANY THINGS.
248 # DO NOT USE THIS MODE EXCEPT FOR TESTING RIGHT NOW.
249 #
250 # To disable it, the easiest thing could be to uncomment the
251 # following; they should effectively disable the UI switch functionality
252 #
253 # $wgLangClass = $wgContLangClass;
254 # $wgLanguageCode = $wgContLanguageCode;
255 # $wgLang = $wgContLang;
256 #
257 # TODO: Need to change reference to $wgLang to $wgContLang at proper
258 # places, including namespaces, dates in signatures, magic words,
259 # and links
260 #
261 # TODO: Need to look at the issue of input/output encoding
262 #
263
264
265 wfProfileIn( $fname.'-OutputPage' );
266
267 $wgOut = new OutputPage();
268
269 wfProfileOut( $fname.'-OutputPage' );
270 wfProfileIn( $fname.'-misc2' );
271
272 $wgDeferredUpdateList = array();
273 $wgPostCommitUpdateList = array();
274
275 $wgParser = new Parser();
276
277 $wgOut->setParserOptions( ParserOptions::newFromUser( $wgUser ) );
278 $wgMsgParserOptions = ParserOptions::newFromUser($wgUser);
279 wfSeedRandom();
280
281 # Placeholders in case of DB error
282 $wgTitle = Title::makeTitle( NS_SPECIAL, 'Error' );
283 $wgArticle = new Article($wgTitle);
284
285 wfProfileOut( $fname.'-misc2' );
286 wfProfileIn( $fname.'-extensions' );
287
288 # Extension setup functions for extensions other than skins
289 # Entries should be added to this variable during the inclusion
290 # of the extension file. This allows the extension to perform
291 # any necessary initialisation in the fully initialised environment
292 foreach ( $wgExtensionFunctions as $func ) {
293 call_user_func( $func );
294 }
295
296 // For compatibility
297 wfRunHooks( 'LogPageValidTypes', array( &$wgLogTypes ) );
298 wfRunHooks( 'LogPageLogName', array( &$wgLogNames ) );
299 wfRunHooks( 'LogPageLogHeader', array( &$wgLogHeaders ) );
300 wfRunHooks( 'LogPageActionText', array( &$wgLogActions ) );
301
302
303 wfDebug( "\n" );
304 $wgFullyInitialised = true;
305 wfProfileOut( $fname.'-extensions' );
306 wfProfileOut( $fname );
307
308 ?>