3 # This file is not a valid entry point, perform no further processing unless MEDIAWIKI is defined
4 if( defined( "MEDIAWIKI" ) ) {
6 # The main wiki script and things like database
7 # conversion and maintenance scripts all share a
8 # common setup of including lots of classes and
9 # setting up a few globals.
12 global $wgProfiling, $wgProfileSampleRate, $wgIP, $wgUseSquid;
14 if( !isset( $wgProfiling ) )
17 if ( $wgProfiling and (0 == rand() %
$wgProfileSampleRate ) ) {
18 require_once( 'Profiling.php' );
20 function wfProfileIn( $fn = '' ) {}
21 function wfProfileOut( $fn = '' ) {}
22 function wfGetProfilingOutput( $s, $e ) {}
23 function wfProfileClose() {}
26 /* collect the originating ips */
27 if( $wgUseSquid && isset( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) {
28 # If the web server is behind a reverse proxy, we need to find
29 # out where our requests are really coming from.
30 $hopips = array_map( 'trim', explode( ',', $_SERVER['HTTP_X_FORWARDED_FOR'] ) );
32 while(in_array(trim(end($hopips)), $wgSquidServers)){
35 $wgIP = trim(end($hopips));
37 $wgIP = getenv('REMOTE_ADDR');
42 wfProfileIn( $fname );
43 global $wgUseDynamicDates;
44 wfProfileIn( $fname.'-includes' );
46 require_once( 'GlobalFunctions.php' );
47 require_once( 'Namespace.php' );
48 require_once( 'RecentChange.php' );
49 require_once( 'User.php' );
50 require_once( 'Skin.php' );
51 require_once( 'OutputPage.php' );
52 require_once( 'LinkCache.php' );
53 require_once( 'Title.php' );
54 require_once( 'Article.php' );
55 require_once( 'MagicWord.php' );
56 require_once( 'memcached-client.php' );
57 require_once( 'Block.php' );
58 require_once( 'SearchEngine.php' );
59 require_once( 'MessageCache.php' );
60 require_once( 'BlockCache.php' );
61 require_once( 'Parser.php' );
62 require_once( 'ParserCache.php' );
63 require_once( 'WebRequest.php' );
64 require_once( 'LoadBalancer.php' );
66 $wgRequest = new WebRequest();
70 wfProfileOut( $fname.'-includes' );
71 wfProfileIn( $fname.'-misc1' );
72 global $wgUser, $wgLang, $wgOut, $wgTitle;
73 global $wgArticle, $wgDeferredUpdateList, $wgLinkCache;
74 global $wgMemc, $wgMagicWords, $wgMwRedir, $wgDebugLogFile;
75 global $wgMessageCache, $wgUseMemCached, $wgUseDatabaseMessages;
76 global $wgMsgCacheExpiry, $wgCommandLineMode;
77 global $wgBlockCache, $wgParserCache, $wgParser, $wgDBConnections;
78 global $wgLoadBalancer, $wgDBservers, $wgDebugDumpSql;
79 global $wgDBserver, $wgDBuser, $wgDBpassword, $wgDBname, $wgDBtype;
80 global $wgUseOldExistenceCheck, $wgEnablePersistentLC;
82 global $wgFullyInitialised;
85 if ( $wgCommandLineMode ) {
86 # wfDebug( '"' . implode( '" "', $argv ) . '"' );
87 } elseif ( function_exists( 'getallheaders' ) ) {
88 wfDebug( "\nStart request\n" );
89 wfDebug( $_SERVER['REQUEST_METHOD'] . ' ' . $_SERVER['REQUEST_URI'] . "\n" );
90 $headers = getallheaders();
91 foreach ($headers as $name => $value) {
92 wfDebug( "$name: $value\n" );
96 wfDebug( $_SERVER['REQUEST_METHOD'] . ' ' . $_SERVER['REQUEST_URI'] . "\n" );
99 # Disable linkscc except if the old existence check method is enabled
100 if (!$wgUseOldExistenceCheck) {
101 $wgEnablePersistentLC = false;
104 wfProfileOut( $fname.'-misc1' );
105 wfProfileIn( $fname.'-memcached' );
109 class MemCachedClientforWiki
extends memcached
{
110 function _debugprint( $text ) {
111 wfDebug( "memcached: $text\n" );
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 class FakeMemCachedClient
{
121 function add ($key, $val, $exp = 0) { return true; }
122 function decr ($key, $amt=1) { return null; }
123 function delete ($key, $time = 0) { return false; }
124 function disconnect_all () { }
125 function enable_compress ($enable) { }
126 function forget_dead_hosts () { }
127 function get ($key) { return null; }
128 function get_multi ($keys) { return array_pad(array(), count($keys), null); }
129 function incr ($key, $amt=1) { return null; }
130 function replace ($key, $value, $exp=0) { return false; }
131 function run_command ($sock, $cmd) { return null; }
132 function set ($key, $value, $exp=0){ return true; }
133 function set_compress_threshold ($thresh){ }
134 function set_debug ($dbg) { }
135 function set_servers ($list) { }
138 if( $wgUseMemCached ) {
139 $wgMemc = new MemCachedClientforWiki( array('persistant' => true) );
140 $wgMemc->set_servers( $wgMemCachedServers );
141 $wgMemc->set_debug( $wgMemCachedDebug );
143 $messageMemc = &$wgMemc;
145 $wgMemc = new FakeMemCachedClient();
147 # Give the message cache a separate cache in the DB.
148 # This is a speedup over separately querying every message used
149 require_once( 'ObjectCache.php' );
150 $messageMemc = new MediaWikiBagOStuff('objectcache');
153 wfProfileOut( $fname.'-memcached' );
154 wfProfileIn( $fname.'-SetupSession' );
156 if( !$wgCommandLineMode && ( isset( $_COOKIE[ini_get('session.name')] ) ||
isset( $_COOKIE[$wgDBname.'Password'] ) ) ) {
157 User
::SetupSession();
158 $wgSessionStarted = true;
160 $wgSessionStarted = false;
163 wfProfileOut( $fname.'-SetupSession' );
164 wfProfileIn( $fname.'-database' );
166 if ( !$wgDBservers ) {
167 $wgDBservers = array(array(
168 'host' => $wgDBserver,
170 'password' => $wgDBpassword,
171 'dbname' => $wgDBname,
174 'flags' => ($wgDebugDumpSql ? DBO_DEBUG
: 0) | DBO_DEFAULT
177 $wgLoadBalancer = LoadBalancer
::newFromParams( $wgDBservers );
178 $wgLoadBalancer->loadMasterPos();
180 wfProfileOut( $fname.'-database' );
181 wfProfileIn( $fname.'-language' );
182 require_once( 'languages/Language.php' );
184 $wgMessageCache = new MessageCache
;
186 $wgLangClass = 'Language' . ucfirst( $wgLanguageCode );
187 if( ! class_exists( $wgLangClass ) ||
($wgLanguageCode == 'en' && !$wgUseLatin1) ) {
188 # Default to English/UTF-8
189 require_once( 'languages/LanguageUtf8.php' );
190 $wgLangClass = 'LanguageUtf8';
193 $wgLang = new $wgLangClass();
194 if ( !is_object($wgLang) ) {
195 print "No language class ($wgLang)\N";
198 if( $wgUseLatin1 && $wgLanguageCode != 'en' ) {
199 # For non-UTF-8 non-English.
200 require_once( 'languages/LanguageLatin1.php' );
201 $xxx = new LanguageLatin1( $wgLang );
205 wfProfileOut( $fname.'-language' );
206 wfProfileIn( $fname.'-MessageCache' );
208 $wgMessageCache->initialise( $messageMemc, $wgUseDatabaseMessages, $wgMsgCacheExpiry, $wgDBname );
210 wfProfileOut( $fname.'-MessageCache' );
211 wfProfileIn( $fname.'-OutputPage' );
213 $wgOut = new OutputPage();
216 wfProfileOut( $fname.'-OutputPage' );
217 wfProfileIn( $fname.'-DateFormatter' );
219 if ( $wgUseDynamicDates ) {
220 require_once( 'DateFormatter.php' );
221 global $wgDateFormatter;
222 $wgDateFormatter = new DateFormatter
;
225 wfProfileOut( $fname.'-DateFormatter' );
226 wfProfileIn( $fname.'-BlockCache' );
228 $wgBlockCache = new BlockCache( true );
230 wfProfileOut( $fname.'-BlockCache' );
231 wfProfileIn( $fname.'-User' );
233 if( $wgCommandLineMode ) {
234 # Used for some maintenance scripts; user session cookies can screw things up
235 # when the database is in an in-between state.
236 $wgUser = new User();
238 $wgUser = User
::loadFromSession();
241 wfProfileOut( $fname.'-User' );
242 wfProfileIn( $fname.'-misc2' );
244 $wgDeferredUpdateList = array();
245 $wgLinkCache = new LinkCache();
246 $wgMagicWords = array();
247 $wgMwRedir =& MagicWord
::get( MAG_REDIRECT
);
248 $wgParserCache = new ParserCache();
249 $wgParser = new Parser();
250 $wgOut->setParserOptions( ParserOptions
::newFromUser( $wgUser ) );
251 $wgDBConnections = array();
254 # Placeholders in case of DB error
255 $wgTitle = Title
::newFromText( wfMsg( 'badtitle' ) );
256 $wgArticle = new Article($wgTitle);
258 wfProfileOut( $fname.'-misc2' );
259 wfProfileIn( $fname.'-extensions' );
261 # Extension setup functions
262 # Entries should be added to this variable during the inclusion
263 # of the extension file. This allows the extension to perform
264 # any necessary initialisation in the fully initialised environment
265 foreach ( $wgExtensionFunctions as $func ) {
269 $wgFullyInitialised = true;
270 wfProfileOut( $fname.'-extensions' );
271 wfProfileOut( $fname );