Split files and classes in different packages for phpdocumentor. I probably changed...
[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 = getenv('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, $wgOut, $wgTitle;
78 global $wgArticle, $wgDeferredUpdateList, $wgLinkCache;
79 global $wgMemc, $wgMagicWords, $wgMwRedir, $wgDebugLogFile;
80 global $wgMessageCache, $wgUseMemCached, $wgUseDatabaseMessages;
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.'-language' );
202 require_once( 'languages/Language.php' );
203
204 $wgMessageCache = new MessageCache;
205
206 $wgLangClass = 'Language' . ucfirst( $wgLanguageCode );
207 if( ! class_exists( $wgLangClass ) || ($wgLanguageCode == 'en' && !$wgUseLatin1) ) {
208 # Default to English/UTF-8
209 require_once( 'languages/LanguageUtf8.php' );
210 $wgLangClass = 'LanguageUtf8';
211 }
212
213 $wgLang = new $wgLangClass();
214 if ( !is_object($wgLang) ) {
215 print "No language class ($wgLang)\N";
216 }
217
218 if( $wgUseLatin1 && $wgLanguageCode != 'en' ) {
219 # For non-UTF-8 non-English.
220 require_once( 'languages/LanguageLatin1.php' );
221 $xxx = new LanguageLatin1( $wgLang );
222 unset( $wgLang );
223 $wgLang = $xxx;
224 }
225 wfProfileOut( $fname.'-language' );
226 wfProfileIn( $fname.'-MessageCache' );
227
228 $wgMessageCache->initialise( $messageMemc, $wgUseDatabaseMessages, $wgMsgCacheExpiry, $wgDBname );
229
230 wfProfileOut( $fname.'-MessageCache' );
231 wfProfileIn( $fname.'-OutputPage' );
232
233 $wgOut = new OutputPage();
234 wfDebug( "\n\n" );
235
236 wfProfileOut( $fname.'-OutputPage' );
237 wfProfileIn( $fname.'-DateFormatter' );
238
239 if ( $wgUseDynamicDates ) {
240 require_once( 'DateFormatter.php' );
241 global $wgDateFormatter;
242 $wgDateFormatter = new DateFormatter;
243 }
244
245 wfProfileOut( $fname.'-DateFormatter' );
246 wfProfileIn( $fname.'-BlockCache' );
247
248 $wgBlockCache = new BlockCache( true );
249
250 wfProfileOut( $fname.'-BlockCache' );
251 wfProfileIn( $fname.'-User' );
252
253 # Extension setup functions
254 # Entries should be added to this variable during the inclusion
255 # of the extension file. This allows the extension to perform
256 # any necessary initialisation in the fully initialised environment
257 foreach ( $wgSkinExtensionFunctions as $func ) {
258 $func();
259 }
260
261 if( $wgCommandLineMode ) {
262 # Used for some maintenance scripts; user session cookies can screw things up
263 # when the database is in an in-between state.
264 $wgUser = new User();
265 } else {
266 $wgUser = User::loadFromSession();
267 }
268
269 wfProfileOut( $fname.'-User' );
270 wfProfileIn( $fname.'-misc2' );
271
272 $wgDeferredUpdateList = array();
273 $wgLinkCache = new LinkCache();
274 $wgMagicWords = array();
275 $wgMwRedir =& MagicWord::get( MAG_REDIRECT );
276 $wgParserCache = new ParserCache();
277 $wgParser = new Parser();
278 $wgOut->setParserOptions( ParserOptions::newFromUser( $wgUser ) );
279 $wgDBConnections = array();
280 wfSeedRandom();
281
282 # Placeholders in case of DB error
283 $wgTitle = Title::newFromText( wfMsg( 'badtitle' ) );
284 $wgArticle = new Article($wgTitle);
285
286 wfProfileOut( $fname.'-misc2' );
287 wfProfileIn( $fname.'-extensions' );
288
289 # Extension setup functions
290 # Entries should be added to this variable during the inclusion
291 # of the extension file. This allows the extension to perform
292 # any necessary initialisation in the fully initialised environment
293 foreach ( $wgExtensionFunctions as $func ) {
294 $func();
295 }
296
297 $wgFullyInitialised = true;
298 wfProfileOut( $fname.'-extensions' );
299 wfProfileOut( $fname );
300
301 }
302 ?>