1f351c316a7b29bdc126f77f96c4ad58fb56653d
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 while(in_array(trim(end($hopips)), $wgSquidServers)){
42 $wgIP = trim(end($hopips));
43 } elseif( isset( $_SERVER['REMOTE_ADDR'] ) ) {
44 $wgIP = $_SERVER['REMOTE_ADDR'];
51 $wgExtraNamespaces[20] = 'Data' ;
52 $wgExtraNamespaces[21] = 'Data_talk' ;
56 wfProfileIn( $fname );
57 global $wgUseDynamicDates;
58 wfProfileIn( $fname.'-includes' );
60 require_once( 'GlobalFunctions.php' );
61 require_once( 'Hooks.php' );
62 require_once( 'Namespace.php' );
63 require_once( 'RecentChange.php' );
64 require_once( 'User.php' );
65 require_once( 'Skin.php' );
66 require_once( 'OutputPage.php' );
67 require_once( 'LinkCache.php' );
68 require_once( 'Title.php' );
69 require_once( 'Article.php' );
70 require_once( 'MagicWord.php' );
71 require_once( 'Block.php' );
72 require_once( 'MessageCache.php' );
73 require_once( 'BlockCache.php' );
74 require_once( 'Parser.php' );
75 require_once( 'ParserXML.php' );
76 require_once( 'ParserCache.php' );
77 require_once( 'WebRequest.php' );
78 require_once( 'LoadBalancer.php' );
79 require_once( 'HistoryBlob.php' );
81 $wgRequest = new WebRequest();
85 wfProfileOut( $fname.'-includes' );
86 wfProfileIn( $fname.'-misc1' );
87 global $wgUser, $wgLang, $wgContLang, $wgOut, $wgTitle;
88 global $wgLangClass, $wgContLangClass;
89 global $wgArticle, $wgDeferredUpdateList, $wgLinkCache;
90 global $wgMemc, $wgMagicWords, $wgMwRedir, $wgDebugLogFile;
91 global $wgMessageCache, $wgUseMemCached, $wgUseDatabaseMessages;
92 global $wgMsgCacheExpiry, $wgCommandLineMode;
93 global $wgBlockCache, $wgParserCache, $wgParser, $wgMsgParserOptions;
94 global $wgLoadBalancer, $wgDBservers, $wgDebugDumpSql;
95 global $wgDBserver, $wgDBuser, $wgDBpassword, $wgDBname, $wgDBtype;
96 global $wgUseOldExistenceCheck, $wgEnablePersistentLC;
98 global $wgFullyInitialised;
100 # Useful debug output
101 if ( $wgCommandLineMode ) {
102 # wfDebug( '"' . implode( '" "', $argv ) . '"' );
103 } elseif ( function_exists( 'getallheaders' ) ) {
104 wfDebug( "\nStart request\n" );
105 wfDebug( $_SERVER['REQUEST_METHOD'] . ' ' . $_SERVER['REQUEST_URI'] . "\n" );
106 $headers = getallheaders();
107 foreach ($headers as $name => $value) {
108 wfDebug( "$name: $value\n" );
112 wfDebug( $_SERVER['REQUEST_METHOD'] . ' ' . $_SERVER['REQUEST_URI'] . "\n" );
115 # Disable linkscc except if the old existence check method is enabled
116 if (!$wgUseOldExistenceCheck) {
117 $wgEnablePersistentLC = false;
120 wfProfileOut( $fname.'-misc1' );
121 wfProfileIn( $fname.'-memcached' );
123 # FakeMemCachedClient imitates the API of memcached-client v. 0.1.2.
124 # It acts as a memcached server with no RAM, that is, all objects are
125 # cleared the moment they are set. All set operations succeed and all
126 # get operations return null.
128 if( $wgUseMemCached ) {
131 require_once( 'memcached-client.php' );
137 class MemCachedClientforWiki
extends memcached
{
138 function _debugprint( $text ) {
139 wfDebug( "memcached: $text\n" );
143 $wgMemc = new MemCachedClientforWiki( array('persistant' => true) );
144 $wgMemc->set_servers( $wgMemCachedServers );
145 $wgMemc->set_debug( $wgMemCachedDebug );
147 $messageMemc = &$wgMemc;
148 } elseif ( $wgUseTurckShm ) {
149 # Turck shared memory
151 require_once( 'ObjectCache.php' );
152 $wgMemc = new TurckBagOStuff
;
153 $messageMemc = &$wgMemc;
159 class FakeMemCachedClient
{
160 function add ($key, $val, $exp = 0) { return true; }
161 function decr ($key, $amt=1) { return null; }
162 function delete ($key, $time = 0) { return false; }
163 function disconnect_all () { }
164 function enable_compress ($enable) { }
165 function forget_dead_hosts () { }
166 function get ($key) { return null; }
167 function get_multi ($keys) { return array_pad(array(), count($keys), null); }
168 function incr ($key, $amt=1) { return null; }
169 function replace ($key, $value, $exp=0) { return false; }
170 function run_command ($sock, $cmd) { return null; }
171 function set ($key, $value, $exp=0){ return true; }
172 function set_compress_threshold ($thresh){ }
173 function set_debug ($dbg) { }
174 function set_servers ($list) { }
176 $wgMemc = new FakeMemCachedClient();
178 # Give the message cache a separate cache in the DB.
179 # This is a speedup over separately querying every message used
180 require_once( 'ObjectCache.php' );
181 $messageMemc = new MediaWikiBagOStuff('objectcache');
184 wfProfileOut( $fname.'-memcached' );
185 wfProfileIn( $fname.'-SetupSession' );
187 if( !$wgCommandLineMode && ( isset( $_COOKIE[ini_get('session.name')] ) ||
isset( $_COOKIE[$wgDBname.'Token'] ) ) ) {
188 User
::SetupSession();
189 $wgSessionStarted = true;
191 $wgSessionStarted = false;
194 wfProfileOut( $fname.'-SetupSession' );
195 wfProfileIn( $fname.'-database' );
197 if ( !$wgDBservers ) {
198 $wgDBservers = array(array(
199 'host' => $wgDBserver,
201 'password' => $wgDBpassword,
202 'dbname' => $wgDBname,
205 'flags' => ($wgDebugDumpSql ? DBO_DEBUG
: 0) | DBO_DEFAULT
208 $wgLoadBalancer = LoadBalancer
::newFromParams( $wgDBservers );
209 $wgLoadBalancer->loadMasterPos();
211 wfProfileOut( $fname.'-database' );
212 wfProfileIn( $fname.'-language1' );
214 require_once( "$IP/languages/Language.php" );
216 wfProfileOut( $fname.'-language1' );
217 wfProfileIn( $fname.'-User' );
219 # Skin setup functions
220 # Entries can be added to this variable during the inclusion
221 # of the extension file. Skins can then perform any necessary initialisation.
222 foreach ( $wgSkinExtensionFunctions as $func ) {
226 if( !is_object( $wgAuth ) ) {
227 require_once( 'AuthPlugin.php' );
228 $wgAuth = new AuthPlugin();
231 if( $wgCommandLineMode ) {
232 # Used for some maintenance scripts; user session cookies can screw things up
233 # when the database is in an in-between state.
234 $wgUser = new User();
236 $wgUser = User
::loadFromSession();
239 wfProfileOut( $fname.'-User' );
240 wfProfileIn( $fname.'-language2' );
242 function setupLangObj(&$langclass, $langcode) {
243 global $wgUseLatin1, $IP;
246 if( ! class_exists( $langclass ) ) {
247 # Default to English/UTF-8
248 require_once( "$IP/languages/LanguageUtf8.php" );
249 $langclass = 'LanguageUtf8';
252 $lang = new $langclass();
253 if ( !is_object($lang) ) {
254 print "No language class ($wgLang)\N";
258 # For non-UTF-8 latin-1 downconversion
259 require_once( "$IP/languages/LanguageLatin1.php" );
260 $xxx = new LanguageLatin1( $lang );
267 # $wgLanguageCode may be changed later to fit with user preference.
268 # The content language will remain fixed as per the configuration,
270 $wgContLanguageCode = $wgLanguageCode;
271 $wgContLangClass = 'Language' . str_replace( '-', '_', ucfirst( $wgContLanguageCode ) );
273 $wgContLang = setupLangObj( $wgContLangClass, $wgContLangClass );
274 $n = get_class($wgContLang);
276 // set default user option from content language
277 if( !$wgUser->mDataLoaded
) {
278 $wgUser->loadDefaultFromLanguage();
281 // wgLanguageCode now specifically means the UI language
282 $wgLanguageCode = $wgUser->getOption('language');
284 $wgLangClass = 'Language'. str_replace( '-', '_', ucfirst( $wgLanguageCode ) );
286 if( $wgLangClass == $wgContLangClass ) {
287 $wgLang = &$wgContLang;
289 require_once("$IP/languages/$wgLangClass.php");
290 $wgLang = setupLangObj( $wgLangClass, $wgLanguageCode );
294 wfProfileOut( $fname.'-language' );
295 wfProfileIn( $fname.'-MessageCache' );
297 $wgMessageCache = new MessageCache
;
298 $wgMessageCache->initialise( $messageMemc, $wgUseDatabaseMessages, $wgMsgCacheExpiry, $wgDBname);
300 wfProfileOut( $fname.'-MessageCache' );
303 # I guess the warning about UI switching might still apply...
305 # FIXME: THE ABOVE MIGHT BREAK NAMESPACES, VARIABLES,
306 # SEARCH INDEX UPDATES, AND MANY MANY THINGS.
307 # DO NOT USE THIS MODE EXCEPT FOR TESTING RIGHT NOW.
309 # To disable it, the easiest thing could be to uncomment the
310 # following; they should effectively disable the UI switch functionality
312 # $wgLangClass = $wgContLangClass;
313 # $wgLanguageCode = $wgContLanguageCode;
314 # $wgLang = $wgContLang;
316 # TODO: Need to change reference to $wgLang to $wgContLang at proper
317 # places, including namespaces, dates in signatures, magic words,
320 # TODO: Need to look at the issue of input/output encoding
324 wfProfileIn( $fname.'-OutputPage' );
326 $wgOut = new OutputPage();
329 wfProfileOut( $fname.'-OutputPage' );
330 wfProfileIn( $fname.'-DateFormatter' );
332 if ( $wgUseDynamicDates ) {
333 require_once( 'DateFormatter.php' );
334 global $wgDateFormatter;
335 $wgDateFormatter = new DateFormatter
;
338 wfProfileOut( $fname.'-DateFormatter' );
339 wfProfileIn( $fname.'-BlockCache' );
341 $wgBlockCache = new BlockCache( true );
343 wfProfileOut( $fname.'-BlockCache' );
344 wfProfileIn( $fname.'-misc2' );
346 $wgDeferredUpdateList = array();
347 $wgLinkCache = new LinkCache();
348 $wgMagicWords = array();
349 $wgMwRedir =& MagicWord
::get( MAG_REDIRECT
);
350 $wgParserCache = new ParserCache( $messageMemc );
352 if ( $wgUseXMLparser ) $wgParser = new ParserXML();
353 else $wgParser = new Parser();
354 $wgOut->setParserOptions( ParserOptions
::newFromUser( $wgUser ) );
355 $wgMsgParserOptions = ParserOptions
::newFromUser($wgUser);
358 # Placeholders in case of DB error
359 $wgTitle = Title
::newFromText( wfMsgForContent( 'badtitle' ) );
360 $wgArticle = new Article($wgTitle);
362 wfProfileOut( $fname.'-misc2' );
363 wfProfileIn( $fname.'-extensions' );
365 # Extension setup functions for extensions other than skins
366 # Entries should be added to this variable during the inclusion
367 # of the extension file. This allows the extension to perform
368 # any necessary initialisation in the fully initialised environment
369 foreach ( $wgExtensionFunctions as $func ) {
373 $wgFullyInitialised = true;
374 wfProfileOut( $fname.'-extensions' );
375 wfProfileOut( $fname );