Switch some HTMLForms in special pages to OOUI
[lhc/web/wiklou.git] / includes / Setup.php
1 <?php
2 /**
3 * Include most things that are needed to make %MediaWiki work.
4 *
5 * This file is included by WebStart.php and doMaintenance.php so that both
6 * web and maintenance scripts share a final set up phase to include necessary
7 * files and create global object variables.
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 * http://www.gnu.org/copyleft/gpl.html
23 *
24 * @file
25 */
26
27 /**
28 * This file is not a valid entry point, perform no further processing unless
29 * MEDIAWIKI is defined
30 */
31 if ( !defined( 'MEDIAWIKI' ) ) {
32 exit( 1 );
33 }
34
35 $fname = 'Setup.php';
36 $ps_setup = Profiler::instance()->scopedProfileIn( $fname );
37
38 // If any extensions are still queued, force load them
39 ExtensionRegistry::getInstance()->loadFromQueue();
40
41 // Check to see if we are at the file scope
42 if ( !isset( $wgVersion ) ) {
43 echo "Error, Setup.php must be included from the file scope, after DefaultSettings.php\n";
44 die( 1 );
45 }
46
47 // Set various default paths sensibly...
48 $ps_default = Profiler::instance()->scopedProfileIn( $fname . '-defaults' );
49
50 if ( $wgScript === false ) {
51 $wgScript = "$wgScriptPath/index$wgScriptExtension";
52 }
53 if ( $wgLoadScript === false ) {
54 $wgLoadScript = "$wgScriptPath/load$wgScriptExtension";
55 }
56
57 if ( $wgArticlePath === false ) {
58 if ( $wgUsePathInfo ) {
59 $wgArticlePath = "$wgScript/$1";
60 } else {
61 $wgArticlePath = "$wgScript?title=$1";
62 }
63 }
64
65 if ( !empty( $wgActionPaths ) && !isset( $wgActionPaths['view'] ) ) {
66 // 'view' is assumed the default action path everywhere in the code
67 // but is rarely filled in $wgActionPaths
68 $wgActionPaths['view'] = $wgArticlePath;
69 }
70
71 if ( $wgStylePath === false ) {
72 $wgStylePath = "$wgScriptPath/skins";
73 }
74 if ( $wgLocalStylePath === false ) {
75 $wgLocalStylePath = "$wgScriptPath/skins";
76 }
77 if ( $wgExtensionAssetsPath === false ) {
78 $wgExtensionAssetsPath = "$wgScriptPath/extensions";
79 }
80 if ( $wgResourceBasePath === null ) {
81 $wgResourceBasePath = $wgScriptPath;
82 }
83
84 if ( $wgLogo === false ) {
85 $wgLogo = "$wgResourceBasePath/resources/assets/wiki.png";
86 }
87
88 if ( $wgUploadPath === false ) {
89 $wgUploadPath = "$wgScriptPath/images";
90 }
91 if ( $wgUploadDirectory === false ) {
92 $wgUploadDirectory = "$IP/images";
93 }
94 if ( $wgReadOnlyFile === false ) {
95 $wgReadOnlyFile = "{$wgUploadDirectory}/lock_yBgMBwiR";
96 }
97 if ( $wgFileCacheDirectory === false ) {
98 $wgFileCacheDirectory = "{$wgUploadDirectory}/cache";
99 }
100 if ( $wgDeletedDirectory === false ) {
101 $wgDeletedDirectory = "{$wgUploadDirectory}/deleted";
102 }
103
104 if ( $wgGitInfoCacheDirectory === false && $wgCacheDirectory !== false ) {
105 $wgGitInfoCacheDirectory = "{$wgCacheDirectory}/gitinfo";
106 }
107
108 if ( $wgEnableParserCache === false ) {
109 $wgParserCacheType = CACHE_NONE;
110 }
111
112 // Fix path to icon images after they were moved in 1.24
113 if ( $wgRightsIcon ) {
114 $wgRightsIcon = str_replace(
115 "{$wgStylePath}/common/images/",
116 "{$wgResourceBasePath}/resources/assets/licenses/",
117 $wgRightsIcon
118 );
119 }
120
121 if ( isset( $wgFooterIcons['copyright'] )
122 && isset( $wgFooterIcons['copyright']['copyright'] )
123 && $wgFooterIcons['copyright']['copyright'] === array()
124 ) {
125 if ( $wgCopyrightIcon ) {
126 $wgFooterIcons['copyright']['copyright'] = $wgCopyrightIcon;
127 } elseif ( $wgRightsIcon || $wgRightsText ) {
128 $wgFooterIcons['copyright']['copyright'] = array(
129 'url' => $wgRightsUrl,
130 'src' => $wgRightsIcon,
131 'alt' => $wgRightsText,
132 );
133 } else {
134 unset( $wgFooterIcons['copyright']['copyright'] );
135 }
136 }
137
138 if ( isset( $wgFooterIcons['poweredby'] )
139 && isset( $wgFooterIcons['poweredby']['mediawiki'] )
140 && $wgFooterIcons['poweredby']['mediawiki']['src'] === null
141 ) {
142 $wgFooterIcons['poweredby']['mediawiki']['src'] =
143 "$wgResourceBasePath/resources/assets/poweredby_mediawiki_88x31.png";
144 $wgFooterIcons['poweredby']['mediawiki']['srcset'] =
145 "$wgResourceBasePath/resources/assets/poweredby_mediawiki_132x47.png 1.5x, " .
146 "$wgResourceBasePath/resources/assets/poweredby_mediawiki_176x62.png 2x";
147 }
148
149 /**
150 * Unconditional protection for NS_MEDIAWIKI since otherwise it's too easy for a
151 * sysadmin to set $wgNamespaceProtection incorrectly and leave the wiki insecure.
152 *
153 * Note that this is the definition of editinterface and it can be granted to
154 * all users if desired.
155 */
156 $wgNamespaceProtection[NS_MEDIAWIKI] = 'editinterface';
157
158 /**
159 * The canonical names of namespaces 6 and 7 are, as of v1.14, "File"
160 * and "File_talk". The old names "Image" and "Image_talk" are
161 * retained as aliases for backwards compatibility.
162 */
163 $wgNamespaceAliases['Image'] = NS_FILE;
164 $wgNamespaceAliases['Image_talk'] = NS_FILE_TALK;
165
166 /**
167 * Initialise $wgLockManagers to include basic FS version
168 */
169 $wgLockManagers[] = array(
170 'name' => 'fsLockManager',
171 'class' => 'FSLockManager',
172 'lockDirectory' => "{$wgUploadDirectory}/lockdir",
173 );
174 $wgLockManagers[] = array(
175 'name' => 'nullLockManager',
176 'class' => 'NullLockManager',
177 );
178
179 /**
180 * Initialise $wgLocalFileRepo from backwards-compatible settings
181 */
182 if ( !$wgLocalFileRepo ) {
183 $wgLocalFileRepo = array(
184 'class' => 'LocalRepo',
185 'name' => 'local',
186 'directory' => $wgUploadDirectory,
187 'scriptDirUrl' => $wgScriptPath,
188 'scriptExtension' => $wgScriptExtension,
189 'url' => $wgUploadBaseUrl ? $wgUploadBaseUrl . $wgUploadPath : $wgUploadPath,
190 'hashLevels' => $wgHashedUploadDirectory ? 2 : 0,
191 'thumbScriptUrl' => $wgThumbnailScriptPath,
192 'transformVia404' => !$wgGenerateThumbnailOnParse,
193 'deletedDir' => $wgDeletedDirectory,
194 'deletedHashLevels' => $wgHashedUploadDirectory ? 3 : 0
195 );
196 }
197 /**
198 * Initialise shared repo from backwards-compatible settings
199 */
200 if ( $wgUseSharedUploads ) {
201 if ( $wgSharedUploadDBname ) {
202 $wgForeignFileRepos[] = array(
203 'class' => 'ForeignDBRepo',
204 'name' => 'shared',
205 'directory' => $wgSharedUploadDirectory,
206 'url' => $wgSharedUploadPath,
207 'hashLevels' => $wgHashedSharedUploadDirectory ? 2 : 0,
208 'thumbScriptUrl' => $wgSharedThumbnailScriptPath,
209 'transformVia404' => !$wgGenerateThumbnailOnParse,
210 'dbType' => $wgDBtype,
211 'dbServer' => $wgDBserver,
212 'dbUser' => $wgDBuser,
213 'dbPassword' => $wgDBpassword,
214 'dbName' => $wgSharedUploadDBname,
215 'dbFlags' => ( $wgDebugDumpSql ? DBO_DEBUG : 0 ) | DBO_DEFAULT,
216 'tablePrefix' => $wgSharedUploadDBprefix,
217 'hasSharedCache' => $wgCacheSharedUploads,
218 'descBaseUrl' => $wgRepositoryBaseUrl,
219 'fetchDescription' => $wgFetchCommonsDescriptions,
220 );
221 } else {
222 $wgForeignFileRepos[] = array(
223 'class' => 'FileRepo',
224 'name' => 'shared',
225 'directory' => $wgSharedUploadDirectory,
226 'url' => $wgSharedUploadPath,
227 'hashLevels' => $wgHashedSharedUploadDirectory ? 2 : 0,
228 'thumbScriptUrl' => $wgSharedThumbnailScriptPath,
229 'transformVia404' => !$wgGenerateThumbnailOnParse,
230 'descBaseUrl' => $wgRepositoryBaseUrl,
231 'fetchDescription' => $wgFetchCommonsDescriptions,
232 );
233 }
234 }
235 if ( $wgUseInstantCommons ) {
236 $wgForeignFileRepos[] = array(
237 'class' => 'ForeignAPIRepo',
238 'name' => 'wikimediacommons',
239 'apibase' => 'https://commons.wikimedia.org/w/api.php',
240 'hashLevels' => 2,
241 'fetchDescription' => true,
242 'descriptionCacheExpiry' => 43200,
243 'apiThumbCacheExpiry' => 86400,
244 );
245 }
246 /*
247 * Add on default file backend config for file repos.
248 * FileBackendGroup will handle initializing the backends.
249 */
250 if ( !isset( $wgLocalFileRepo['backend'] ) ) {
251 $wgLocalFileRepo['backend'] = $wgLocalFileRepo['name'] . '-backend';
252 }
253 foreach ( $wgForeignFileRepos as &$repo ) {
254 if ( !isset( $repo['directory'] ) && $repo['class'] === 'ForeignAPIRepo' ) {
255 $repo['directory'] = $wgUploadDirectory; // b/c
256 }
257 if ( !isset( $repo['backend'] ) ) {
258 $repo['backend'] = $repo['name'] . '-backend';
259 }
260 }
261 unset( $repo ); // no global pollution; destroy reference
262
263 if ( $wgRCFilterByAge ) {
264 // Trim down $wgRCLinkDays so that it only lists links which are valid
265 // as determined by $wgRCMaxAge.
266 // Note that we allow 1 link higher than the max for things like 56 days but a 60 day link.
267 sort( $wgRCLinkDays );
268
269 // @codingStandardsIgnoreStart Generic.CodeAnalysis.ForLoopWithTestFunctionCall.NotAllowed
270 for ( $i = 0; $i < count( $wgRCLinkDays ); $i++ ) {
271 // @codingStandardsIgnoreEnd
272 if ( $wgRCLinkDays[$i] >= $wgRCMaxAge / ( 3600 * 24 ) ) {
273 $wgRCLinkDays = array_slice( $wgRCLinkDays, 0, $i + 1, false );
274 break;
275 }
276 }
277 }
278
279 if ( $wgSkipSkin ) {
280 $wgSkipSkins[] = $wgSkipSkin;
281 }
282
283 // Register skins
284 // Use a closure to avoid leaking into global state
285 call_user_func( function () use ( $wgValidSkinNames ) {
286 $factory = SkinFactory::getDefaultInstance();
287 foreach ( $wgValidSkinNames as $name => $skin ) {
288 $factory->register( $name, $skin, function () use ( $name, $skin ) {
289 $class = "Skin$skin";
290 return new $class( $name );
291 } );
292 }
293 // Register a hidden "fallback" skin
294 $factory->register( 'fallback', 'Fallback', function () {
295 return new SkinFallback;
296 } );
297 // Register a hidden skin for api output
298 $factory->register( 'apioutput', 'ApiOutput', function () {
299 return new SkinApi;
300 } );
301 } );
302 $wgSkipSkins[] = 'fallback';
303 $wgSkipSkins[] = 'apioutput';
304
305 if ( $wgLocalInterwiki ) {
306 array_unshift( $wgLocalInterwikis, $wgLocalInterwiki );
307 }
308
309 // Set default shared prefix
310 if ( $wgSharedPrefix === false ) {
311 $wgSharedPrefix = $wgDBprefix;
312 }
313
314 // Set default shared schema
315 if ( $wgSharedSchema === false ) {
316 $wgSharedSchema = $wgDBmwschema;
317 }
318
319 if ( !$wgCookiePrefix ) {
320 if ( $wgSharedDB && $wgSharedPrefix && in_array( 'user', $wgSharedTables ) ) {
321 $wgCookiePrefix = $wgSharedDB . '_' . $wgSharedPrefix;
322 } elseif ( $wgSharedDB && in_array( 'user', $wgSharedTables ) ) {
323 $wgCookiePrefix = $wgSharedDB;
324 } elseif ( $wgDBprefix ) {
325 $wgCookiePrefix = $wgDBname . '_' . $wgDBprefix;
326 } else {
327 $wgCookiePrefix = $wgDBname;
328 }
329 }
330 $wgCookiePrefix = strtr( $wgCookiePrefix, '=,; +."\'\\[', '__________' );
331
332 if ( $wgEnableEmail ) {
333 $wgUseEnotif = $wgEnotifUserTalk || $wgEnotifWatchlist;
334 } else {
335 // Disable all other email settings automatically if $wgEnableEmail
336 // is set to false. - bug 63678
337 $wgAllowHTMLEmail = false;
338 $wgEmailAuthentication = false; // do not require auth if you're not sending email anyway
339 $wgEnableUserEmail = false;
340 $wgEnotifFromEditor = false;
341 $wgEnotifImpersonal = false;
342 $wgEnotifMaxRecips = 0;
343 $wgEnotifMinorEdits = false;
344 $wgEnotifRevealEditorAddress = false;
345 $wgEnotifUseJobQ = false;
346 $wgEnotifUseRealName = false;
347 $wgEnotifUserTalk = false;
348 $wgEnotifWatchlist = false;
349 unset( $wgGroupPermissions['user']['sendemail'] );
350 $wgUseEnotif = false;
351 $wgUserEmailUseReplyTo = false;
352 $wgUsersNotifiedOnAllChanges = array();
353 }
354
355 // Doesn't make sense to have if disabled.
356 if ( !$wgEnotifMinorEdits ) {
357 $wgHiddenPrefs[] = 'enotifminoredits';
358 }
359
360 if ( $wgMetaNamespace === false ) {
361 $wgMetaNamespace = str_replace( ' ', '_', $wgSitename );
362 }
363
364 // Default value is 2000 or the suhosin limit if it is between 1 and 2000
365 if ( $wgResourceLoaderMaxQueryLength === false ) {
366 $suhosinMaxValueLength = (int)ini_get( 'suhosin.get.max_value_length' );
367 if ( $suhosinMaxValueLength > 0 && $suhosinMaxValueLength < 2000 ) {
368 $wgResourceLoaderMaxQueryLength = $suhosinMaxValueLength;
369 } else {
370 $wgResourceLoaderMaxQueryLength = 2000;
371 }
372 unset( $suhosinMaxValueLength );
373 }
374
375 /**
376 * Definitions of the NS_ constants are in Defines.php
377 * @private
378 */
379 $wgCanonicalNamespaceNames = array(
380 NS_MEDIA => 'Media',
381 NS_SPECIAL => 'Special',
382 NS_TALK => 'Talk',
383 NS_USER => 'User',
384 NS_USER_TALK => 'User_talk',
385 NS_PROJECT => 'Project',
386 NS_PROJECT_TALK => 'Project_talk',
387 NS_FILE => 'File',
388 NS_FILE_TALK => 'File_talk',
389 NS_MEDIAWIKI => 'MediaWiki',
390 NS_MEDIAWIKI_TALK => 'MediaWiki_talk',
391 NS_TEMPLATE => 'Template',
392 NS_TEMPLATE_TALK => 'Template_talk',
393 NS_HELP => 'Help',
394 NS_HELP_TALK => 'Help_talk',
395 NS_CATEGORY => 'Category',
396 NS_CATEGORY_TALK => 'Category_talk',
397 );
398
399 /// @todo UGLY UGLY
400 if ( is_array( $wgExtraNamespaces ) ) {
401 $wgCanonicalNamespaceNames = $wgCanonicalNamespaceNames + $wgExtraNamespaces;
402 }
403
404 // These are now the same, always
405 // To determine the user language, use $wgLang->getCode()
406 $wgContLanguageCode = $wgLanguageCode;
407
408 // Easy to forget to falsify $wgShowIPinHeader for static caches.
409 // If file cache or squid cache is on, just disable this (DWIMD).
410 // Do the same for $wgDebugToolbar.
411 if ( $wgUseFileCache || $wgUseSquid ) {
412 $wgShowIPinHeader = false;
413 $wgDebugToolbar = false;
414 }
415
416 // We always output HTML5 since 1.22, overriding these is no longer supported
417 // we set them here for extensions that depend on its value.
418 $wgHtml5 = true;
419 $wgXhtmlDefaultNamespace = 'http://www.w3.org/1999/xhtml';
420 $wgJsMimeType = 'text/javascript';
421
422 if ( !$wgHtml5Version && $wgAllowRdfaAttributes ) {
423 // see http://www.w3.org/TR/rdfa-in-html/#document-conformance
424 if ( $wgMimeType == 'application/xhtml+xml' ) {
425 $wgHtml5Version = 'XHTML+RDFa 1.0';
426 } else {
427 $wgHtml5Version = 'HTML+RDFa 1.0';
428 }
429 }
430
431 // Blacklisted file extensions shouldn't appear on the "allowed" list
432 $wgFileExtensions = array_values( array_diff( $wgFileExtensions, $wgFileBlacklist ) );
433
434 if ( $wgInvalidateCacheOnLocalSettingsChange ) {
435 MediaWiki\suppressWarnings();
436 $wgCacheEpoch = max( $wgCacheEpoch, gmdate( 'YmdHis', filemtime( "$IP/LocalSettings.php" ) ) );
437 MediaWiki\restoreWarnings();
438 }
439
440 if ( $wgNewUserLog ) {
441 // Add a new log type
442 $wgLogTypes[] = 'newusers';
443 $wgLogNames['newusers'] = 'newuserlogpage';
444 $wgLogHeaders['newusers'] = 'newuserlogpagetext';
445 $wgLogActionsHandlers['newusers/newusers'] = 'NewUsersLogFormatter';
446 $wgLogActionsHandlers['newusers/create'] = 'NewUsersLogFormatter';
447 $wgLogActionsHandlers['newusers/create2'] = 'NewUsersLogFormatter';
448 $wgLogActionsHandlers['newusers/byemail'] = 'NewUsersLogFormatter';
449 $wgLogActionsHandlers['newusers/autocreate'] = 'NewUsersLogFormatter';
450 }
451
452 if ( $wgPageLanguageUseDB ) {
453 $wgLogTypes[] = 'pagelang';
454 $wgLogActionsHandlers['pagelang/pagelang'] = 'PageLangLogFormatter';
455 }
456
457 if ( $wgCookieSecure === 'detect' ) {
458 $wgCookieSecure = ( WebRequest::detectProtocol() === 'https' );
459 }
460
461 // Back compatibility for $wgRateLimitLog deprecated with 1.23
462 if ( $wgRateLimitLog && !array_key_exists( 'ratelimit', $wgDebugLogGroups ) ) {
463 $wgDebugLogGroups['ratelimit'] = $wgRateLimitLog;
464 }
465
466 if ( $wgProfileOnly ) {
467 $wgDebugLogGroups['profileoutput'] = $wgDebugLogFile;
468 $wgDebugLogFile = '';
469 }
470
471 // Backwards compatibility with old password limits
472 if ( $wgMinimalPasswordLength !== false ) {
473 $wgPasswordPolicy['policies']['default']['MinimalPasswordLength'] = $wgMinimalPasswordLength;
474 }
475
476 if ( $wgMaximalPasswordLength !== false ) {
477 $wgPasswordPolicy['policies']['default']['MaximalPasswordLength'] = $wgMaximalPasswordLength;
478 }
479
480 Profiler::instance()->scopedProfileOut( $ps_default );
481
482 // Disable MWDebug for command line mode, this prevents MWDebug from eating up
483 // all the memory from logging SQL queries on maintenance scripts
484 global $wgCommandLineMode;
485 if ( $wgDebugToolbar && !$wgCommandLineMode ) {
486 MWDebug::init();
487 }
488
489 if ( !class_exists( 'AutoLoader' ) ) {
490 require_once "$IP/includes/AutoLoader.php";
491 }
492
493 MWExceptionHandler::installHandler();
494
495 require_once "$IP/includes/libs/normal/UtfNormalUtil.php";
496
497 $ps_default2 = Profiler::instance()->scopedProfileIn( $fname . '-defaults2' );
498
499 if ( $wgScriptExtension !== '.php' || defined( 'MW_ENTRY_PHP5' ) ) {
500 wfWarn( 'Script extensions other than ".php" are deprecated.' );
501 }
502
503 if ( $wgCanonicalServer === false ) {
504 $wgCanonicalServer = wfExpandUrl( $wgServer, PROTO_HTTP );
505 }
506
507 // Set server name
508 $serverParts = wfParseUrl( $wgCanonicalServer );
509 if ( $wgServerName !== false ) {
510 wfWarn( '$wgServerName should be derived from $wgCanonicalServer, '
511 . 'not customized. Overwriting $wgServerName.' );
512 }
513 $wgServerName = $serverParts['host'];
514 unset( $serverParts );
515
516 // Set defaults for configuration variables
517 // that are derived from the server name by default
518 if ( $wgEmergencyContact === false ) {
519 $wgEmergencyContact = 'wikiadmin@' . $wgServerName;
520 }
521
522 if ( $wgPasswordSender === false ) {
523 $wgPasswordSender = 'apache@' . $wgServerName;
524 }
525
526 if ( $wgSecureLogin && substr( $wgServer, 0, 2 ) !== '//' ) {
527 $wgSecureLogin = false;
528 wfWarn( 'Secure login was enabled on a server that only supports '
529 . 'HTTP or HTTPS. Disabling secure login.' );
530 }
531
532 // Now that GlobalFunctions is loaded, set defaults that depend on it.
533 if ( $wgTmpDirectory === false ) {
534 $wgTmpDirectory = wfTempDir();
535 }
536
537 // We don't use counters anymore. Left here for extensions still
538 // expecting this to exist. Should be removed sometime 1.26 or later.
539 if ( !isset( $wgDisableCounters ) ) {
540 $wgDisableCounters = true;
541 }
542
543 if ( $wgMainWANCache === false ) {
544 // Setup a WAN cache from $wgMainCacheType with no relayer.
545 // Sites using multiple datacenters can configure a relayer.
546 $wgMainWANCache = 'mediawiki-main-default';
547 $wgWANObjectCaches[$wgMainWANCache] = array(
548 'class' => 'WANObjectCache',
549 'cacheId' => $wgMainCacheType,
550 'pool' => 'mediawiki-main-default',
551 'relayerConfig' => array( 'class' => 'EventRelayerNull' )
552 );
553 }
554
555 Profiler::instance()->scopedProfileOut( $ps_default2 );
556
557 $ps_misc = Profiler::instance()->scopedProfileIn( $fname . '-misc1' );
558
559 // Raise the memory limit if it's too low
560 wfMemoryLimit();
561
562 /**
563 * Set up the timezone, suppressing the pseudo-security warning in PHP 5.1+
564 * that happens whenever you use a date function without the timezone being
565 * explicitly set. Inspired by phpMyAdmin's treatment of the problem.
566 */
567 if ( is_null( $wgLocaltimezone ) ) {
568 MediaWiki\suppressWarnings();
569 $wgLocaltimezone = date_default_timezone_get();
570 MediaWiki\restoreWarnings();
571 }
572
573 date_default_timezone_set( $wgLocaltimezone );
574 if ( is_null( $wgLocalTZoffset ) ) {
575 $wgLocalTZoffset = date( 'Z' ) / 60;
576 }
577
578 if ( !$wgDBerrorLogTZ ) {
579 $wgDBerrorLogTZ = $wgLocaltimezone;
580 }
581
582 // Useful debug output
583 if ( $wgCommandLineMode ) {
584 $wgRequest = new FauxRequest( array() );
585
586 wfDebug( "\n\nStart command line script $self\n" );
587 } else {
588 // Can't stub this one, it sets up $_GET and $_REQUEST in its constructor
589 $wgRequest = new WebRequest;
590
591 $debug = "\n\nStart request {$wgRequest->getMethod()} {$wgRequest->getRequestURL()}\n";
592
593 if ( $wgDebugPrintHttpHeaders ) {
594 $debug .= "HTTP HEADERS:\n";
595
596 foreach ( $wgRequest->getAllHeaders() as $name => $value ) {
597 $debug .= "$name: $value\n";
598 }
599 }
600 wfDebug( $debug );
601 }
602
603 Profiler::instance()->scopedProfileOut( $ps_misc );
604 $ps_memcached = Profiler::instance()->scopedProfileIn( $fname . '-memcached' );
605
606 $wgMemc = wfGetMainCache();
607 $messageMemc = wfGetMessageCacheStorage();
608 $parserMemc = wfGetParserCacheStorage();
609
610 wfDebugLog( 'caches', 'main: ' . get_class( $wgMemc ) .
611 ', message: ' . get_class( $messageMemc ) .
612 ', parser: ' . get_class( $parserMemc ) );
613
614 Profiler::instance()->scopedProfileOut( $ps_memcached );
615
616 // Most of the config is out, some might want to run hooks here.
617 Hooks::run( 'SetupAfterCache' );
618
619 $ps_session = Profiler::instance()->scopedProfileIn( $fname . '-session' );
620
621 if ( !defined( 'MW_NO_SESSION' ) && !$wgCommandLineMode ) {
622 // If session.auto_start is there, we can't touch session name
623 if ( !wfIniGetBool( 'session.auto_start' ) ) {
624 session_name( $wgSessionName ? $wgSessionName : $wgCookiePrefix . '_session' );
625 }
626
627 if ( $wgRequest->checkSessionCookie() || isset( $_COOKIE[$wgCookiePrefix . 'Token'] ) ) {
628 wfSetupSession();
629 }
630 }
631
632 Profiler::instance()->scopedProfileOut( $ps_session );
633 $ps_globals = Profiler::instance()->scopedProfileIn( $fname . '-globals' );
634
635 /**
636 * @var Language $wgContLang
637 */
638 $wgContLang = Language::factory( $wgLanguageCode );
639 $wgContLang->initEncoding();
640 $wgContLang->initContLang();
641
642 // Now that variant lists may be available...
643 $wgRequest->interpolateTitle();
644
645 /**
646 * @var User $wgUser
647 */
648 $wgUser = RequestContext::getMain()->getUser(); // BackCompat
649
650 /**
651 * @var Language $wgLang
652 */
653 $wgLang = new StubUserLang;
654
655 /**
656 * @var OutputPage $wgOut
657 */
658 $wgOut = RequestContext::getMain()->getOutput(); // BackCompat
659
660 /**
661 * @var Parser $wgParser
662 */
663 $wgParser = new StubObject( 'wgParser', $wgParserConf['class'], array( $wgParserConf ) );
664
665 if ( !is_object( $wgAuth ) ) {
666 $wgAuth = new AuthPlugin;
667 Hooks::run( 'AuthPluginSetup', array( &$wgAuth ) );
668 }
669
670 /**
671 * @var Title $wgTitle
672 */
673 $wgTitle = null;
674
675 /**
676 * @deprecated since 1.24 Use DeferredUpdates::addUpdate instead
677 * @var array
678 */
679 $wgDeferredUpdateList = array();
680
681 Profiler::instance()->scopedProfileOut( $ps_globals );
682 $ps_extensions = Profiler::instance()->scopedProfileIn( $fname . '-extensions' );
683
684 // Extension setup functions for extensions other than skins
685 // Entries should be added to this variable during the inclusion
686 // of the extension file. This allows the extension to perform
687 // any necessary initialisation in the fully initialised environment
688 foreach ( $wgExtensionFunctions as $func ) {
689 // Allow closures in PHP 5.3+
690 if ( is_object( $func ) && $func instanceof Closure ) {
691 $profName = $fname . '-extensions-closure';
692 } elseif ( is_array( $func ) ) {
693 if ( is_object( $func[0] ) ) {
694 $profName = $fname . '-extensions-' . get_class( $func[0] ) . '::' . $func[1];
695 } else {
696 $profName = $fname . '-extensions-' . implode( '::', $func );
697 }
698 } else {
699 $profName = $fname . '-extensions-' . strval( $func );
700 }
701
702 $ps_ext_func = Profiler::instance()->scopedProfileIn( $profName );
703 call_user_func( $func );
704 Profiler::instance()->scopedProfileOut( $ps_ext_func );
705 }
706
707 wfDebug( "Fully initialised\n" );
708 $wgFullyInitialised = true;
709
710 Profiler::instance()->scopedProfileOut( $ps_extensions );
711 Profiler::instance()->scopedProfileOut( $ps_setup );
712