* Yummie ? : syntax.
[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 global $wgProfiling, $wgProfileSampleRate, $wgIP, $IP;
20
21 if( !isset( $wgProfiling ) )
22 $wgProfiling = false;
23
24 if ( $wgProfiling and (0 == rand() % $wgProfileSampleRate ) ) {
25 require_once( 'Profiling.php' );
26 } else {
27 function wfProfileIn( $fn = '' ) {
28 global $hackwhere, $wgDBname;
29 $hackwhere[] = $fn;
30 if (function_exists("setproctitle"))
31 setproctitle($fn . " [$wgDBname]");
32 }
33 function wfProfileOut( $fn = '' ) {
34 global $hackwhere, $wgDBname;
35 if (count($hackwhere))
36 array_pop($hackwhere);
37 if (function_exists("setproctitle") && count($hackwhere))
38 setproctitle($hackwhere[count($hackwhere)-1] . " [$wgDBname]");
39 }
40 function wfGetProfilingOutput( $s, $e ) {}
41 function wfProfileClose() {}
42 }
43
44 $fname = 'Setup.php';
45 wfProfileIn( $fname );
46 global $wgUseDynamicDates;
47 wfProfileIn( $fname.'-includes' );
48
49 require_once( 'GlobalFunctions.php' );
50 require_once( 'Hooks.php' );
51 require_once( 'Namespace.php' );
52 require_once( 'RecentChange.php' );
53 require_once( 'User.php' );
54 require_once( 'Skin.php' );
55 require_once( 'OutputPage.php' );
56 require_once( 'LinkCache.php' );
57 require_once( 'Title.php' );
58 require_once( 'Article.php' );
59 require_once( 'MagicWord.php' );
60 require_once( 'Block.php' );
61 require_once( 'MessageCache.php' );
62 require_once( 'BlockCache.php' );
63 require_once( 'Parser.php' );
64 require_once( 'Parser.php' );
65 require_once( 'ParserCache.php' );
66 require_once( 'WebRequest.php' );
67 require_once( 'LoadBalancer.php' );
68 require_once( 'HistoryBlob.php' );
69 require_once( 'ProxyTools.php' );
70
71 wfProfileOut( $fname.'-includes' );
72 wfProfileIn( $fname.'-misc1' );
73 global $wgUser, $wgLang, $wgContLang, $wgOut, $wgTitle;
74 global $wgLangClass, $wgContLangClass;
75 global $wgArticle, $wgDeferredUpdateList, $wgLinkCache;
76 global $wgMemc, $wgMagicWords, $wgMwRedir, $wgDebugLogFile;
77 global $wgMessageCache, $wgUseMemCached, $wgUseDatabaseMessages;
78 global $wgMsgCacheExpiry, $wgCommandLineMode;
79 global $wgBlockCache, $wgParserCache, $wgParser, $wgMsgParserOptions;
80 global $wgLoadBalancer, $wgDBservers, $wgDebugDumpSql;
81 global $wgDBserver, $wgDBuser, $wgDBpassword, $wgDBname, $wgDBtype;
82 global $wgUseOldExistenceCheck, $wgEnablePersistentLC, $wgMasterWaitTimeout;
83
84 global $wgFullyInitialised;
85
86 $wgIP = wfGetIP();
87 $wgRequest = new WebRequest();
88
89 # Useful debug output
90 if ( $wgCommandLineMode ) {
91 # wfDebug( '"' . implode( '" "', $argv ) . '"' );
92 } elseif ( function_exists( 'getallheaders' ) ) {
93 wfDebug( "\nStart request\n" );
94 wfDebug( $_SERVER['REQUEST_METHOD'] . ' ' . $_SERVER['REQUEST_URI'] . "\n" );
95 $headers = getallheaders();
96 foreach ($headers as $name => $value) {
97 wfDebug( "$name: $value\n" );
98 }
99 wfDebug( "\n" );
100 } elseif( isset( $_SERVER['REQUEST_URI'] ) ) {
101 wfDebug( $_SERVER['REQUEST_METHOD'] . ' ' . $_SERVER['REQUEST_URI'] . "\n" );
102 }
103
104 # Disable linkscc except if the old existence check method is enabled
105 if (!$wgUseOldExistenceCheck) {
106 $wgEnablePersistentLC = false;
107 }
108
109 wfProfileOut( $fname.'-misc1' );
110 wfProfileIn( $fname.'-memcached' );
111
112 # FakeMemCachedClient imitates the API of memcached-client v. 0.1.2.
113 # It acts as a memcached server with no RAM, that is, all objects are
114 # cleared the moment they are set. All set operations succeed and all
115 # get operations return null.
116
117 if( $wgUseMemCached ) {
118 # Set up Memcached
119 #
120 require_once( 'memcached-client.php' );
121
122 /**
123 *
124 * @package MediaWiki
125 */
126 class MemCachedClientforWiki extends memcached {
127 function _debugprint( $text ) {
128 wfDebug( "memcached: $text\n" );
129 }
130 }
131
132 $wgMemc = new MemCachedClientforWiki( array('persistant' => true, 'compress_threshold' => 1500 ) );
133 $wgMemc->set_servers( $wgMemCachedServers );
134 $wgMemc->set_debug( $wgMemCachedDebug );
135
136 $messageMemc = &$wgMemc;
137 } elseif ( $wgUseTurckShm ) {
138 # Turck shared memory
139 #
140 require_once( 'ObjectCache.php' );
141 $wgMemc = new TurckBagOStuff;
142 $messageMemc = &$wgMemc;
143 } elseif ( $wgUseEAccelShm ) {
144 # eAccelerator shared memory
145 #
146 require_once( 'ObjectCache.php' );
147 $wgMemc = new eAccelBagOStuff;
148 $messageMemc = &$wgMemc;
149 } else {
150 /**
151 * No shared memory
152 * @package MediaWiki
153 */
154 class FakeMemCachedClient {
155 function add ($key, $val, $exp = 0) { return true; }
156 function decr ($key, $amt=1) { return null; }
157 function delete ($key, $time = 0) { return false; }
158 function disconnect_all () { }
159 function enable_compress ($enable) { }
160 function forget_dead_hosts () { }
161 function get ($key) { return null; }
162 function get_multi ($keys) { return array_pad(array(), count($keys), null); }
163 function incr ($key, $amt=1) { return null; }
164 function replace ($key, $value, $exp=0) { return false; }
165 function run_command ($sock, $cmd) { return null; }
166 function set ($key, $value, $exp=0){ return true; }
167 function set_compress_threshold ($thresh){ }
168 function set_debug ($dbg) { }
169 function set_servers ($list) { }
170 }
171 $wgMemc = new FakeMemCachedClient();
172
173 # Give the message cache a separate cache in the DB.
174 # This is a speedup over separately querying every message used
175 require_once( 'ObjectCache.php' );
176 $messageMemc = new MediaWikiBagOStuff('objectcache');
177 }
178
179 wfProfileOut( $fname.'-memcached' );
180 wfProfileIn( $fname.'-SetupSession' );
181
182 if( !$wgCommandLineMode && ( isset( $_COOKIE[ini_get('session.name')] ) || isset( $_COOKIE[$wgDBname.'Token'] ) ) ) {
183 User::SetupSession();
184 $wgSessionStarted = true;
185 } else {
186 $wgSessionStarted = false;
187 }
188
189 wfProfileOut( $fname.'-SetupSession' );
190 wfProfileIn( $fname.'-database' );
191
192 if ( !$wgDBservers ) {
193 $wgDBservers = array(array(
194 'host' => $wgDBserver,
195 'user' => $wgDBuser,
196 'password' => $wgDBpassword,
197 'dbname' => $wgDBname,
198 'type' => $wgDBtype,
199 'load' => 1,
200 'flags' => ($wgDebugDumpSql ? DBO_DEBUG : 0) | DBO_DEFAULT
201 ));
202 }
203 $wgLoadBalancer = LoadBalancer::newFromParams( $wgDBservers, false, $wgMasterWaitTimeout );
204 $wgLoadBalancer->loadMasterPos();
205
206 wfProfileOut( $fname.'-database' );
207 wfProfileIn( $fname.'-language1' );
208
209 require_once( "$IP/languages/Language.php" );
210
211 wfProfileOut( $fname.'-language1' );
212 wfProfileIn( $fname.'-User' );
213
214 # Skin setup functions
215 # Entries can be added to this variable during the inclusion
216 # of the extension file. Skins can then perform any necessary initialisation.
217 foreach ( $wgSkinExtensionFunctions as $func ) {
218 $func();
219 }
220
221 if( !is_object( $wgAuth ) ) {
222 require_once( 'AuthPlugin.php' );
223 $wgAuth = new AuthPlugin();
224 }
225
226 if( $wgCommandLineMode ) {
227 # Used for some maintenance scripts; user session cookies can screw things up
228 # when the database is in an in-between state.
229 $wgUser = new User();
230 # Prevent loading User settings from the DB.
231 $wgUser->setLoaded( true );
232 } else {
233 $wgUser = User::loadFromSession();
234 }
235
236 wfProfileOut( $fname.'-User' );
237 wfProfileIn( $fname.'-language2' );
238
239 function setupLangObj(&$langclass) {
240 global $IP;
241
242 if( ! class_exists( $langclass ) ) {
243 # Default to English/UTF-8
244 $baseclass = 'LanguageUtf8';
245 require_once( "$IP/languages/$baseclass.php" );
246 $lc = strtolower(substr($langclass, 8));
247 $snip = "
248 class $langclass extends $baseclass {
249 function getVariants() {
250 return array(\"$lc\");
251 }
252
253 }";
254 eval($snip);
255 }
256
257 $lang = new $langclass();
258
259 return $lang;
260 }
261
262 # $wgLanguageCode may be changed later to fit with user preference.
263 # The content language will remain fixed as per the configuration,
264 # so let's keep it.
265 $wgContLanguageCode = $wgLanguageCode;
266 $wgContLangClass = 'Language' . str_replace( '-', '_', ucfirst( $wgContLanguageCode ) );
267
268 $wgContLang = setupLangObj( $wgContLangClass );
269 $wgContLang->initEncoding();
270
271 // set default user option from content language
272 if( !$wgUser->mDataLoaded ) {
273 $wgUser->loadDefaultFromLanguage();
274 }
275
276 // wgLanguageCode now specifically means the UI language
277 $wgLanguageCode = $wgUser->getOption('language');
278 # Validate $wgLanguageCode, which will soon be sent to an eval()
279 if( empty( $wgLanguageCode ) || !preg_match( '/^[a-z\-]*$/', $wgLanguageCode ) ) {
280 $wgLanguageCode = $wgContLanguageCode;
281 }
282
283 $wgLangClass = 'Language'. str_replace( '-', '_', ucfirst( $wgLanguageCode ) );
284
285 if( $wgLangClass == $wgContLangClass ) {
286 $wgLang = &$wgContLang;
287 } else {
288 wfSuppressWarnings();
289 include_once("$IP/languages/$wgLangClass.php");
290 wfRestoreWarnings();
291
292 $wgLang = setupLangObj( $wgLangClass );
293 }
294
295 wfProfileOut( $fname.'-language' );
296 wfProfileIn( $fname.'-MessageCache' );
297
298 $wgMessageCache = new MessageCache;
299 $wgMessageCache->initialise( $messageMemc, $wgUseDatabaseMessages, $wgMsgCacheExpiry, $wgDBname);
300
301 wfProfileOut( $fname.'-MessageCache' );
302
303 #
304 # I guess the warning about UI switching might still apply...
305 #
306 # FIXME: THE ABOVE MIGHT BREAK NAMESPACES, VARIABLES,
307 # SEARCH INDEX UPDATES, AND MANY MANY THINGS.
308 # DO NOT USE THIS MODE EXCEPT FOR TESTING RIGHT NOW.
309 #
310 # To disable it, the easiest thing could be to uncomment the
311 # following; they should effectively disable the UI switch functionality
312 #
313 # $wgLangClass = $wgContLangClass;
314 # $wgLanguageCode = $wgContLanguageCode;
315 # $wgLang = $wgContLang;
316 #
317 # TODO: Need to change reference to $wgLang to $wgContLang at proper
318 # places, including namespaces, dates in signatures, magic words,
319 # and links
320 #
321 # TODO: Need to look at the issue of input/output encoding
322 #
323
324
325 wfProfileIn( $fname.'-OutputPage' );
326
327 $wgOut = new OutputPage();
328 wfDebug( "\n\n" );
329
330 wfProfileOut( $fname.'-OutputPage' );
331 wfProfileIn( $fname.'-DateFormatter' );
332
333 if ( $wgUseDynamicDates ) {
334 require_once( 'DateFormatter.php' );
335 global $wgDateFormatter;
336 $wgDateFormatter = new DateFormatter;
337 }
338
339 wfProfileOut( $fname.'-DateFormatter' );
340 wfProfileIn( $fname.'-BlockCache' );
341
342 $wgBlockCache = new BlockCache( true );
343
344 wfProfileOut( $fname.'-BlockCache' );
345 wfProfileIn( $fname.'-misc2' );
346
347 $wgDeferredUpdateList = array();
348 $wgPostCommitUpdateList = array();
349
350 $wgLinkCache = new LinkCache();
351 $wgMagicWords = array();
352 $wgMwRedir =& MagicWord::get( MAG_REDIRECT );
353 $wgParserCache = new ParserCache( $messageMemc );
354
355 if ( $wgUseXMLparser ) {
356 require_once( 'ParserXML.php' );
357 $wgParser = new ParserXML();
358 } else {
359 $wgParser = new Parser();
360 }
361 $wgOut->setParserOptions( ParserOptions::newFromUser( $wgUser ) );
362 $wgMsgParserOptions = ParserOptions::newFromUser($wgUser);
363 wfSeedRandom();
364
365 # Placeholders in case of DB error
366 $wgTitle = Title::makeTitle( NS_SPECIAL, 'Error' );
367 $wgArticle = new Article($wgTitle);
368
369 wfProfileOut( $fname.'-misc2' );
370 wfProfileIn( $fname.'-extensions' );
371
372 # Extension setup functions for extensions other than skins
373 # Entries should be added to this variable during the inclusion
374 # of the extension file. This allows the extension to perform
375 # any necessary initialisation in the fully initialised environment
376 foreach ( $wgExtensionFunctions as $func ) {
377 $func();
378 }
379
380 $wgFullyInitialised = true;
381 wfProfileOut( $fname.'-extensions' );
382 wfProfileOut( $fname );
383
384 }
385 ?>