Debian Codegraph @

includes/Setup.php

raw symbols SCIP
1 <?php
2 /**
3 * The setup for all MediaWiki processes (both web-based and CLI).
4 *
5 * The entry point (such as WebStart.php and doMaintenance.php) has these responsibilities:
6 * - The entry point MUST:
7 * - define the 'MEDIAWIKI' constant.
8 * - The entry point SHOULD:
9 * - define the 'MW_ENTRY_POINT' constant.
10 * - display an error if MW_CONFIG_CALLBACK is not defined and the
11 * file specified in MW_CONFIG_FILE (or the LocalSettings.php default location)
12 * does not exist. The error should either be sent before and instead
13 * of the Setup.php inclusion, or (if it needs classes and dependencies
14 * from core) the error can be displayed via a MW_CONFIG_CALLBACK,
15 * which must then abort the process to prevent the rest of Setup.php
16 * from executing.
17 *
18 * This file does:
19 * - run-time environment checks,
20 * - define MW_INSTALL_PATH, $IP, and $wgBaseDirectory,
21 * - load autoloaders, constants, default settings, and global functions,
22 * - load the site configuration (e.g. LocalSettings.php),
23 * - load the enabled extensions (via ExtensionRegistry),
24 * - trivial expansion of site configuration defaults and shortcuts
25 * (no calls to MediaWikiServices or other parts of MediaWiki),
26 * - initialization of:
27 * - PHP run-time (setlocale, memory limit, default date timezone)
28 * - the debug logger (MWDebug)
29 * - the service container (MediaWikiServices)
30 * - the exception handler (MWExceptionHandler)
31 * - the session manager (SessionManager)
32 * - complex expansion of site configuration defaults (those that require
33 * calling into MediaWikiServices, global functions, or other classes.).
34 *
35 * This program is free software; you can redistribute it and/or modify
36 * it under the terms of the GNU General Public License as published by
37 * the Free Software Foundation; either version 2 of the License, or
38 * (at your option) any later version.
39 *
40 * This program is distributed in the hope that it will be useful,
41 * but WITHOUT ANY WARRANTY; without even the implied warranty of
42 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
43 * GNU General Public License for more details.
44 *
45 * You should have received a copy of the GNU General Public License along
46 * with this program; if not, write to the Free Software Foundation, Inc.,
47 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
48 * http://www.gnu.org/copyleft/gpl.html
49 *
50 * @file
51 */
52
53 // phpcs:disable MediaWiki.Usage.DeprecatedGlobalVariables
54 use MediaWiki\Config\SiteConfiguration;
55 use MediaWiki\Context\RequestContext;
56 use MediaWiki\Debug\MWDebug;
57 use MediaWiki\Deferred\DeferredUpdates;
58 use MediaWiki\HookContainer\FauxGlobalHookArray;
59 use MediaWiki\HookContainer\HookRunner;
60 use MediaWiki\Language\Language;
61 use MediaWiki\Logger\LoggerFactory;
62 use MediaWiki\MainConfigNames;
63 use MediaWiki\MainConfigSchema;
64 use MediaWiki\MediaWikiServices;
65 use MediaWiki\Message\Message;
66 use MediaWiki\Registration\ExtensionRegistry;
67 use MediaWiki\Registration\MissingExtensionException;
68 use MediaWiki\Request\HeaderCallback;
69 use MediaWiki\Settings\DynamicDefaultValues;
70 use MediaWiki\Settings\LocalSettingsLoader;
71 use MediaWiki\Settings\SettingsBuilder;
72 use MediaWiki\Settings\Source\PhpSettingsSource;
73 use MediaWiki\Settings\Source\ReflectionSchemaSource;
74 use MediaWiki\Settings\WikiFarmSettingsLoader;
75 use MediaWiki\StubObject\StubGlobalUser;
76 use MediaWiki\StubObject\StubUserLang;
77 use MediaWiki\Title\Title;
78 use MediaWiki\User\User;
79 use Psr\Log\LoggerInterface;
80 use Wikimedia\RequestTimeout\RequestTimeout;
81
82 /**
83 * Environment checks
84 *
85 * These are inline checks done before we include any source files,
86 * and thus these conditions may be assumed by all source code.
87 */
88
89 // This file must be included from a valid entry point (e.g. WebStart.php, Maintenance.php)
90 if ( !defined( 'MEDIAWIKI' ) ) {
91 exit( 1 );
92 }
93
94 // The MW_ENTRY_POINT constant must always exists, to make it safe to access.
95 // For compat, we do support older and custom MW entrypoints that don't set this,
96 // in which case we assign a default here.
97 if ( !defined( 'MW_ENTRY_POINT' ) ) {
98 /**
99 * The entry point, which may be either the script filename without the
100 * file extension, or "cli" for maintenance scripts, or "unknown" for any
101 * entry point that does not set the constant.
102 */
103 define( 'MW_ENTRY_POINT', 'unknown' );
104 }
105
106 // The $IP variable is defined for use by LocalSettings.php.
107 // It is made available as a global variable for backwards compatibility.
108 //
109 // Source code should instead use the MW_INSTALL_PATH constant, or the
110 // MainConfigNames::BaseDirectory setting. The BaseDirectory setting is set further
111 // down in Setup.php to the value of MW_INSTALL_PATH.
112 global $IP;
113 $IP = wfDetectInstallPath(); // ensure MW_INSTALL_PATH is defined
114
115 /**
116 * Pre-config setup: Before loading LocalSettings.php
117 *
118 * These are changes and additions to runtime that don't vary on site configuration.
119 */
120 require_once MW_INSTALL_PATH . '/includes/AutoLoader.php';
121 require_once MW_INSTALL_PATH . '/includes/Defines.php';
122
123 // Assert that composer dependencies were successfully loaded
124 if ( !interface_exists( LoggerInterface::class ) ) {
125 $message = (
126 '<strong>Error: Missing external libraries.</strong> ' .
127 'MediaWiki depends on external libraries bundled with most MediaWiki distributions. ' .
128 "When installing MediaWiki from its Git reposistory, these must be installed separately.\n\n" .
129 'Please see the <a href="https://www.mediawiki.org/wiki/Download_from_Git' .
130 '#Fetch_external_libraries">instructions for installing libraries</a> on mediawiki.org ' .
131 'for help on installing the required libraries.'
132 );
133 http_response_code( 500 );
134 echo $message;
135 error_log( $message );
136 exit( 1 );
137 }
138
139 // Deprecated global variable for backwards-compatibility.
140 // New code should check MW_ENTRY_POINT directly.
141 $wgCommandLineMode = MW_ENTRY_POINT === 'cli';
142
143 /**
144 * $wgConf hold the site configuration.
145 * Not used for much in a default install.
146 * @since 1.5
147 */
148 $wgConf = new SiteConfiguration;
149
150 $wgAutoloadClasses ??= [];
151
152 $wgSettings = SettingsBuilder::getInstance();
153
154 if ( defined( 'MW_USE_CONFIG_SCHEMA_CLASS' ) ) {
155 // Load config schema from MainConfigSchema. Useful for running scripts that
156 // generate other representations of the config schema. This is slow, so it
157 // should not be used for serving web traffic.
158 $wgSettings->load( new ReflectionSchemaSource( MainConfigSchema::class ) );
159 } else {
160 $wgSettings->load( new PhpSettingsSource( MW_INSTALL_PATH . '/includes/config-schema.php' ) );
161 }
162
163 require_once MW_INSTALL_PATH . '/includes/GlobalFunctions.php';
164
165 HeaderCallback::register();
166
167 // Set the encoding used by PHP for reading HTTP input, and writing output.
168 // This is also the default for mbstring functions.
169 mb_internal_encoding( 'UTF-8' );
170
171 /**
172 * Load LocalSettings.php
173 */
174
175 // Initialize some config settings with dynamic defaults, and
176 // make default settings available in globals for use in LocalSettings.php.
177 $wgSettings->putConfigValues( [
178 MainConfigNames::BaseDirectory => MW_INSTALL_PATH,
179 MainConfigNames::ExtensionDirectory => MW_INSTALL_PATH . '/extensions',
180 MainConfigNames::StyleDirectory => MW_INSTALL_PATH . '/skins',
181 MainConfigNames::ServiceWiringFiles => [ MW_INSTALL_PATH . '/includes/ServiceWiring.php' ],
182 'Version' => MW_VERSION,
183 ] );
184 $wgSettings->apply();
185
186 // $wgSettings->apply() puts all configuration into global variables.
187 // If we are not in global scope, make all relevant globals available
188 // in this file's scope as well.
189 $wgScopeTest = 'MediaWiki Setup.php scope test';
190 if ( !isset( $GLOBALS['wgScopeTest'] ) || $GLOBALS['wgScopeTest'] !== $wgScopeTest ) {
191 foreach ( $wgSettings->getConfigSchema()->getDefinedKeys() as $key ) {
192 $var = "wg$key";
193 // phpcs:ignore MediaWiki.NamingConventions.ValidGlobalName.allowedPrefix
194 global $$var;
195 }
196 unset( $key, $var );
197 }
198 unset( $wgScopeTest );
199
200 try {
201 if ( defined( 'MW_CONFIG_CALLBACK' ) ) {
202 call_user_func( MW_CONFIG_CALLBACK, $wgSettings );
203 } else {
204 wfDetectLocalSettingsFile( MW_INSTALL_PATH );
205
206 if ( getenv( 'MW_USE_LOCAL_SETTINGS_LOADER' ) ) {
207 // NOTE: This will not work for configuration variables that use a prefix
208 // other than "wg".
209 $localSettingsLoader = new LocalSettingsLoader( $wgSettings, MW_INSTALL_PATH );
210 $localSettingsLoader->loadLocalSettingsFile( MW_CONFIG_FILE );
211 unset( $localSettingsLoader );
212 } else {
213 if ( str_ends_with( MW_CONFIG_FILE, '.php' ) ) {
214 // make defaults available as globals
215 $wgSettings->apply();
216 require_once MW_CONFIG_FILE;
217 } else {
218 $wgSettings->loadFile( MW_CONFIG_FILE );
219 }
220 }
221 }
222
223 // Make settings loaded by LocalSettings.php available in globals for use here
224 $wgSettings->apply();
225 } catch ( MissingExtensionException $e ) {
226 // Make a common mistake give a friendly error
227 $e->render();
228 }
229
230 // If in a wiki-farm, load site-specific settings
231 if ( $wgSettings->getConfig()->get( MainConfigNames::WikiFarmSettingsDirectory ) ) {
232 $wikiFarmSettingsLoader = new WikiFarmSettingsLoader( $wgSettings );
233 $wikiFarmSettingsLoader->loadWikiFarmSettings();
234 unset( $wikiFarmSettingsLoader );
235 }
236
237 // All settings should be loaded now.
238 $wgSettings->enterRegistrationStage();
239
240 /**
241 * Customization point after most things are loaded (constants, functions, classes,
242 * LocalSettings.
243 * Note that this runs before extensions are registered, and before most singletons become
244 * available, and before MediaWikiServices is initialized.
245 */
246
247 if ( defined( 'MW_SETUP_CALLBACK' ) ) {
248 call_user_func( MW_SETUP_CALLBACK, $wgSettings );
249 // Make any additional settings available in globals for use here
250 $wgSettings->apply();
251 }
252
253 // Apply dynamic defaults declared in config schema callbacks.
254 $dynamicDefaults = new DynamicDefaultValues( $wgSettings->getConfigSchema() );
255 $dynamicDefaults->applyDynamicDefaults( $wgSettings->getConfigBuilder() );
256
257 // Make updated config available in global scope.
258 $wgSettings->apply();
259
260 // Apply dynamic defaults implemented in SetupDynamicConfig.php.
261 // Ideally, all logic in SetupDynamicConfig would be converted to
262 // callbacks in the config schema.
263 require __DIR__ . '/SetupDynamicConfig.php';
264
265 if ( defined( 'MW_AUTOLOAD_TEST_CLASSES' ) ) {
266 require_once __DIR__ . '/../tests/common/TestsAutoLoader.php';
267 }
268
269 if ( $wgBaseDirectory !== MW_INSTALL_PATH ) {
270 throw new FatalError(
271 '$wgBaseDirectory must not be modified in settings files! ' .
272 'Use the MW_INSTALL_PATH environment variable to override the installation root directory.'
273 );
274 }
275
276 // Start time limit
277 if ( $wgRequestTimeLimit && MW_ENTRY_POINT !== 'cli' ) {
278 RequestTimeout::singleton()->setWallTimeLimit( $wgRequestTimeLimit );
279 }
280
281 /**
282 * Load queued extensions
283 */
284 if ( defined( 'MW_AUTOLOAD_TEST_CLASSES' ) ) {
285 ExtensionRegistry::getInstance()->setLoadTestClassesAndNamespaces( true );
286 }
287
288 ExtensionRegistry::getInstance()->setSettingsBuilder( $wgSettings );
289 ExtensionRegistry::getInstance()->loadFromQueue();
290 // Don't let any other extensions load
291 ExtensionRegistry::getInstance()->finish();
292
293 /**
294 * Customization point after ALL loading (constants, functions, classes,
295 * LocalSettings, extensions, dynamic defaults).
296 * Note that this runs before MediaWikiServices is initialized.
297 */
298 if ( defined( 'MW_FINAL_SETUP_CALLBACK' ) ) {
299 call_user_func( MW_FINAL_SETUP_CALLBACK, $wgSettings );
300 // Make any additional settings available in globals for use below
301 $wgSettings->apply();
302 }
303
304 // Config can no longer be changed.
305 $wgSettings->enterReadOnlyStage();
306
307 // Set an appropriate locale (T291234)
308 // setlocale() will return the locale name actually set.
309 // The putenv() is meant to propagate the choice of locale to shell commands
310 // so that they will interpret UTF-8 correctly. If you have a problem with a
311 // shell command and need to send a special locale, you can override the locale
312 // with Command::environment().
313 putenv( "LC_ALL=" . setlocale( LC_ALL, 'C.UTF-8', 'C' ) );
314
315 // Set PHP runtime to the desired timezone
316 date_default_timezone_set( $wgLocaltimezone );
317
318 MWDebug::setup();
319
320 // Enable the global service locator.
321 // Trivial expansion of site configuration should go before this point.
322 // Any non-trivial expansion that requires calling into MediaWikiServices or other parts of MW.
323 MediaWikiServices::allowGlobalInstance();
324
325 // Define a constant that indicates that the bootstrapping of the service locator
326 // is complete.
327 define( 'MW_SERVICE_BOOTSTRAP_COMPLETE', 1 );
328
329 MWExceptionRenderer::setShowExceptionDetails( $wgShowExceptionDetails );
330 if ( !defined( 'MW_PHPUNIT_TEST' ) ) {
331 // Never install the handler in PHPUnit tests, otherwise PHPUnit's own handler will be unset and things
332 // like convertWarningsToExceptions won't work.
333 MWExceptionHandler::installHandler( $wgLogExceptionBacktrace, $wgPropagateErrors );
334 }
335 Profiler::init( $wgProfiler );
336
337 // Non-trivial validation of: $wgServer
338 // The FatalError page only renders cleanly after MWExceptionHandler is installed.
339 if ( $wgServer === false ) {
340 // T30798: $wgServer must be explicitly set
341 throw new FatalError(
342 '$wgServer must be set in LocalSettings.php. ' .
343 'See <a href="https://www.mediawiki.org/wiki/Manual:$wgServer">' .
344 'https://www.mediawiki.org/wiki/Manual:$wgServer</a>.'
345 );
346 }
347
348 // Set up a fake $wgHooks array.
349 // XXX: It would be nice if we could still get the originally configured hook handlers
350 // using the MainConfigNames::Hooks setting, but it's not really needed,
351 // since we need the HookContainer to be initialized first anyway.
352
353 global $wgHooks;
354 $wgHooks = new FauxGlobalHookArray(
355 MediaWikiServices::getInstance()->getHookContainer(),
356 $wgHooks
357 );
358
359 // Non-trivial expansion of: $wgCanonicalServer, $wgServerName.
360 // These require calling global functions.
361 // Also here are other settings that further depend on these two.
362 if ( $wgCanonicalServer === false ) {
363 $wgCanonicalServer = MediaWikiServices::getInstance()->getUrlUtils()->getCanonicalServer();
364 }
365 $wgVirtualRestConfig['global']['domain'] = $wgCanonicalServer;
366
367 if ( $wgServerName !== false ) {
368 wfWarn( '$wgServerName should be derived from $wgCanonicalServer, '
369 . 'not customized. Overwriting $wgServerName.' );
370 }
371 $wgServerName = parse_url( $wgCanonicalServer, PHP_URL_HOST );
372
373 // $wgEmergencyContact and $wgPasswordSender may be false or empty string (T104142)
374 if ( !$wgEmergencyContact ) {
375 $wgEmergencyContact = 'wikiadmin@' . $wgServerName;
376 }
377 if ( !$wgPasswordSender ) {
378 $wgPasswordSender = 'apache@' . $wgServerName;
379 }
380 if ( !$wgNoReplyAddress ) {
381 $wgNoReplyAddress = $wgPasswordSender;
382 }
383
384 // Non-trivial expansion of: $wgSecureLogin
385 // (due to calling wfWarn).
386 if ( $wgSecureLogin && substr( $wgServer, 0, 2 ) !== '//' ) {
387 $wgSecureLogin = false;
388 wfWarn( 'Secure login was enabled on a server that only supports '
389 . 'HTTP or HTTPS. Disabling secure login.' );
390 }
391
392 // Now that GlobalFunctions is loaded, set defaults that depend on it.
393 if ( $wgTmpDirectory === false ) {
394 $wgTmpDirectory = wfTempDir();
395 }
396
397 if ( $wgSharedDB && $wgSharedTables ) {
398 // Apply $wgSharedDB table aliases for the local LB (all non-foreign DB connections)
399 MediaWikiServices::getInstance()->getDBLoadBalancer()->setTableAliases(
400 array_fill_keys(
401 $wgSharedTables,
402 [
403 'dbname' => $wgSharedDB,
404 'schema' => $wgSharedSchema,
405 'prefix' => $wgSharedPrefix
406 ]
407 )
408 );
409 }
410
411 // Raise the memory limit if it's too low
412 // NOTE: This use wfDebug, and must remain after the MWDebug::setup() call.
413 wfMemoryLimit( $wgMemoryLimit );
414
415 // Explicit globals, so this works with bootstrap.php
416 global $wgRequest, $wgInitialSessionId;
417
418 // Initialize the request object in $wgRequest
419 $wgRequest = RequestContext::getMain()->getRequest(); // BackCompat
420
421 // Make sure that object caching does not undermine the ChronologyProtector improvements
422 if ( $wgRequest->getCookie( 'UseDC', '' ) === 'master' ) {
423 // The user is pinned to the primary DC, meaning that they made recent changes which should
424 // be reflected in their subsequent web requests. Avoid the use of interim cache keys because
425 // they use a blind TTL and could be stale if an object changes twice in a short time span.
426 MediaWikiServices::getInstance()->getMainWANObjectCache()->useInterimHoldOffCaching( false );
427 }
428
429 // Useful debug output
430 ( static function () {
431 global $wgRequest;
432
433 $logger = LoggerFactory::getInstance( 'wfDebug' );
434 if ( MW_ENTRY_POINT === 'cli' ) {
435 $self = $_SERVER['PHP_SELF'] ?? '';
436 $logger->debug( "\n\nStart command line script $self" );
437 } else {
438 $debug = "\n\nStart request {$wgRequest->getMethod()} {$wgRequest->getRequestURL()}\n";
439 $debug .= "IP: " . $wgRequest->getIP() . "\n";
440 $debug .= "HTTP HEADERS:\n";
441 foreach ( $wgRequest->getAllHeaders() as $name => $value ) {
442 $debug .= "$name: $value\n";
443 }
444 $debug .= "(end headers)";
445 $logger->debug( $debug );
446 }
447 } )();
448
449 // Most of the config is out, some might want to run hooks here.
450 ( new HookRunner( MediaWikiServices::getInstance()->getHookContainer() ) )->onSetupAfterCache();
451
452 // Now that variant lists may be available, parse any action paths and article paths
453 // as query parameters.
454 //
455 // Skip title interpolation on API queries where it is useless and sometimes harmful (T18019).
456 //
457 // Optimization: Skip on load.php and all other entrypoints besides index.php to save time.
458 //
459 // TODO: Figure out if this can be safely done after everything else in Setup.php (e.g. any
460 // hooks or other state that would miss this?). If so, move to wfIndexMain or MediaWiki::run.
461 if ( MW_ENTRY_POINT === 'index' ) {
462 $wgRequest->interpolateTitle();
463 }
464
465 /**
466 * @var MediaWiki\Session\SessionId|null $wgInitialSessionId The persistent session ID (if any) loaded at startup
467 */
468 $wgInitialSessionId = null;
469 if ( !defined( 'MW_NO_SESSION' ) && MW_ENTRY_POINT !== 'cli' ) {
470 // If session.auto_start is there, we can't touch session name
471 if ( $wgPHPSessionHandling !== 'disable' && !wfIniGetBool( 'session.auto_start' ) ) {
472 HeaderCallback::warnIfHeadersSent();
473 session_name( $wgSessionName ?: $wgCookiePrefix . '_session' );
474 }
475
476 // Create the SessionManager singleton and set up our session handler,
477 // unless we're specifically asked not to.
478 if ( !defined( 'MW_NO_SESSION_HANDLER' ) ) {
479 MediaWiki\Session\PHPSessionHandler::install(
480 MediaWiki\Session\SessionManager::singleton()
481 );
482 }
483
484 $contLang = MediaWikiServices::getInstance()->getContentLanguage();
485
486 // Initialize the session
487 try {
488 $session = MediaWiki\Session\SessionManager::getGlobalSession();
489 } catch ( MediaWiki\Session\SessionOverflowException $ex ) {
490 // The exception is because the request had multiple possible
491 // sessions tied for top priority. Report this to the user.
492 $list = [];
493 foreach ( $ex->getSessionInfos() as $info ) {
494 $list[] = $info->getProvider()->describe( $contLang );
495 }
496 $list = $contLang->listToText( $list );
497 throw new HttpError( 400,
498 Message::newFromKey( 'sessionmanager-tie', $list )->inLanguage( $contLang )
499 );
500 }
501
502 unset( $contLang );
503
504 if ( $session->isPersistent() ) {
505 $wgInitialSessionId = $session->getSessionId();
506 }
507
508 $session->renew();
509 if ( MediaWiki\Session\PHPSessionHandler::isEnabled() &&
510 ( $session->isPersistent() || $session->shouldRememberUser() ) &&
511 session_id() !== $session->getId()
512 ) {
513 // Start the PHP-session for backwards compatibility
514 if ( session_id() !== '' ) {
515 wfDebugLog( 'session', 'PHP session {old_id} was already started, changing to {new_id}', 'all', [
516 'old_id' => session_id(),
517 'new_id' => $session->getId(),
518 ] );
519 session_write_close();
520 }
521 session_id( $session->getId() );
522 session_start();
523 }
524
525 unset( $session );
526 } else {
527 // Even if we didn't set up a global Session, still install our session
528 // handler unless specifically requested not to.
529 if ( !defined( 'MW_NO_SESSION_HANDLER' ) ) {
530 MediaWiki\Session\PHPSessionHandler::install(
531 MediaWiki\Session\SessionManager::singleton()
532 );
533 }
534 }
535
536 // Explicit globals, so this works with bootstrap.php
537 global $wgUser, $wgLang, $wgOut, $wgTitle;
538
539 /**
540 * @var User $wgUser
541 * @deprecated since 1.35, use an available context source when possible, or, as a backup,
542 * RequestContext::getMain()
543 */
544 $wgUser = new StubGlobalUser( RequestContext::getMain()->getUser() ); // BackCompat
545 register_shutdown_function( static function () {
546 StubGlobalUser::$destructorDeprecationDisarmed = true;
547 } );
548
549 /**
550 * @var Language|StubUserLang $wgLang
551 */
552 $wgLang = new StubUserLang;
553
554 /**
555 * @var MediaWiki\Output\OutputPage $wgOut
556 */
557 $wgOut = RequestContext::getMain()->getOutput(); // BackCompat
558
559 /**
560 * @var Title|null $wgTitle
561 */
562 $wgTitle = null;
563
564 // Explicit globals, so this works with bootstrap.php
565 global $wgFullyInitialised, $wgExtensionFunctions;
566
567 // Extension setup functions
568 // Entries should be added to this variable during the inclusion
569 // of the extension file. This allows the extension to perform
570 // any necessary initialisation in the fully initialised environment
571 foreach ( $wgExtensionFunctions as $func ) {
572 call_user_func( $func );
573 }
574 unset( $func ); // no global pollution; destroy reference
575
576 // If the session user has a 0 id but a valid name, that means we need to
577 // autocreate it.
578 if ( !defined( 'MW_NO_SESSION' ) && MW_ENTRY_POINT !== 'cli' ) {
579 $sessionUser = MediaWiki\Session\SessionManager::getGlobalSession()->getUser();
580 if ( $sessionUser->getId() === 0 &&
581 MediaWikiServices::getInstance()->getUserNameUtils()->isValid( $sessionUser->getName() )
582 ) {
583 $res = MediaWikiServices::getInstance()->getAuthManager()->autoCreateUser(
584 $sessionUser,
585 MediaWiki\Auth\AuthManager::AUTOCREATE_SOURCE_SESSION,
586 true,
587 true,
588 $sessionUser
589 );
590 $firstMessage = $res->getMessages( 'error' )[0] ?? $res->getMessages( 'warning' )[0] ?? null;
591 \MediaWiki\Logger\LoggerFactory::getInstance( 'authevents' )->info( 'Autocreation attempt', [
592 'event' => 'autocreate',
593 'successful' => $res->isGood(),
594 'status' => $firstMessage ? $firstMessage->getKey() : '-',
595 ] );
596 unset( $res );
597 unset( $firstMessage );
598 }
599 unset( $sessionUser );
600 }
601
602 // Optimization: Avoid overhead from DeferredUpdates and Pingback deps when turned off.
603 if ( MW_ENTRY_POINT !== 'cli' && $wgPingback ) {
604 // NOTE: Do not refactor to inject Config or otherwise make unconditional service call.
605 //
606 // On a plain install of MediaWiki, Pingback is likely the *only* feature
607 // involving DeferredUpdates or DB_PRIMARY on a regular page view.
608 // To allow for error recovery and fault isolation, let admins turn this
609 // off completely. (T269516)
610 DeferredUpdates::addCallableUpdate( static function () {
611 MediaWikiServices::getInstance()->getPingback()->run();
612 } );
613 }
614
615 $settingsWarnings = $wgSettings->getWarnings();
616 if ( $settingsWarnings ) {
617 $logger = LoggerFactory::getInstance( 'Settings' );
618 foreach ( $settingsWarnings as $msg ) {
619 $logger->warning( $msg );
620 }
621 unset( $logger );
622 }
623
624 unset( $settingsWarnings );
625
626 // Explicit globals, so this works with bootstrap.php
627 global $wgFullyInitialised;
628 $wgFullyInitialised = true;
629
630 // T264370
631 if ( !defined( 'MW_NO_SESSION' ) && MW_ENTRY_POINT !== 'cli' ) {
632 MediaWiki\Session\SessionManager::singleton()->logPotentialSessionLeakage();
633 }