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