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));
44 $wgIP = $_SERVER['REMOTE_ADDR'];
49 wfProfileIn( $fname );
50 global $wgUseDynamicDates;
51 wfProfileIn( $fname.'-includes' );
53 require_once( 'GlobalFunctions.php' );
54 require_once( 'Namespace.php' );
55 require_once( 'RecentChange.php' );
56 require_once( 'User.php' );
57 require_once( 'Skin.php' );
58 require_once( 'OutputPage.php' );
59 require_once( 'LinkCache.php' );
60 require_once( 'Title.php' );
61 require_once( 'Article.php' );
62 require_once( 'MagicWord.php' );
63 require_once( 'Block.php' );
64 require_once( 'MessageCache.php' );
65 require_once( 'BlockCache.php' );
66 require_once( 'Parser.php' );
67 require_once( 'ParserCache.php' );
68 require_once( 'WebRequest.php' );
69 require_once( 'LoadBalancer.php' );
71 $wgRequest = new WebRequest();
75 wfProfileOut( $fname.'-includes' );
76 wfProfileIn( $fname.'-misc1' );
77 global $wgUser, $wgLang, $wgContLang, $wgOut, $wgTitle;
78 global $wgArticle, $wgDeferredUpdateList, $wgLinkCache;
79 global $wgMemc, $wgMagicWords, $wgMwRedir, $wgDebugLogFile;
80 global $wgMessageCache, $wgUseMemCached, $wgUseDatabaseMessages, $wgContMessageCach;
81 global $wgMsgCacheExpiry, $wgCommandLineMode;
82 global $wgBlockCache, $wgParserCache, $wgParser, $wgDBConnections;
83 global $wgLoadBalancer, $wgDBservers, $wgDebugDumpSql;
84 global $wgDBserver, $wgDBuser, $wgDBpassword, $wgDBname, $wgDBtype;
85 global $wgUseOldExistenceCheck, $wgEnablePersistentLC;
87 global $wgFullyInitialised;
90 if ( $wgCommandLineMode ) {
91 # wfDebug( '"' . implode( '" "', $argv ) . '"' );
92 } elseif ( function_exists( 'getallheaders' ) ) {
93 wfDebug( "\nStart request\n" );
94 wfDebug( $_SERVER['REQUEST_METHOD'] . ' ' . $_SERVER['REQUEST_URI'] . "\n" );
95 $headers = getallheaders();
96 foreach ($headers as $name => $value) {
97 wfDebug( "$name: $value\n" );
101 wfDebug( $_SERVER['REQUEST_METHOD'] . ' ' . $_SERVER['REQUEST_URI'] . "\n" );
104 # Disable linkscc except if the old existence check method is enabled
105 if (!$wgUseOldExistenceCheck) {
106 $wgEnablePersistentLC = false;
109 wfProfileOut( $fname.'-misc1' );
110 wfProfileIn( $fname.'-memcached' );
112 # FakeMemCachedClient imitates the API of memcached-client v. 0.1.2.
113 # It acts as a memcached server with no RAM, that is, all objects are
114 # cleared the moment they are set. All set operations succeed and all
115 # get operations return null.
117 if( $wgUseMemCached ) {
120 require_once( 'memcached-client.php' );
126 class MemCachedClientforWiki
extends memcached
{
127 function _debugprint( $text ) {
128 wfDebug( "memcached: $text\n" );
132 $wgMemc = new MemCachedClientforWiki( array('persistant' => true) );
133 $wgMemc->set_servers( $wgMemCachedServers );
134 $wgMemc->set_debug( $wgMemCachedDebug );
136 $messageMemc = &$wgMemc;
137 } elseif ( $wgUseTurckShm ) {
138 # Turck shared memory
140 require_once( 'ObjectCache.php' );
141 $wgMemc = new TurckBagOStuff
;
142 $messageMemc = &$wgMemc;
148 class FakeMemCachedClient
{
149 function add ($key, $val, $exp = 0) { return true; }
150 function decr ($key, $amt=1) { return null; }
151 function delete ($key, $time = 0) { return false; }
152 function disconnect_all () { }
153 function enable_compress ($enable) { }
154 function forget_dead_hosts () { }
155 function get ($key) { return null; }
156 function get_multi ($keys) { return array_pad(array(), count($keys), null); }
157 function incr ($key, $amt=1) { return null; }
158 function replace ($key, $value, $exp=0) { return false; }
159 function run_command ($sock, $cmd) { return null; }
160 function set ($key, $value, $exp=0){ return true; }
161 function set_compress_threshold ($thresh){ }
162 function set_debug ($dbg) { }
163 function set_servers ($list) { }
165 $wgMemc = new FakeMemCachedClient();
167 # Give the message cache a separate cache in the DB.
168 # This is a speedup over separately querying every message used
169 require_once( 'ObjectCache.php' );
170 $messageMemc = new MediaWikiBagOStuff('objectcache');
173 wfProfileOut( $fname.'-memcached' );
174 wfProfileIn( $fname.'-SetupSession' );
176 if( !$wgCommandLineMode && ( isset( $_COOKIE[ini_get('session.name')] ) ||
isset( $_COOKIE[$wgDBname.'Password'] ) ) ) {
177 User
::SetupSession();
178 $wgSessionStarted = true;
180 $wgSessionStarted = false;
183 wfProfileOut( $fname.'-SetupSession' );
184 wfProfileIn( $fname.'-database' );
186 if ( !$wgDBservers ) {
187 $wgDBservers = array(array(
188 'host' => $wgDBserver,
190 'password' => $wgDBpassword,
191 'dbname' => $wgDBname,
194 'flags' => ($wgDebugDumpSql ? DBO_DEBUG
: 0) | DBO_DEFAULT
197 $wgLoadBalancer = LoadBalancer
::newFromParams( $wgDBservers );
198 $wgLoadBalancer->loadMasterPos();
200 wfProfileOut( $fname.'-database' );
201 wfProfileIn( $fname.'-User' );
203 # Extension setup functions
204 # Entries should be added to this variable during the inclusion
205 # of the extension file. This allows the extension to perform
206 # any necessary initialisation in the fully initialised environment
207 foreach ( $wgSkinExtensionFunctions as $func ) {
211 if( $wgCommandLineMode ) {
212 # Used for some maintenance scripts; user session cookies can screw things up
213 # when the database is in an in-between state.
214 $wgUser = new User();
216 $wgUser = User
::loadFromSession();
219 // FIXME : we don't know what the user entered (see SpecialPreferences.php [AV])
220 if( count( $wgUserLanguages ) &&
221 !empty( $wgUser->mOptions
['language'] ) &&
222 in_array( $wgUser->mOptions
['language'], $wgUserLanguages ) ) {
223 // Change language of the site
224 $wgUserLanguageCode = $wgUser->mOptions
['language'];
225 // we will load messages from file instead of from database
226 $wgUseDatabaseMessages = false;
227 # FIXME: THIS WILL BREAK NAMESPACES, VARIABLES,
228 # SEARCH INDEX UPDATES, AND MANY MANY THINGS.
229 # DO NOT USE THIS MODE EXCEPT FOR TESTING RIGHT NOW.
232 wfProfileOut( $fname.'-User' );
233 wfProfileIn( $fname.'-language' );
235 function setupLangObj($langclass, $langcode) {
239 if( ! class_exists( $langclass ) ||
($langcode == 'en' && !$wgUseLatin1) ) {
240 # Default to English/UTF-8
241 require_once( 'languages/LanguageUtf8.php' );
242 $langclass = 'LanguageUtf8';
245 $lang = new $langclass();
246 if ( !is_object($lang) ) {
247 print "No language class ($wgLang)\N";
250 if( $wgUseLatin1 && $langcode != 'en' ) {
251 # For non-UTF-8 non-English.
252 require_once( 'languages/LanguageLatin1.php' );
253 $xxx = new LanguageLatin1( $lang );
260 /* TODO: change the installation script so that
261 wgContLanguageCode is set there instead of here
263 require_once( 'languages/Language.php' );
264 $wgContLanguageCode = $wgLanguageCode;
265 $wgContLangClass = 'Language' . str_replace( '-', '_', ucfirst( $wgContLanguageCode ) );
266 $wgContLang = setupLangObj(&$wgContLangClass, $wgContLangClass);
268 // set default user option from content language
269 if(!$wgUser->mDataLoaded
) { $wgUser->loadDefaultFromLanguage(); }
271 // wgLanguageCode now specifically means the UI language
272 $wgLanguageCode = $wgUser->getOption('language');
274 $wgLangClass = 'Language'. str_replace( '-', '_', ucfirst( $wgLanguageCode ) );
275 if($wgLangClass == $wgContLangClass) {
276 $wgLang = &$wgContLang;
279 include_once("languages/$wgLangClass.php");
280 $wgLang = setupLangObj(&$wgLangClass, $wgLanguageCode);
284 wfProfileOut( $fname.'-language' );
285 wfProfileIn( $fname.'-MessageCache' );
287 $wgContMessageCache = new MessageCache
;
288 $wgContMessageCache->initialise( $messageMemc, $wgUseDatabaseMessages, $wgMsgCacheExpiry, $wgDBname, true );
289 if($wgLangClass == $wgContLangClass) {
290 $wgMessageCache = &$wgContMessageCache;
293 $wgMessageCache = new MessageCache
;
294 $wgMessageCache->initialise( $messageMemc,false , $wgMsgCacheExpiry, $wgDBname.":$wgLangClass", false);
297 wfProfileOut( $fname.'-MessageCache' );
298 wfProfileIn( $fname.'-OutputPage' );
300 $wgOut = new OutputPage();
303 wfProfileOut( $fname.'-OutputPage' );
304 wfProfileIn( $fname.'-DateFormatter' );
306 if ( $wgUseDynamicDates ) {
307 require_once( 'DateFormatter.php' );
308 global $wgDateFormatter;
309 $wgDateFormatter = new DateFormatter
;
312 wfProfileOut( $fname.'-DateFormatter' );
313 wfProfileIn( $fname.'-BlockCache' );
315 $wgBlockCache = new BlockCache( true );
317 wfProfileOut( $fname.'-BlockCache' );
318 wfProfileIn( $fname.'-misc2' );
320 $wgDeferredUpdateList = array();
321 $wgLinkCache = new LinkCache();
322 $wgMagicWords = array();
323 $wgMwRedir =& MagicWord
::get( MAG_REDIRECT
);
324 $wgParserCache = new ParserCache();
325 $wgParser = new Parser();
326 $wgOut->setParserOptions( ParserOptions
::newFromUser( $wgUser ) );
327 $wgDBConnections = array();
330 # Placeholders in case of DB error
331 $wgTitle = Title
::newFromText( wfMsgForContent( 'badtitle' ) );
332 $wgArticle = new Article($wgTitle);
334 wfProfileOut( $fname.'-misc2' );
335 wfProfileIn( $fname.'-extensions' );
337 # Extension setup functions
338 # Entries should be added to this variable during the inclusion
339 # of the extension file. This allows the extension to perform
340 # any necessary initialisation in the fully initialised environment
341 foreach ( $wgExtensionFunctions as $func ) {
345 $wgFullyInitialised = true;
346 wfProfileOut( $fname.'-extensions' );
347 wfProfileOut( $fname );