2ef0b4758d82def23f901fb01bc0580f2e37724c
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 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 ) );
264 if($wgLangClass == $wgContLangClass) {
265 $wgLang = &$wgContLang;
268 include_once("languages/$wgLangClass.php");
269 $wgLang = setupLangObj($wgLangClass, $wgLanguageCode);
273 wfProfileOut( $fname.'-language' );
274 wfProfileIn( $fname.'-MessageCache' );
276 $wgContMessageCache = new MessageCache
;
277 $wgContMessageCache->initialise( $messageMemc, $wgUseDatabaseMessages, $wgMsgCacheExpiry, $wgDBname, $wgContLang, $wgContLanguageCode );
278 if($wgLangClass == $wgContLangClass) {
279 $wgMessageCache = &$wgContMessageCache;
282 $wgMessageCache = new MessageCache
;
283 $wgMessageCache->initialise( $messageMemc,false , $wgMsgCacheExpiry, $wgDBname.":$wgLangClass", $wgLang, $wgLanguageCode);
286 wfProfileOut( $fname.'-MessageCache' );
289 # I guess the warning about UI switching might still apply...
291 # FIXME: THE ABOVE MIGHT BREAK NAMESPACES, VARIABLES,
292 # SEARCH INDEX UPDATES, AND MANY MANY THINGS.
293 # DO NOT USE THIS MODE EXCEPT FOR TESTING RIGHT NOW.
295 # To disable it, the easiest thing could be to uncomment the
296 # following; they should effectively disable the UI switch functionality
298 # $wgLangClass = $wgContLangClass;
299 # $wgLanguageCode = $wgContLanguageCode;
300 # $wgLang = $wgContLang;
301 # $wgMessageCache = $wgContMessageCache;
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();
336 # Placeholders in case of DB error
337 $wgTitle = Title
::newFromText( wfMsgForContent( 'badtitle' ) );
338 $wgArticle = new Article($wgTitle);
340 wfProfileOut( $fname.'-misc2' );
341 wfProfileIn( $fname.'-extensions' );
343 # Extension setup functions
344 # Entries should be added to this variable during the inclusion
345 # of the extension file. This allows the extension to perform
346 # any necessary initialisation in the fully initialised environment
347 foreach ( $wgExtensionFunctions as $func ) {
351 $wgFullyInitialised = true;
352 wfProfileOut( $fname.'-extensions' );
353 wfProfileOut( $fname );