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