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