Make Math rendering options user settable strings in MediaWiki namespace. Last batch
[mediawiki.git] / includes / Setup.php
blob90be866249ea9cecb1665da3602499fc97d74cf0
1 <?php
2 # The main wiki script and things like database
3 # conversion and maintenance scripts all share a
4 # common setup of including lots of classes and
5 # setting up a few globals.
8 global $wgProfiling, $wgProfileSampleRate, $wgIP, $wgUseSquid;
10 if( !isset( $wgProfiling ) )
11 $wgProfiling = false;
13 if ( $wgProfiling and (0 == rand() % $wgProfileSampleRate ) ) {
14 require_once( 'Profiling.php' );
15 } else {
16 function wfProfileIn( $fn = '' ) {}
17 function wfProfileOut( $fn = '' ) {}
18 function wfGetProfilingOutput( $s, $e ) {}
19 function wfProfileClose() {}
22 /* collect the originating ips */
23 if( $wgUseSquid && isset( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) {
24 # If the web server is behind a reverse proxy, we need to find
25 # out where our requests are really coming from.
26 $hopips = array_map( 'trim', explode( ',', $_SERVER['HTTP_X_FORWARDED_FOR'] ) );
28 while(in_array(trim(end($hopips)), $wgSquidServers)){
29 array_pop($hopips);
31 $wgIP = trim(end($hopips));
32 } else {
33 $wgIP = getenv('REMOTE_ADDR');
37 $fname = 'Setup.php';
38 wfProfileIn( $fname );
39 global $wgUseDynamicDates;
40 wfProfileIn( $fname.'-includes' );
42 require_once( 'GlobalFunctions.php' );
43 require_once( 'Namespace.php' );
44 require_once( 'RecentChange.php' );
45 require_once( 'User.php' );
46 require_once( 'Skin.php' );
47 require_once( 'OutputPage.php' );
48 require_once( 'LinkCache.php' );
49 require_once( 'Title.php' );
50 require_once( 'Article.php' );
51 require_once( 'MagicWord.php' );
52 require_once( 'memcached-client.php' );
53 require_once( 'Block.php' );
54 require_once( 'SearchEngine.php' );
55 require_once( 'DifferenceEngine.php' );
56 require_once( 'MessageCache.php' );
57 require_once( 'BlockCache.php' );
58 require_once( 'Parser.php' );
59 require_once( 'ParserCache.php' );
60 require_once( 'WebRequest.php' );
61 require_once( 'LoadBalancer.php' );
63 $wgRequest = new WebRequest();
67 wfProfileOut( $fname.'-includes' );
68 wfProfileIn( $fname.'-memcached' );
69 global $wgUser, $wgLang, $wgOut, $wgTitle;
70 global $wgArticle, $wgDeferredUpdateList, $wgLinkCache;
71 global $wgMemc, $wgMagicWords, $wgMwRedir, $wgDebugLogFile;
72 global $wgMessageCache, $wgUseMemCached, $wgUseDatabaseMessages;
73 global $wgMsgCacheExpiry, $wgCommandLineMode;
74 global $wgBlockCache, $wgParserCache, $wgParser, $wgDBConnections;
75 global $wgLoadBalancer, $wgDBservers;
76 global $wgDBserver, $wgDBuser, $wgDBpassword, $wgDBname, $wgDBtype;
78 # Useful debug output
79 if ( $wgCommandLineMode ) {
80 # wfDebug( '"' . implode( '" "', $argv ) . '"' );
81 } elseif ( function_exists( 'getallheaders' ) ) {
82 wfDebug( "\nStart request\n" );
83 wfDebug( $_SERVER['REQUEST_METHOD'] . ' ' . $_SERVER['REQUEST_URI'] . "\n" );
84 $headers = getallheaders();
85 foreach ($headers as $name => $value) {
86 wfDebug( "$name: $value\n" );
88 wfDebug( "\n" );
89 } else {
90 wfDebug( $_SERVER['REQUEST_METHOD'] . ' ' . $_SERVER['REQUEST_URI'] . "\n" );
93 # Set up Memcached
95 class MemCachedClientforWiki extends memcached {
96 function _debugprint( $text ) {
97 wfDebug( "memcached: $text\n" );
101 # FakeMemCachedClient imitates the API of memcached-client v. 0.1.2.
102 # It acts as a memcached server with no RAM, that is, all objects are
103 # cleared the moment they are set. All set operations succeed and all
104 # get operations return null.
106 class FakeMemCachedClient {
107 function add ($key, $val, $exp = 0) { return true; }
108 function decr ($key, $amt=1) { return null; }
109 function delete ($key, $time = 0) { return false; }
110 function disconnect_all () { }
111 function enable_compress ($enable) { }
112 function forget_dead_hosts () { }
113 function get ($key) { return null; }
114 function get_multi ($keys) { return array_pad(array(), count($keys), null); }
115 function incr ($key, $amt=1) { return null; }
116 function replace ($key, $value, $exp=0) { return false; }
117 function run_command ($sock, $cmd) { return null; }
118 function set ($key, $value, $exp=0){ return true; }
119 function set_compress_threshold ($thresh){ }
120 function set_debug ($dbg) { }
121 function set_servers ($list) { }
124 if( $wgUseMemCached ) {
125 $wgMemc = new MemCachedClientforWiki( array('persistant' => true) );
126 $wgMemc->set_servers( $wgMemCachedServers );
127 $wgMemc->set_debug( $wgMemCachedDebug );
129 # Test it to see if it's working
130 # This is necessary because otherwise wfMsg would be extremely inefficient
131 if ( !$wgMemc->set( 'test', '', 0 ) ) {
132 wfDebug( "Memcached failed setup test - connection error?\n" );
133 $wgUseMemCached = false;
134 $wgMemc = new FakeMemCachedClient();
136 $messageMemc = &$wgMemc;
137 } else {
138 $wgMemc = new FakeMemCachedClient();
140 # Give the message cache a separate cache in the DB.
141 # This is a speedup over separately querying every message used
142 require_once( 'ObjectCache.php' );
143 $messageMemc = new MediaWikiBagOStuff('objectcache');
146 wfProfileOut( $fname.'-memcached' );
147 wfProfileIn( $fname.'-database' );
149 if ( !$wgDBservers ) {
150 $wgDBservers = array(array(
151 'host' => $wgDBserver,
152 'user' => $wgDBuser,
153 'password' => $wgDBpassword,
154 'dbname' => $wgDBname,
155 'type' => $wgDBtype,
156 'load' => 1
159 $wgLoadBalancer = LoadBalancer::newFromParams( $wgDBservers );
160 $wgLoadBalancer->force(0);
162 wfProfileOut( $fname.'-database' );
163 wfProfileIn( $fname.'-language' );
164 require_once( 'languages/Language.php' );
166 $wgMessageCache = new MessageCache;
168 $wgLangClass = 'Language' . ucfirst( $wgLanguageCode );
169 if( ! class_exists( $wgLangClass ) || ($wgLanguageCode == 'en' && !$wgUseLatin1) ) {
170 # Default to English/UTF-8
171 require_once( 'languages/LanguageUtf8.php' );
172 $wgLangClass = 'LanguageUtf8';
175 $wgLang = new $wgLangClass();
176 if ( !is_object($wgLang) ) {
177 print "No language class ($wgLang)\N";
180 if( $wgUseLatin1 && $wgLanguageCode != 'en' ) {
181 # For non-UTF-8 non-English.
182 require_once( 'languages/LanguageLatin1.php' );
183 $xxx = new LanguageLatin1( $wgLang );
184 unset( $wgLang );
185 $wgLang = $xxx;
187 wfProfileOut( $fname.'-language' );
188 wfProfileIn( $fname.'-MessageCache' );
190 $wgMessageCache->initialise( $messageMemc, $wgUseDatabaseMessages, $wgMsgCacheExpiry, $wgDBname );
192 wfProfileOut( $fname.'-MessageCache' );
193 wfProfileIn( $fname.'-OutputPage' );
195 $wgOut = new OutputPage();
196 wfDebug( "\n\n" );
198 wfProfileOut( $fname.'-OutputPage' );
199 wfProfileIn( $fname.'-DateFormatter' );
201 if ( $wgUseDynamicDates ) {
202 require_once( 'DateFormatter.php' );
203 global $wgDateFormatter;
204 $wgDateFormatter = new DateFormatter;
207 wfProfileOut( $fname.'-DateFormatter' );
208 wfProfileIn( $fname.'-SetupSession' );
210 if( !$wgCommandLineMode && ( isset( $_COOKIE[ini_get('session.name')] ) || isset( $_COOKIE[$wgDBname.'Password'] ) ) ) {
211 User::SetupSession();
214 wfProfileOut( $fname.'-SetupSession' );
215 wfProfileIn( $fname.'-BlockCache' );
217 $wgBlockCache = new BlockCache( true );
219 wfProfileOut( $fname.'-BlockCache' );
220 wfProfileIn( $fname.'-User' );
222 if( $wgCommandLineMode ) {
223 # Used for some maintenance scripts; user session cookies can screw things up
224 # when the database is in an in-between state.
225 $wgUser = new User();
226 } else {
227 $wgUser = User::loadFromSession();
230 wfProfileOut( $fname.'-User' );
231 wfProfileIn( $fname.'-misc' );
233 $wgDeferredUpdateList = array();
234 $wgLinkCache = new LinkCache();
235 $wgMagicWords = array();
236 $wgMwRedir =& MagicWord::get( MAG_REDIRECT );
237 $wgParserCache = new ParserCache();
238 $wgParser = new Parser();
239 $wgOut->setParserOptions( ParserOptions::newFromUser( $wgUser ) );
240 $wgDBConnections = array();
242 # Placeholders in case of DB error
243 $wgTitle = Title::newFromText( wfMsg( 'badtitle' ) );
244 $wgArticle = new Article($wgTitle);
246 wfProfileOut( $fname.'-misc' );
247 wfProfileIn( $fname.'-extensions' );
249 # Extension setup functions
250 # Entries should be added to this variable during the inclusion
251 # of the extension file. This allows the extension to perform
252 # any necessary initialisation in the fully initialised environment
253 foreach ( $wgExtensionFunctions as $func ) {
254 $func();
257 wfProfileOut( $fname.'-extensions' );
258 wfProfileOut( $fname );