Title.php: Avoid wfGetLangObj for Language objects
[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.php";
52 }
53 if ( $wgLoadScript === false ) {
54 $wgLoadScript = "$wgScriptPath/load.php";
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 ( $wgResourceBasePath === null ) {
72 $wgResourceBasePath = $wgScriptPath;
73 }
74 if ( $wgStylePath === false ) {
75 $wgStylePath = "$wgResourceBasePath/skins";
76 }
77 if ( $wgLocalStylePath === false ) {
78 // Avoid wgResourceBasePath here since that may point to a different domain (e.g. CDN)
79 $wgLocalStylePath = "$wgScriptPath/skins";
80 }
81 if ( $wgExtensionAssetsPath === false ) {
82 $wgExtensionAssetsPath = "$wgResourceBasePath/extensions";
83 }
84
85 if ( $wgLogo === false ) {
86 $wgLogo = "$wgResourceBasePath/resources/assets/wiki.png";
87 }
88
89 if ( $wgUploadPath === false ) {
90 $wgUploadPath = "$wgScriptPath/images";
91 }
92 if ( $wgUploadDirectory === false ) {
93 $wgUploadDirectory = "$IP/images";
94 }
95 if ( $wgReadOnlyFile === false ) {
96 $wgReadOnlyFile = "{$wgUploadDirectory}/lock_yBgMBwiR";
97 }
98 if ( $wgFileCacheDirectory === false ) {
99 $wgFileCacheDirectory = "{$wgUploadDirectory}/cache";
100 }
101 if ( $wgDeletedDirectory === false ) {
102 $wgDeletedDirectory = "{$wgUploadDirectory}/deleted";
103 }
104
105 if ( $wgGitInfoCacheDirectory === false && $wgCacheDirectory !== false ) {
106 $wgGitInfoCacheDirectory = "{$wgCacheDirectory}/gitinfo";
107 }
108
109 if ( $wgEnableParserCache === false ) {
110 $wgParserCacheType = CACHE_NONE;
111 }
112
113 // Fix path to icon images after they were moved in 1.24
114 if ( $wgRightsIcon ) {
115 $wgRightsIcon = str_replace(
116 "{$wgStylePath}/common/images/",
117 "{$wgResourceBasePath}/resources/assets/licenses/",
118 $wgRightsIcon
119 );
120 }
121
122 if ( isset( $wgFooterIcons['copyright'] )
123 && isset( $wgFooterIcons['copyright']['copyright'] )
124 && $wgFooterIcons['copyright']['copyright'] === array()
125 ) {
126 if ( $wgCopyrightIcon ) {
127 $wgFooterIcons['copyright']['copyright'] = $wgCopyrightIcon;
128 } elseif ( $wgRightsIcon || $wgRightsText ) {
129 $wgFooterIcons['copyright']['copyright'] = array(
130 'url' => $wgRightsUrl,
131 'src' => $wgRightsIcon,
132 'alt' => $wgRightsText,
133 );
134 } else {
135 unset( $wgFooterIcons['copyright']['copyright'] );
136 }
137 }
138
139 if ( isset( $wgFooterIcons['poweredby'] )
140 && isset( $wgFooterIcons['poweredby']['mediawiki'] )
141 && $wgFooterIcons['poweredby']['mediawiki']['src'] === null
142 ) {
143 $wgFooterIcons['poweredby']['mediawiki']['src'] =
144 "$wgResourceBasePath/resources/assets/poweredby_mediawiki_88x31.png";
145 $wgFooterIcons['poweredby']['mediawiki']['srcset'] =
146 "$wgResourceBasePath/resources/assets/poweredby_mediawiki_132x47.png 1.5x, " .
147 "$wgResourceBasePath/resources/assets/poweredby_mediawiki_176x62.png 2x";
148 }
149
150 /**
151 * Unconditional protection for NS_MEDIAWIKI since otherwise it's too easy for a
152 * sysadmin to set $wgNamespaceProtection incorrectly and leave the wiki insecure.
153 *
154 * Note that this is the definition of editinterface and it can be granted to
155 * all users if desired.
156 */
157 $wgNamespaceProtection[NS_MEDIAWIKI] = 'editinterface';
158
159 /**
160 * The canonical names of namespaces 6 and 7 are, as of v1.14, "File"
161 * and "File_talk". The old names "Image" and "Image_talk" are
162 * retained as aliases for backwards compatibility.
163 */
164 $wgNamespaceAliases['Image'] = NS_FILE;
165 $wgNamespaceAliases['Image_talk'] = NS_FILE_TALK;
166
167 /**
168 * Initialise $wgLockManagers to include basic FS version
169 */
170 $wgLockManagers[] = array(
171 'name' => 'fsLockManager',
172 'class' => 'FSLockManager',
173 'lockDirectory' => "{$wgUploadDirectory}/lockdir",
174 );
175 $wgLockManagers[] = array(
176 'name' => 'nullLockManager',
177 'class' => 'NullLockManager',
178 );
179
180 /**
181 * Initialise $wgLocalFileRepo from backwards-compatible settings
182 */
183 if ( !$wgLocalFileRepo ) {
184 $wgLocalFileRepo = array(
185 'class' => 'LocalRepo',
186 'name' => 'local',
187 'directory' => $wgUploadDirectory,
188 'scriptDirUrl' => $wgScriptPath,
189 'scriptExtension' => '.php',
190 'url' => $wgUploadBaseUrl ? $wgUploadBaseUrl . $wgUploadPath : $wgUploadPath,
191 'hashLevels' => $wgHashedUploadDirectory ? 2 : 0,
192 'thumbScriptUrl' => $wgThumbnailScriptPath,
193 'transformVia404' => !$wgGenerateThumbnailOnParse,
194 'deletedDir' => $wgDeletedDirectory,
195 'deletedHashLevels' => $wgHashedUploadDirectory ? 3 : 0
196 );
197 }
198 /**
199 * Initialise shared repo from backwards-compatible settings
200 */
201 if ( $wgUseSharedUploads ) {
202 if ( $wgSharedUploadDBname ) {
203 $wgForeignFileRepos[] = array(
204 'class' => 'ForeignDBRepo',
205 'name' => 'shared',
206 'directory' => $wgSharedUploadDirectory,
207 'url' => $wgSharedUploadPath,
208 'hashLevels' => $wgHashedSharedUploadDirectory ? 2 : 0,
209 'thumbScriptUrl' => $wgSharedThumbnailScriptPath,
210 'transformVia404' => !$wgGenerateThumbnailOnParse,
211 'dbType' => $wgDBtype,
212 'dbServer' => $wgDBserver,
213 'dbUser' => $wgDBuser,
214 'dbPassword' => $wgDBpassword,
215 'dbName' => $wgSharedUploadDBname,
216 'dbFlags' => ( $wgDebugDumpSql ? DBO_DEBUG : 0 ) | DBO_DEFAULT,
217 'tablePrefix' => $wgSharedUploadDBprefix,
218 'hasSharedCache' => $wgCacheSharedUploads,
219 'descBaseUrl' => $wgRepositoryBaseUrl,
220 'fetchDescription' => $wgFetchCommonsDescriptions,
221 );
222 } else {
223 $wgForeignFileRepos[] = array(
224 'class' => 'FileRepo',
225 'name' => 'shared',
226 'directory' => $wgSharedUploadDirectory,
227 'url' => $wgSharedUploadPath,
228 'hashLevels' => $wgHashedSharedUploadDirectory ? 2 : 0,
229 'thumbScriptUrl' => $wgSharedThumbnailScriptPath,
230 'transformVia404' => !$wgGenerateThumbnailOnParse,
231 'descBaseUrl' => $wgRepositoryBaseUrl,
232 'fetchDescription' => $wgFetchCommonsDescriptions,
233 );
234 }
235 }
236 if ( $wgUseInstantCommons ) {
237 $wgForeignFileRepos[] = array(
238 'class' => 'ForeignAPIRepo',
239 'name' => 'wikimediacommons',
240 'apibase' => 'https://commons.wikimedia.org/w/api.php',
241 'url' => 'https://upload.wikimedia.org/wikipedia/commons',
242 'thumbUrl' => 'https://upload.wikimedia.org/wikipedia/commons/thumb',
243 'hashLevels' => 2,
244 'transformVia404' => true,
245 'fetchDescription' => true,
246 'descriptionCacheExpiry' => 43200,
247 'apiThumbCacheExpiry' => 86400,
248 );
249 }
250 /*
251 * Add on default file backend config for file repos.
252 * FileBackendGroup will handle initializing the backends.
253 */
254 if ( !isset( $wgLocalFileRepo['backend'] ) ) {
255 $wgLocalFileRepo['backend'] = $wgLocalFileRepo['name'] . '-backend';
256 }
257 foreach ( $wgForeignFileRepos as &$repo ) {
258 if ( !isset( $repo['directory'] ) && $repo['class'] === 'ForeignAPIRepo' ) {
259 $repo['directory'] = $wgUploadDirectory; // b/c
260 }
261 if ( !isset( $repo['backend'] ) ) {
262 $repo['backend'] = $repo['name'] . '-backend';
263 }
264 }
265 unset( $repo ); // no global pollution; destroy reference
266
267 $rcMaxAgeDays = $wgRCMaxAge / ( 3600 * 24 );
268 if ( $wgRCFilterByAge ) {
269 // Trim down $wgRCLinkDays so that it only lists links which are valid
270 // as determined by $wgRCMaxAge.
271 // Note that we allow 1 link higher than the max for things like 56 days but a 60 day link.
272 sort( $wgRCLinkDays );
273
274 // @codingStandardsIgnoreStart Generic.CodeAnalysis.ForLoopWithTestFunctionCall.NotAllowed
275 for ( $i = 0; $i < count( $wgRCLinkDays ); $i++ ) {
276 // @codingStandardsIgnoreEnd
277 if ( $wgRCLinkDays[$i] >= $rcMaxAgeDays ) {
278 $wgRCLinkDays = array_slice( $wgRCLinkDays, 0, $i + 1, false );
279 break;
280 }
281 }
282 }
283 // Ensure that default user options are not invalid, since that breaks Special:Preferences
284 $wgDefaultUserOptions['rcdays'] = min(
285 $wgDefaultUserOptions['rcdays'],
286 ceil( $rcMaxAgeDays )
287 );
288 $wgDefaultUserOptions['watchlistdays'] = min(
289 $wgDefaultUserOptions['watchlistdays'],
290 ceil( $rcMaxAgeDays )
291 );
292 unset( $rcMaxAgeDays );
293
294 if ( $wgSkipSkin ) {
295 $wgSkipSkins[] = $wgSkipSkin;
296 }
297
298 // Register skins
299 // Use a closure to avoid leaking into global state
300 call_user_func( function () use ( $wgValidSkinNames ) {
301 $factory = SkinFactory::getDefaultInstance();
302 foreach ( $wgValidSkinNames as $name => $skin ) {
303 $factory->register( $name, $skin, function () use ( $name, $skin ) {
304 $class = "Skin$skin";
305 return new $class( $name );
306 } );
307 }
308 // Register a hidden "fallback" skin
309 $factory->register( 'fallback', 'Fallback', function () {
310 return new SkinFallback;
311 } );
312 // Register a hidden skin for api output
313 $factory->register( 'apioutput', 'ApiOutput', function () {
314 return new SkinApi;
315 } );
316 } );
317 $wgSkipSkins[] = 'fallback';
318 $wgSkipSkins[] = 'apioutput';
319
320 if ( $wgLocalInterwiki ) {
321 array_unshift( $wgLocalInterwikis, $wgLocalInterwiki );
322 }
323
324 // Set default shared prefix
325 if ( $wgSharedPrefix === false ) {
326 $wgSharedPrefix = $wgDBprefix;
327 }
328
329 // Set default shared schema
330 if ( $wgSharedSchema === false ) {
331 $wgSharedSchema = $wgDBmwschema;
332 }
333
334 if ( !$wgCookiePrefix ) {
335 if ( $wgSharedDB && $wgSharedPrefix && in_array( 'user', $wgSharedTables ) ) {
336 $wgCookiePrefix = $wgSharedDB . '_' . $wgSharedPrefix;
337 } elseif ( $wgSharedDB && in_array( 'user', $wgSharedTables ) ) {
338 $wgCookiePrefix = $wgSharedDB;
339 } elseif ( $wgDBprefix ) {
340 $wgCookiePrefix = $wgDBname . '_' . $wgDBprefix;
341 } else {
342 $wgCookiePrefix = $wgDBname;
343 }
344 }
345 $wgCookiePrefix = strtr( $wgCookiePrefix, '=,; +."\'\\[', '__________' );
346
347 if ( $wgEnableEmail ) {
348 $wgUseEnotif = $wgEnotifUserTalk || $wgEnotifWatchlist;
349 } else {
350 // Disable all other email settings automatically if $wgEnableEmail
351 // is set to false. - bug 63678
352 $wgAllowHTMLEmail = false;
353 $wgEmailAuthentication = false; // do not require auth if you're not sending email anyway
354 $wgEnableUserEmail = false;
355 $wgEnotifFromEditor = false;
356 $wgEnotifImpersonal = false;
357 $wgEnotifMaxRecips = 0;
358 $wgEnotifMinorEdits = false;
359 $wgEnotifRevealEditorAddress = false;
360 $wgEnotifUseJobQ = false;
361 $wgEnotifUseRealName = false;
362 $wgEnotifUserTalk = false;
363 $wgEnotifWatchlist = false;
364 unset( $wgGroupPermissions['user']['sendemail'] );
365 $wgUseEnotif = false;
366 $wgUserEmailUseReplyTo = false;
367 $wgUsersNotifiedOnAllChanges = array();
368 }
369
370 // Doesn't make sense to have if disabled.
371 if ( !$wgEnotifMinorEdits ) {
372 $wgHiddenPrefs[] = 'enotifminoredits';
373 }
374
375 if ( $wgMetaNamespace === false ) {
376 $wgMetaNamespace = str_replace( ' ', '_', $wgSitename );
377 }
378
379 // Default value is 2000 or the suhosin limit if it is between 1 and 2000
380 if ( $wgResourceLoaderMaxQueryLength === false ) {
381 $suhosinMaxValueLength = (int)ini_get( 'suhosin.get.max_value_length' );
382 if ( $suhosinMaxValueLength > 0 && $suhosinMaxValueLength < 2000 ) {
383 $wgResourceLoaderMaxQueryLength = $suhosinMaxValueLength;
384 } else {
385 $wgResourceLoaderMaxQueryLength = 2000;
386 }
387 unset( $suhosinMaxValueLength );
388 }
389
390 // Ensure the minimum chunk size is less than PHP upload limits or the maximum
391 // upload size.
392 $wgMinUploadChunkSize = min(
393 $wgMinUploadChunkSize,
394 UploadBase::getMaxUploadSize( 'file' ),
395 UploadBase::getMaxPhpUploadSize(),
396 ( wfShorthandToInteger(
397 ini_get( 'post_max_size' ) ?: ini_get( 'hhvm.server.max_post_size' ),
398 PHP_INT_MAX
399 ) ?: PHP_INT_MAX ) - 1024 // Leave some room for other POST parameters
400 );
401
402 /**
403 * Definitions of the NS_ constants are in Defines.php
404 * @private
405 */
406 $wgCanonicalNamespaceNames = array(
407 NS_MEDIA => 'Media',
408 NS_SPECIAL => 'Special',
409 NS_TALK => 'Talk',
410 NS_USER => 'User',
411 NS_USER_TALK => 'User_talk',
412 NS_PROJECT => 'Project',
413 NS_PROJECT_TALK => 'Project_talk',
414 NS_FILE => 'File',
415 NS_FILE_TALK => 'File_talk',
416 NS_MEDIAWIKI => 'MediaWiki',
417 NS_MEDIAWIKI_TALK => 'MediaWiki_talk',
418 NS_TEMPLATE => 'Template',
419 NS_TEMPLATE_TALK => 'Template_talk',
420 NS_HELP => 'Help',
421 NS_HELP_TALK => 'Help_talk',
422 NS_CATEGORY => 'Category',
423 NS_CATEGORY_TALK => 'Category_talk',
424 );
425
426 /// @todo UGLY UGLY
427 if ( is_array( $wgExtraNamespaces ) ) {
428 $wgCanonicalNamespaceNames = $wgCanonicalNamespaceNames + $wgExtraNamespaces;
429 }
430
431 // These are now the same, always
432 // To determine the user language, use $wgLang->getCode()
433 $wgContLanguageCode = $wgLanguageCode;
434
435 // Easy to forget to falsify $wgDebugToolbar for static caches.
436 // If file cache or CDN cache is on, just disable this (DWIMD).
437 if ( $wgUseFileCache || $wgUseSquid ) {
438 $wgDebugToolbar = false;
439 }
440
441 // We always output HTML5 since 1.22, overriding these is no longer supported
442 // we set them here for extensions that depend on its value.
443 $wgHtml5 = true;
444 $wgXhtmlDefaultNamespace = 'http://www.w3.org/1999/xhtml';
445 $wgJsMimeType = 'text/javascript';
446
447 if ( !$wgHtml5Version && $wgAllowRdfaAttributes ) {
448 // see http://www.w3.org/TR/rdfa-in-html/#document-conformance
449 if ( $wgMimeType == 'application/xhtml+xml' ) {
450 $wgHtml5Version = 'XHTML+RDFa 1.0';
451 } else {
452 $wgHtml5Version = 'HTML+RDFa 1.0';
453 }
454 }
455
456 // Blacklisted file extensions shouldn't appear on the "allowed" list
457 $wgFileExtensions = array_values( array_diff( $wgFileExtensions, $wgFileBlacklist ) );
458
459 if ( $wgInvalidateCacheOnLocalSettingsChange ) {
460 MediaWiki\suppressWarnings();
461 $wgCacheEpoch = max( $wgCacheEpoch, gmdate( 'YmdHis', filemtime( "$IP/LocalSettings.php" ) ) );
462 MediaWiki\restoreWarnings();
463 }
464
465 if ( $wgNewUserLog ) {
466 // Add a new log type
467 $wgLogTypes[] = 'newusers';
468 $wgLogNames['newusers'] = 'newuserlogpage';
469 $wgLogHeaders['newusers'] = 'newuserlogpagetext';
470 $wgLogActionsHandlers['newusers/newusers'] = 'NewUsersLogFormatter';
471 $wgLogActionsHandlers['newusers/create'] = 'NewUsersLogFormatter';
472 $wgLogActionsHandlers['newusers/create2'] = 'NewUsersLogFormatter';
473 $wgLogActionsHandlers['newusers/byemail'] = 'NewUsersLogFormatter';
474 $wgLogActionsHandlers['newusers/autocreate'] = 'NewUsersLogFormatter';
475 }
476
477 if ( $wgPageLanguageUseDB ) {
478 $wgLogTypes[] = 'pagelang';
479 $wgLogActionsHandlers['pagelang/pagelang'] = 'PageLangLogFormatter';
480 }
481
482 if ( $wgCookieSecure === 'detect' ) {
483 $wgCookieSecure = ( WebRequest::detectProtocol() === 'https' );
484 }
485
486 if ( $wgProfileOnly ) {
487 $wgDebugLogGroups['profileoutput'] = $wgDebugLogFile;
488 $wgDebugLogFile = '';
489 }
490
491 // Backwards compatibility with old password limits
492 if ( $wgMinimalPasswordLength !== false ) {
493 $wgPasswordPolicy['policies']['default']['MinimalPasswordLength'] = $wgMinimalPasswordLength;
494 }
495
496 if ( $wgMaximalPasswordLength !== false ) {
497 $wgPasswordPolicy['policies']['default']['MaximalPasswordLength'] = $wgMaximalPasswordLength;
498 }
499
500 // Backwards compatibility warning
501 if ( !$wgSessionsInObjectCache && !$wgSessionsInMemcached ) {
502 wfDeprecated( '$wgSessionsInObjectCache = false', '1.27' );
503 if ( $wgSessionHandler ) {
504 wfDeprecated( '$wgSessionsHandler', '1.27' );
505 }
506 $cacheType = get_class( ObjectCache::getInstance( $wgSessionCacheType ) );
507 wfDebugLog(
508 "Session data will be stored in \"$cacheType\" cache with " .
509 "expiry $wgObjectCacheSessionExpiry seconds"
510 );
511 }
512 $wgSessionsInObjectCache = true;
513
514 if ( $wgPHPSessionHandling !== 'enable' &&
515 $wgPHPSessionHandling !== 'warn' &&
516 $wgPHPSessionHandling !== 'disable'
517 ) {
518 $wgPHPSessionHandling = 'warn';
519 }
520
521 Profiler::instance()->scopedProfileOut( $ps_default );
522
523 // Disable MWDebug for command line mode, this prevents MWDebug from eating up
524 // all the memory from logging SQL queries on maintenance scripts
525 global $wgCommandLineMode;
526 if ( $wgDebugToolbar && !$wgCommandLineMode ) {
527 MWDebug::init();
528 }
529
530 if ( !class_exists( 'AutoLoader' ) ) {
531 require_once "$IP/includes/AutoLoader.php";
532 }
533
534 MWExceptionHandler::installHandler();
535
536 require_once "$IP/includes/compat/normal/UtfNormalUtil.php";
537
538 $ps_validation = Profiler::instance()->scopedProfileIn( $fname . '-validation' );
539
540 // T48998: Bail out early if $wgArticlePath is non-absolute
541 if ( !preg_match( '/^(https?:\/\/|\/)/', $wgArticlePath ) ) {
542 throw new FatalError(
543 'If you use a relative URL for $wgArticlePath, it must start ' .
544 'with a slash (<code>/</code>).<br><br>See ' .
545 '<a href="https://www.mediawiki.org/wiki/Manual:$wgArticlePath">' .
546 'https://www.mediawiki.org/wiki/Manual:$wgArticlePath</a>.'
547 );
548 }
549
550 Profiler::instance()->scopedProfileOut( $ps_validation );
551
552 $ps_default2 = Profiler::instance()->scopedProfileIn( $fname . '-defaults2' );
553
554 if ( $wgCanonicalServer === false ) {
555 $wgCanonicalServer = wfExpandUrl( $wgServer, PROTO_HTTP );
556 }
557
558 // Set server name
559 $serverParts = wfParseUrl( $wgCanonicalServer );
560 if ( $wgServerName !== false ) {
561 wfWarn( '$wgServerName should be derived from $wgCanonicalServer, '
562 . 'not customized. Overwriting $wgServerName.' );
563 }
564 $wgServerName = $serverParts['host'];
565 unset( $serverParts );
566
567 // Set defaults for configuration variables
568 // that are derived from the server name by default
569 // Note: $wgEmergencyContact and $wgPasswordSender may be false or empty string (T104142)
570 if ( !$wgEmergencyContact ) {
571 $wgEmergencyContact = 'wikiadmin@' . $wgServerName;
572 }
573 if ( !$wgPasswordSender ) {
574 $wgPasswordSender = 'apache@' . $wgServerName;
575 }
576
577 if ( $wgSecureLogin && substr( $wgServer, 0, 2 ) !== '//' ) {
578 $wgSecureLogin = false;
579 wfWarn( 'Secure login was enabled on a server that only supports '
580 . 'HTTP or HTTPS. Disabling secure login.' );
581 }
582
583 $wgVirtualRestConfig['global']['domain'] = $wgCanonicalServer;
584
585 // Now that GlobalFunctions is loaded, set defaults that depend on it.
586 if ( $wgTmpDirectory === false ) {
587 $wgTmpDirectory = wfTempDir();
588 }
589
590 // We don't use counters anymore. Left here for extensions still
591 // expecting this to exist. Should be removed sometime 1.26 or later.
592 if ( !isset( $wgDisableCounters ) ) {
593 $wgDisableCounters = true;
594 }
595
596 if ( $wgMainWANCache === false ) {
597 // Setup a WAN cache from $wgMainCacheType with no relayer.
598 // Sites using multiple datacenters can configure a relayer.
599 $wgMainWANCache = 'mediawiki-main-default';
600 $wgWANObjectCaches[$wgMainWANCache] = array(
601 'class' => 'WANObjectCache',
602 'cacheId' => $wgMainCacheType,
603 'pool' => 'mediawiki-main-default',
604 'relayerConfig' => array( 'class' => 'EventRelayerNull' )
605 );
606 }
607
608 Profiler::instance()->scopedProfileOut( $ps_default2 );
609
610 $ps_misc = Profiler::instance()->scopedProfileIn( $fname . '-misc1' );
611
612 // Raise the memory limit if it's too low
613 wfMemoryLimit();
614
615 /**
616 * Set up the timezone, suppressing the pseudo-security warning in PHP 5.1+
617 * that happens whenever you use a date function without the timezone being
618 * explicitly set. Inspired by phpMyAdmin's treatment of the problem.
619 */
620 if ( is_null( $wgLocaltimezone ) ) {
621 MediaWiki\suppressWarnings();
622 $wgLocaltimezone = date_default_timezone_get();
623 MediaWiki\restoreWarnings();
624 }
625
626 date_default_timezone_set( $wgLocaltimezone );
627 if ( is_null( $wgLocalTZoffset ) ) {
628 $wgLocalTZoffset = date( 'Z' ) / 60;
629 }
630
631 if ( !$wgDBerrorLogTZ ) {
632 $wgDBerrorLogTZ = $wgLocaltimezone;
633 }
634
635 // initialize the request object in $wgRequest
636 $wgRequest = RequestContext::getMain()->getRequest(); // BackCompat
637
638 // Useful debug output
639 if ( $wgCommandLineMode ) {
640 wfDebug( "\n\nStart command line script $self\n" );
641 } else {
642 $debug = "\n\nStart request {$wgRequest->getMethod()} {$wgRequest->getRequestURL()}\n";
643
644 if ( $wgDebugPrintHttpHeaders ) {
645 $debug .= "HTTP HEADERS:\n";
646
647 foreach ( $wgRequest->getAllHeaders() as $name => $value ) {
648 $debug .= "$name: $value\n";
649 }
650 }
651 wfDebug( $debug );
652 }
653
654 Profiler::instance()->scopedProfileOut( $ps_misc );
655 $ps_memcached = Profiler::instance()->scopedProfileIn( $fname . '-memcached' );
656
657 $wgMemc = wfGetMainCache();
658 $messageMemc = wfGetMessageCacheStorage();
659 $parserMemc = wfGetParserCacheStorage();
660
661 wfDebugLog( 'caches',
662 'cluster: ' . get_class( $wgMemc ) .
663 ', WAN: ' . $wgMainWANCache .
664 ', stash: ' . $wgMainStash .
665 ', message: ' . get_class( $messageMemc ) .
666 ', parser: ' . get_class( $parserMemc ) );
667
668 Profiler::instance()->scopedProfileOut( $ps_memcached );
669
670 // Most of the config is out, some might want to run hooks here.
671 Hooks::run( 'SetupAfterCache' );
672
673 $ps_globals = Profiler::instance()->scopedProfileIn( $fname . '-globals' );
674
675 /**
676 * @var Language $wgContLang
677 */
678 $wgContLang = Language::factory( $wgLanguageCode );
679 $wgContLang->initEncoding();
680 $wgContLang->initContLang();
681
682 // Now that variant lists may be available...
683 $wgRequest->interpolateTitle();
684
685 if ( !is_object( $wgAuth ) ) {
686 $wgAuth = new AuthPlugin;
687 Hooks::run( 'AuthPluginSetup', array( &$wgAuth ) );
688 }
689
690 // Set up the session
691 $ps_session = Profiler::instance()->scopedProfileIn( $fname . '-session' );
692 if ( !defined( 'MW_NO_SESSION' ) && !$wgCommandLineMode ) {
693 // If session.auto_start is there, we can't touch session name
694 if ( $wgPHPSessionHandling !== 'disable' && !wfIniGetBool( 'session.auto_start' ) ) {
695 session_name( $wgSessionName ? $wgSessionName : $wgCookiePrefix . '_session' );
696 }
697
698 // Create the SessionManager singleton and set up our session handler
699 MediaWiki\Session\PHPSessionHandler::install(
700 MediaWiki\Session\SessionManager::singleton()
701 );
702
703 // Initialize the session
704 try {
705 $session = MediaWiki\Session\SessionManager::getGlobalSession();
706 } catch ( OverflowException $ex ) {
707 if ( isset( $ex->sessionInfos ) && count( $ex->sessionInfos ) >= 2 ) {
708 // The exception is because the request had multiple possible
709 // sessions tied for top priority. Report this to the user.
710 $list = array();
711 foreach ( $ex->sessionInfos as $info ) {
712 $list[] = $info->getProvider()->describe( $wgContLang );
713 }
714 $list = $wgContLang->listToText( $list );
715 throw new HttpError( 400,
716 Message::newFromKey( 'sessionmanager-tie', $list )->inLanguage( $wgContLang )->plain()
717 );
718 }
719
720 // Not the one we want, rethrow
721 throw $ex;
722 }
723
724 $session->renew();
725 if ( MediaWiki\Session\PHPSessionHandler::isEnabled() &&
726 ( $session->isPersistent() || $session->shouldRememberUser() )
727 ) {
728 // Start the PHP-session for backwards compatibility
729 session_id( $session->getId() );
730 MediaWiki\quietCall( 'session_start' );
731 }
732 }
733 Profiler::instance()->scopedProfileOut( $ps_session );
734
735 /**
736 * @var User $wgUser
737 */
738 $wgUser = RequestContext::getMain()->getUser(); // BackCompat
739
740 /**
741 * @var Language $wgLang
742 */
743 $wgLang = new StubUserLang;
744
745 /**
746 * @var OutputPage $wgOut
747 */
748 $wgOut = RequestContext::getMain()->getOutput(); // BackCompat
749
750 /**
751 * @var Parser $wgParser
752 */
753 $wgParser = new StubObject( 'wgParser', $wgParserConf['class'], array( $wgParserConf ) );
754
755 /**
756 * @var Title $wgTitle
757 */
758 $wgTitle = null;
759
760 Profiler::instance()->scopedProfileOut( $ps_globals );
761 $ps_extensions = Profiler::instance()->scopedProfileIn( $fname . '-extensions' );
762
763 // Extension setup functions
764 // Entries should be added to this variable during the inclusion
765 // of the extension file. This allows the extension to perform
766 // any necessary initialisation in the fully initialised environment
767 foreach ( $wgExtensionFunctions as $func ) {
768 // Allow closures in PHP 5.3+
769 if ( is_object( $func ) && $func instanceof Closure ) {
770 $profName = $fname . '-extensions-closure';
771 } elseif ( is_array( $func ) ) {
772 if ( is_object( $func[0] ) ) {
773 $profName = $fname . '-extensions-' . get_class( $func[0] ) . '::' . $func[1];
774 } else {
775 $profName = $fname . '-extensions-' . implode( '::', $func );
776 }
777 } else {
778 $profName = $fname . '-extensions-' . strval( $func );
779 }
780
781 $ps_ext_func = Profiler::instance()->scopedProfileIn( $profName );
782 call_user_func( $func );
783 Profiler::instance()->scopedProfileOut( $ps_ext_func );
784 }
785
786 // If the session user has a 0 id but a valid name, that means we need to
787 // autocreate it.
788 $sessionUser = MediaWiki\Session\SessionManager::getGlobalSession()->getUser();
789 if ( $sessionUser->getId() === 0 && User::isValidUserName( $sessionUser->getName() ) ) {
790 $ps_autocreate = Profiler::instance()->scopedProfileIn( $fname . '-autocreate' );
791 MediaWiki\Session\SessionManager::autoCreateUser( $sessionUser );
792 Profiler::instance()->scopedProfileOut( $ps_autocreate );
793 }
794 unset( $sessionUser );
795
796 wfDebug( "Fully initialised\n" );
797 $wgFullyInitialised = true;
798
799 Profiler::instance()->scopedProfileOut( $ps_extensions );
800 Profiler::instance()->scopedProfileOut( $ps_setup );