Changed installation code so that wgContLanguageCode is set, replacing wgLanguageCode.
[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
51 $fname = 'Setup.php';
52 wfProfileIn( $fname );
53 global $wgUseDynamicDates;
54 wfProfileIn( $fname.'-includes' );
55
56 require_once( 'GlobalFunctions.php' );
57 require_once( 'Namespace.php' );
58 require_once( 'RecentChange.php' );
59 require_once( 'User.php' );
60 require_once( 'Skin.php' );
61 require_once( 'OutputPage.php' );
62 require_once( 'LinkCache.php' );
63 require_once( 'Title.php' );
64 require_once( 'Article.php' );
65 require_once( 'MagicWord.php' );
66 require_once( 'Block.php' );
67 require_once( 'MessageCache.php' );
68 require_once( 'BlockCache.php' );
69 require_once( 'Parser.php' );
70 require_once( 'ParserCache.php' );
71 require_once( 'WebRequest.php' );
72 require_once( 'LoadBalancer.php' );
73
74 $wgRequest = new WebRequest();
75
76
77
78 wfProfileOut( $fname.'-includes' );
79 wfProfileIn( $fname.'-misc1' );
80 global $wgUser, $wgLang, $wgContLang, $wgOut, $wgTitle;
81 global $wgArticle, $wgDeferredUpdateList, $wgLinkCache;
82 global $wgMemc, $wgMagicWords, $wgMwRedir, $wgDebugLogFile;
83 global $wgMessageCache, $wgUseMemCached, $wgUseDatabaseMessages, $wgContMessageCach;
84 global $wgMsgCacheExpiry, $wgCommandLineMode;
85 global $wgBlockCache, $wgParserCache, $wgParser, $wgDBConnections;
86 global $wgLoadBalancer, $wgDBservers, $wgDebugDumpSql;
87 global $wgDBserver, $wgDBuser, $wgDBpassword, $wgDBname, $wgDBtype;
88 global $wgUseOldExistenceCheck, $wgEnablePersistentLC;
89
90 global $wgFullyInitialised;
91
92 # Useful debug output
93 if ( $wgCommandLineMode ) {
94 # wfDebug( '"' . implode( '" "', $argv ) . '"' );
95 } elseif ( function_exists( 'getallheaders' ) ) {
96 wfDebug( "\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 } else {
104 wfDebug( $_SERVER['REQUEST_METHOD'] . ' ' . $_SERVER['REQUEST_URI'] . "\n" );
105 }
106
107 # Disable linkscc except if the old existence check method is enabled
108 if (!$wgUseOldExistenceCheck) {
109 $wgEnablePersistentLC = false;
110 }
111
112 wfProfileOut( $fname.'-misc1' );
113 wfProfileIn( $fname.'-memcached' );
114
115 # FakeMemCachedClient imitates the API of memcached-client v. 0.1.2.
116 # It acts as a memcached server with no RAM, that is, all objects are
117 # cleared the moment they are set. All set operations succeed and all
118 # get operations return null.
119
120 if( $wgUseMemCached ) {
121 # Set up Memcached
122 #
123 require_once( 'memcached-client.php' );
124
125 /**
126 *
127 * @package MediaWiki
128 */
129 class MemCachedClientforWiki extends memcached {
130 function _debugprint( $text ) {
131 wfDebug( "memcached: $text\n" );
132 }
133 }
134
135 $wgMemc = new MemCachedClientforWiki( array('persistant' => true) );
136 $wgMemc->set_servers( $wgMemCachedServers );
137 $wgMemc->set_debug( $wgMemCachedDebug );
138
139 $messageMemc = &$wgMemc;
140 } elseif ( $wgUseTurckShm ) {
141 # Turck shared memory
142 #
143 require_once( 'ObjectCache.php' );
144 $wgMemc = new TurckBagOStuff;
145 $messageMemc = &$wgMemc;
146 } else {
147 /**
148 * No shared memory
149 * @package MediaWiki
150 */
151 class FakeMemCachedClient {
152 function add ($key, $val, $exp = 0) { return true; }
153 function decr ($key, $amt=1) { return null; }
154 function delete ($key, $time = 0) { return false; }
155 function disconnect_all () { }
156 function enable_compress ($enable) { }
157 function forget_dead_hosts () { }
158 function get ($key) { return null; }
159 function get_multi ($keys) { return array_pad(array(), count($keys), null); }
160 function incr ($key, $amt=1) { return null; }
161 function replace ($key, $value, $exp=0) { return false; }
162 function run_command ($sock, $cmd) { return null; }
163 function set ($key, $value, $exp=0){ return true; }
164 function set_compress_threshold ($thresh){ }
165 function set_debug ($dbg) { }
166 function set_servers ($list) { }
167 }
168 $wgMemc = new FakeMemCachedClient();
169
170 # Give the message cache a separate cache in the DB.
171 # This is a speedup over separately querying every message used
172 require_once( 'ObjectCache.php' );
173 $messageMemc = new MediaWikiBagOStuff('objectcache');
174 }
175
176 wfProfileOut( $fname.'-memcached' );
177 wfProfileIn( $fname.'-SetupSession' );
178
179 if( !$wgCommandLineMode && ( isset( $_COOKIE[ini_get('session.name')] ) || isset( $_COOKIE[$wgDBname.'Password'] ) ) ) {
180 User::SetupSession();
181 $wgSessionStarted = true;
182 } else {
183 $wgSessionStarted = false;
184 }
185
186 wfProfileOut( $fname.'-SetupSession' );
187 wfProfileIn( $fname.'-database' );
188
189 if ( !$wgDBservers ) {
190 $wgDBservers = array(array(
191 'host' => $wgDBserver,
192 'user' => $wgDBuser,
193 'password' => $wgDBpassword,
194 'dbname' => $wgDBname,
195 'type' => $wgDBtype,
196 'load' => 1,
197 'flags' => ($wgDebugDumpSql ? DBO_DEBUG : 0) | DBO_DEFAULT
198 ));
199 }
200 $wgLoadBalancer = LoadBalancer::newFromParams( $wgDBservers );
201 $wgLoadBalancer->loadMasterPos();
202
203 wfProfileOut( $fname.'-database' );
204 wfProfileIn( $fname.'-User' );
205
206 # Extension setup functions
207 # Entries should be added to this variable during the inclusion
208 # of the extension file. This allows the extension to perform
209 # any necessary initialisation in the fully initialised environment
210 foreach ( $wgSkinExtensionFunctions as $func ) {
211 $func();
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 } else {
219 $wgUser = User::loadFromSession();
220 }
221
222 // FIXME : we don't know what the user entered (see SpecialPreferences.php [AV])
223 if( count( $wgUserLanguages ) &&
224 !empty( $wgUser->mOptions['language'] ) &&
225 in_array( $wgUser->mOptions['language'], $wgUserLanguages ) ) {
226 // Change language of the site
227 $wgUserLanguageCode = $wgUser->mOptions['language'];
228 // we will load messages from file instead of from database
229 $wgUseDatabaseMessages = false;
230 # FIXME: THIS WILL BREAK NAMESPACES, VARIABLES,
231 # SEARCH INDEX UPDATES, AND MANY MANY THINGS.
232 # DO NOT USE THIS MODE EXCEPT FOR TESTING RIGHT NOW.
233 }
234
235 wfProfileOut( $fname.'-User' );
236 wfProfileIn( $fname.'-language' );
237
238 function setupLangObj(&$langclass, $langcode) {
239 global $wgUseLatin1;
240
241
242 if( ! class_exists( $langclass ) || ($langcode == 'en' && !$wgUseLatin1) ) {
243 # Default to English/UTF-8
244 require_once( 'languages/LanguageUtf8.php' );
245 $langclass = 'LanguageUtf8';
246 }
247
248 $lang = new $langclass();
249 if ( !is_object($lang) ) {
250 print "No language class ($wgLang)\N";
251 }
252
253 if( $wgUseLatin1 && $langcode != 'en' ) {
254 # For non-UTF-8 non-English.
255 require_once( 'languages/LanguageLatin1.php' );
256 $xxx = new LanguageLatin1( $lang );
257 unset( $lang );
258 $lang = $xxx;
259 }
260 return $lang;
261 }
262
263 require_once( 'languages/Language.php' );
264
265 $wgContLangClass = 'Language' . str_replace( '-', '_', ucfirst( $wgContLanguageCode ) );
266
267 $wgContLang = setupLangObj($wgContLangClass, $wgContLangClass);
268 $n = get_class($wgContLang);
269
270 // set default user option from content language
271 if(!$wgUser->mDataLoaded) { $wgUser->loadDefaultFromLanguage(); }
272
273 // wgLanguageCode now specifically means the UI language
274 $wgLanguageCode = $wgUser->getOption('language');
275
276 $wgLangClass = 'Language'. str_replace( '-', '_', ucfirst( $wgLanguageCode ) );
277 if($wgLangClass == $wgContLangClass) {
278 $wgLang = &$wgContLang;
279 }
280 else {
281 include_once("languages/$wgLangClass.php");
282 $wgLang = setupLangObj($wgLangClass, $wgLanguageCode);
283 }
284
285
286 wfProfileOut( $fname.'-language' );
287 wfProfileIn( $fname.'-MessageCache' );
288
289 $wgContMessageCache = new MessageCache;
290 $wgContMessageCache->initialise( $messageMemc, $wgUseDatabaseMessages, $wgMsgCacheExpiry, $wgDBname, $wgContLang, $wgContLanguageCode );
291 if($wgLangClass == $wgContLangClass) {
292 $wgMessageCache = &$wgContMessageCache;
293 }
294 else {
295 $wgMessageCache = new MessageCache;
296 $wgMessageCache->initialise( $messageMemc,false , $wgMsgCacheExpiry, $wgDBname.":$wgLangClass", $wgLang, $wgLanguageCode);
297 }
298
299 wfProfileOut( $fname.'-MessageCache' );
300 wfProfileIn( $fname.'-OutputPage' );
301
302 $wgOut = new OutputPage();
303 wfDebug( "\n\n" );
304
305 wfProfileOut( $fname.'-OutputPage' );
306 wfProfileIn( $fname.'-DateFormatter' );
307
308 if ( $wgUseDynamicDates ) {
309 require_once( 'DateFormatter.php' );
310 global $wgDateFormatter;
311 $wgDateFormatter = new DateFormatter;
312 }
313
314 wfProfileOut( $fname.'-DateFormatter' );
315 wfProfileIn( $fname.'-BlockCache' );
316
317 $wgBlockCache = new BlockCache( true );
318
319 wfProfileOut( $fname.'-BlockCache' );
320 wfProfileIn( $fname.'-misc2' );
321
322 $wgDeferredUpdateList = array();
323 $wgLinkCache = new LinkCache();
324 $wgMagicWords = array();
325 $wgMwRedir =& MagicWord::get( MAG_REDIRECT );
326 $wgParserCache = new ParserCache();
327 $wgParser = new Parser();
328 $wgOut->setParserOptions( ParserOptions::newFromUser( $wgUser ) );
329 $wgDBConnections = array();
330 wfSeedRandom();
331
332 # Placeholders in case of DB error
333 $wgTitle = Title::newFromText( wfMsgForContent( 'badtitle' ) );
334 $wgArticle = new Article($wgTitle);
335
336 wfProfileOut( $fname.'-misc2' );
337 wfProfileIn( $fname.'-extensions' );
338
339 # Extension setup functions
340 # Entries should be added to this variable during the inclusion
341 # of the extension file. This allows the extension to perform
342 # any necessary initialisation in the fully initialised environment
343 foreach ( $wgExtensionFunctions as $func ) {
344 $func();
345 }
346
347 $wgFullyInitialised = true;
348 wfProfileOut( $fname.'-extensions' );
349 wfProfileOut( $fname );
350
351 }
352 ?>