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