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