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, $IP;
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'];
51 $wgExtraNamespaces[20] = 'Data' ;
52 $wgExtraNamespaces[21] = 'Data_talk' ;
56 wfProfileIn( $fname );
57 global $wgUseDynamicDates;
58 wfProfileIn( $fname.'-includes' );
60 require_once( 'GlobalFunctions.php' );
61 require_once( 'Namespace.php' );
62 require_once( 'RecentChange.php' );
63 require_once( 'User.php' );
64 require_once( 'Skin.php' );
65 require_once( 'OutputPage.php' );
66 require_once( 'LinkCache.php' );
67 require_once( 'Title.php' );
68 require_once( 'Article.php' );
69 require_once( 'MagicWord.php' );
70 require_once( 'Block.php' );
71 require_once( 'MessageCache.php' );
72 require_once( 'BlockCache.php' );
73 require_once( 'Parser.php' );
74 require_once( 'ParserCache.php' );
75 require_once( 'WebRequest.php' );
76 require_once( 'LoadBalancer.php' );
77 require_once( 'HistoryBlob.php' );
79 $wgRequest = new WebRequest();
83 wfProfileOut( $fname.'-includes' );
84 wfProfileIn( $fname.'-misc1' );
85 global $wgUser, $wgLang, $wgContLang, $wgOut, $wgTitle;
86 global $wgLangClass, $wgContLangClass;
87 global $wgArticle, $wgDeferredUpdateList, $wgLinkCache;
88 global $wgMemc, $wgMagicWords, $wgMwRedir, $wgDebugLogFile;
89 global $wgMessageCache, $wgUseMemCached, $wgUseDatabaseMessages;
90 global $wgMsgCacheExpiry, $wgCommandLineMode;
91 global $wgBlockCache, $wgParserCache, $wgParser, $wgMsgParserOptions;
92 global $wgLoadBalancer, $wgDBservers, $wgDebugDumpSql;
93 global $wgDBserver, $wgDBuser, $wgDBpassword, $wgDBname, $wgDBtype;
94 global $wgUseOldExistenceCheck, $wgEnablePersistentLC;
96 global $wgFullyInitialised;
99 if ( $wgCommandLineMode ) {
100 # wfDebug( '"' . implode( '" "', $argv ) . '"' );
101 } elseif ( function_exists( 'getallheaders' ) ) {
102 wfDebug( "\nStart request\n" );
103 wfDebug( $_SERVER['REQUEST_METHOD'] . ' ' . $_SERVER['REQUEST_URI'] . "\n" );
104 $headers = getallheaders();
105 foreach ($headers as $name => $value) {
106 wfDebug( "$name: $value\n" );
110 wfDebug( $_SERVER['REQUEST_METHOD'] . ' ' . $_SERVER['REQUEST_URI'] . "\n" );
113 # Disable linkscc except if the old existence check method is enabled
114 if (!$wgUseOldExistenceCheck) {
115 $wgEnablePersistentLC = false;
118 wfProfileOut( $fname.'-misc1' );
119 wfProfileIn( $fname.'-memcached' );
121 # FakeMemCachedClient imitates the API of memcached-client v. 0.1.2.
122 # It acts as a memcached server with no RAM, that is, all objects are
123 # cleared the moment they are set. All set operations succeed and all
124 # get operations return null.
126 if( $wgUseMemCached ) {
129 require_once( 'memcached-client.php' );
135 class MemCachedClientforWiki
extends memcached
{
136 function _debugprint( $text ) {
137 wfDebug( "memcached: $text\n" );
141 $wgMemc = new MemCachedClientforWiki( array('persistant' => true) );
142 $wgMemc->set_servers( $wgMemCachedServers );
143 $wgMemc->set_debug( $wgMemCachedDebug );
145 $messageMemc = &$wgMemc;
146 } elseif ( $wgUseTurckShm ) {
147 # Turck shared memory
149 require_once( 'ObjectCache.php' );
150 $wgMemc = new TurckBagOStuff
;
151 $messageMemc = &$wgMemc;
157 class FakeMemCachedClient
{
158 function add ($key, $val, $exp = 0) { return true; }
159 function decr ($key, $amt=1) { return null; }
160 function delete ($key, $time = 0) { return false; }
161 function disconnect_all () { }
162 function enable_compress ($enable) { }
163 function forget_dead_hosts () { }
164 function get ($key) { return null; }
165 function get_multi ($keys) { return array_pad(array(), count($keys), null); }
166 function incr ($key, $amt=1) { return null; }
167 function replace ($key, $value, $exp=0) { return false; }
168 function run_command ($sock, $cmd) { return null; }
169 function set ($key, $value, $exp=0){ return true; }
170 function set_compress_threshold ($thresh){ }
171 function set_debug ($dbg) { }
172 function set_servers ($list) { }
174 $wgMemc = new FakeMemCachedClient();
176 # Give the message cache a separate cache in the DB.
177 # This is a speedup over separately querying every message used
178 require_once( 'ObjectCache.php' );
179 $messageMemc = new MediaWikiBagOStuff('objectcache');
182 wfProfileOut( $fname.'-memcached' );
183 wfProfileIn( $fname.'-SetupSession' );
185 if( !$wgCommandLineMode && ( isset( $_COOKIE[ini_get('session.name')] ) ||
isset( $_COOKIE[$wgDBname.'Password'] ) ) ) {
186 User
::SetupSession();
187 $wgSessionStarted = true;
189 $wgSessionStarted = false;
192 wfProfileOut( $fname.'-SetupSession' );
193 wfProfileIn( $fname.'-database' );
195 if ( !$wgDBservers ) {
196 $wgDBservers = array(array(
197 'host' => $wgDBserver,
199 'password' => $wgDBpassword,
200 'dbname' => $wgDBname,
203 'flags' => ($wgDebugDumpSql ? DBO_DEBUG
: 0) | DBO_DEFAULT
206 $wgLoadBalancer = LoadBalancer
::newFromParams( $wgDBservers );
207 $wgLoadBalancer->loadMasterPos();
209 wfProfileOut( $fname.'-database' );
210 wfProfileIn( $fname.'-User' );
212 # Skin setup functions
213 # Entries can be added to this variable during the inclusion
214 # of the extension file. Skins can then perform any necessary initialisation.
215 foreach ( $wgSkinExtensionFunctions as $func ) {
219 if( $wgCommandLineMode ) {
220 # Used for some maintenance scripts; user session cookies can screw things up
221 # when the database is in an in-between state.
222 $wgUser = new User();
224 $wgUser = User
::loadFromSession();
227 wfProfileOut( $fname.'-User' );
228 wfProfileIn( $fname.'-language' );
230 function setupLangObj(&$langclass, $langcode) {
231 global $wgUseLatin1, $IP;
234 if( ! class_exists( $langclass ) ) {
235 # Default to English/UTF-8
236 require_once( "$IP/languages/LanguageUtf8.php" );
237 $langclass = 'LanguageUtf8';
240 $lang = new $langclass();
241 if ( !is_object($lang) ) {
242 print "No language class ($wgLang)\N";
246 # For non-UTF-8 latin-1 downconversion
247 require_once( "$IP/languages/LanguageLatin1.php" );
248 $xxx = new LanguageLatin1( $lang );
255 require_once( "$IP/languages/Language.php" );
257 # $wgLanguageCode may be changed later to fit with user preference.
258 # The content language will remain fixed as per the configuration,
260 $wgContLanguageCode = $wgLanguageCode;
261 $wgContLangClass = 'Language' . str_replace( '-', '_', ucfirst( $wgContLanguageCode ) );
263 $wgContLang = setupLangObj( $wgContLangClass, $wgContLangClass );
264 $n = get_class($wgContLang);
266 // set default user option from content language
267 if( !$wgUser->mDataLoaded
) {
268 $wgUser->loadDefaultFromLanguage();
271 // wgLanguageCode now specifically means the UI language
272 $wgLanguageCode = $wgUser->getOption('language');
274 $wgLangClass = 'Language'. str_replace( '-', '_', ucfirst( $wgLanguageCode ) );
276 if( $wgLangClass == $wgContLangClass ) {
277 $wgLang = &$wgContLang;
279 require_once("$IP/languages/$wgLangClass.php");
280 $wgLang = setupLangObj( $wgLangClass, $wgLanguageCode );
284 wfProfileOut( $fname.'-language' );
285 wfProfileIn( $fname.'-MessageCache' );
287 $wgMessageCache = new MessageCache
;
288 $wgMessageCache->initialise( $messageMemc, $wgUseDatabaseMessages, $wgMsgCacheExpiry, $wgDBname);
290 wfProfileOut( $fname.'-MessageCache' );
293 # I guess the warning about UI switching might still apply...
295 # FIXME: THE ABOVE MIGHT BREAK NAMESPACES, VARIABLES,
296 # SEARCH INDEX UPDATES, AND MANY MANY THINGS.
297 # DO NOT USE THIS MODE EXCEPT FOR TESTING RIGHT NOW.
299 # To disable it, the easiest thing could be to uncomment the
300 # following; they should effectively disable the UI switch functionality
302 # $wgLangClass = $wgContLangClass;
303 # $wgLanguageCode = $wgContLanguageCode;
304 # $wgLang = $wgContLang;
306 # TODO: Need to change reference to $wgLang to $wgContLang at proper
307 # places, including namespaces, dates in signatures, magic words,
310 # TODO: Need to look at the issue of input/output encoding
314 wfProfileIn( $fname.'-OutputPage' );
316 $wgOut = new OutputPage();
319 wfProfileOut( $fname.'-OutputPage' );
320 wfProfileIn( $fname.'-DateFormatter' );
322 if ( $wgUseDynamicDates ) {
323 require_once( 'DateFormatter.php' );
324 global $wgDateFormatter;
325 $wgDateFormatter = new DateFormatter
;
328 wfProfileOut( $fname.'-DateFormatter' );
329 wfProfileIn( $fname.'-BlockCache' );
331 $wgBlockCache = new BlockCache( true );
333 wfProfileOut( $fname.'-BlockCache' );
334 wfProfileIn( $fname.'-misc2' );
336 $wgDeferredUpdateList = array();
337 $wgLinkCache = new LinkCache();
338 $wgMagicWords = array();
339 $wgMwRedir =& MagicWord
::get( MAG_REDIRECT
);
340 $wgParserCache = new ParserCache();
341 $wgParser = new Parser();
342 $wgOut->setParserOptions( ParserOptions
::newFromUser( $wgUser ) );
343 $wgMsgParserOptions = ParserOptions
::newFromUser($wgUser);
346 # Placeholders in case of DB error
347 $wgTitle = Title
::newFromText( wfMsgForContent( 'badtitle' ) );
348 $wgArticle = new Article($wgTitle);
350 wfProfileOut( $fname.'-misc2' );
351 wfProfileIn( $fname.'-extensions' );
353 # Extension setup functions for extensions other than skins
354 # Entries should be added to this variable during the inclusion
355 # of the extension file. This allows the extension to perform
356 # any necessary initialisation in the fully initialised environment
357 foreach ( $wgExtensionFunctions as $func ) {
361 $wgFullyInitialised = true;
362 wfProfileOut( $fname.'-extensions' );
363 wfProfileOut( $fname );