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, $wgContMessageCach;
84 global $wgMsgCacheExpiry, $wgCommandLineMode;
85 global $wgBlockCache, $wgParserCache, $wgParser, $wgDBConnections;
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 // FIXME : we don't know what the user entered (see SpecialPreferences.php [AV])
223 if( count( $wgUserLanguages ) &&
224 !empty( $wgUser->mOptions
['language'] ) &&
225 in_array( $wgUser->mOptions
['language'], $wgUserLanguages ) ) {
226 // Change language of the site
227 $wgUserLanguageCode = $wgUser->mOptions
['language'];
228 // we will load messages from file instead of from database
229 $wgUseDatabaseMessages = false;
230 # FIXME: THIS WILL BREAK NAMESPACES, VARIABLES,
231 # SEARCH INDEX UPDATES, AND MANY MANY THINGS.
232 # DO NOT USE THIS MODE EXCEPT FOR TESTING RIGHT NOW.
235 wfProfileOut( $fname.'-User' );
236 wfProfileIn( $fname.'-language' );
238 function setupLangObj($langclass, $langcode) {
242 if( ! class_exists( $langclass ) ||
($langcode == 'en' && !$wgUseLatin1) ) {
243 # Default to English/UTF-8
244 require_once( 'languages/LanguageUtf8.php' );
245 $langclass = 'LanguageUtf8';
248 $lang = new $langclass();
249 if ( !is_object($lang) ) {
250 print "No language class ($wgLang)\N";
253 if( $wgUseLatin1 && $langcode != 'en' ) {
254 # For non-UTF-8 non-English.
255 require_once( 'languages/LanguageLatin1.php' );
256 $xxx = new LanguageLatin1( $lang );
263 /* TODO: change the installation script so that
264 wgContLanguageCode is set there instead of here
266 require_once( 'languages/Language.php' );
267 $wgContLanguageCode = $wgLanguageCode;
268 $wgContLangClass = 'Language' . str_replace( '-', '_', ucfirst( $wgContLanguageCode ) );
269 $wgContLang = setupLangObj($wgContLangClass, $wgContLangClass);
271 // set default user option from content language
272 if(!$wgUser->mDataLoaded
) { $wgUser->loadDefaultFromLanguage(); }
274 // wgLanguageCode now specifically means the UI language
275 $wgLanguageCode = $wgUser->getOption('language');
277 $wgLangClass = 'Language'. str_replace( '-', '_', ucfirst( $wgLanguageCode ) );
278 if($wgLangClass == $wgContLangClass) {
279 $wgLang = &$wgContLang;
282 include_once("languages/$wgLangClass.php");
283 $wgLang = setupLangObj($wgLangClass, $wgLanguageCode);
287 wfProfileOut( $fname.'-language' );
288 wfProfileIn( $fname.'-MessageCache' );
290 $wgContMessageCache = new MessageCache
;
291 $wgContMessageCache->initialise( $messageMemc, $wgUseDatabaseMessages, $wgMsgCacheExpiry, $wgDBname, true );
292 if($wgLangClass == $wgContLangClass) {
293 $wgMessageCache = &$wgContMessageCache;
296 $wgMessageCache = new MessageCache
;
297 $wgMessageCache->initialise( $messageMemc,false , $wgMsgCacheExpiry, $wgDBname.":$wgLangClass", false);
300 wfProfileOut( $fname.'-MessageCache' );
301 wfProfileIn( $fname.'-OutputPage' );
303 $wgOut = new OutputPage();
306 wfProfileOut( $fname.'-OutputPage' );
307 wfProfileIn( $fname.'-DateFormatter' );
309 if ( $wgUseDynamicDates ) {
310 require_once( 'DateFormatter.php' );
311 global $wgDateFormatter;
312 $wgDateFormatter = new DateFormatter
;
315 wfProfileOut( $fname.'-DateFormatter' );
316 wfProfileIn( $fname.'-BlockCache' );
318 $wgBlockCache = new BlockCache( true );
320 wfProfileOut( $fname.'-BlockCache' );
321 wfProfileIn( $fname.'-misc2' );
323 $wgDeferredUpdateList = array();
324 $wgLinkCache = new LinkCache();
325 $wgMagicWords = array();
326 $wgMwRedir =& MagicWord
::get( MAG_REDIRECT
);
327 $wgParserCache = new ParserCache();
328 $wgParser = new Parser();
329 $wgOut->setParserOptions( ParserOptions
::newFromUser( $wgUser ) );
330 $wgDBConnections = array();
333 # Placeholders in case of DB error
334 $wgTitle = Title
::newFromText( wfMsgForContent( 'badtitle' ) );
335 $wgArticle = new Article($wgTitle);
337 wfProfileOut( $fname.'-misc2' );
338 wfProfileIn( $fname.'-extensions' );
340 # Extension setup functions
341 # Entries should be added to this variable during the inclusion
342 # of the extension file. This allows the extension to perform
343 # any necessary initialisation in the fully initialised environment
344 foreach ( $wgExtensionFunctions as $func ) {
348 $wgFullyInitialised = true;
349 wfProfileOut( $fname.'-extensions' );
350 wfProfileOut( $fname );