Don't include SearchEngine.php when it's not used. Saves about 180k of memory at...
[lhc/web/wiklou.git] / includes / Setup.php
1 <?php
2
3 # This file is not a valid entry point, perform no further processing unless MEDIAWIKI is defined
4 if( defined( "MEDIAWIKI" ) ) {
5
6 # The main wiki script and things like database
7 # conversion and maintenance scripts all share a
8 # common setup of including lots of classes and
9 # setting up a few globals.
10 #
11
12 global $wgProfiling, $wgProfileSampleRate, $wgIP, $wgUseSquid;
13
14 if( !isset( $wgProfiling ) )
15 $wgProfiling = false;
16
17 if ( $wgProfiling and (0 == rand() % $wgProfileSampleRate ) ) {
18 require_once( 'Profiling.php' );
19 } else {
20 function wfProfileIn( $fn = '' ) {}
21 function wfProfileOut( $fn = '' ) {}
22 function wfGetProfilingOutput( $s, $e ) {}
23 function wfProfileClose() {}
24 }
25
26 /* collect the originating ips */
27 if( $wgUseSquid && isset( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) {
28 # If the web server is behind a reverse proxy, we need to find
29 # out where our requests are really coming from.
30 $hopips = array_map( 'trim', explode( ',', $_SERVER['HTTP_X_FORWARDED_FOR'] ) );
31
32 while(in_array(trim(end($hopips)), $wgSquidServers)){
33 array_pop($hopips);
34 }
35 $wgIP = trim(end($hopips));
36 } else {
37 $wgIP = getenv('REMOTE_ADDR');
38 }
39
40
41 $fname = 'Setup.php';
42 wfProfileIn( $fname );
43 global $wgUseDynamicDates;
44 wfProfileIn( $fname.'-includes' );
45
46 require_once( 'GlobalFunctions.php' );
47 require_once( 'Namespace.php' );
48 require_once( 'RecentChange.php' );
49 require_once( 'User.php' );
50 require_once( 'Skin.php' );
51 require_once( 'OutputPage.php' );
52 require_once( 'LinkCache.php' );
53 require_once( 'Title.php' );
54 require_once( 'Article.php' );
55 require_once( 'MagicWord.php' );
56 require_once( 'memcached-client.php' );
57 require_once( 'Block.php' );
58 require_once( 'MessageCache.php' );
59 require_once( 'BlockCache.php' );
60 require_once( 'Parser.php' );
61 require_once( 'ParserCache.php' );
62 require_once( 'WebRequest.php' );
63 require_once( 'LoadBalancer.php' );
64
65 $wgRequest = new WebRequest();
66
67
68
69 wfProfileOut( $fname.'-includes' );
70 wfProfileIn( $fname.'-misc1' );
71 global $wgUser, $wgLang, $wgOut, $wgTitle;
72 global $wgArticle, $wgDeferredUpdateList, $wgLinkCache;
73 global $wgMemc, $wgMagicWords, $wgMwRedir, $wgDebugLogFile;
74 global $wgMessageCache, $wgUseMemCached, $wgUseDatabaseMessages;
75 global $wgMsgCacheExpiry, $wgCommandLineMode;
76 global $wgBlockCache, $wgParserCache, $wgParser, $wgDBConnections;
77 global $wgLoadBalancer, $wgDBservers, $wgDebugDumpSql;
78 global $wgDBserver, $wgDBuser, $wgDBpassword, $wgDBname, $wgDBtype;
79 global $wgUseOldExistenceCheck, $wgEnablePersistentLC;
80
81 global $wgFullyInitialised;
82
83 # Useful debug output
84 if ( $wgCommandLineMode ) {
85 # wfDebug( '"' . implode( '" "', $argv ) . '"' );
86 } elseif ( function_exists( 'getallheaders' ) ) {
87 wfDebug( "\nStart request\n" );
88 wfDebug( $_SERVER['REQUEST_METHOD'] . ' ' . $_SERVER['REQUEST_URI'] . "\n" );
89 $headers = getallheaders();
90 foreach ($headers as $name => $value) {
91 wfDebug( "$name: $value\n" );
92 }
93 wfDebug( "\n" );
94 } else {
95 wfDebug( $_SERVER['REQUEST_METHOD'] . ' ' . $_SERVER['REQUEST_URI'] . "\n" );
96 }
97
98 # Disable linkscc except if the old existence check method is enabled
99 if (!$wgUseOldExistenceCheck) {
100 $wgEnablePersistentLC = false;
101 }
102
103 wfProfileOut( $fname.'-misc1' );
104 wfProfileIn( $fname.'-memcached' );
105
106 # Set up Memcached
107 #
108 class MemCachedClientforWiki extends memcached {
109 function _debugprint( $text ) {
110 wfDebug( "memcached: $text\n" );
111 }
112 }
113
114 # FakeMemCachedClient imitates the API of memcached-client v. 0.1.2.
115 # It acts as a memcached server with no RAM, that is, all objects are
116 # cleared the moment they are set. All set operations succeed and all
117 # get operations return null.
118
119 class FakeMemCachedClient {
120 function add ($key, $val, $exp = 0) { return true; }
121 function decr ($key, $amt=1) { return null; }
122 function delete ($key, $time = 0) { return false; }
123 function disconnect_all () { }
124 function enable_compress ($enable) { }
125 function forget_dead_hosts () { }
126 function get ($key) { return null; }
127 function get_multi ($keys) { return array_pad(array(), count($keys), null); }
128 function incr ($key, $amt=1) { return null; }
129 function replace ($key, $value, $exp=0) { return false; }
130 function run_command ($sock, $cmd) { return null; }
131 function set ($key, $value, $exp=0){ return true; }
132 function set_compress_threshold ($thresh){ }
133 function set_debug ($dbg) { }
134 function set_servers ($list) { }
135 }
136
137 if( $wgUseMemCached ) {
138 $wgMemc = new MemCachedClientforWiki( array('persistant' => true) );
139 $wgMemc->set_servers( $wgMemCachedServers );
140 $wgMemc->set_debug( $wgMemCachedDebug );
141
142 $messageMemc = &$wgMemc;
143 } else {
144 $wgMemc = new FakeMemCachedClient();
145
146 # Give the message cache a separate cache in the DB.
147 # This is a speedup over separately querying every message used
148 require_once( 'ObjectCache.php' );
149 $messageMemc = new MediaWikiBagOStuff('objectcache');
150 }
151
152 wfProfileOut( $fname.'-memcached' );
153 wfProfileIn( $fname.'-SetupSession' );
154
155 if( !$wgCommandLineMode && ( isset( $_COOKIE[ini_get('session.name')] ) || isset( $_COOKIE[$wgDBname.'Password'] ) ) ) {
156 User::SetupSession();
157 $wgSessionStarted = true;
158 } else {
159 $wgSessionStarted = false;
160 }
161
162 wfProfileOut( $fname.'-SetupSession' );
163 wfProfileIn( $fname.'-database' );
164
165 if ( !$wgDBservers ) {
166 $wgDBservers = array(array(
167 'host' => $wgDBserver,
168 'user' => $wgDBuser,
169 'password' => $wgDBpassword,
170 'dbname' => $wgDBname,
171 'type' => $wgDBtype,
172 'load' => 1,
173 'flags' => ($wgDebugDumpSql ? DBO_DEBUG : 0) | DBO_DEFAULT
174 ));
175 }
176 $wgLoadBalancer = LoadBalancer::newFromParams( $wgDBservers );
177 $wgLoadBalancer->loadMasterPos();
178
179 wfProfileOut( $fname.'-database' );
180 wfProfileIn( $fname.'-language' );
181 require_once( 'languages/Language.php' );
182
183 $wgMessageCache = new MessageCache;
184
185 $wgLangClass = 'Language' . ucfirst( $wgLanguageCode );
186 if( ! class_exists( $wgLangClass ) || ($wgLanguageCode == 'en' && !$wgUseLatin1) ) {
187 # Default to English/UTF-8
188 require_once( 'languages/LanguageUtf8.php' );
189 $wgLangClass = 'LanguageUtf8';
190 }
191
192 $wgLang = new $wgLangClass();
193 if ( !is_object($wgLang) ) {
194 print "No language class ($wgLang)\N";
195 }
196
197 if( $wgUseLatin1 && $wgLanguageCode != 'en' ) {
198 # For non-UTF-8 non-English.
199 require_once( 'languages/LanguageLatin1.php' );
200 $xxx = new LanguageLatin1( $wgLang );
201 unset( $wgLang );
202 $wgLang = $xxx;
203 }
204 wfProfileOut( $fname.'-language' );
205 wfProfileIn( $fname.'-MessageCache' );
206
207 $wgMessageCache->initialise( $messageMemc, $wgUseDatabaseMessages, $wgMsgCacheExpiry, $wgDBname );
208
209 wfProfileOut( $fname.'-MessageCache' );
210 wfProfileIn( $fname.'-OutputPage' );
211
212 $wgOut = new OutputPage();
213 wfDebug( "\n\n" );
214
215 wfProfileOut( $fname.'-OutputPage' );
216 wfProfileIn( $fname.'-DateFormatter' );
217
218 if ( $wgUseDynamicDates ) {
219 require_once( 'DateFormatter.php' );
220 global $wgDateFormatter;
221 $wgDateFormatter = new DateFormatter;
222 }
223
224 wfProfileOut( $fname.'-DateFormatter' );
225 wfProfileIn( $fname.'-BlockCache' );
226
227 $wgBlockCache = new BlockCache( true );
228
229 wfProfileOut( $fname.'-BlockCache' );
230 wfProfileIn( $fname.'-User' );
231
232 if( $wgCommandLineMode ) {
233 # Used for some maintenance scripts; user session cookies can screw things up
234 # when the database is in an in-between state.
235 $wgUser = new User();
236 } else {
237 $wgUser = User::loadFromSession();
238 }
239
240 wfProfileOut( $fname.'-User' );
241 wfProfileIn( $fname.'-misc2' );
242
243 $wgDeferredUpdateList = array();
244 $wgLinkCache = new LinkCache();
245 $wgMagicWords = array();
246 $wgMwRedir =& MagicWord::get( MAG_REDIRECT );
247 $wgParserCache = new ParserCache();
248 $wgParser = new Parser();
249 $wgOut->setParserOptions( ParserOptions::newFromUser( $wgUser ) );
250 $wgDBConnections = array();
251 wfSeedRandom();
252
253 # Placeholders in case of DB error
254 $wgTitle = Title::newFromText( wfMsg( 'badtitle' ) );
255 $wgArticle = new Article($wgTitle);
256
257 wfProfileOut( $fname.'-misc2' );
258 wfProfileIn( $fname.'-extensions' );
259
260 # Extension setup functions
261 # Entries should be added to this variable during the inclusion
262 # of the extension file. This allows the extension to perform
263 # any necessary initialisation in the fully initialised environment
264 foreach ( $wgExtensionFunctions as $func ) {
265 $func();
266 }
267
268 $wgFullyInitialised = true;
269 wfProfileOut( $fname.'-extensions' );
270 wfProfileOut( $fname );
271
272 }
273 ?>