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