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 $wgExtraNamespaces[20] = 'Data' ;
53 $wgExtraNamespaces[21] = 'Data_talk' ;
57 wfProfileIn( $fname );
58 global $wgUseDynamicDates;
59 wfProfileIn( $fname.'-includes' );
61 require_once( 'GlobalFunctions.php' );
62 require_once( 'Hooks.php' );
63 require_once( 'Namespace.php' );
64 require_once( 'RecentChange.php' );
65 require_once( 'User.php' );
66 require_once( 'Skin.php' );
67 require_once( 'OutputPage.php' );
68 require_once( 'LinkCache.php' );
69 require_once( 'Title.php' );
70 require_once( 'Article.php' );
71 require_once( 'MagicWord.php' );
72 require_once( 'Block.php' );
73 require_once( 'MessageCache.php' );
74 require_once( 'BlockCache.php' );
75 require_once( 'Parser.php' );
76 require_once( 'ParserXML.php' );
77 require_once( 'ParserCache.php' );
78 require_once( 'WebRequest.php' );
79 require_once( 'LoadBalancer.php' );
80 require_once( 'HistoryBlob.php' );
82 $wgRequest = new WebRequest();
84 wfProfileOut( $fname.'-includes' );
85 wfProfileIn( $fname.'-misc1' );
86 global $wgUser, $wgLang, $wgContLang, $wgOut, $wgTitle;
87 global $wgLangClass, $wgContLangClass;
88 global $wgArticle, $wgDeferredUpdateList, $wgLinkCache;
89 global $wgMemc, $wgMagicWords, $wgMwRedir, $wgDebugLogFile;
90 global $wgMessageCache, $wgUseMemCached, $wgUseDatabaseMessages;
91 global $wgMsgCacheExpiry, $wgCommandLineMode;
92 global $wgBlockCache, $wgParserCache, $wgParser, $wgMsgParserOptions;
93 global $wgLoadBalancer, $wgDBservers, $wgDebugDumpSql;
94 global $wgDBserver, $wgDBuser, $wgDBpassword, $wgDBname, $wgDBtype;
95 global $wgUseOldExistenceCheck, $wgEnablePersistentLC;
97 global $wgFullyInitialised;
100 if ( $wgCommandLineMode ) {
101 # wfDebug( '"' . implode( '" "', $argv ) . '"' );
102 } elseif ( function_exists( 'getallheaders' ) ) {
103 wfDebug( "\nStart request\n" );
104 wfDebug( $_SERVER['REQUEST_METHOD'] . ' ' . $_SERVER['REQUEST_URI'] . "\n" );
105 $headers = getallheaders();
106 foreach ($headers as $name => $value) {
107 wfDebug( "$name: $value\n" );
111 wfDebug( $_SERVER['REQUEST_METHOD'] . ' ' . $_SERVER['REQUEST_URI'] . "\n" );
114 # Disable linkscc except if the old existence check method is enabled
115 if (!$wgUseOldExistenceCheck) {
116 $wgEnablePersistentLC = false;
119 wfProfileOut( $fname.'-misc1' );
120 wfProfileIn( $fname.'-memcached' );
122 # FakeMemCachedClient imitates the API of memcached-client v. 0.1.2.
123 # It acts as a memcached server with no RAM, that is, all objects are
124 # cleared the moment they are set. All set operations succeed and all
125 # get operations return null.
127 if( $wgUseMemCached ) {
130 require_once( 'memcached-client.php' );
136 class MemCachedClientforWiki
extends memcached
{
137 function _debugprint( $text ) {
138 wfDebug( "memcached: $text\n" );
142 $wgMemc = new MemCachedClientforWiki( array('persistant' => true) );
143 $wgMemc->set_servers( $wgMemCachedServers );
144 $wgMemc->set_debug( $wgMemCachedDebug );
146 $messageMemc = &$wgMemc;
147 } elseif ( $wgUseTurckShm ) {
148 # Turck shared memory
150 require_once( 'ObjectCache.php' );
151 $wgMemc = new TurckBagOStuff
;
152 $messageMemc = &$wgMemc;
158 class FakeMemCachedClient
{
159 function add ($key, $val, $exp = 0) { return true; }
160 function decr ($key, $amt=1) { return null; }
161 function delete ($key, $time = 0) { return false; }
162 function disconnect_all () { }
163 function enable_compress ($enable) { }
164 function forget_dead_hosts () { }
165 function get ($key) { return null; }
166 function get_multi ($keys) { return array_pad(array(), count($keys), null); }
167 function incr ($key, $amt=1) { return null; }
168 function replace ($key, $value, $exp=0) { return false; }
169 function run_command ($sock, $cmd) { return null; }
170 function set ($key, $value, $exp=0){ return true; }
171 function set_compress_threshold ($thresh){ }
172 function set_debug ($dbg) { }
173 function set_servers ($list) { }
175 $wgMemc = new FakeMemCachedClient();
177 # Give the message cache a separate cache in the DB.
178 # This is a speedup over separately querying every message used
179 require_once( 'ObjectCache.php' );
180 $messageMemc = new MediaWikiBagOStuff('objectcache');
183 wfProfileOut( $fname.'-memcached' );
184 wfProfileIn( $fname.'-SetupSession' );
186 if( !$wgCommandLineMode && ( isset( $_COOKIE[ini_get('session.name')] ) ||
isset( $_COOKIE[$wgDBname.'Token'] ) ) ) {
187 User
::SetupSession();
188 $wgSessionStarted = true;
190 $wgSessionStarted = false;
193 wfProfileOut( $fname.'-SetupSession' );
194 wfProfileIn( $fname.'-database' );
196 if ( !$wgDBservers ) {
197 $wgDBservers = array(array(
198 'host' => $wgDBserver,
200 'password' => $wgDBpassword,
201 'dbname' => $wgDBname,
204 'flags' => ($wgDebugDumpSql ? DBO_DEBUG
: 0) | DBO_DEFAULT
207 $wgLoadBalancer = LoadBalancer
::newFromParams( $wgDBservers );
208 $wgLoadBalancer->loadMasterPos();
210 wfProfileOut( $fname.'-database' );
211 wfProfileIn( $fname.'-language1' );
213 require_once( "$IP/languages/Language.php" );
215 wfProfileOut( $fname.'-language1' );
216 wfProfileIn( $fname.'-User' );
218 # Skin setup functions
219 # Entries can be added to this variable during the inclusion
220 # of the extension file. Skins can then perform any necessary initialisation.
221 foreach ( $wgSkinExtensionFunctions as $func ) {
225 if( !is_object( $wgAuth ) ) {
226 require_once( 'AuthPlugin.php' );
227 $wgAuth = new AuthPlugin();
230 if( $wgCommandLineMode ) {
231 # Used for some maintenance scripts; user session cookies can screw things up
232 # when the database is in an in-between state.
233 $wgUser = new User();
234 # Prevent loading User settings from the DB.
235 $wgUser->setLoaded( true );
237 $wgUser = User
::loadFromSession();
240 wfProfileOut( $fname.'-User' );
241 wfProfileIn( $fname.'-language2' );
243 function setupLangObj(&$langclass) {
244 global $wgUseLatin1, $IP;
246 if( ! class_exists( $langclass ) ) {
247 # Default to English/UTF-8, or for non-UTF-8, to latin-1
248 $baseclass = 'LanguageUtf8';
250 $baseclass = 'LanguageLatin1';
251 require_once( "$IP/languages/$baseclass.php" );
252 $lc = strtolower(substr($langclass, 8));
254 class $langclass extends $baseclass {
255 function getVariants() {
256 return array(\"$lc\");
264 $lang = new $langclass();
269 # $wgLanguageCode may be changed later to fit with user preference.
270 # The content language will remain fixed as per the configuration,
272 $wgContLanguageCode = $wgLanguageCode;
273 $wgContLangClass = 'Language' . str_replace( '-', '_', ucfirst( $wgContLanguageCode ) );
275 $wgContLang = setupLangObj( $wgContLangClass );
277 // set default user option from content language
278 if( !$wgUser->mDataLoaded
) {
279 $wgUser->loadDefaultFromLanguage();
282 // wgLanguageCode now specifically means the UI language
283 $wgLanguageCode = $wgUser->getOption('language');
284 if( empty( $wgLanguageCode ) ) {
285 # Quick hack for upgrades where this will be blank,
286 # and it's not handled right. Set to default.
287 $wgLanguageCode = $wgContLanguageCode;
290 $wgLangClass = 'Language'. str_replace( '-', '_', ucfirst( $wgLanguageCode ) );
292 if( $wgLangClass == $wgContLangClass ) {
293 $wgLang = &$wgContLang;
295 wfSuppressWarnings();
296 include_once("$IP/languages/$wgLangClass.php");
299 $wgLang = setupLangObj( $wgLangClass );
302 wfProfileOut( $fname.'-language' );
303 wfProfileIn( $fname.'-MessageCache' );
305 $wgMessageCache = new MessageCache
;
306 $wgMessageCache->initialise( $messageMemc, $wgUseDatabaseMessages, $wgMsgCacheExpiry, $wgDBname);
308 wfProfileOut( $fname.'-MessageCache' );
311 # I guess the warning about UI switching might still apply...
313 # FIXME: THE ABOVE MIGHT BREAK NAMESPACES, VARIABLES,
314 # SEARCH INDEX UPDATES, AND MANY MANY THINGS.
315 # DO NOT USE THIS MODE EXCEPT FOR TESTING RIGHT NOW.
317 # To disable it, the easiest thing could be to uncomment the
318 # following; they should effectively disable the UI switch functionality
320 # $wgLangClass = $wgContLangClass;
321 # $wgLanguageCode = $wgContLanguageCode;
322 # $wgLang = $wgContLang;
324 # TODO: Need to change reference to $wgLang to $wgContLang at proper
325 # places, including namespaces, dates in signatures, magic words,
328 # TODO: Need to look at the issue of input/output encoding
332 wfProfileIn( $fname.'-OutputPage' );
334 $wgOut = new OutputPage();
337 wfProfileOut( $fname.'-OutputPage' );
338 wfProfileIn( $fname.'-DateFormatter' );
340 if ( $wgUseDynamicDates ) {
341 require_once( 'DateFormatter.php' );
342 global $wgDateFormatter;
343 $wgDateFormatter = new DateFormatter
;
346 wfProfileOut( $fname.'-DateFormatter' );
347 wfProfileIn( $fname.'-BlockCache' );
349 $wgBlockCache = new BlockCache( true );
351 wfProfileOut( $fname.'-BlockCache' );
352 wfProfileIn( $fname.'-misc2' );
354 $wgDeferredUpdateList = array();
355 $wgLinkCache = new LinkCache();
356 $wgMagicWords = array();
357 $wgMwRedir =& MagicWord
::get( MAG_REDIRECT
);
358 $wgParserCache = new ParserCache( $messageMemc );
360 if ( $wgUseXMLparser ) $wgParser = new ParserXML();
361 else $wgParser = new Parser();
362 $wgOut->setParserOptions( ParserOptions
::newFromUser( $wgUser ) );
363 $wgMsgParserOptions = ParserOptions
::newFromUser($wgUser);
366 # Placeholders in case of DB error
367 $wgTitle = Title
::makeTitle( NS_SPECIAL
, 'Error' );
368 $wgArticle = new Article($wgTitle);
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();
389 wfProfileOut( $fname.'-misc2' );
390 wfProfileIn( $fname.'-extensions' );
392 # Extension setup functions for extensions other than skins
393 # Entries should be added to this variable during the inclusion
394 # of the extension file. This allows the extension to perform
395 # any necessary initialisation in the fully initialised environment
396 foreach ( $wgExtensionFunctions as $func ) {
400 $wgFullyInitialised = true;
401 wfProfileOut( $fname.'-extensions' );
402 wfProfileOut( $fname );