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 = getenv('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, $wgOut, $wgTitle;
78 global $wgArticle, $wgDeferredUpdateList, $wgLinkCache;
79 global $wgMemc, $wgMagicWords, $wgMwRedir, $wgDebugLogFile;
80 global $wgMessageCache, $wgUseMemCached, $wgUseDatabaseMessages;
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.'-language' );
202 require_once( 'languages/Language.php' );
204 $wgMessageCache = new MessageCache
;
206 $wgLangClass = 'Language' . str_replace( '-', '_', ucfirst( $wgLanguageCode ) );
207 if( ! class_exists( $wgLangClass ) ||
($wgLanguageCode == 'en' && !$wgUseLatin1) ) {
208 # Default to English/UTF-8
209 require_once( 'languages/LanguageUtf8.php' );
210 $wgLangClass = 'LanguageUtf8';
213 $wgLang = new $wgLangClass();
214 if ( !is_object($wgLang) ) {
215 print "No language class ($wgLang)\N";
218 if( $wgUseLatin1 && $wgLanguageCode != 'en' ) {
219 # For non-UTF-8 non-English.
220 require_once( 'languages/LanguageLatin1.php' );
221 $xxx = new LanguageLatin1( $wgLang );
225 wfProfileOut( $fname.'-language' );
226 wfProfileIn( $fname.'-MessageCache' );
228 $wgMessageCache->initialise( $messageMemc, $wgUseDatabaseMessages, $wgMsgCacheExpiry, $wgDBname );
230 wfProfileOut( $fname.'-MessageCache' );
231 wfProfileIn( $fname.'-OutputPage' );
233 $wgOut = new OutputPage();
236 wfProfileOut( $fname.'-OutputPage' );
237 wfProfileIn( $fname.'-DateFormatter' );
239 if ( $wgUseDynamicDates ) {
240 require_once( 'DateFormatter.php' );
241 global $wgDateFormatter;
242 $wgDateFormatter = new DateFormatter
;
245 wfProfileOut( $fname.'-DateFormatter' );
246 wfProfileIn( $fname.'-BlockCache' );
248 $wgBlockCache = new BlockCache( true );
250 wfProfileOut( $fname.'-BlockCache' );
251 wfProfileIn( $fname.'-User' );
253 # Extension setup functions
254 # Entries should be added to this variable during the inclusion
255 # of the extension file. This allows the extension to perform
256 # any necessary initialisation in the fully initialised environment
257 foreach ( $wgSkinExtensionFunctions as $func ) {
261 if( $wgCommandLineMode ) {
262 # Used for some maintenance scripts; user session cookies can screw things up
263 # when the database is in an in-between state.
264 $wgUser = new User();
266 $wgUser = User
::loadFromSession();
269 wfProfileOut( $fname.'-User' );
270 wfProfileIn( $fname.'-misc2' );
272 $wgDeferredUpdateList = array();
273 $wgLinkCache = new LinkCache();
274 $wgMagicWords = array();
275 $wgMwRedir =& MagicWord
::get( MAG_REDIRECT
);
276 $wgParserCache = new ParserCache();
277 $wgParser = new Parser();
278 $wgOut->setParserOptions( ParserOptions
::newFromUser( $wgUser ) );
279 $wgDBConnections = array();
282 # Placeholders in case of DB error
283 $wgTitle = Title
::newFromText( wfMsg( 'badtitle' ) );
284 $wgArticle = new Article($wgTitle);
286 wfProfileOut( $fname.'-misc2' );
287 wfProfileIn( $fname.'-extensions' );
289 # Extension setup functions
290 # Entries should be added to this variable during the inclusion
291 # of the extension file. This allows the extension to perform
292 # any necessary initialisation in the fully initialised environment
293 foreach ( $wgExtensionFunctions as $func ) {
297 $wgFullyInitialised = true;
298 wfProfileOut( $fname.'-extensions' );
299 wfProfileOut( $fname );