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, $IP;
21 if( !isset( $wgProfiling ) )
24 if ( $wgProfiling and (0 == rand() %
$wgProfileSampleRate ) ) {
25 require_once( 'Profiling.php' );
27 function wfProfileIn( $fn = '' ) {
28 global $hackwhere, $wgDBname;
30 if (function_exists("setproctitle"))
31 setproctitle($fn . " [$wgDBname]");
33 function wfProfileOut( $fn = '' ) {
34 global $hackwhere, $wgDBname;
35 if (count($hackwhere))
36 array_pop($hackwhere);
37 if (function_exists("setproctitle") && count($hackwhere))
38 setproctitle($hackwhere[count($hackwhere)-1] . " [$wgDBname]");
40 function wfGetProfilingOutput( $s, $e ) {}
41 function wfProfileClose() {}
45 wfProfileIn( $fname );
46 global $wgUseDynamicDates;
47 wfProfileIn( $fname.'-includes' );
49 require_once( 'GlobalFunctions.php' );
50 require_once( 'Hooks.php' );
51 require_once( 'Namespace.php' );
52 require_once( 'RecentChange.php' );
53 require_once( 'User.php' );
54 require_once( 'Skin.php' );
55 require_once( 'OutputPage.php' );
56 require_once( 'LinkCache.php' );
57 require_once( 'Title.php' );
58 require_once( 'Article.php' );
59 require_once( 'MagicWord.php' );
60 require_once( 'Block.php' );
61 require_once( 'MessageCache.php' );
62 require_once( 'BlockCache.php' );
63 require_once( 'Parser.php' );
64 require_once( 'Parser.php' );
65 require_once( 'ParserCache.php' );
66 require_once( 'WebRequest.php' );
67 require_once( 'LoadBalancer.php' );
68 require_once( 'HistoryBlob.php' );
70 wfProfileOut( $fname.'-includes' );
71 wfProfileIn( $fname.'-misc1' );
72 global $wgUser, $wgLang, $wgContLang, $wgOut, $wgTitle;
73 global $wgLangClass, $wgContLangClass;
74 global $wgArticle, $wgDeferredUpdateList, $wgLinkCache;
75 global $wgMemc, $wgMagicWords, $wgMwRedir, $wgDebugLogFile;
76 global $wgMessageCache, $wgUseMemCached, $wgUseDatabaseMessages;
77 global $wgMsgCacheExpiry, $wgCommandLineMode;
78 global $wgBlockCache, $wgParserCache, $wgParser, $wgMsgParserOptions;
79 global $wgLoadBalancer, $wgDBservers, $wgDebugDumpSql;
80 global $wgDBserver, $wgDBuser, $wgDBpassword, $wgDBname, $wgDBtype;
81 global $wgUseOldExistenceCheck, $wgEnablePersistentLC, $wgMasterWaitTimeout;
83 global $wgFullyInitialised;
86 $wgRequest = new WebRequest();
89 if ( $wgCommandLineMode ) {
90 # wfDebug( '"' . implode( '" "', $argv ) . '"' );
91 } elseif ( function_exists( 'getallheaders' ) ) {
92 wfDebug( "\nStart request\n" );
93 wfDebug( $_SERVER['REQUEST_METHOD'] . ' ' . $_SERVER['REQUEST_URI'] . "\n" );
94 $headers = getallheaders();
95 foreach ($headers as $name => $value) {
96 wfDebug( "$name: $value\n" );
99 } elseif( isset( $_SERVER['REQUEST_URI'] ) ) {
100 wfDebug( $_SERVER['REQUEST_METHOD'] . ' ' . $_SERVER['REQUEST_URI'] . "\n" );
103 # Disable linkscc except if the old existence check method is enabled
104 if (!$wgUseOldExistenceCheck) {
105 $wgEnablePersistentLC = false;
108 wfProfileOut( $fname.'-misc1' );
109 wfProfileIn( $fname.'-memcached' );
111 # FakeMemCachedClient imitates the API of memcached-client v. 0.1.2.
112 # It acts as a memcached server with no RAM, that is, all objects are
113 # cleared the moment they are set. All set operations succeed and all
114 # get operations return null.
116 if( $wgUseMemCached ) {
119 require_once( 'memcached-client.php' );
125 class MemCachedClientforWiki
extends memcached
{
126 function _debugprint( $text ) {
127 wfDebug( "memcached: $text\n" );
131 $wgMemc = new MemCachedClientforWiki( array('persistant' => true, 'compress_threshold' => 1500 ) );
132 $wgMemc->set_servers( $wgMemCachedServers );
133 $wgMemc->set_debug( $wgMemCachedDebug );
135 $messageMemc = &$wgMemc;
136 } elseif ( $wgUseTurckShm ) {
137 # Turck shared memory
139 require_once( 'ObjectCache.php' );
140 $wgMemc = new TurckBagOStuff
;
141 $messageMemc = &$wgMemc;
142 } elseif ( $wgUseEAccelShm ) {
143 # eAccelerator shared memory
145 require_once( 'ObjectCache.php' );
146 $wgMemc = new eAccelBagOStuff
;
147 $messageMemc = &$wgMemc;
153 class FakeMemCachedClient
{
154 function add ($key, $val, $exp = 0) { return true; }
155 function decr ($key, $amt=1) { return null; }
156 function delete ($key, $time = 0) { return false; }
157 function disconnect_all () { }
158 function enable_compress ($enable) { }
159 function forget_dead_hosts () { }
160 function get ($key) { return null; }
161 function get_multi ($keys) { return array_pad(array(), count($keys), null); }
162 function incr ($key, $amt=1) { return null; }
163 function replace ($key, $value, $exp=0) { return false; }
164 function run_command ($sock, $cmd) { return null; }
165 function set ($key, $value, $exp=0){ return true; }
166 function set_compress_threshold ($thresh){ }
167 function set_debug ($dbg) { }
168 function set_servers ($list) { }
170 $wgMemc = new FakeMemCachedClient();
172 # Give the message cache a separate cache in the DB.
173 # This is a speedup over separately querying every message used
174 require_once( 'ObjectCache.php' );
175 $messageMemc = new MediaWikiBagOStuff('objectcache');
178 wfProfileOut( $fname.'-memcached' );
179 wfProfileIn( $fname.'-SetupSession' );
181 if( !$wgCommandLineMode && ( isset( $_COOKIE[ini_get('session.name')] ) ||
isset( $_COOKIE[$wgDBname.'Token'] ) ) ) {
182 User
::SetupSession();
183 $wgSessionStarted = true;
185 $wgSessionStarted = false;
188 wfProfileOut( $fname.'-SetupSession' );
189 wfProfileIn( $fname.'-database' );
191 if ( !$wgDBservers ) {
192 $wgDBservers = array(array(
193 'host' => $wgDBserver,
195 'password' => $wgDBpassword,
196 'dbname' => $wgDBname,
199 'flags' => ($wgDebugDumpSql ? DBO_DEBUG
: 0) | DBO_DEFAULT
202 $wgLoadBalancer = LoadBalancer
::newFromParams( $wgDBservers, false, $wgMasterWaitTimeout );
203 $wgLoadBalancer->loadMasterPos();
205 wfProfileOut( $fname.'-database' );
206 wfProfileIn( $fname.'-language1' );
208 require_once( "$IP/languages/Language.php" );
210 wfProfileOut( $fname.'-language1' );
211 wfProfileIn( $fname.'-User' );
213 # Skin setup functions
214 # Entries can be added to this variable during the inclusion
215 # of the extension file. Skins can then perform any necessary initialisation.
216 foreach ( $wgSkinExtensionFunctions as $func ) {
220 if( !is_object( $wgAuth ) ) {
221 require_once( 'AuthPlugin.php' );
222 $wgAuth = new AuthPlugin();
225 if( $wgCommandLineMode ) {
226 # Used for some maintenance scripts; user session cookies can screw things up
227 # when the database is in an in-between state.
228 $wgUser = new User();
229 # Prevent loading User settings from the DB.
230 $wgUser->setLoaded( true );
232 $wgUser = User
::loadFromSession();
235 wfProfileOut( $fname.'-User' );
236 wfProfileIn( $fname.'-language2' );
238 function setupLangObj(&$langclass) {
241 if( ! class_exists( $langclass ) ) {
242 # Default to English/UTF-8
243 $baseclass = 'LanguageUtf8';
244 require_once( "$IP/languages/$baseclass.php" );
245 $lc = strtolower(substr($langclass, 8));
247 class $langclass extends $baseclass {
248 function getVariants() {
249 return array(\"$lc\");
256 $lang = new $langclass();
261 # $wgLanguageCode may be changed later to fit with user preference.
262 # The content language will remain fixed as per the configuration,
264 $wgContLanguageCode = $wgLanguageCode;
265 $wgContLangClass = 'Language' . str_replace( '-', '_', ucfirst( $wgContLanguageCode ) );
267 $wgContLang = setupLangObj( $wgContLangClass );
268 $wgContLang->initEncoding();
270 // set default user option from content language
271 if( !$wgUser->mDataLoaded
) {
272 $wgUser->loadDefaultFromLanguage();
275 // wgLanguageCode now specifically means the UI language
276 $wgLanguageCode = $wgUser->getOption('language');
277 # Validate $wgLanguageCode, which will soon be sent to an eval()
278 if( empty( $wgLanguageCode ) ||
!preg_match( '/^[a-z\-]*$/', $wgLanguageCode ) ) {
279 $wgLanguageCode = $wgContLanguageCode;
282 $wgLangClass = 'Language'. str_replace( '-', '_', ucfirst( $wgLanguageCode ) );
284 if( $wgLangClass == $wgContLangClass ) {
285 $wgLang = &$wgContLang;
287 wfSuppressWarnings();
288 include_once("$IP/languages/$wgLangClass.php");
291 $wgLang = setupLangObj( $wgLangClass );
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 $wgPostCommitUpdateList = array();
349 $wgLinkCache = new LinkCache();
350 $wgMagicWords = array();
351 $wgMwRedir =& MagicWord
::get( MAG_REDIRECT
);
352 $wgParserCache = new ParserCache( $messageMemc );
354 if ( $wgUseXMLparser ) {
355 require_once( 'ParserXML.php' );
356 $wgParser = new ParserXML();
358 $wgParser = new Parser();
360 $wgOut->setParserOptions( ParserOptions
::newFromUser( $wgUser ) );
361 $wgMsgParserOptions = ParserOptions
::newFromUser($wgUser);
364 # Placeholders in case of DB error
365 $wgTitle = Title
::makeTitle( NS_SPECIAL
, 'Error' );
366 $wgArticle = new Article($wgTitle);
368 wfProfileOut( $fname.'-misc2' );
369 wfProfileIn( $fname.'-extensions' );
371 # Extension setup functions for extensions other than skins
372 # Entries should be added to this variable during the inclusion
373 # of the extension file. This allows the extension to perform
374 # any necessary initialisation in the fully initialised environment
375 foreach ( $wgExtensionFunctions as $func ) {
379 $wgFullyInitialised = true;
380 wfProfileOut( $fname.'-extensions' );
381 wfProfileOut( $fname );