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