Merge "Update namespaces and special pages for Northern Luri (lrc) from translatewiki"
[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' => WebRequest::detectProtocol() === 'https' ?
240 'https://commons.wikimedia.org/w/api.php' :
241 'http://commons.wikimedia.org/w/api.php',
242 'hashLevels' => 2,
243 'fetchDescription' => true,
244 'descriptionCacheExpiry' => 43200,
245 'apiThumbCacheExpiry' => 86400,
246 );
247 }
248 /*
249 * Add on default file backend config for file repos.
250 * FileBackendGroup will handle initializing the backends.
251 */
252 if ( !isset( $wgLocalFileRepo['backend'] ) ) {
253 $wgLocalFileRepo['backend'] = $wgLocalFileRepo['name'] . '-backend';
254 }
255 foreach ( $wgForeignFileRepos as &$repo ) {
256 if ( !isset( $repo['directory'] ) && $repo['class'] === 'ForeignAPIRepo' ) {
257 $repo['directory'] = $wgUploadDirectory; // b/c
258 }
259 if ( !isset( $repo['backend'] ) ) {
260 $repo['backend'] = $repo['name'] . '-backend';
261 }
262 }
263 unset( $repo ); // no global pollution; destroy reference
264
265 if ( $wgRCFilterByAge ) {
266 // Trim down $wgRCLinkDays so that it only lists links which are valid
267 // as determined by $wgRCMaxAge.
268 // Note that we allow 1 link higher than the max for things like 56 days but a 60 day link.
269 sort( $wgRCLinkDays );
270
271 // @codingStandardsIgnoreStart Generic.CodeAnalysis.ForLoopWithTestFunctionCall.NotAllowed
272 for ( $i = 0; $i < count( $wgRCLinkDays ); $i++ ) {
273 // @codingStandardsIgnoreEnd
274 if ( $wgRCLinkDays[$i] >= $wgRCMaxAge / ( 3600 * 24 ) ) {
275 $wgRCLinkDays = array_slice( $wgRCLinkDays, 0, $i + 1, false );
276 break;
277 }
278 }
279 }
280
281 if ( $wgSkipSkin ) {
282 $wgSkipSkins[] = $wgSkipSkin;
283 }
284
285 // Register skins
286 // Use a closure to avoid leaking into global state
287 call_user_func( function () use ( $wgValidSkinNames ) {
288 $factory = SkinFactory::getDefaultInstance();
289 foreach ( $wgValidSkinNames as $name => $skin ) {
290 $factory->register( $name, $skin, function () use ( $name, $skin ) {
291 $class = "Skin$skin";
292 return new $class( $name );
293 } );
294 }
295 // Register a hidden "fallback" skin
296 $factory->register( 'fallback', 'Fallback', function () {
297 return new SkinFallback;
298 } );
299 // Register a hidden skin for api output
300 $factory->register( 'apioutput', 'ApiOutput', function () {
301 return new SkinApi;
302 } );
303 } );
304 $wgSkipSkins[] = 'fallback';
305 $wgSkipSkins[] = 'apioutput';
306
307 if ( $wgLocalInterwiki ) {
308 array_unshift( $wgLocalInterwikis, $wgLocalInterwiki );
309 }
310
311 // Set default shared prefix
312 if ( $wgSharedPrefix === false ) {
313 $wgSharedPrefix = $wgDBprefix;
314 }
315
316 // Set default shared schema
317 if ( $wgSharedSchema === false ) {
318 $wgSharedSchema = $wgDBmwschema;
319 }
320
321 if ( !$wgCookiePrefix ) {
322 if ( $wgSharedDB && $wgSharedPrefix && in_array( 'user', $wgSharedTables ) ) {
323 $wgCookiePrefix = $wgSharedDB . '_' . $wgSharedPrefix;
324 } elseif ( $wgSharedDB && in_array( 'user', $wgSharedTables ) ) {
325 $wgCookiePrefix = $wgSharedDB;
326 } elseif ( $wgDBprefix ) {
327 $wgCookiePrefix = $wgDBname . '_' . $wgDBprefix;
328 } else {
329 $wgCookiePrefix = $wgDBname;
330 }
331 }
332 $wgCookiePrefix = strtr( $wgCookiePrefix, '=,; +."\'\\[', '__________' );
333
334 if ( $wgEnableEmail ) {
335 $wgUseEnotif = $wgEnotifUserTalk || $wgEnotifWatchlist;
336 } else {
337 // Disable all other email settings automatically if $wgEnableEmail
338 // is set to false. - bug 63678
339 $wgAllowHTMLEmail = false;
340 $wgEmailAuthentication = false; // do not require auth if you're not sending email anyway
341 $wgEnableUserEmail = false;
342 $wgEnotifFromEditor = false;
343 $wgEnotifImpersonal = false;
344 $wgEnotifMaxRecips = 0;
345 $wgEnotifMinorEdits = false;
346 $wgEnotifRevealEditorAddress = false;
347 $wgEnotifUseJobQ = false;
348 $wgEnotifUseRealName = false;
349 $wgEnotifUserTalk = false;
350 $wgEnotifWatchlist = false;
351 unset( $wgGroupPermissions['user']['sendemail'] );
352 $wgUseEnotif = false;
353 $wgUserEmailUseReplyTo = false;
354 $wgUsersNotifiedOnAllChanges = array();
355 }
356
357 // Doesn't make sense to have if disabled.
358 if ( !$wgEnotifMinorEdits ) {
359 $wgHiddenPrefs[] = 'enotifminoredits';
360 }
361
362 if ( $wgMetaNamespace === false ) {
363 $wgMetaNamespace = str_replace( ' ', '_', $wgSitename );
364 }
365
366 // Default value is 2000 or the suhosin limit if it is between 1 and 2000
367 if ( $wgResourceLoaderMaxQueryLength === false ) {
368 $suhosinMaxValueLength = (int) ini_get( 'suhosin.get.max_value_length' );
369 if ( $suhosinMaxValueLength > 0 && $suhosinMaxValueLength < 2000 ) {
370 $wgResourceLoaderMaxQueryLength = $suhosinMaxValueLength;
371 } else {
372 $wgResourceLoaderMaxQueryLength = 2000;
373 }
374 unset($suhosinMaxValueLength);
375 }
376
377 /**
378 * Definitions of the NS_ constants are in Defines.php
379 * @private
380 */
381 $wgCanonicalNamespaceNames = array(
382 NS_MEDIA => 'Media',
383 NS_SPECIAL => 'Special',
384 NS_TALK => 'Talk',
385 NS_USER => 'User',
386 NS_USER_TALK => 'User_talk',
387 NS_PROJECT => 'Project',
388 NS_PROJECT_TALK => 'Project_talk',
389 NS_FILE => 'File',
390 NS_FILE_TALK => 'File_talk',
391 NS_MEDIAWIKI => 'MediaWiki',
392 NS_MEDIAWIKI_TALK => 'MediaWiki_talk',
393 NS_TEMPLATE => 'Template',
394 NS_TEMPLATE_TALK => 'Template_talk',
395 NS_HELP => 'Help',
396 NS_HELP_TALK => 'Help_talk',
397 NS_CATEGORY => 'Category',
398 NS_CATEGORY_TALK => 'Category_talk',
399 );
400
401 /// @todo UGLY UGLY
402 if ( is_array( $wgExtraNamespaces ) ) {
403 $wgCanonicalNamespaceNames = $wgCanonicalNamespaceNames + $wgExtraNamespaces;
404 }
405
406 // These are now the same, always
407 // To determine the user language, use $wgLang->getCode()
408 $wgContLanguageCode = $wgLanguageCode;
409
410 // Easy to forget to falsify $wgShowIPinHeader for static caches.
411 // If file cache or squid cache is on, just disable this (DWIMD).
412 // Do the same for $wgDebugToolbar.
413 if ( $wgUseFileCache || $wgUseSquid ) {
414 $wgShowIPinHeader = false;
415 $wgDebugToolbar = false;
416 }
417
418 // We always output HTML5 since 1.22, overriding these is no longer supported
419 // we set them here for extensions that depend on its value.
420 $wgHtml5 = true;
421 $wgXhtmlDefaultNamespace = 'http://www.w3.org/1999/xhtml';
422 $wgJsMimeType = 'text/javascript';
423
424 if ( !$wgHtml5Version && $wgAllowRdfaAttributes ) {
425 // see http://www.w3.org/TR/rdfa-in-html/#document-conformance
426 if ( $wgMimeType == 'application/xhtml+xml' ) {
427 $wgHtml5Version = 'XHTML+RDFa 1.0';
428 } else {
429 $wgHtml5Version = 'HTML+RDFa 1.0';
430 }
431 }
432
433 // Blacklisted file extensions shouldn't appear on the "allowed" list
434 $wgFileExtensions = array_values( array_diff ( $wgFileExtensions, $wgFileBlacklist ) );
435
436 if ( $wgInvalidateCacheOnLocalSettingsChange ) {
437 // @codingStandardsIgnoreStart Generic.PHP.NoSilencedErrors.Discouraged - No GlobalFunction here yet.
438 $wgCacheEpoch = max( $wgCacheEpoch, gmdate( 'YmdHis', @filemtime( "$IP/LocalSettings.php" ) ) );
439 // @codingStandardsIgnoreEnd
440 }
441
442 if ( $wgNewUserLog ) {
443 // Add a new log type
444 $wgLogTypes[] = 'newusers';
445 $wgLogNames['newusers'] = 'newuserlogpage';
446 $wgLogHeaders['newusers'] = 'newuserlogpagetext';
447 $wgLogActionsHandlers['newusers/newusers'] = 'NewUsersLogFormatter';
448 $wgLogActionsHandlers['newusers/create'] = 'NewUsersLogFormatter';
449 $wgLogActionsHandlers['newusers/create2'] = 'NewUsersLogFormatter';
450 $wgLogActionsHandlers['newusers/byemail'] = 'NewUsersLogFormatter';
451 $wgLogActionsHandlers['newusers/autocreate'] = 'NewUsersLogFormatter';
452 }
453
454 if ( $wgPageLanguageUseDB ) {
455 $wgLogTypes[] = 'pagelang';
456 $wgLogActionsHandlers['pagelang/pagelang'] = 'PageLangLogFormatter';
457 }
458
459 if ( $wgCookieSecure === 'detect' ) {
460 $wgCookieSecure = ( WebRequest::detectProtocol() === 'https' );
461 }
462
463 // Back compatibility for $wgRateLimitLog deprecated with 1.23
464 if ( $wgRateLimitLog && !array_key_exists( 'ratelimit', $wgDebugLogGroups ) ) {
465 $wgDebugLogGroups['ratelimit'] = $wgRateLimitLog;
466 }
467
468 if ( $wgProfileOnly ) {
469 $wgDebugLogGroups['profileoutput'] = $wgDebugLogFile;
470 $wgDebugLogFile = '';
471 }
472
473 // Backwards compatibility with old password limits
474 if ( $wgMinimalPasswordLength !== false ) {
475 $wgPasswordPolicy['policies']['default']['MinimalPasswordLength'] = $wgMinimalPasswordLength;
476 }
477
478 if ( $wgMaximalPasswordLength !== false ) {
479 $wgPasswordPolicy['policies']['default']['MaximalPasswordLength'] = $wgMaximalPasswordLength;
480 }
481
482 Profiler::instance()->scopedProfileOut( $ps_default );
483
484 // Disable MWDebug for command line mode, this prevents MWDebug from eating up
485 // all the memory from logging SQL queries on maintenance scripts
486 global $wgCommandLineMode;
487 if ( $wgDebugToolbar && !$wgCommandLineMode ) {
488 MWDebug::init();
489 }
490
491 if ( !class_exists( 'AutoLoader' ) ) {
492 require_once "$IP/includes/AutoLoader.php";
493 }
494
495 MWExceptionHandler::installHandler();
496
497 require_once "$IP/includes/libs/normal/UtfNormalUtil.php";
498
499 $ps_default2 = Profiler::instance()->scopedProfileIn( $fname . '-defaults2' );
500
501 if ( $wgScriptExtension !== '.php' || defined( 'MW_ENTRY_PHP5' ) ) {
502 wfWarn( 'Script extensions other than ".php" are deprecated.' );
503 }
504
505 if ( $wgCanonicalServer === false ) {
506 $wgCanonicalServer = wfExpandUrl( $wgServer, PROTO_HTTP );
507 }
508
509 // Set server name
510 $serverParts = wfParseUrl( $wgCanonicalServer );
511 if ( $wgServerName !== false ) {
512 wfWarn( '$wgServerName should be derived from $wgCanonicalServer, '
513 . 'not customized. Overwriting $wgServerName.' );
514 }
515 $wgServerName = $serverParts['host'];
516 unset( $serverParts );
517
518 // Set defaults for configuration variables
519 // that are derived from the server name by default
520 if ( $wgEmergencyContact === false ) {
521 $wgEmergencyContact = 'wikiadmin@' . $wgServerName;
522 }
523
524 if ( $wgPasswordSender === false ) {
525 $wgPasswordSender = 'apache@' . $wgServerName;
526 }
527
528 if ( $wgSecureLogin && substr( $wgServer, 0, 2 ) !== '//' ) {
529 $wgSecureLogin = false;
530 wfWarn( 'Secure login was enabled on a server that only supports '
531 . 'HTTP or HTTPS. Disabling secure login.' );
532 }
533
534 // Now that GlobalFunctions is loaded, set defaults that depend on it.
535 if ( $wgTmpDirectory === false ) {
536 $wgTmpDirectory = wfTempDir();
537 }
538
539 // We don't use counters anymore. Left here for extensions still
540 // expecting this to exist. Should be removed sometime 1.26 or later.
541 $wgDisableCounters = true;
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 wfSuppressWarnings();
569 $wgLocaltimezone = date_default_timezone_get();
570 wfRestoreWarnings();
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