Adjust some spacing
[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 ) {
260 $wgUser->loadDefaultFromLanguage();
261 }
262
263 // wgLanguageCode now specifically means the UI language
264 $wgLanguageCode = $wgUser->getOption('language');
265
266 $wgLangClass = 'Language'. str_replace( '-', '_', ucfirst( $wgLanguageCode ) );
267
268 if( $wgLangClass == $wgContLangClass ) {
269 $wgLang = &$wgContLang;
270 } else {
271 require_once("languages/$wgLangClass.php");
272 $wgLang = setupLangObj( $wgLangClass, $wgLanguageCode );
273 }
274
275
276 wfProfileOut( $fname.'-language' );
277 wfProfileIn( $fname.'-MessageCache' );
278
279 $wgMessageCache = new MessageCache;
280 $wgMessageCache->initialise( $messageMemc, $wgUseDatabaseMessages, $wgMsgCacheExpiry, $wgDBname);
281
282 wfProfileOut( $fname.'-MessageCache' );
283
284 #
285 # I guess the warning about UI switching might still apply...
286 #
287 # FIXME: THE ABOVE MIGHT BREAK NAMESPACES, VARIABLES,
288 # SEARCH INDEX UPDATES, AND MANY MANY THINGS.
289 # DO NOT USE THIS MODE EXCEPT FOR TESTING RIGHT NOW.
290 #
291 # To disable it, the easiest thing could be to uncomment the
292 # following; they should effectively disable the UI switch functionality
293 #
294 # $wgLangClass = $wgContLangClass;
295 # $wgLanguageCode = $wgContLanguageCode;
296 # $wgLang = $wgContLang;
297 #
298 # TODO: Need to change reference to $wgLang to $wgContLang at proper
299 # places, including namespaces, dates in signatures, magic words,
300 # and links
301 #
302 # TODO: Need to look at the issue of input/output encoding
303 #
304
305
306 wfProfileIn( $fname.'-OutputPage' );
307
308 $wgOut = new OutputPage();
309 wfDebug( "\n\n" );
310
311 wfProfileOut( $fname.'-OutputPage' );
312 wfProfileIn( $fname.'-DateFormatter' );
313
314 if ( $wgUseDynamicDates ) {
315 require_once( 'DateFormatter.php' );
316 global $wgDateFormatter;
317 $wgDateFormatter = new DateFormatter;
318 }
319
320 wfProfileOut( $fname.'-DateFormatter' );
321 wfProfileIn( $fname.'-BlockCache' );
322
323 $wgBlockCache = new BlockCache( true );
324
325 wfProfileOut( $fname.'-BlockCache' );
326 wfProfileIn( $fname.'-misc2' );
327
328 $wgDeferredUpdateList = array();
329 $wgLinkCache = new LinkCache();
330 $wgMagicWords = array();
331 $wgMwRedir =& MagicWord::get( MAG_REDIRECT );
332 $wgParserCache = new ParserCache();
333 $wgParser = new Parser();
334 $wgOut->setParserOptions( ParserOptions::newFromUser( $wgUser ) );
335 $wgDBConnections = array();
336 $wgMsgParserOptions = ParserOptions::newFromUser($wgUser);
337 wfSeedRandom();
338
339 # Placeholders in case of DB error
340 $wgTitle = Title::newFromText( wfMsgForContent( 'badtitle' ) );
341 $wgArticle = new Article($wgTitle);
342
343 wfProfileOut( $fname.'-misc2' );
344 wfProfileIn( $fname.'-extensions' );
345
346 # Extension setup functions
347 # Entries should be added to this variable during the inclusion
348 # of the extension file. This allows the extension to perform
349 # any necessary initialisation in the fully initialised environment
350 foreach ( $wgExtensionFunctions as $func ) {
351 $func();
352 }
353
354 $wgFullyInitialised = true;
355 wfProfileOut( $fname.'-extensions' );
356 wfProfileOut( $fname );
357
358 }
359 ?>