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