Ahh, so that's what that does
[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( 'SearchEngine.php' );
59 require_once( 'DifferenceEngine.php' );
60 require_once( 'MessageCache.php' );
61 require_once( 'BlockCache.php' );
62 require_once( 'Parser.php' );
63 require_once( 'ParserCache.php' );
64 require_once( 'WebRequest.php' );
65 require_once( 'LoadBalancer.php' );
66
67 $wgRequest = new WebRequest();
68
69
70
71 wfProfileOut( $fname.'-includes' );
72 wfProfileIn( $fname.'-memcached' );
73 global $wgUser, $wgLang, $wgOut, $wgTitle;
74 global $wgArticle, $wgDeferredUpdateList, $wgLinkCache;
75 global $wgMemc, $wgMagicWords, $wgMwRedir, $wgDebugLogFile;
76 global $wgMessageCache, $wgUseMemCached, $wgUseDatabaseMessages;
77 global $wgMsgCacheExpiry, $wgCommandLineMode;
78 global $wgBlockCache, $wgParserCache, $wgParser, $wgDBConnections;
79 global $wgLoadBalancer, $wgDBservers, $wgDebugDumpSql;
80 global $wgDBserver, $wgDBuser, $wgDBpassword, $wgDBname, $wgDBtype;
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 # Set up Memcached
99 #
100 class MemCachedClientforWiki extends memcached {
101 function _debugprint( $text ) {
102 wfDebug( "memcached: $text\n" );
103 }
104 }
105
106 # FakeMemCachedClient imitates the API of memcached-client v. 0.1.2.
107 # It acts as a memcached server with no RAM, that is, all objects are
108 # cleared the moment they are set. All set operations succeed and all
109 # get operations return null.
110
111 class FakeMemCachedClient {
112 function add ($key, $val, $exp = 0) { return true; }
113 function decr ($key, $amt=1) { return null; }
114 function delete ($key, $time = 0) { return false; }
115 function disconnect_all () { }
116 function enable_compress ($enable) { }
117 function forget_dead_hosts () { }
118 function get ($key) { return null; }
119 function get_multi ($keys) { return array_pad(array(), count($keys), null); }
120 function incr ($key, $amt=1) { return null; }
121 function replace ($key, $value, $exp=0) { return false; }
122 function run_command ($sock, $cmd) { return null; }
123 function set ($key, $value, $exp=0){ return true; }
124 function set_compress_threshold ($thresh){ }
125 function set_debug ($dbg) { }
126 function set_servers ($list) { }
127 }
128
129 if( $wgUseMemCached ) {
130 $wgMemc = new MemCachedClientforWiki( array('persistant' => true) );
131 $wgMemc->set_servers( $wgMemCachedServers );
132 $wgMemc->set_debug( $wgMemCachedDebug );
133
134 $messageMemc = &$wgMemc;
135 } else {
136 $wgMemc = new FakeMemCachedClient();
137
138 # Give the message cache a separate cache in the DB.
139 # This is a speedup over separately querying every message used
140 require_once( 'ObjectCache.php' );
141 $messageMemc = new MediaWikiBagOStuff('objectcache');
142 }
143
144 wfProfileOut( $fname.'-memcached' );
145 wfProfileIn( $fname.'-SetupSession' );
146
147 if( !$wgCommandLineMode && ( isset( $_COOKIE[ini_get('session.name')] ) || isset( $_COOKIE[$wgDBname.'Password'] ) ) ) {
148 User::SetupSession();
149 $wgSessionStarted = true;
150 } else {
151 $wgSessionStarted = false;
152 }
153
154 wfProfileOut( $fname.'-SetupSession' );
155 wfProfileIn( $fname.'-database' );
156
157 if ( !$wgDBservers ) {
158 $wgDBservers = array(array(
159 'host' => $wgDBserver,
160 'user' => $wgDBuser,
161 'password' => $wgDBpassword,
162 'dbname' => $wgDBname,
163 'type' => $wgDBtype,
164 'load' => 1,
165 'flags' => ($wgDebugDumpSql ? DBO_DEBUG : 0) | DBO_DEFAULT
166 ));
167 }
168 $wgLoadBalancer = LoadBalancer::newFromParams( $wgDBservers );
169 $wgLoadBalancer->loadMasterPos();
170
171 wfProfileOut( $fname.'-database' );
172 wfProfileIn( $fname.'-language' );
173 require_once( 'languages/Language.php' );
174
175 $wgMessageCache = new MessageCache;
176
177 $wgLangClass = 'Language' . ucfirst( $wgLanguageCode );
178 if( ! class_exists( $wgLangClass ) || ($wgLanguageCode == 'en' && !$wgUseLatin1) ) {
179 # Default to English/UTF-8
180 require_once( 'languages/LanguageUtf8.php' );
181 $wgLangClass = 'LanguageUtf8';
182 }
183
184 $wgLang = new $wgLangClass();
185 if ( !is_object($wgLang) ) {
186 print "No language class ($wgLang)\N";
187 }
188
189 if( $wgUseLatin1 && $wgLanguageCode != 'en' ) {
190 # For non-UTF-8 non-English.
191 require_once( 'languages/LanguageLatin1.php' );
192 $xxx = new LanguageLatin1( $wgLang );
193 unset( $wgLang );
194 $wgLang = $xxx;
195 }
196 wfProfileOut( $fname.'-language' );
197 wfProfileIn( $fname.'-MessageCache' );
198
199 $wgMessageCache->initialise( $messageMemc, $wgUseDatabaseMessages, $wgMsgCacheExpiry, $wgDBname );
200
201 wfProfileOut( $fname.'-MessageCache' );
202 wfProfileIn( $fname.'-OutputPage' );
203
204 $wgOut = new OutputPage();
205 wfDebug( "\n\n" );
206
207 wfProfileOut( $fname.'-OutputPage' );
208 wfProfileIn( $fname.'-DateFormatter' );
209
210 if ( $wgUseDynamicDates ) {
211 require_once( 'DateFormatter.php' );
212 global $wgDateFormatter;
213 $wgDateFormatter = new DateFormatter;
214 }
215
216 wfProfileOut( $fname.'-DateFormatter' );
217 wfProfileIn( $fname.'-BlockCache' );
218
219 $wgBlockCache = new BlockCache( true );
220
221 wfProfileOut( $fname.'-BlockCache' );
222 wfProfileIn( $fname.'-User' );
223
224 if( $wgCommandLineMode ) {
225 # Used for some maintenance scripts; user session cookies can screw things up
226 # when the database is in an in-between state.
227 $wgUser = new User();
228 } else {
229 $wgUser = User::loadFromSession();
230 }
231
232 wfProfileOut( $fname.'-User' );
233 wfProfileIn( $fname.'-misc' );
234
235 $wgDeferredUpdateList = array();
236 $wgLinkCache = new LinkCache();
237 $wgMagicWords = array();
238 $wgMwRedir =& MagicWord::get( MAG_REDIRECT );
239 $wgParserCache = new ParserCache();
240 $wgParser = new Parser();
241 $wgOut->setParserOptions( ParserOptions::newFromUser( $wgUser ) );
242 $wgDBConnections = array();
243 wfSeedRandom();
244
245 # Placeholders in case of DB error
246 $wgTitle = Title::newFromText( wfMsg( 'badtitle' ) );
247 $wgArticle = new Article($wgTitle);
248
249 wfProfileOut( $fname.'-misc' );
250 wfProfileIn( $fname.'-extensions' );
251
252 # Extension setup functions
253 # Entries should be added to this variable during the inclusion
254 # of the extension file. This allows the extension to perform
255 # any necessary initialisation in the fully initialised environment
256 foreach ( $wgExtensionFunctions as $func ) {
257 $func();
258 }
259
260 $wgFullyInitialised = true;
261 wfProfileOut( $fname.'-extensions' );
262 wfProfileOut( $fname );
263
264 }
265 ?>