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