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