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