more cssification of diff rendering, some " -> ' in diff engine
[lhc/web/wiklou.git] / includes / Setup.php
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.
6 #
7
8 global $wgProfiling, $wgProfileSampleRate, $wgIP, $wgUseSquid;
9
10 if( !isset( $wgProfiling ) )
11 $wgProfiling = false;
12
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() {}
20 }
21
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'] ) );
27
28 while(in_array(trim(end($hopips)), $wgSquidServers)){
29 array_pop($hopips);
30 }
31 $wgIP = trim(end($hopips));
32 } else {
33 $wgIP = getenv('REMOTE_ADDR');
34 }
35
36
37 $fname = 'Setup.php';
38 wfProfileIn( $fname );
39 global $wgUseDynamicDates;
40 wfProfileIn( $fname.'-includes' );
41
42 require_once( 'GlobalFunctions.php' );
43 require_once( 'Namespace.php' );
44 require_once( 'RecentChange.php' );
45 require_once( 'Skin.php' );
46 require_once( 'OutputPage.php' );
47 require_once( 'User.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( 'SpecialPage.php' );
62
63 $wgRequest = new WebRequest();
64
65
66
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, $wgDBname, $wgCommandLineMode;
74 global $wgBlockCache, $wgParserCache, $wgParser, $wgDontTrustMemcachedWithImportantStuff;
75
76 # Useful debug output
77 if ( $wgCommandLineMode ) {
78 # wfDebug( '"' . implode( '" "', $argv ) . '"' );
79 } elseif ( function_exists( 'getallheaders' ) ) {
80 wfDebug( "\nStart request\n" );
81 wfDebug( $_SERVER['REQUEST_METHOD'] . ' ' . $_SERVER['REQUEST_URI'] . "\n" );
82 $headers = getallheaders();
83 foreach ($headers as $name => $value) {
84 wfDebug( "$name: $value\n" );
85 }
86 wfDebug( "\n" );
87 } else {
88 wfDebug( $_SERVER['REQUEST_METHOD'] . ' ' . $_SERVER['REQUEST_URI'] . "\n" );
89 }
90
91 # Set up Memcached
92 #
93 class MemCachedClientforWiki extends memcached {
94 function _debugprint( $text ) {
95 wfDebug( "memcached: $text\n" );
96 }
97 }
98
99 # FakeMemCachedClient imitates the API of memcached-client v. 0.1.2.
100 # It acts as a memcached server with no RAM, that is, all objects are
101 # cleared the moment they are set. All set operations succeed and all
102 # get operations return null.
103
104 class FakeMemCachedClient {
105 function add ($key, $val, $exp = 0) { return true; }
106 function decr ($key, $amt=1) { return null; }
107 function delete ($key, $time = 0) { return false; }
108 function disconnect_all () { }
109 function enable_compress ($enable) { }
110 function forget_dead_hosts () { }
111 function get ($key) { return null; }
112 function get_multi ($keys) { return array_pad(array(), count($keys), null); }
113 function incr ($key, $amt=1) { return null; }
114 function replace ($key, $value, $exp=0) { return false; }
115 function run_command ($sock, $cmd) { return null; }
116 function set ($key, $value, $exp=0){ return true; }
117 function set_compress_threshold ($thresh){ }
118 function set_debug ($dbg) { }
119 function set_servers ($list) { }
120 }
121
122 if( $wgUseMemCached ) {
123 $wgMemc = new MemCachedClientforWiki( array('persistant' => true) );
124 $wgMemc->set_servers( $wgMemCachedServers );
125 $wgMemc->set_debug( $wgMemCachedDebug );
126
127 # Test it to see if it's working
128 # This is necessary because otherwise wfMsg would be extremely inefficient
129 if ( !$wgMemc->set( 'test', '', 0 ) ) {
130 wfDebug( "Memcached failed setup test - connection error?\n" );
131 $wgUseMemCached = false;
132 $wgMemc = new FakeMemCachedClient();
133 }
134 $messageMemc = &$wgMemc;
135 } else {
136 $wgMemc = new FakeMemCachedClient();
137
138 # Give the message cache a separate cache in the DB.
139 # This is a speedup over separately querying every message used
140 require_once( 'ObjectCache.php' );
141 $messageMemc = new MediaWikiBagOStuff('objectcache');
142 }
143
144 wfProfileOut( $fname.'-memcached' );
145 wfProfileIn( $fname.'-language' );
146 require_once( 'languages/Language.php' );
147
148 $wgMessageCache = new MessageCache;
149
150 $wgLangClass = 'Language' . ucfirst( $wgLanguageCode );
151 if( ! class_exists( $wgLangClass ) || ($wgLanguageCode == 'en' && !$wgUseLatin1) ) {
152 # Default to English/UTF-8
153 require_once( 'languages/LanguageUtf8.php' );
154 $wgLangClass = 'LanguageUtf8';
155 }
156
157 $wgLang = new $wgLangClass();
158 if ( !is_object($wgLang) ) {
159 print "No language class ($wgLang)\N";
160 }
161
162 if( $wgUseLatin1 && $wgLanguageCode != 'en' ) {
163 # For non-UTF-8 non-English.
164 require_once( 'languages/LanguageLatin1.php' );
165 $xxx = new LanguageLatin1( $wgLang );
166 unset( $wgLang );
167 $wgLang = $xxx;
168 }
169 wfProfileOut( $fname.'-language' );
170 wfProfileIn( $fname.'-MessageCache' );
171
172 $wgMessageCache->initialise( $messageMemc, $wgUseDatabaseMessages, $wgMsgCacheExpiry, $wgDBname );
173
174 wfProfileOut( $fname.'-MessageCache' );
175 wfProfileIn( $fname.'-OutputPage' );
176
177 $wgOut = new OutputPage();
178 wfDebug( "\n\n" );
179
180 wfProfileOut( $fname.'-OutputPage' );
181 wfProfileIn( $fname.'-DateFormatter' );
182
183 if ( $wgUseDynamicDates ) {
184 require_once( 'DateFormatter.php' );
185 global $wgDateFormatter;
186 $wgDateFormatter = new DateFormatter;
187 }
188
189 wfProfileOut( $fname.'-DateFormatter' );
190 wfProfileIn( $fname.'-SetupSession' );
191
192 if( !$wgCommandLineMode && ( isset( $_COOKIE[ini_get('session.name')] ) || isset( $_COOKIE[$wgDBname.'Password'] ) ) ) {
193 User::SetupSession();
194 }
195
196 wfProfileOut( $fname.'-SetupSession' );
197 wfProfileIn( $fname.'-BlockCache' );
198
199 $wgBlockCache = new BlockCache( true );
200
201 wfProfileOut( $fname.'-BlockCache' );
202 wfProfileIn( $fname.'-User' );
203
204 if( $wgCommandLineMode ) {
205 # Used for some maintenance scripts; user session cookies can screw things up
206 # when the database is in an in-between state.
207 $wgUser = new User();
208 } else {
209 $wgUser = User::loadFromSession();
210 }
211
212 wfProfileOut( $fname.'-User' );
213 wfProfileIn( $fname.'-misc' );
214
215 $wgDeferredUpdateList = array();
216 $wgLinkCache = new LinkCache();
217 $wgMagicWords = array();
218 $wgMwRedir =& MagicWord::get( MAG_REDIRECT );
219 $wgParserCache = new ParserCache();
220 $wgParser = new Parser();
221 $wgOut->setParserOptions( ParserOptions::newFromUser( $wgUser ) );
222
223 if ( !$wgAllowSysopQueries ) {
224 SpecialPage::removePage( 'Asksql' );
225 }
226
227 # Placeholders in case of DB error
228 $wgTitle = Title::newFromText( wfMsg( 'badtitle' ) );
229 $wgArticle = new Article($wgTitle);
230
231 wfProfileOut( $fname.'-misc' );
232 wfProfileIn( $fname.'-extensions' );
233
234 # Extension setup functions
235 # Entries should be added to this variable during the inclusion
236 # of the extension file. This allows the extension to perform
237 # any necessary initialisation in the fully initialised environment
238 foreach ( $wgExtensionFunctions as $func ) {
239 $func();
240 }
241
242 wfProfileOut( $fname.'-extensions' );
243 wfProfileOut( $fname );
244
245
246 ?>