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;
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'];
52 wfProfileIn( $fname );
53 global $wgUseDynamicDates;
54 wfProfileIn( $fname.'-includes' );
56 require_once( 'GlobalFunctions.php' );
57 require_once( 'Namespace.php' );
58 require_once( 'RecentChange.php' );
59 require_once( 'User.php' );
60 require_once( 'Skin.php' );
61 require_once( 'OutputPage.php' );
62 require_once( 'LinkCache.php' );
63 require_once( 'Title.php' );
64 require_once( 'Article.php' );
65 require_once( 'MagicWord.php' );
66 require_once( 'Block.php' );
67 require_once( 'MessageCache.php' );
68 require_once( 'BlockCache.php' );
69 require_once( 'Parser.php' );
70 require_once( 'ParserCache.php' );
71 require_once( 'WebRequest.php' );
72 require_once( 'LoadBalancer.php' );
74 $wgRequest = new WebRequest();
78 wfProfileOut( $fname.'-includes' );
79 wfProfileIn( $fname.'-misc1' );
80 global $wgUser, $wgLang, $wgContLang, $wgOut, $wgTitle;
81 global $wgArticle, $wgDeferredUpdateList, $wgLinkCache;
82 global $wgMemc, $wgMagicWords, $wgMwRedir, $wgDebugLogFile;
83 global $wgMessageCache, $wgUseMemCached, $wgUseDatabaseMessages;
84 global $wgMsgCacheExpiry, $wgCommandLineMode;
85 global $wgBlockCache, $wgParserCache, $wgParser, $wgDBConnections, $wgMsgParserOptions;
86 global $wgLoadBalancer, $wgDBservers, $wgDebugDumpSql;
87 global $wgDBserver, $wgDBuser, $wgDBpassword, $wgDBname, $wgDBtype;
88 global $wgUseOldExistenceCheck, $wgEnablePersistentLC;
90 global $wgFullyInitialised;
93 if ( $wgCommandLineMode ) {
94 # wfDebug( '"' . implode( '" "', $argv ) . '"' );
95 } elseif ( function_exists( 'getallheaders' ) ) {
96 wfDebug( "\nStart request\n" );
97 wfDebug( $_SERVER['REQUEST_METHOD'] . ' ' . $_SERVER['REQUEST_URI'] . "\n" );
98 $headers = getallheaders();
99 foreach ($headers as $name => $value) {
100 wfDebug( "$name: $value\n" );
104 wfDebug( $_SERVER['REQUEST_METHOD'] . ' ' . $_SERVER['REQUEST_URI'] . "\n" );
107 # Disable linkscc except if the old existence check method is enabled
108 if (!$wgUseOldExistenceCheck) {
109 $wgEnablePersistentLC = false;
112 wfProfileOut( $fname.'-misc1' );
113 wfProfileIn( $fname.'-memcached' );
115 # FakeMemCachedClient imitates the API of memcached-client v. 0.1.2.
116 # It acts as a memcached server with no RAM, that is, all objects are
117 # cleared the moment they are set. All set operations succeed and all
118 # get operations return null.
120 if( $wgUseMemCached ) {
123 require_once( 'memcached-client.php' );
129 class MemCachedClientforWiki
extends memcached
{
130 function _debugprint( $text ) {
131 wfDebug( "memcached: $text\n" );
135 $wgMemc = new MemCachedClientforWiki( array('persistant' => true) );
136 $wgMemc->set_servers( $wgMemCachedServers );
137 $wgMemc->set_debug( $wgMemCachedDebug );
139 $messageMemc = &$wgMemc;
140 } elseif ( $wgUseTurckShm ) {
141 # Turck shared memory
143 require_once( 'ObjectCache.php' );
144 $wgMemc = new TurckBagOStuff
;
145 $messageMemc = &$wgMemc;
151 class FakeMemCachedClient
{
152 function add ($key, $val, $exp = 0) { return true; }
153 function decr ($key, $amt=1) { return null; }
154 function delete ($key, $time = 0) { return false; }
155 function disconnect_all () { }
156 function enable_compress ($enable) { }
157 function forget_dead_hosts () { }
158 function get ($key) { return null; }
159 function get_multi ($keys) { return array_pad(array(), count($keys), null); }
160 function incr ($key, $amt=1) { return null; }
161 function replace ($key, $value, $exp=0) { return false; }
162 function run_command ($sock, $cmd) { return null; }
163 function set ($key, $value, $exp=0){ return true; }
164 function set_compress_threshold ($thresh){ }
165 function set_debug ($dbg) { }
166 function set_servers ($list) { }
168 $wgMemc = new FakeMemCachedClient();
170 # Give the message cache a separate cache in the DB.
171 # This is a speedup over separately querying every message used
172 require_once( 'ObjectCache.php' );
173 $messageMemc = new MediaWikiBagOStuff('objectcache');
176 wfProfileOut( $fname.'-memcached' );
177 wfProfileIn( $fname.'-SetupSession' );
179 if( !$wgCommandLineMode && ( isset( $_COOKIE[ini_get('session.name')] ) ||
isset( $_COOKIE[$wgDBname.'Password'] ) ) ) {
180 User
::SetupSession();
181 $wgSessionStarted = true;
183 $wgSessionStarted = false;
186 wfProfileOut( $fname.'-SetupSession' );
187 wfProfileIn( $fname.'-database' );
189 if ( !$wgDBservers ) {
190 $wgDBservers = array(array(
191 'host' => $wgDBserver,
193 'password' => $wgDBpassword,
194 'dbname' => $wgDBname,
197 'flags' => ($wgDebugDumpSql ? DBO_DEBUG
: 0) | DBO_DEFAULT
200 $wgLoadBalancer = LoadBalancer
::newFromParams( $wgDBservers );
201 $wgLoadBalancer->loadMasterPos();
203 wfProfileOut( $fname.'-database' );
204 wfProfileIn( $fname.'-User' );
206 # Extension setup functions
207 # Entries should be added to this variable during the inclusion
208 # of the extension file. This allows the extension to perform
209 # any necessary initialisation in the fully initialised environment
210 foreach ( $wgSkinExtensionFunctions as $func ) {
214 if( $wgCommandLineMode ) {
215 # Used for some maintenance scripts; user session cookies can screw things up
216 # when the database is in an in-between state.
217 $wgUser = new User();
219 $wgUser = User
::loadFromSession();
222 wfProfileOut( $fname.'-User' );
223 wfProfileIn( $fname.'-language' );
225 function setupLangObj(&$langclass, $langcode) {
229 if( ! class_exists( $langclass ) ||
($langcode == 'en' && !$wgUseLatin1) ) {
230 # Default to English/UTF-8
231 require_once( 'languages/LanguageUtf8.php' );
232 $langclass = 'LanguageUtf8';
235 $lang = new $langclass();
236 if ( !is_object($lang) ) {
237 print "No language class ($wgLang)\N";
240 if( $wgUseLatin1 && $langcode != 'en' ) {
241 # For non-UTF-8 non-English.
242 require_once( 'languages/LanguageLatin1.php' );
243 $xxx = new LanguageLatin1( $lang );
250 require_once( 'languages/Language.php' );
252 $wgContLangClass = 'Language' . str_replace( '-', '_', ucfirst( $wgContLanguageCode ) );
254 $wgContLang = setupLangObj($wgContLangClass, $wgContLangClass);
255 $n = get_class($wgContLang);
257 // set default user option from content language
258 if(!$wgUser->mDataLoaded
) { $wgUser->loadDefaultFromLanguage(); }
260 // wgLanguageCode now specifically means the UI language
261 $wgLanguageCode = $wgUser->getOption('language');
263 $wgLangClass = 'Language'. str_replace( '-', '_', ucfirst( $wgLanguageCode ) );
265 if($wgLangClass == $wgContLangClass ) {
266 $wgLang = &$wgContLang;
269 include_once("languages/$wgLangClass.php");
270 $wgLang = setupLangObj($wgLangClass, $wgLanguageCode);
274 wfProfileOut( $fname.'-language' );
275 wfProfileIn( $fname.'-MessageCache' );
277 $wgMessageCache = new MessageCache
;
278 $wgMessageCache->initialise( $messageMemc, $wgUseDatabaseMessages, $wgMsgCacheExpiry, $wgDBname);
280 wfProfileOut( $fname.'-MessageCache' );
283 # I guess the warning about UI switching might still apply...
285 # FIXME: THE ABOVE MIGHT BREAK NAMESPACES, VARIABLES,
286 # SEARCH INDEX UPDATES, AND MANY MANY THINGS.
287 # DO NOT USE THIS MODE EXCEPT FOR TESTING RIGHT NOW.
289 # To disable it, the easiest thing could be to uncomment the
290 # following; they should effectively disable the UI switch functionality
292 # $wgLangClass = $wgContLangClass;
293 # $wgLanguageCode = $wgContLanguageCode;
294 # $wgLang = $wgContLang;
296 # TODO: Need to change reference to $wgLang to $wgContLang at proper
297 # places, including namespaces, dates in signatures, magic words,
300 # TODO: Need to look at the issue of input/output encoding
304 wfProfileIn( $fname.'-OutputPage' );
306 $wgOut = new OutputPage();
309 wfProfileOut( $fname.'-OutputPage' );
310 wfProfileIn( $fname.'-DateFormatter' );
312 if ( $wgUseDynamicDates ) {
313 require_once( 'DateFormatter.php' );
314 global $wgDateFormatter;
315 $wgDateFormatter = new DateFormatter
;
318 wfProfileOut( $fname.'-DateFormatter' );
319 wfProfileIn( $fname.'-BlockCache' );
321 $wgBlockCache = new BlockCache( true );
323 wfProfileOut( $fname.'-BlockCache' );
324 wfProfileIn( $fname.'-misc2' );
326 $wgDeferredUpdateList = array();
327 $wgLinkCache = new LinkCache();
328 $wgMagicWords = array();
329 $wgMwRedir =& MagicWord
::get( MAG_REDIRECT
);
330 $wgParserCache = new ParserCache();
331 $wgParser = new Parser();
332 $wgOut->setParserOptions( ParserOptions
::newFromUser( $wgUser ) );
333 $wgDBConnections = array();
334 $wgMsgParserOptions = ParserOptions
::newFromUser($wgUser);
337 # Placeholders in case of DB error
338 $wgTitle = Title
::newFromText( wfMsgForContent( 'badtitle' ) );
339 $wgArticle = new Article($wgTitle);
341 wfProfileOut( $fname.'-misc2' );
342 wfProfileIn( $fname.'-extensions' );
344 # Extension setup functions
345 # Entries should be added to this variable during the inclusion
346 # of the extension file. This allows the extension to perform
347 # any necessary initialisation in the fully initialised environment
348 foreach ( $wgExtensionFunctions as $func ) {
352 $wgFullyInitialised = true;
353 wfProfileOut( $fname.'-extensions' );
354 wfProfileOut( $fname );