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