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