made some more wfMsg() to wfMsgForContent changes
[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 } else {
44 $wgIP = $_SERVER['REMOTE_ADDR'];
45 }
46
47
48 $fname = 'Setup.php';
49 wfProfileIn( $fname );
50 global $wgUseDynamicDates;
51 wfProfileIn( $fname.'-includes' );
52
53 require_once( 'GlobalFunctions.php' );
54 require_once( 'Namespace.php' );
55 require_once( 'RecentChange.php' );
56 require_once( 'User.php' );
57 require_once( 'Skin.php' );
58 require_once( 'OutputPage.php' );
59 require_once( 'LinkCache.php' );
60 require_once( 'Title.php' );
61 require_once( 'Article.php' );
62 require_once( 'MagicWord.php' );
63 require_once( 'Block.php' );
64 require_once( 'MessageCache.php' );
65 require_once( 'BlockCache.php' );
66 require_once( 'Parser.php' );
67 require_once( 'ParserCache.php' );
68 require_once( 'WebRequest.php' );
69 require_once( 'LoadBalancer.php' );
70
71 $wgRequest = new WebRequest();
72
73
74
75 wfProfileOut( $fname.'-includes' );
76 wfProfileIn( $fname.'-misc1' );
77 global $wgUser, $wgLang, $wgContLang, $wgOut, $wgTitle;
78 global $wgArticle, $wgDeferredUpdateList, $wgLinkCache;
79 global $wgMemc, $wgMagicWords, $wgMwRedir, $wgDebugLogFile;
80 global $wgMessageCache, $wgUseMemCached, $wgUseDatabaseMessages, $wgContMessageCach;
81 global $wgMsgCacheExpiry, $wgCommandLineMode;
82 global $wgBlockCache, $wgParserCache, $wgParser, $wgDBConnections;
83 global $wgLoadBalancer, $wgDBservers, $wgDebugDumpSql;
84 global $wgDBserver, $wgDBuser, $wgDBpassword, $wgDBname, $wgDBtype;
85 global $wgUseOldExistenceCheck, $wgEnablePersistentLC;
86
87 global $wgFullyInitialised;
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 } else {
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) );
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 } else {
144 /**
145 * No shared memory
146 * @package MediaWiki
147 */
148 class FakeMemCachedClient {
149 function add ($key, $val, $exp = 0) { return true; }
150 function decr ($key, $amt=1) { return null; }
151 function delete ($key, $time = 0) { return false; }
152 function disconnect_all () { }
153 function enable_compress ($enable) { }
154 function forget_dead_hosts () { }
155 function get ($key) { return null; }
156 function get_multi ($keys) { return array_pad(array(), count($keys), null); }
157 function incr ($key, $amt=1) { return null; }
158 function replace ($key, $value, $exp=0) { return false; }
159 function run_command ($sock, $cmd) { return null; }
160 function set ($key, $value, $exp=0){ return true; }
161 function set_compress_threshold ($thresh){ }
162 function set_debug ($dbg) { }
163 function set_servers ($list) { }
164 }
165 $wgMemc = new FakeMemCachedClient();
166
167 # Give the message cache a separate cache in the DB.
168 # This is a speedup over separately querying every message used
169 require_once( 'ObjectCache.php' );
170 $messageMemc = new MediaWikiBagOStuff('objectcache');
171 }
172
173 wfProfileOut( $fname.'-memcached' );
174 wfProfileIn( $fname.'-SetupSession' );
175
176 if( !$wgCommandLineMode && ( isset( $_COOKIE[ini_get('session.name')] ) || isset( $_COOKIE[$wgDBname.'Password'] ) ) ) {
177 User::SetupSession();
178 $wgSessionStarted = true;
179 } else {
180 $wgSessionStarted = false;
181 }
182
183 wfProfileOut( $fname.'-SetupSession' );
184 wfProfileIn( $fname.'-database' );
185
186 if ( !$wgDBservers ) {
187 $wgDBservers = array(array(
188 'host' => $wgDBserver,
189 'user' => $wgDBuser,
190 'password' => $wgDBpassword,
191 'dbname' => $wgDBname,
192 'type' => $wgDBtype,
193 'load' => 1,
194 'flags' => ($wgDebugDumpSql ? DBO_DEBUG : 0) | DBO_DEFAULT
195 ));
196 }
197 $wgLoadBalancer = LoadBalancer::newFromParams( $wgDBservers );
198 $wgLoadBalancer->loadMasterPos();
199
200 wfProfileOut( $fname.'-database' );
201 wfProfileIn( $fname.'-User' );
202
203 # Extension setup functions
204 # Entries should be added to this variable during the inclusion
205 # of the extension file. This allows the extension to perform
206 # any necessary initialisation in the fully initialised environment
207 foreach ( $wgSkinExtensionFunctions as $func ) {
208 $func();
209 }
210
211 if( $wgCommandLineMode ) {
212 # Used for some maintenance scripts; user session cookies can screw things up
213 # when the database is in an in-between state.
214 $wgUser = new User();
215 } else {
216 $wgUser = User::loadFromSession();
217 }
218
219 // FIXME : we don't know what the user entered (see SpecialPreferences.php [AV])
220 if( count( $wgUserLanguages ) &&
221 !empty( $wgUser->mOptions['language'] ) &&
222 in_array( $wgUser->mOptions['language'], $wgUserLanguages ) ) {
223 // Change language of the site
224 $wgUserLanguageCode = $wgUser->mOptions['language'];
225 // we will load messages from file instead of from database
226 $wgUseDatabaseMessages = false;
227 # FIXME: THIS WILL BREAK NAMESPACES, VARIABLES,
228 # SEARCH INDEX UPDATES, AND MANY MANY THINGS.
229 # DO NOT USE THIS MODE EXCEPT FOR TESTING RIGHT NOW.
230 }
231
232 wfProfileOut( $fname.'-User' );
233 wfProfileIn( $fname.'-language' );
234
235 function setupLangObj($langclass, $langcode) {
236 global $wgUseLatin1;
237
238
239 if( ! class_exists( $langclass ) || ($langcode == 'en' && !$wgUseLatin1) ) {
240 # Default to English/UTF-8
241 require_once( 'languages/LanguageUtf8.php' );
242 $langclass = 'LanguageUtf8';
243 }
244
245 $lang = new $langclass();
246 if ( !is_object($lang) ) {
247 print "No language class ($wgLang)\N";
248 }
249
250 if( $wgUseLatin1 && $langcode != 'en' ) {
251 # For non-UTF-8 non-English.
252 require_once( 'languages/LanguageLatin1.php' );
253 $xxx = new LanguageLatin1( $lang );
254 unset( $lang );
255 $lang = $xxx;
256 }
257 return $lang;
258 }
259
260 /* TODO: change the installation script so that
261 wgContLanguageCode is set there instead of here
262 */
263 require_once( 'languages/Language.php' );
264 $wgContLanguageCode = $wgLanguageCode;
265 $wgContLangClass = 'Language' . str_replace( '-', '_', ucfirst( $wgContLanguageCode ) );
266 $wgContLang = setupLangObj(&$wgContLangClass, $wgContLangClass);
267
268 // set default user option from content language
269 if(!$wgUser->mDataLoaded) { $wgUser->loadDefaultFromLanguage(); }
270
271 // wgLanguageCode now specifically means the UI language
272 $wgLanguageCode = $wgUser->getOption('language');
273
274 $wgLangClass = 'Language'. str_replace( '-', '_', ucfirst( $wgLanguageCode ) );
275 if($wgLangClass == $wgContLangClass) {
276 $wgLang = &$wgContLang;
277 }
278 else {
279 include_once("languages/$wgLangClass.php");
280 $wgLang = setupLangObj(&$wgLangClass, $wgLanguageCode);
281 }
282
283
284 wfProfileOut( $fname.'-language' );
285 wfProfileIn( $fname.'-MessageCache' );
286
287 $wgContMessageCache = new MessageCache;
288 $wgContMessageCache->initialise( $messageMemc, $wgUseDatabaseMessages, $wgMsgCacheExpiry, $wgDBname, true );
289 if($wgLangClass == $wgContLangClass) {
290 $wgMessageCache = &$wgContMessageCache;
291 }
292 else {
293 $wgMessageCache = new MessageCache;
294 $wgMessageCache->initialise( $messageMemc,false , $wgMsgCacheExpiry, $wgDBname.":$wgLangClass", false);
295 }
296
297 wfProfileOut( $fname.'-MessageCache' );
298 wfProfileIn( $fname.'-OutputPage' );
299
300 $wgOut = new OutputPage();
301 wfDebug( "\n\n" );
302
303 wfProfileOut( $fname.'-OutputPage' );
304 wfProfileIn( $fname.'-DateFormatter' );
305
306 if ( $wgUseDynamicDates ) {
307 require_once( 'DateFormatter.php' );
308 global $wgDateFormatter;
309 $wgDateFormatter = new DateFormatter;
310 }
311
312 wfProfileOut( $fname.'-DateFormatter' );
313 wfProfileIn( $fname.'-BlockCache' );
314
315 $wgBlockCache = new BlockCache( true );
316
317 wfProfileOut( $fname.'-BlockCache' );
318 wfProfileIn( $fname.'-misc2' );
319
320 $wgDeferredUpdateList = array();
321 $wgLinkCache = new LinkCache();
322 $wgMagicWords = array();
323 $wgMwRedir =& MagicWord::get( MAG_REDIRECT );
324 $wgParserCache = new ParserCache();
325 $wgParser = new Parser();
326 $wgOut->setParserOptions( ParserOptions::newFromUser( $wgUser ) );
327 $wgDBConnections = array();
328 wfSeedRandom();
329
330 # Placeholders in case of DB error
331 $wgTitle = Title::newFromText( wfMsgForContent( 'badtitle' ) );
332 $wgArticle = new Article($wgTitle);
333
334 wfProfileOut( $fname.'-misc2' );
335 wfProfileIn( $fname.'-extensions' );
336
337 # Extension setup functions
338 # Entries should be added to this variable during the inclusion
339 # of the extension file. This allows the extension to perform
340 # any necessary initialisation in the fully initialised environment
341 foreach ( $wgExtensionFunctions as $func ) {
342 $func();
343 }
344
345 $wgFullyInitialised = true;
346 wfProfileOut( $fname.'-extensions' );
347 wfProfileOut( $fname );
348
349 }
350 ?>