3 * Include most things that's need to customize the site
8 * This file is not a valid entry point, perform no further processing unless
11 if( defined( 'MEDIAWIKI' ) ) {
13 # The main wiki script and things like database
14 # conversion and maintenance scripts all share a
15 # common setup of including lots of classes and
16 # setting up a few globals.
19 global $wgProfiling, $wgProfileSampleRate, $wgIP, $wgUseSquid, $IP;
21 if( !isset( $wgProfiling ) )
24 if ( $wgProfiling and (0 == rand() %
$wgProfileSampleRate ) ) {
25 require_once( 'Profiling.php' );
27 function wfProfileIn( $fn = '' ) {}
28 function wfProfileOut( $fn = '' ) {}
29 function wfGetProfilingOutput( $s, $e ) {}
30 function wfProfileClose() {}
33 /* collect the originating ips */
34 if( $wgUseSquid && isset( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) {
35 # If the web server is behind a reverse proxy, we need to find
36 # out where our requests are really coming from.
37 $hopips = array_map( 'trim', explode( ',', $_SERVER['HTTP_X_FORWARDED_FOR'] ) );
39 $allsquids = array_merge($wgSquidServers, $wgSquidServersNoPurge);
40 while(in_array(trim(end($hopips)), $allsquids)){
43 $wgIP = trim(end($hopips));
44 } elseif( isset( $_SERVER['REMOTE_ADDR'] ) ) {
45 $wgIP = $_SERVER['REMOTE_ADDR'];
52 wfProfileIn( $fname );
53 global $wgUseDynamicDates;
54 wfProfileIn( $fname.'-includes' );
56 require_once( 'GlobalFunctions.php' );
57 require_once( 'Hooks.php' );
58 require_once( 'Namespace.php' );
59 require_once( 'RecentChange.php' );
60 require_once( 'User.php' );
61 require_once( 'Skin.php' );
62 require_once( 'OutputPage.php' );
63 require_once( 'LinkCache.php' );
64 require_once( 'Title.php' );
65 require_once( 'Article.php' );
66 require_once( 'MagicWord.php' );
67 require_once( 'Block.php' );
68 require_once( 'MessageCache.php' );
69 require_once( 'BlockCache.php' );
70 require_once( 'Parser.php' );
71 require_once( 'Parser.php' );
72 require_once( 'ParserCache.php' );
73 require_once( 'WebRequest.php' );
74 require_once( 'LoadBalancer.php' );
75 require_once( 'HistoryBlob.php' );
77 $wgRequest = new WebRequest();
79 wfProfileOut( $fname.'-includes' );
80 wfProfileIn( $fname.'-misc1' );
81 global $wgUser, $wgLang, $wgContLang, $wgOut, $wgTitle;
82 global $wgLangClass, $wgContLangClass;
83 global $wgArticle, $wgDeferredUpdateList, $wgLinkCache;
84 global $wgMemc, $wgMagicWords, $wgMwRedir, $wgDebugLogFile;
85 global $wgMessageCache, $wgUseMemCached, $wgUseDatabaseMessages;
86 global $wgMsgCacheExpiry, $wgCommandLineMode;
87 global $wgBlockCache, $wgParserCache, $wgParser, $wgMsgParserOptions;
88 global $wgLoadBalancer, $wgDBservers, $wgDebugDumpSql;
89 global $wgDBserver, $wgDBuser, $wgDBpassword, $wgDBname, $wgDBtype;
90 global $wgUseOldExistenceCheck, $wgEnablePersistentLC, $wgMasterWaitTimeout;
92 global $wgFullyInitialised;
95 if ( $wgCommandLineMode ) {
96 # wfDebug( '"' . implode( '" "', $argv ) . '"' );
97 } elseif ( function_exists( 'getallheaders' ) ) {
98 wfDebug( "\nStart request\n" );
99 wfDebug( $_SERVER['REQUEST_METHOD'] . ' ' . $_SERVER['REQUEST_URI'] . "\n" );
100 $headers = getallheaders();
101 foreach ($headers as $name => $value) {
102 wfDebug( "$name: $value\n" );
106 wfDebug( $_SERVER['REQUEST_METHOD'] . ' ' . $_SERVER['REQUEST_URI'] . "\n" );
109 # Disable linkscc except if the old existence check method is enabled
110 if (!$wgUseOldExistenceCheck) {
111 $wgEnablePersistentLC = false;
114 wfProfileOut( $fname.'-misc1' );
115 wfProfileIn( $fname.'-memcached' );
117 # FakeMemCachedClient imitates the API of memcached-client v. 0.1.2.
118 # It acts as a memcached server with no RAM, that is, all objects are
119 # cleared the moment they are set. All set operations succeed and all
120 # get operations return null.
122 if( $wgUseMemCached ) {
125 require_once( 'memcached-client.php' );
131 class MemCachedClientforWiki
extends memcached
{
132 function _debugprint( $text ) {
133 wfDebug( "memcached: $text\n" );
137 $wgMemc = new MemCachedClientforWiki( array('persistant' => true) );
138 $wgMemc->set_servers( $wgMemCachedServers );
139 $wgMemc->set_debug( $wgMemCachedDebug );
141 $messageMemc = &$wgMemc;
142 } elseif ( $wgUseTurckShm ) {
143 # Turck shared memory
145 require_once( 'ObjectCache.php' );
146 $wgMemc = new TurckBagOStuff
;
147 $messageMemc = &$wgMemc;
153 class FakeMemCachedClient
{
154 function add ($key, $val, $exp = 0) { return true; }
155 function decr ($key, $amt=1) { return null; }
156 function delete ($key, $time = 0) { return false; }
157 function disconnect_all () { }
158 function enable_compress ($enable) { }
159 function forget_dead_hosts () { }
160 function get ($key) { return null; }
161 function get_multi ($keys) { return array_pad(array(), count($keys), null); }
162 function incr ($key, $amt=1) { return null; }
163 function replace ($key, $value, $exp=0) { return false; }
164 function run_command ($sock, $cmd) { return null; }
165 function set ($key, $value, $exp=0){ return true; }
166 function set_compress_threshold ($thresh){ }
167 function set_debug ($dbg) { }
168 function set_servers ($list) { }
170 $wgMemc = new FakeMemCachedClient();
172 # Give the message cache a separate cache in the DB.
173 # This is a speedup over separately querying every message used
174 require_once( 'ObjectCache.php' );
175 $messageMemc = new MediaWikiBagOStuff('objectcache');
178 wfProfileOut( $fname.'-memcached' );
179 wfProfileIn( $fname.'-SetupSession' );
181 if( !$wgCommandLineMode && ( isset( $_COOKIE[ini_get('session.name')] ) ||
isset( $_COOKIE[$wgDBname.'Token'] ) ) ) {
182 User
::SetupSession();
183 $wgSessionStarted = true;
185 $wgSessionStarted = false;
188 wfProfileOut( $fname.'-SetupSession' );
189 wfProfileIn( $fname.'-database' );
191 if ( !$wgDBservers ) {
192 $wgDBservers = array(array(
193 'host' => $wgDBserver,
195 'password' => $wgDBpassword,
196 'dbname' => $wgDBname,
199 'flags' => ($wgDebugDumpSql ? DBO_DEBUG
: 0) | DBO_DEFAULT
202 $wgLoadBalancer = LoadBalancer
::newFromParams( $wgDBservers, false, $wgMasterWaitTimeout );
203 $wgLoadBalancer->loadMasterPos();
205 wfProfileOut( $fname.'-database' );
206 wfProfileIn( $fname.'-language1' );
208 require_once( "$IP/languages/Language.php" );
210 wfProfileOut( $fname.'-language1' );
211 wfProfileIn( $fname.'-User' );
213 # Skin setup functions
214 # Entries can be added to this variable during the inclusion
215 # of the extension file. Skins can then perform any necessary initialisation.
216 foreach ( $wgSkinExtensionFunctions as $func ) {
220 if( !is_object( $wgAuth ) ) {
221 require_once( 'AuthPlugin.php' );
222 $wgAuth = new AuthPlugin();
225 if( $wgCommandLineMode ) {
226 # Used for some maintenance scripts; user session cookies can screw things up
227 # when the database is in an in-between state.
228 $wgUser = new User();
229 # Prevent loading User settings from the DB.
230 $wgUser->setLoaded( true );
232 $wgUser = User
::loadFromSession();
235 wfProfileOut( $fname.'-User' );
236 wfProfileIn( $fname.'-language2' );
238 function setupLangObj(&$langclass) {
239 global $wgUseLatin1, $IP;
241 if( ! class_exists( $langclass ) ) {
242 # Default to English/UTF-8, or for non-UTF-8, to latin-1
243 $baseclass = 'LanguageUtf8';
245 $baseclass = 'LanguageLatin1';
246 require_once( "$IP/languages/$baseclass.php" );
247 $lc = strtolower(substr($langclass, 8));
249 class $langclass extends $baseclass {
250 function getVariants() {
251 return array(\"$lc\");
258 $lang = new $langclass();
263 # $wgLanguageCode may be changed later to fit with user preference.
264 # The content language will remain fixed as per the configuration,
266 $wgContLanguageCode = $wgLanguageCode;
267 $wgContLangClass = 'Language' . str_replace( '-', '_', ucfirst( $wgContLanguageCode ) );
269 $wgContLang = setupLangObj( $wgContLangClass );
271 // set default user option from content language
272 if( !$wgUser->mDataLoaded
) {
273 $wgUser->loadDefaultFromLanguage();
276 // wgLanguageCode now specifically means the UI language
277 $wgLanguageCode = $wgUser->getOption('language');
278 # Validate $wgLanguageCode, which will soon be sent to an eval()
279 if( empty( $wgLanguageCode ) ||
!preg_match( '/^[a-z\-]*$/', $wgLanguageCode ) ) {
280 $wgLanguageCode = $wgContLanguageCode;
283 $wgLangClass = 'Language'. str_replace( '-', '_', ucfirst( $wgLanguageCode ) );
285 if( $wgLangClass == $wgContLangClass ) {
286 $wgLang = &$wgContLang;
288 wfSuppressWarnings();
289 include_once("$IP/languages/$wgLangClass.php");
292 $wgLang = setupLangObj( $wgLangClass );
295 wfProfileOut( $fname.'-language' );
296 wfProfileIn( $fname.'-MessageCache' );
298 $wgMessageCache = new MessageCache
;
299 $wgMessageCache->initialise( $messageMemc, $wgUseDatabaseMessages, $wgMsgCacheExpiry, $wgDBname);
301 wfProfileOut( $fname.'-MessageCache' );
304 # I guess the warning about UI switching might still apply...
306 # FIXME: THE ABOVE MIGHT BREAK NAMESPACES, VARIABLES,
307 # SEARCH INDEX UPDATES, AND MANY MANY THINGS.
308 # DO NOT USE THIS MODE EXCEPT FOR TESTING RIGHT NOW.
310 # To disable it, the easiest thing could be to uncomment the
311 # following; they should effectively disable the UI switch functionality
313 # $wgLangClass = $wgContLangClass;
314 # $wgLanguageCode = $wgContLanguageCode;
315 # $wgLang = $wgContLang;
317 # TODO: Need to change reference to $wgLang to $wgContLang at proper
318 # places, including namespaces, dates in signatures, magic words,
321 # TODO: Need to look at the issue of input/output encoding
325 wfProfileIn( $fname.'-OutputPage' );
327 $wgOut = new OutputPage();
330 wfProfileOut( $fname.'-OutputPage' );
331 wfProfileIn( $fname.'-DateFormatter' );
333 if ( $wgUseDynamicDates ) {
334 require_once( 'DateFormatter.php' );
335 global $wgDateFormatter;
336 $wgDateFormatter = new DateFormatter
;
339 wfProfileOut( $fname.'-DateFormatter' );
340 wfProfileIn( $fname.'-BlockCache' );
342 $wgBlockCache = new BlockCache( true );
344 wfProfileOut( $fname.'-BlockCache' );
345 wfProfileIn( $fname.'-misc2' );
347 $wgDeferredUpdateList = array();
348 $wgLinkCache = new LinkCache();
349 $wgMagicWords = array();
350 $wgMwRedir =& MagicWord
::get( MAG_REDIRECT
);
351 $wgParserCache = new ParserCache( $messageMemc );
353 if ( $wgUseXMLparser ) {
354 require_once( 'ParserXML.php' );
355 $wgParser = new ParserXML();
357 $wgParser = new Parser();
359 $wgOut->setParserOptions( ParserOptions
::newFromUser( $wgUser ) );
360 $wgMsgParserOptions = ParserOptions
::newFromUser($wgUser);
363 # Placeholders in case of DB error
364 $wgTitle = Title
::makeTitle( NS_SPECIAL
, 'Error' );
365 $wgArticle = new Article($wgTitle);
368 # FIXME: This is an ugly hack, which wastes runtime on cache hits
369 # and raw page views by forcing initialization of the message cache.
370 # Try to fake around it for raw at least:
371 if( !isset( $_REQUEST['action'] ) ||
$_REQUEST['action'] != 'raw' ) {
372 $notice = wfMsg( 'sitenotice' );
373 if($notice == '<sitenotice>') $notice = '';
374 # Allow individual wikis to turn it off
375 if ( $notice == '-' ) {
378 # if($wgSiteNotice) $notice .= $wgSiteNotice;
380 $notice = $wgSiteNotice;
382 if($notice != '-' && $notice != '') {
383 $specialparser = new Parser();
384 $parserOutput = $specialparser->parse( $notice, $wgTitle, $wgOut->mParserOptions
, false );
385 $wgSiteNotice = $parserOutput->getText();
390 wfProfileOut( $fname.'-misc2' );
391 wfProfileIn( $fname.'-extensions' );
393 # Extension setup functions for extensions other than skins
394 # Entries should be added to this variable during the inclusion
395 # of the extension file. This allows the extension to perform
396 # any necessary initialisation in the fully initialised environment
397 foreach ( $wgExtensionFunctions as $func ) {
401 $wgFullyInitialised = true;
402 wfProfileOut( $fname.'-extensions' );
403 wfProfileOut( $fname );