9b90b899fee66c91f3ab38dfa9547b9573940c3c
[lhc/web/wiklou.git] / includes / Setup.php
1 <?php
2 /**
3 * Include most things that's need to customize the site
4 * @package MediaWiki
5 */
6
7 /**
8 * This file is not a valid entry point, perform no further processing unless
9 * MEDIAWIKI is defined
10 */
11 if( defined( 'MEDIAWIKI' ) ) {
12
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.
17 #
18
19 // Check to see if we are at the file scope
20 if ( !isset( $wgVersion ) ) {
21 echo "Error, Setup.php must be included from the file scope, after DefaultSettings.php\n";
22 die( 1 );
23 }
24
25 if( !isset( $wgProfiling ) )
26 $wgProfiling = false;
27
28 if ( function_exists( 'wfProfileIn' ) ) {
29 /* nada, everything should be done already */
30 } elseif ( $wgProfiling and (0 == rand() % $wgProfileSampleRate ) ) {
31 require_once( 'Profiling.php' );
32 $wgProfiling = true;
33 if ($wgProfilerType == "") {
34 $wgProfiler = new Profiler();
35 } else {
36 $prclass="Profiler{$wgProfilerType}";
37 require_once( $prclass.".php" );
38 $wgProfiler = new $prclass();
39 }
40 } else {
41 require_once( 'ProfilerStub.php' );
42 }
43
44 $fname = 'Setup.php';
45 wfProfileIn( $fname );
46
47 wfProfileIn( $fname.'-exception' );
48 require_once( 'Exception.php' );
49 wfInstallExceptionHandler();
50 wfProfileOut( $fname.'-exception' );
51
52 wfProfileIn( $fname.'-includes' );
53
54 require_once( 'AutoLoader.php' );
55 require_once( 'GlobalFunctions.php' );
56 require_once( 'Hooks.php' );
57 require_once( 'Namespace.php' );
58 require_once( 'User.php' );
59 require_once( 'Skin.php' );
60 require_once( 'OutputPage.php' );
61 require_once( 'MagicWord.php' );
62 require_once( 'Block.php' );
63 require_once( 'MessageCache.php' );
64 require_once( 'Parser.php' );
65 require_once( 'ParserCache.php' );
66 require_once( 'WebRequest.php' );
67 require_once( 'LoadBalancer.php' );
68 require_once( 'HistoryBlob.php' );
69 require_once( 'ProxyTools.php' );
70 require_once( 'ObjectCache.php' );
71 require_once( 'SpecialPage.php' );
72
73 if ( $wgUseDynamicDates ) {
74 require_once( 'DateFormatter.php' );
75 }
76
77 wfProfileOut( $fname.'-includes' );
78 wfProfileIn( $fname.'-misc1' );
79
80 $wgIP = false; # Load on demand
81 $wgRequest = new WebRequest();
82 if ( function_exists( 'posix_uname' ) ) {
83 $wguname = posix_uname();
84 $wgNodeName = $wguname['nodename'];
85 } else {
86 $wgNodeName = '';
87 }
88
89 # Useful debug output
90 if ( $wgCommandLineMode ) {
91 # wfDebug( '"' . implode( '" "', $argv ) . '"' );
92 } elseif ( function_exists( 'getallheaders' ) ) {
93 wfDebug( "\n\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" );
98 }
99 wfDebug( "\n" );
100 } elseif( isset( $_SERVER['REQUEST_URI'] ) ) {
101 wfDebug( $_SERVER['REQUEST_METHOD'] . ' ' . $_SERVER['REQUEST_URI'] . "\n" );
102 }
103
104 if ( $wgSkipSkin ) {
105 $wgSkipSkins[] = $wgSkipSkin;
106 }
107
108 $wgUseEnotif = $wgEnotifUserTalk || $wgEnotifWatchlist;
109
110 wfProfileOut( $fname.'-misc1' );
111 wfProfileIn( $fname.'-memcached' );
112
113 $wgMemc =& wfGetMainCache();
114 $messageMemc =& wfGetMessageCacheStorage();
115 $parserMemc =& wfGetParserCacheStorage();
116
117 wfDebug( 'Main cache: ' . get_class( $wgMemc ) .
118 "\nMessage cache: " . get_class( $messageMemc ) .
119 "\nParser cache: " . get_class( $parserMemc ) . "\n" );
120
121 wfProfileOut( $fname.'-memcached' );
122 wfProfileIn( $fname.'-SetupSession' );
123
124 if ( $wgDBprefix ) {
125 $wgCookiePrefix = $wgDBname . '_' . $wgDBprefix;
126 } elseif ( $wgSharedDB ) {
127 $wgCookiePrefix = $wgSharedDB;
128 } else {
129 $wgCookiePrefix = $wgDBname;
130 }
131
132 # If session.auto_start is there, we can't touch session name
133 #
134 if (!ini_get('session.auto_start')) {
135 session_name( $wgCookiePrefix . '_session' );
136 }
137
138 if( !$wgCommandLineMode && ( isset( $_COOKIE[session_name()] ) || isset( $_COOKIE[$wgCookiePrefix.'Token'] ) ) ) {
139 wfIncrStats( 'request_with_session' );
140 User::SetupSession();
141 $wgSessionStarted = true;
142 } else {
143 wfIncrStats( 'request_without_session' );
144 $wgSessionStarted = false;
145 }
146
147 wfProfileOut( $fname.'-SetupSession' );
148 wfProfileIn( $fname.'-database' );
149
150 if ( !$wgDBservers ) {
151 $wgDBservers = array(array(
152 'host' => $wgDBserver,
153 'user' => $wgDBuser,
154 'password' => $wgDBpassword,
155 'dbname' => $wgDBname,
156 'type' => $wgDBtype,
157 'load' => 1,
158 'flags' => ($wgDebugDumpSql ? DBO_DEBUG : 0) | DBO_DEFAULT
159 ));
160 }
161 $wgLoadBalancer = LoadBalancer::newFromParams( $wgDBservers, false, $wgMasterWaitTimeout );
162 $wgLoadBalancer->loadMasterPos();
163
164 wfProfileOut( $fname.'-database' );
165 wfProfileIn( $fname.'-language1' );
166
167 require_once( "$IP/languages/Language.php" );
168
169 function setupLangObj($langclass) {
170 global $IP;
171
172 if( ! class_exists( $langclass ) ) {
173 # Default to English/UTF-8
174 $baseclass = 'LanguageUtf8';
175 require_once( "$IP/languages/$baseclass.php" );
176 $lc = strtolower(substr($langclass, 8));
177 $snip = "
178 class $langclass extends $baseclass {
179 function getVariants() {
180 return array(\"$lc\");
181 }
182
183 }";
184 eval($snip);
185 }
186
187 $lang = new $langclass();
188
189 return $lang;
190 }
191
192 # $wgLanguageCode may be changed later to fit with user preference.
193 # The content language will remain fixed as per the configuration,
194 # so let's keep it.
195 $wgContLanguageCode = $wgLanguageCode;
196 $wgContLangClass = 'Language' . str_replace( '-', '_', ucfirst( $wgContLanguageCode ) );
197
198 $wgContLang = setupLangObj( $wgContLangClass );
199 $wgContLang->initEncoding();
200
201 wfProfileOut( $fname.'-language1' );
202 wfProfileIn( $fname.'-User' );
203
204 # Skin setup functions
205 # Entries can be added to this variable during the inclusion
206 # of the extension file. Skins can then perform any necessary initialisation.
207 #
208 foreach ( $wgSkinExtensionFunctions as $func ) {
209 call_user_func( $func );
210 }
211
212 if( !is_object( $wgAuth ) ) {
213 require_once( 'AuthPlugin.php' );
214 $wgAuth = new AuthPlugin();
215 }
216
217 if( $wgCommandLineMode ) {
218 # Used for some maintenance scripts; user session cookies can screw things up
219 # when the database is in an in-between state.
220 $wgUser = new User();
221 # Prevent loading User settings from the DB.
222 $wgUser->setLoaded( true );
223 } else {
224 $wgUser = null;
225 wfRunHooks('AutoAuthenticate',array(&$wgUser));
226 if ($wgUser === null) {
227 $wgUser = User::loadFromSession();
228 }
229 }
230
231 wfProfileOut( $fname.'-User' );
232 wfProfileIn( $fname.'-language2' );
233
234 // wgLanguageCode now specifically means the UI language
235 $wgLanguageCode = $wgRequest->getText('uselang', '');
236 if ($wgLanguageCode == '')
237 $wgLanguageCode = $wgUser->getOption('language');
238 # Validate $wgLanguageCode, which will soon be sent to an eval()
239 if( empty( $wgLanguageCode ) || !preg_match( '/^[a-z]+(-[a-z]+)?$/', $wgLanguageCode ) ) {
240 $wgLanguageCode = $wgContLanguageCode;
241 }
242
243 $wgLangClass = 'Language'. str_replace( '-', '_', ucfirst( $wgLanguageCode ) );
244
245 if( $wgLangClass == $wgContLangClass ) {
246 $wgLang = &$wgContLang;
247 } else {
248 wfSuppressWarnings();
249 // Preload base classes to work around APC/PHP5 bug
250 include_once("$IP/languages/$wgLangClass.deps.php");
251 include_once("$IP/languages/$wgLangClass.php");
252 wfRestoreWarnings();
253
254 $wgLang = setupLangObj( $wgLangClass );
255 }
256
257 wfProfileOut( $fname.'-language2' );
258 wfProfileIn( $fname.'-MessageCache' );
259
260 $wgMessageCache = new MessageCache;
261 $wgMessageCache->initialise( $parserMemc, $wgUseDatabaseMessages, $wgMsgCacheExpiry, $wgDBname);
262
263 wfProfileOut( $fname.'-MessageCache' );
264
265 #
266 # I guess the warning about UI switching might still apply...
267 #
268 # FIXME: THE ABOVE MIGHT BREAK NAMESPACES, VARIABLES,
269 # SEARCH INDEX UPDATES, AND MANY MANY THINGS.
270 # DO NOT USE THIS MODE EXCEPT FOR TESTING RIGHT NOW.
271 #
272 # To disable it, the easiest thing could be to uncomment the
273 # following; they should effectively disable the UI switch functionality
274 #
275 # $wgLangClass = $wgContLangClass;
276 # $wgLanguageCode = $wgContLanguageCode;
277 # $wgLang = $wgContLang;
278 #
279 # TODO: Need to change reference to $wgLang to $wgContLang at proper
280 # places, including namespaces, dates in signatures, magic words,
281 # and links
282 #
283 # TODO: Need to look at the issue of input/output encoding
284 #
285
286
287 wfProfileIn( $fname.'-OutputPage' );
288
289 $wgOut = new OutputPage();
290
291 wfProfileOut( $fname.'-OutputPage' );
292 wfProfileIn( $fname.'-misc2' );
293
294 $wgDeferredUpdateList = array();
295 $wgPostCommitUpdateList = array();
296
297 $wgMagicWords = array();
298 $wgMwRedir =& MagicWord::get( MAG_REDIRECT );
299
300 if ( $wgUseXMLparser ) {
301 require_once( 'ParserXML.php' );
302 $wgParser = new ParserXML();
303 } else {
304 $wgParser = new Parser();
305 }
306 $wgOut->setParserOptions( ParserOptions::newFromUser( $wgUser ) );
307 $wgMsgParserOptions = ParserOptions::newFromUser($wgUser);
308 wfSeedRandom();
309
310 # Placeholders in case of DB error
311 $wgTitle = Title::makeTitle( NS_SPECIAL, 'Error' );
312 $wgArticle = new Article($wgTitle);
313
314 wfProfileOut( $fname.'-misc2' );
315 wfProfileIn( $fname.'-extensions' );
316
317 # Extension setup functions for extensions other than skins
318 # Entries should be added to this variable during the inclusion
319 # of the extension file. This allows the extension to perform
320 # any necessary initialisation in the fully initialised environment
321 foreach ( $wgExtensionFunctions as $func ) {
322 call_user_func( $func );
323 }
324
325 // For compatibility
326 wfRunHooks( 'LogPageValidTypes', array( &$wgLogTypes ) );
327 wfRunHooks( 'LogPageLogName', array( &$wgLogNames ) );
328 wfRunHooks( 'LogPageLogHeader', array( &$wgLogHeaders ) );
329 wfRunHooks( 'LogPageActionText', array( &$wgLogActions ) );
330
331
332 wfDebug( "\n" );
333 $wgFullyInitialised = true;
334 wfProfileOut( $fname.'-extensions' );
335 wfProfileOut( $fname );
336
337 }
338 ?>