2004-02-18 02:15:00 +00:00
|
|
|
<?php
|
2004-09-02 23:28:24 +00:00
|
|
|
/**
|
2020-03-14 18:56:18 +00:00
|
|
|
* The setup for all MediaWiki processes (both web-based and CLI).
|
2014-04-13 20:07:50 +00:00
|
|
|
*
|
2022-05-04 18:12:23 +00:00
|
|
|
* The entry point (such as WebStart.php and doMaintenance.php) has these responsibilities:
|
|
|
|
|
* - The entry point MUST:
|
2020-04-12 20:22:41 +00:00
|
|
|
* - define the 'MEDIAWIKI' constant.
|
2022-05-04 18:12:23 +00:00
|
|
|
* - The entry point SHOULD:
|
|
|
|
|
* - define the 'MW_ENTRY_POINT' constant.
|
|
|
|
|
* - display an error if MW_CONFIG_CALLBACK is not defined and the
|
|
|
|
|
* file specified in MW_CONFIG_FILE (or the LocalSettings.php default location)
|
|
|
|
|
* does not exist. The error should either be sent before and instead
|
|
|
|
|
* of the Setup.php inclusion, or (if it needs classes and dependencies
|
|
|
|
|
* from core) the error can be displayed via a MW_CONFIG_CALLBACK,
|
|
|
|
|
* which must then abort the process to prevent the rest of Setup.php
|
|
|
|
|
* from executing.
|
2020-03-14 18:56:18 +00:00
|
|
|
*
|
2022-05-04 18:12:23 +00:00
|
|
|
* This file does:
|
2020-03-14 18:56:18 +00:00
|
|
|
* - run-time environment checks,
|
2022-05-04 18:12:23 +00:00
|
|
|
* - define MW_INSTALL_PATH, $IP, and $wgBaseDirectory,
|
2020-03-14 18:56:18 +00:00
|
|
|
* - load autoloaders, constants, default settings, and global functions,
|
|
|
|
|
* - load the site configuration (e.g. LocalSettings.php),
|
|
|
|
|
* - load the enabled extensions (via ExtensionRegistry),
|
2021-07-26 16:48:37 +00:00
|
|
|
* - trivial expansion of site configuration defaults and shortcuts
|
|
|
|
|
* (no calls to MediaWikiServices or other parts of MediaWiki),
|
2020-03-14 18:56:18 +00:00
|
|
|
* - initialization of:
|
|
|
|
|
* - PHP run-time (setlocale, memory limit, default date timezone)
|
|
|
|
|
* - the debug logger (MWDebug)
|
|
|
|
|
* - the service container (MediaWikiServices)
|
|
|
|
|
* - the exception handler (MWExceptionHandler)
|
|
|
|
|
* - the session manager (SessionManager)
|
2021-07-26 16:48:37 +00:00
|
|
|
* - complex expansion of site configuration defaults (those that require
|
|
|
|
|
* calling into MediaWikiServices, global functions, or other classes.).
|
2012-05-10 15:51:44 +00:00
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
2010-10-02 07:57:43 +00:00
|
|
|
*
|
|
|
|
|
* @file
|
2004-09-02 23:28:24 +00:00
|
|
|
*/
|
2020-06-01 05:00:39 +00:00
|
|
|
|
2022-02-21 16:21:36 +00:00
|
|
|
// phpcs:disable MediaWiki.Usage.DeprecatedGlobalVariables
|
2023-09-07 11:37:31 +00:00
|
|
|
use MediaWiki\Config\SiteConfiguration;
|
2024-02-08 14:56:54 +00:00
|
|
|
use MediaWiki\Context\RequestContext;
|
2024-05-03 19:28:04 +00:00
|
|
|
use MediaWiki\Debug\MWDebug;
|
2023-11-21 21:08:14 +00:00
|
|
|
use MediaWiki\Deferred\DeferredUpdates;
|
2022-10-25 14:03:05 +00:00
|
|
|
use MediaWiki\HookContainer\FauxGlobalHookArray;
|
2023-05-06 20:01:10 +00:00
|
|
|
use MediaWiki\HookContainer\HookRunner;
|
2024-10-21 18:33:42 +00:00
|
|
|
use MediaWiki\Language\Language;
|
2020-06-01 05:00:39 +00:00
|
|
|
use MediaWiki\Logger\LoggerFactory;
|
2022-04-01 15:58:32 +00:00
|
|
|
use MediaWiki\MainConfigNames;
|
2022-05-02 19:46:38 +00:00
|
|
|
use MediaWiki\MainConfigSchema;
|
2016-05-01 19:29:11 +00:00
|
|
|
use MediaWiki\MediaWikiServices;
|
2024-06-16 18:18:23 +00:00
|
|
|
use MediaWiki\Message\Message;
|
2024-08-10 05:17:59 +00:00
|
|
|
use MediaWiki\Registration\ExtensionRegistry;
|
|
|
|
|
use MediaWiki\Registration\MissingExtensionException;
|
2022-11-02 17:22:08 +00:00
|
|
|
use MediaWiki\Request\HeaderCallback;
|
2022-04-24 16:14:51 +00:00
|
|
|
use MediaWiki\Settings\DynamicDefaultValues;
|
2022-02-22 16:41:08 +00:00
|
|
|
use MediaWiki\Settings\LocalSettingsLoader;
|
2021-11-11 20:31:47 +00:00
|
|
|
use MediaWiki\Settings\SettingsBuilder;
|
2021-12-08 20:04:36 +00:00
|
|
|
use MediaWiki\Settings\Source\PhpSettingsSource;
|
2022-05-02 19:46:38 +00:00
|
|
|
use MediaWiki\Settings\Source\ReflectionSchemaSource;
|
2021-12-12 21:20:17 +00:00
|
|
|
use MediaWiki\Settings\WikiFarmSettingsLoader;
|
2022-10-25 16:58:49 +00:00
|
|
|
use MediaWiki\StubObject\StubGlobalUser;
|
|
|
|
|
use MediaWiki\StubObject\StubUserLang;
|
2023-03-01 20:33:26 +00:00
|
|
|
use MediaWiki\Title\Title;
|
2023-09-19 12:13:45 +00:00
|
|
|
use MediaWiki\User\User;
|
2019-10-03 04:01:38 +00:00
|
|
|
use Psr\Log\LoggerInterface;
|
2021-01-06 05:23:15 +00:00
|
|
|
use Wikimedia\RequestTimeout\RequestTimeout;
|
2004-09-02 23:28:24 +00:00
|
|
|
|
|
|
|
|
/**
|
2020-03-13 16:20:13 +00:00
|
|
|
* Environment checks
|
|
|
|
|
*
|
|
|
|
|
* These are inline checks done before we include any source files,
|
|
|
|
|
* and thus these conditions may be assumed by all source code.
|
2004-09-02 23:28:24 +00:00
|
|
|
*/
|
2020-03-13 16:20:13 +00:00
|
|
|
|
|
|
|
|
// This file must be included from a valid entry point (e.g. WebStart.php, Maintenance.php)
|
2011-01-14 21:42:38 +00:00
|
|
|
if ( !defined( 'MEDIAWIKI' ) ) {
|
2006-07-14 05:35:31 +00:00
|
|
|
exit( 1 );
|
2008-04-14 07:45:50 +00:00
|
|
|
}
|
2004-08-06 22:30:47 +00:00
|
|
|
|
2020-03-13 16:20:13 +00:00
|
|
|
// PHP must not be configured to overload mbstring functions. (T5782, T122807)
|
2022-11-16 00:58:55 +00:00
|
|
|
// This was deprecated by upstream in PHP 7.2 and was removed in PHP 8.0.
|
2018-04-17 22:07:48 +00:00
|
|
|
if ( ini_get( 'mbstring.func_overload' ) ) {
|
|
|
|
|
die( 'MediaWiki does not support installations where mbstring.func_overload is non-zero.' );
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-13 16:20:13 +00:00
|
|
|
// The MW_ENTRY_POINT constant must always exists, to make it safe to access.
|
2022-01-09 17:58:53 +00:00
|
|
|
// For compat, we do support older and custom MW entrypoints that don't set this,
|
2020-03-13 16:20:13 +00:00
|
|
|
// in which case we assign a default here.
|
2019-09-02 23:55:00 +00:00
|
|
|
if ( !defined( 'MW_ENTRY_POINT' ) ) {
|
|
|
|
|
/**
|
|
|
|
|
* The entry point, which may be either the script filename without the
|
|
|
|
|
* file extension, or "cli" for maintenance scripts, or "unknown" for any
|
|
|
|
|
* entry point that does not set the constant.
|
|
|
|
|
*/
|
|
|
|
|
define( 'MW_ENTRY_POINT', 'unknown' );
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-04 18:12:23 +00:00
|
|
|
// The $IP variable is defined for use by LocalSettings.php.
|
|
|
|
|
// It is made available as a global variable for backwards compatibility.
|
|
|
|
|
//
|
|
|
|
|
// Source code should instead use the MW_INSTALL_PATH constant, or the
|
|
|
|
|
// MainConfigNames::BaseDirectory setting. The BaseDirectory setting is set further
|
|
|
|
|
// down in Setup.php to the value of MW_INSTALL_PATH.
|
2022-04-27 19:33:22 +00:00
|
|
|
global $IP;
|
2023-03-23 19:50:01 +00:00
|
|
|
$IP = wfDetectInstallPath(); // ensure MW_INSTALL_PATH is defined
|
2022-01-27 20:24:12 +00:00
|
|
|
|
2020-03-13 16:20:13 +00:00
|
|
|
/**
|
|
|
|
|
* Pre-config setup: Before loading LocalSettings.php
|
|
|
|
|
*
|
|
|
|
|
* These are changes and additions to runtime that don't vary on site configuration.
|
|
|
|
|
*/
|
2022-05-04 18:12:23 +00:00
|
|
|
require_once MW_INSTALL_PATH . '/includes/AutoLoader.php';
|
|
|
|
|
require_once MW_INSTALL_PATH . '/includes/Defines.php';
|
2017-09-19 19:24:19 +00:00
|
|
|
|
|
|
|
|
// Assert that composer dependencies were successfully loaded
|
2019-10-03 04:01:38 +00:00
|
|
|
if ( !interface_exists( LoggerInterface::class ) ) {
|
2017-09-19 19:24:19 +00:00
|
|
|
$message = (
|
2025-06-12 01:13:59 +00:00
|
|
|
'<strong>Error: Missing external libraries.</strong> ' .
|
|
|
|
|
'MediaWiki depends on external libraries bundled with most MediaWiki distributions. ' .
|
|
|
|
|
"When installing MediaWiki from its Git reposistory, these must be installed separately.\n\n" .
|
2021-11-14 07:05:27 +00:00
|
|
|
'Please see the <a href="https://www.mediawiki.org/wiki/Download_from_Git' .
|
|
|
|
|
'#Fetch_external_libraries">instructions for installing libraries</a> on mediawiki.org ' .
|
2025-06-12 01:13:59 +00:00
|
|
|
'for help on installing the required libraries.'
|
2017-09-19 19:24:19 +00:00
|
|
|
);
|
Setup: Switch vendor error from echo+E_USER_ERROR to echo+exit
== Background ==
E_USER_ERROR is a deprecated error code for "recoverable fatal error",
a confusing description no longer used upstream and replaced by the
Throwable/Error concept, i.e. something that is meant to be fatal,
but could in theory be caught if you know what you're doing, via a
risky catch for Throwable instead of Exception.
What trigger_error with E_USER_ERROR does:
* (If we haven't sent headers yet)
Emit header "HTTP/1.1 500 Internal Server Error".
* (If display_errors is enabled)
Print the message, again, along with a strack trace.
* Notify set_error_handler letting you "catch" a non-Exception error.
* Write it to error_log, e.g. STDERR for composer serve and CLI,
or an Apache/php-fpm error.log file.
* End with exit(1).
Issues:
* When enabling display_errors, the message is printed twice.
* The HTTP 500 status didn't work because headers are already sent,
... by the "echo" statement, right above it.
== Option A: throw Error $message ==
`throw Error($message)` is the natural successor to E_USER_ERROR.
I would recommend this, if
1) we didn't already echo it, and
2) the message didn't contain HTML, and
3) we needed to keep compat with someone catching this, or
4) we wanted a stack trace.
We echo it because display_errors can be off, and the most likely
audience for this is someone new to PHP/MediaWiki, installing in prod
or locally, when debugging is either intentionally off, or before
they're familiar with debugging modes. As such, we want to print it
ourselves either way, and printing it again as part of E_USER_ERROR
isn't needed.
The HTML part is important because one subtle difference between
trigger_error and throw Error is that the former allows raw HTML,
while the latter treats exception messages as plain text. Our message
intentionally uses HTML to link to docs in the browser, so this is
unhelpful.
The catchable-ness of this is not important to us, as no extension or
distro code (e.g. PlatformSettings.php) can run this early. There
are no runtime consumers of this error, only the end-user's browser.
== Option B: echo+exit ==
Given we already print the message, we just need to exit.
== History ==
* 2014 (Ie66794441): Add first ever Composer dependency (psr/log)
* 2015 (Ie47467657): Add LoggerFactory with check for missing Composer
dependency, to address a then-common issue.
* 2015 (Ib60261237): Move check earlier, to WebStart.
* 2017 (I633a6ff23): Move check earlier, to Setup.
* 2021 (Ia81903fb2): Remove redundant exit(1).
== Change ==
* Emit HTTP 500 before the echo.
* Keep echo (for browser) and error_log (for discovery via CLI or log
file).
* Replace trigger_error with just exit(1), avoid duplicate message.
Bug: T379445
Change-Id: I6050ec4ca857d3c92c1c43f6a38e4154cd60e5d5
(cherry picked from commit 98c6d3c4c3511ecf60ffc693ff6c7164964270ca)
2025-06-12 00:12:51 +00:00
|
|
|
http_response_code( 500 );
|
2017-09-19 19:24:19 +00:00
|
|
|
echo $message;
|
Setup: Switch vendor error from echo+E_USER_ERROR to echo+exit
== Background ==
E_USER_ERROR is a deprecated error code for "recoverable fatal error",
a confusing description no longer used upstream and replaced by the
Throwable/Error concept, i.e. something that is meant to be fatal,
but could in theory be caught if you know what you're doing, via a
risky catch for Throwable instead of Exception.
What trigger_error with E_USER_ERROR does:
* (If we haven't sent headers yet)
Emit header "HTTP/1.1 500 Internal Server Error".
* (If display_errors is enabled)
Print the message, again, along with a strack trace.
* Notify set_error_handler letting you "catch" a non-Exception error.
* Write it to error_log, e.g. STDERR for composer serve and CLI,
or an Apache/php-fpm error.log file.
* End with exit(1).
Issues:
* When enabling display_errors, the message is printed twice.
* The HTTP 500 status didn't work because headers are already sent,
... by the "echo" statement, right above it.
== Option A: throw Error $message ==
`throw Error($message)` is the natural successor to E_USER_ERROR.
I would recommend this, if
1) we didn't already echo it, and
2) the message didn't contain HTML, and
3) we needed to keep compat with someone catching this, or
4) we wanted a stack trace.
We echo it because display_errors can be off, and the most likely
audience for this is someone new to PHP/MediaWiki, installing in prod
or locally, when debugging is either intentionally off, or before
they're familiar with debugging modes. As such, we want to print it
ourselves either way, and printing it again as part of E_USER_ERROR
isn't needed.
The HTML part is important because one subtle difference between
trigger_error and throw Error is that the former allows raw HTML,
while the latter treats exception messages as plain text. Our message
intentionally uses HTML to link to docs in the browser, so this is
unhelpful.
The catchable-ness of this is not important to us, as no extension or
distro code (e.g. PlatformSettings.php) can run this early. There
are no runtime consumers of this error, only the end-user's browser.
== Option B: echo+exit ==
Given we already print the message, we just need to exit.
== History ==
* 2014 (Ie66794441): Add first ever Composer dependency (psr/log)
* 2015 (Ie47467657): Add LoggerFactory with check for missing Composer
dependency, to address a then-common issue.
* 2015 (Ib60261237): Move check earlier, to WebStart.
* 2017 (I633a6ff23): Move check earlier, to Setup.
* 2021 (Ia81903fb2): Remove redundant exit(1).
== Change ==
* Emit HTTP 500 before the echo.
* Keep echo (for browser) and error_log (for discovery via CLI or log
file).
* Replace trigger_error with just exit(1), avoid duplicate message.
Bug: T379445
Change-Id: I6050ec4ca857d3c92c1c43f6a38e4154cd60e5d5
(cherry picked from commit 98c6d3c4c3511ecf60ffc693ff6c7164964270ca)
2025-06-12 00:12:51 +00:00
|
|
|
error_log( $message );
|
|
|
|
|
exit( 1 );
|
2017-09-19 19:24:19 +00:00
|
|
|
}
|
|
|
|
|
|
2024-01-02 21:21:50 +00:00
|
|
|
// Deprecated global variable for backwards-compatibility.
|
|
|
|
|
// New code should check MW_ENTRY_POINT directly.
|
|
|
|
|
$wgCommandLineMode = MW_ENTRY_POINT === 'cli';
|
2022-02-21 16:21:36 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* $wgConf hold the site configuration.
|
|
|
|
|
* Not used for much in a default install.
|
|
|
|
|
* @since 1.5
|
|
|
|
|
*/
|
|
|
|
|
$wgConf = new SiteConfiguration;
|
|
|
|
|
|
2022-10-21 02:26:49 +00:00
|
|
|
$wgAutoloadClasses ??= [];
|
2022-02-21 16:21:36 +00:00
|
|
|
|
2022-11-06 20:35:07 +00:00
|
|
|
$wgSettings = SettingsBuilder::getInstance();
|
2021-11-11 20:31:47 +00:00
|
|
|
|
2022-05-02 19:46:38 +00:00
|
|
|
if ( defined( 'MW_USE_CONFIG_SCHEMA_CLASS' ) ) {
|
|
|
|
|
// Load config schema from MainConfigSchema. Useful for running scripts that
|
|
|
|
|
// generate other representations of the config schema. This is slow, so it
|
|
|
|
|
// should not be used for serving web traffic.
|
|
|
|
|
$wgSettings->load( new ReflectionSchemaSource( MainConfigSchema::class ) );
|
2022-03-31 16:47:27 +00:00
|
|
|
} else {
|
2022-05-04 18:12:23 +00:00
|
|
|
$wgSettings->load( new PhpSettingsSource( MW_INSTALL_PATH . '/includes/config-schema.php' ) );
|
2022-02-21 16:21:36 +00:00
|
|
|
}
|
2021-11-11 20:31:47 +00:00
|
|
|
|
2022-05-04 18:12:23 +00:00
|
|
|
require_once MW_INSTALL_PATH . '/includes/GlobalFunctions.php';
|
2021-12-08 20:04:36 +00:00
|
|
|
|
2021-01-06 05:23:15 +00:00
|
|
|
HeaderCallback::register();
|
2017-09-19 19:24:19 +00:00
|
|
|
|
2019-08-25 18:22:26 +00:00
|
|
|
// Set the encoding used by PHP for reading HTTP input, and writing output.
|
2019-07-13 00:46:56 +00:00
|
|
|
// This is also the default for mbstring functions.
|
|
|
|
|
mb_internal_encoding( 'UTF-8' );
|
|
|
|
|
|
2017-09-19 19:24:19 +00:00
|
|
|
/**
|
|
|
|
|
* Load LocalSettings.php
|
|
|
|
|
*/
|
|
|
|
|
|
2022-01-28 19:17:51 +00:00
|
|
|
// Initialize some config settings with dynamic defaults, and
|
|
|
|
|
// make default settings available in globals for use in LocalSettings.php.
|
2022-02-20 21:15:06 +00:00
|
|
|
$wgSettings->putConfigValues( [
|
2022-05-04 18:12:23 +00:00
|
|
|
MainConfigNames::BaseDirectory => MW_INSTALL_PATH,
|
|
|
|
|
MainConfigNames::ExtensionDirectory => MW_INSTALL_PATH . '/extensions',
|
|
|
|
|
MainConfigNames::StyleDirectory => MW_INSTALL_PATH . '/skins',
|
|
|
|
|
MainConfigNames::ServiceWiringFiles => [ MW_INSTALL_PATH . '/includes/ServiceWiring.php' ],
|
2022-02-21 16:21:36 +00:00
|
|
|
'Version' => MW_VERSION,
|
2022-01-28 19:17:51 +00:00
|
|
|
] );
|
2021-11-11 20:31:47 +00:00
|
|
|
$wgSettings->apply();
|
|
|
|
|
|
2022-02-21 16:28:35 +00:00
|
|
|
// $wgSettings->apply() puts all configuration into global variables.
|
|
|
|
|
// If we are not in global scope, make all relevant globals available
|
|
|
|
|
// in this file's scope as well.
|
|
|
|
|
$wgScopeTest = 'MediaWiki Setup.php scope test';
|
|
|
|
|
if ( !isset( $GLOBALS['wgScopeTest'] ) || $GLOBALS['wgScopeTest'] !== $wgScopeTest ) {
|
|
|
|
|
foreach ( $wgSettings->getConfigSchema()->getDefinedKeys() as $key ) {
|
|
|
|
|
$var = "wg$key";
|
|
|
|
|
// phpcs:ignore MediaWiki.NamingConventions.ValidGlobalName.allowedPrefix
|
|
|
|
|
global $$var;
|
|
|
|
|
}
|
|
|
|
|
unset( $key, $var );
|
|
|
|
|
}
|
|
|
|
|
unset( $wgScopeTest );
|
|
|
|
|
|
2022-10-21 00:40:24 +00:00
|
|
|
try {
|
|
|
|
|
if ( defined( 'MW_CONFIG_CALLBACK' ) ) {
|
|
|
|
|
call_user_func( MW_CONFIG_CALLBACK, $wgSettings );
|
2021-11-16 18:22:57 +00:00
|
|
|
} else {
|
2022-10-21 00:40:24 +00:00
|
|
|
wfDetectLocalSettingsFile( MW_INSTALL_PATH );
|
|
|
|
|
|
|
|
|
|
if ( getenv( 'MW_USE_LOCAL_SETTINGS_LOADER' ) ) {
|
|
|
|
|
// NOTE: This will not work for configuration variables that use a prefix
|
|
|
|
|
// other than "wg".
|
|
|
|
|
$localSettingsLoader = new LocalSettingsLoader( $wgSettings, MW_INSTALL_PATH );
|
|
|
|
|
$localSettingsLoader->loadLocalSettingsFile( MW_CONFIG_FILE );
|
|
|
|
|
unset( $localSettingsLoader );
|
2022-02-22 16:41:08 +00:00
|
|
|
} else {
|
2022-10-21 00:40:24 +00:00
|
|
|
if ( str_ends_with( MW_CONFIG_FILE, '.php' ) ) {
|
|
|
|
|
// make defaults available as globals
|
|
|
|
|
$wgSettings->apply();
|
|
|
|
|
require_once MW_CONFIG_FILE;
|
|
|
|
|
} else {
|
|
|
|
|
$wgSettings->loadFile( MW_CONFIG_FILE );
|
|
|
|
|
}
|
2022-02-22 16:41:08 +00:00
|
|
|
}
|
2017-09-19 19:24:19 +00:00
|
|
|
}
|
|
|
|
|
|
2022-10-21 00:40:24 +00:00
|
|
|
// Make settings loaded by LocalSettings.php available in globals for use here
|
|
|
|
|
$wgSettings->apply();
|
|
|
|
|
} catch ( MissingExtensionException $e ) {
|
|
|
|
|
// Make a common mistake give a friendly error
|
|
|
|
|
$e->render();
|
|
|
|
|
}
|
2021-11-11 20:31:47 +00:00
|
|
|
|
2022-11-16 16:44:29 +00:00
|
|
|
// If in a wiki-farm, load site-specific settings
|
|
|
|
|
if ( $wgSettings->getConfig()->get( MainConfigNames::WikiFarmSettingsDirectory ) ) {
|
|
|
|
|
$wikiFarmSettingsLoader = new WikiFarmSettingsLoader( $wgSettings );
|
|
|
|
|
$wikiFarmSettingsLoader->loadWikiFarmSettings();
|
|
|
|
|
unset( $wikiFarmSettingsLoader );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// All settings should be loaded now.
|
|
|
|
|
$wgSettings->enterRegistrationStage();
|
|
|
|
|
|
2017-09-19 19:24:19 +00:00
|
|
|
/**
|
2022-07-31 10:39:13 +00:00
|
|
|
* Customization point after most things are loaded (constants, functions, classes,
|
|
|
|
|
* LocalSettings.
|
|
|
|
|
* Note that this runs before extensions are registered, and before most singletons become
|
|
|
|
|
* available, and before MediaWikiServices is initialized.
|
2017-09-19 19:24:19 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
if ( defined( 'MW_SETUP_CALLBACK' ) ) {
|
2022-01-26 17:46:06 +00:00
|
|
|
call_user_func( MW_SETUP_CALLBACK, $wgSettings );
|
2021-11-11 20:31:47 +00:00
|
|
|
// Make any additional settings available in globals for use here
|
|
|
|
|
$wgSettings->apply();
|
2017-09-19 19:24:19 +00:00
|
|
|
}
|
|
|
|
|
|
2022-04-24 16:14:51 +00:00
|
|
|
// Apply dynamic defaults declared in config schema callbacks.
|
|
|
|
|
$dynamicDefaults = new DynamicDefaultValues( $wgSettings->getConfigSchema() );
|
|
|
|
|
$dynamicDefaults->applyDynamicDefaults( $wgSettings->getConfigBuilder() );
|
|
|
|
|
|
|
|
|
|
// Make updated config available in global scope.
|
|
|
|
|
$wgSettings->apply();
|
|
|
|
|
|
|
|
|
|
// Apply dynamic defaults implemented in SetupDynamicConfig.php.
|
|
|
|
|
// Ideally, all logic in SetupDynamicConfig would be converted to
|
|
|
|
|
// callbacks in the config schema.
|
|
|
|
|
require __DIR__ . '/SetupDynamicConfig.php';
|
|
|
|
|
|
2023-03-27 17:25:03 +00:00
|
|
|
if ( defined( 'MW_AUTOLOAD_TEST_CLASSES' ) ) {
|
|
|
|
|
require_once __DIR__ . '/../tests/common/TestsAutoLoader.php';
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-27 20:24:12 +00:00
|
|
|
if ( $wgBaseDirectory !== MW_INSTALL_PATH ) {
|
|
|
|
|
throw new FatalError(
|
|
|
|
|
'$wgBaseDirectory must not be modified in settings files! ' .
|
|
|
|
|
'Use the MW_INSTALL_PATH environment variable to override the installation root directory.'
|
|
|
|
|
);
|
|
|
|
|
}
|
2021-11-11 20:31:47 +00:00
|
|
|
|
2021-01-06 05:23:15 +00:00
|
|
|
// Start time limit
|
2023-12-19 15:26:32 +00:00
|
|
|
if ( $wgRequestTimeLimit && MW_ENTRY_POINT !== 'cli' ) {
|
2021-01-06 05:23:15 +00:00
|
|
|
RequestTimeout::singleton()->setWallTimeLimit( $wgRequestTimeLimit );
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-19 19:24:19 +00:00
|
|
|
/**
|
2020-03-14 18:56:18 +00:00
|
|
|
* Load queued extensions
|
2017-09-19 19:24:19 +00:00
|
|
|
*/
|
2023-03-27 17:25:03 +00:00
|
|
|
if ( defined( 'MW_AUTOLOAD_TEST_CLASSES' ) ) {
|
|
|
|
|
ExtensionRegistry::getInstance()->setLoadTestClassesAndNamespaces( true );
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-16 16:44:29 +00:00
|
|
|
ExtensionRegistry::getInstance()->setSettingsBuilder( $wgSettings );
|
Implement extension registration from an extension.json file
Introduces wfLoadExtension()/wfLoadSkin() which should be used in
LocalSettings.php rather than require-ing a PHP entry point.
Extensions and skins would add "extension.json" or "skin.json" files
in their root, which contains all the information typically
present in PHP entry point files (classes to autoload, special pages,
API modules, etc.) A full schema can be found at
docs/extension.schema.json, and a script to validate these to the
schema is provided. An additional script is provided to convert
typical PHP entry point files into their JSON equivalents.
The basic flow of loading an extension goes like:
* Get the ExtensionRegistry singleton instance
* ExtensionRegistry takes a filename, reads the file or tries
to get the parsed JSON from APC if possible.
* The JSON is run through a Processor instance,
which registers things with the appropriate
global settings.
* The output of the processor is cached in APC if possible.
* The extension/skin is marked as loaded in the
ExtensionRegistry and a callback function is executed
if one was specified.
For ideal performance, a batch loading method is also provided:
* The absolute path name to the JSON file is queued
in the ExtensionRegistry instance.
* When loadFromQueue() is called, it constructs a hash
unique to the members of the current queue, and sees
if the queue has been cached in APC. If not, it processes
each file individually, and combines the result of each
Processor into one giant array, which is cached in APC.
* The giant array then sets various global settings,
defines constants, and calls callbacks.
To invalidate the cached processed info, by default the mtime
of each JSON file is checked. However that can be slow if you
have a large number of extensions, so you can set $wgExtensionInfoMTime
to the mtime of one file, and `touch` it whenever you update
your extensions.
Change-Id: I7074b65d07c5c7d4e3f1fb0755d74a0b07ed4596
2014-10-15 00:31:15 +00:00
|
|
|
ExtensionRegistry::getInstance()->loadFromQueue();
|
2016-12-03 17:46:48 +00:00
|
|
|
// Don't let any other extensions load
|
|
|
|
|
ExtensionRegistry::getInstance()->finish();
|
Implement extension registration from an extension.json file
Introduces wfLoadExtension()/wfLoadSkin() which should be used in
LocalSettings.php rather than require-ing a PHP entry point.
Extensions and skins would add "extension.json" or "skin.json" files
in their root, which contains all the information typically
present in PHP entry point files (classes to autoload, special pages,
API modules, etc.) A full schema can be found at
docs/extension.schema.json, and a script to validate these to the
schema is provided. An additional script is provided to convert
typical PHP entry point files into their JSON equivalents.
The basic flow of loading an extension goes like:
* Get the ExtensionRegistry singleton instance
* ExtensionRegistry takes a filename, reads the file or tries
to get the parsed JSON from APC if possible.
* The JSON is run through a Processor instance,
which registers things with the appropriate
global settings.
* The output of the processor is cached in APC if possible.
* The extension/skin is marked as loaded in the
ExtensionRegistry and a callback function is executed
if one was specified.
For ideal performance, a batch loading method is also provided:
* The absolute path name to the JSON file is queued
in the ExtensionRegistry instance.
* When loadFromQueue() is called, it constructs a hash
unique to the members of the current queue, and sees
if the queue has been cached in APC. If not, it processes
each file individually, and combines the result of each
Processor into one giant array, which is cached in APC.
* The giant array then sets various global settings,
defines constants, and calls callbacks.
To invalidate the cached processed info, by default the mtime
of each JSON file is checked. However that can be slow if you
have a large number of extensions, so you can set $wgExtensionInfoMTime
to the mtime of one file, and `touch` it whenever you update
your extensions.
Change-Id: I7074b65d07c5c7d4e3f1fb0755d74a0b07ed4596
2014-10-15 00:31:15 +00:00
|
|
|
|
2022-07-31 10:39:13 +00:00
|
|
|
/**
|
|
|
|
|
* Customization point after ALL loading (constants, functions, classes,
|
|
|
|
|
* LocalSettings, extensions, dynamic defaults).
|
|
|
|
|
* Note that this runs before MediaWikiServices is initialized.
|
|
|
|
|
*/
|
|
|
|
|
if ( defined( 'MW_FINAL_SETUP_CALLBACK' ) ) {
|
|
|
|
|
call_user_func( MW_FINAL_SETUP_CALLBACK, $wgSettings );
|
|
|
|
|
// Make any additional settings available in globals for use below
|
|
|
|
|
$wgSettings->apply();
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-16 16:44:29 +00:00
|
|
|
// Config can no longer be changed.
|
|
|
|
|
$wgSettings->enterReadOnlyStage();
|
|
|
|
|
|
2021-09-21 05:40:55 +00:00
|
|
|
// Set an appropriate locale (T291234)
|
|
|
|
|
// setlocale() will return the locale name actually set.
|
|
|
|
|
// The putenv() is meant to propagate the choice of locale to shell commands
|
|
|
|
|
// so that they will interpret UTF-8 correctly. If you have a problem with a
|
|
|
|
|
// shell command and need to send a special locale, you can override the locale
|
|
|
|
|
// with Command::environment().
|
|
|
|
|
putenv( "LC_ALL=" . setlocale( LC_ALL, 'C.UTF-8', 'C' ) );
|
2017-05-09 16:12:41 +00:00
|
|
|
|
2022-07-09 16:06:21 +00:00
|
|
|
// Set PHP runtime to the desired timezone
|
|
|
|
|
date_default_timezone_set( $wgLocaltimezone );
|
|
|
|
|
|
2019-08-31 22:43:23 +00:00
|
|
|
MWDebug::setup();
|
2011-12-04 18:29:57 +00:00
|
|
|
|
2020-12-22 14:51:13 +00:00
|
|
|
// Enable the global service locator.
|
2021-07-26 16:48:37 +00:00
|
|
|
// Trivial expansion of site configuration should go before this point.
|
|
|
|
|
// Any non-trivial expansion that requires calling into MediaWikiServices or other parts of MW.
|
2020-12-22 14:51:13 +00:00
|
|
|
MediaWikiServices::allowGlobalInstance();
|
2016-09-15 18:52:55 +00:00
|
|
|
|
2016-05-01 19:29:11 +00:00
|
|
|
// Define a constant that indicates that the bootstrapping of the service locator
|
|
|
|
|
// is complete.
|
|
|
|
|
define( 'MW_SERVICE_BOOTSTRAP_COMPLETE', 1 );
|
|
|
|
|
|
2022-05-19 12:57:14 +00:00
|
|
|
MWExceptionRenderer::setShowExceptionDetails( $wgShowExceptionDetails );
|
2023-07-13 17:12:45 +00:00
|
|
|
if ( !defined( 'MW_PHPUNIT_TEST' ) ) {
|
|
|
|
|
// Never install the handler in PHPUnit tests, otherwise PHPUnit's own handler will be unset and things
|
|
|
|
|
// like convertWarningsToExceptions won't work.
|
|
|
|
|
MWExceptionHandler::installHandler( $wgLogExceptionBacktrace, $wgPropagateErrors );
|
|
|
|
|
}
|
2022-06-28 01:39:08 +00:00
|
|
|
Profiler::init( $wgProfiler );
|
The beginnings of HipHop compiled mode support. It works now for parser cache hits.
* Work around HipHop issue 314 (volatile broken) and issue 308 (no compilation detection) by adding some large and ugly compilation detection code to WebStart.php and doMaintenance.php.
* Provide an MW_COMPILED constant which can be used to detect compiled mode throughout the codebase.
* Introduced wfIsHipHop(), which detects either compiled or interpreted mode. Used this to work around unusual eval() return value in eval.php.
* Work around lack of ini_get() in Maintenance.php, by duplicating wfIsHipHop().
* In Maintenance::shouldExecute(), accept "include" as an inclusion function name, since all kinds of inclusion give this string in HipHop.
* Introduced new class MWInit, which provides some static functions in the pre-autoloader environment.
* Introduced MWInit::compiledPath(), which provides a relative path for invoking a compiled file, and MWInit::interpretedPath(), which provides an absolute path for interpreting a PHP file. Used these new functions in the appropriate places.
* When we are running compiled code, don't include files which would generate duplicate class, function or constant definitions. Documented the new requirements on the contents of Defines.php and UtfNormalDefines.php.
* In HipHop compiled mode, it's not possible to have executable code in the same file as a class definition.
** Moved MimeMagic initialisation to the constructor.
** Moved Namespace.php global variable initialisation to Setup.php.
** Moved MemcachedSessions.php initialisation to the caller in GlobalFunctions.php.
** Moved Sanitizer.php constants and global variables to static class members. Introduced an accessor function for the attribs regex, as a new place to put code formerly at file level.
** Moved Language.php initialisation of $wgLanguageNames to Language::getLanguageNames(). Removed the global variable, marked "private" since forever.
* In two places: don't use error_log() with type=3 to append to a file, HipHop doesn't support it. Use file_put_contents() with FILE_APPEND instead.
* Work around the terrible breakage of class_exists() by using MWInit::classExists() instead in various places. In WebInstaller::getPageByName(), the class_exists() was marked with a fixme comment already, so I replaced it with an autoloader solution.
2011-04-04 12:59:55 +00:00
|
|
|
|
2021-07-31 19:05:38 +00:00
|
|
|
// Non-trivial validation of: $wgServer
|
|
|
|
|
// The FatalError page only renders cleanly after MWExceptionHandler is installed.
|
|
|
|
|
if ( $wgServer === false ) {
|
|
|
|
|
// T30798: $wgServer must be explicitly set
|
|
|
|
|
throw new FatalError(
|
|
|
|
|
'$wgServer must be set in LocalSettings.php. ' .
|
|
|
|
|
'See <a href="https://www.mediawiki.org/wiki/Manual:$wgServer">' .
|
|
|
|
|
'https://www.mediawiki.org/wiki/Manual:$wgServer</a>.'
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-25 14:03:05 +00:00
|
|
|
// Set up a fake $wgHooks array.
|
|
|
|
|
// XXX: It would be nice if we could still get the originally configured hook handlers
|
|
|
|
|
// using the MainConfigNames::Hooks setting, but it's not really needed,
|
|
|
|
|
// since we need the HookContainer to be initialized first anyway.
|
|
|
|
|
|
|
|
|
|
global $wgHooks;
|
|
|
|
|
$wgHooks = new FauxGlobalHookArray(
|
|
|
|
|
MediaWikiServices::getInstance()->getHookContainer(),
|
|
|
|
|
$wgHooks
|
|
|
|
|
);
|
|
|
|
|
|
2021-07-26 16:48:37 +00:00
|
|
|
// Non-trivial expansion of: $wgCanonicalServer, $wgServerName.
|
|
|
|
|
// These require calling global functions.
|
|
|
|
|
// Also here are other settings that further depend on these two.
|
2014-05-06 09:31:24 +00:00
|
|
|
if ( $wgCanonicalServer === false ) {
|
2023-03-16 22:27:45 +00:00
|
|
|
$wgCanonicalServer = MediaWikiServices::getInstance()->getUrlUtils()->getCanonicalServer();
|
2014-05-06 09:31:24 +00:00
|
|
|
}
|
2021-07-26 16:48:37 +00:00
|
|
|
$wgVirtualRestConfig['global']['domain'] = $wgCanonicalServer;
|
2014-05-06 09:31:24 +00:00
|
|
|
|
|
|
|
|
if ( $wgServerName !== false ) {
|
2014-05-11 15:33:33 +00:00
|
|
|
wfWarn( '$wgServerName should be derived from $wgCanonicalServer, '
|
|
|
|
|
. 'not customized. Overwriting $wgServerName.' );
|
2014-05-06 09:31:24 +00:00
|
|
|
}
|
2024-02-12 20:29:57 +00:00
|
|
|
$wgServerName = parse_url( $wgCanonicalServer, PHP_URL_HOST );
|
2014-05-06 09:31:24 +00:00
|
|
|
|
2021-07-26 16:48:37 +00:00
|
|
|
// $wgEmergencyContact and $wgPasswordSender may be false or empty string (T104142)
|
2015-08-31 15:32:56 +00:00
|
|
|
if ( !$wgEmergencyContact ) {
|
2014-05-06 09:31:24 +00:00
|
|
|
$wgEmergencyContact = 'wikiadmin@' . $wgServerName;
|
|
|
|
|
}
|
2015-08-31 15:32:56 +00:00
|
|
|
if ( !$wgPasswordSender ) {
|
2014-05-06 09:31:24 +00:00
|
|
|
$wgPasswordSender = 'apache@' . $wgServerName;
|
|
|
|
|
}
|
2015-04-30 21:38:05 +00:00
|
|
|
if ( !$wgNoReplyAddress ) {
|
2016-03-18 14:19:07 +00:00
|
|
|
$wgNoReplyAddress = $wgPasswordSender;
|
2015-04-30 21:38:05 +00:00
|
|
|
}
|
2014-05-06 09:31:24 +00:00
|
|
|
|
2021-07-26 16:48:37 +00:00
|
|
|
// Non-trivial expansion of: $wgSecureLogin
|
|
|
|
|
// (due to calling wfWarn).
|
2012-10-08 04:21:08 +00:00
|
|
|
if ( $wgSecureLogin && substr( $wgServer, 0, 2 ) !== '//' ) {
|
|
|
|
|
$wgSecureLogin = false;
|
2014-05-11 15:33:33 +00:00
|
|
|
wfWarn( 'Secure login was enabled on a server that only supports '
|
|
|
|
|
. 'HTTP or HTTPS. Disabling secure login.' );
|
2012-10-08 04:21:08 +00:00
|
|
|
}
|
|
|
|
|
|
2015-01-07 21:57:56 +00:00
|
|
|
// Now that GlobalFunctions is loaded, set defaults that depend on it.
|
2012-05-26 03:19:55 +00:00
|
|
|
if ( $wgTmpDirectory === false ) {
|
|
|
|
|
$wgTmpDirectory = wfTempDir();
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-22 16:03:50 +00:00
|
|
|
if ( $wgSharedDB && $wgSharedTables ) {
|
|
|
|
|
// Apply $wgSharedDB table aliases for the local LB (all non-foreign DB connections)
|
|
|
|
|
MediaWikiServices::getInstance()->getDBLoadBalancer()->setTableAliases(
|
|
|
|
|
array_fill_keys(
|
|
|
|
|
$wgSharedTables,
|
|
|
|
|
[
|
|
|
|
|
'dbname' => $wgSharedDB,
|
|
|
|
|
'schema' => $wgSharedSchema,
|
|
|
|
|
'prefix' => $wgSharedPrefix
|
|
|
|
|
]
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-13 20:07:50 +00:00
|
|
|
// Raise the memory limit if it's too low
|
2021-07-26 16:48:37 +00:00
|
|
|
// NOTE: This use wfDebug, and must remain after the MWDebug::setup() call.
|
2019-07-13 01:05:54 +00:00
|
|
|
wfMemoryLimit( $wgMemoryLimit );
|
2006-07-26 07:15:39 +00:00
|
|
|
|
2022-02-21 16:21:36 +00:00
|
|
|
// Explicit globals, so this works with bootstrap.php
|
|
|
|
|
global $wgRequest, $wgInitialSessionId;
|
|
|
|
|
|
2017-11-29 02:40:04 +00:00
|
|
|
// Initialize the request object in $wgRequest
|
2015-11-17 18:43:47 +00:00
|
|
|
$wgRequest = RequestContext::getMain()->getRequest(); // BackCompat
|
2021-04-15 22:48:58 +00:00
|
|
|
|
2018-02-01 00:47:09 +00:00
|
|
|
// Make sure that object caching does not undermine the ChronologyProtector improvements
|
|
|
|
|
if ( $wgRequest->getCookie( 'UseDC', '' ) === 'master' ) {
|
|
|
|
|
// The user is pinned to the primary DC, meaning that they made recent changes which should
|
|
|
|
|
// be reflected in their subsequent web requests. Avoid the use of interim cache keys because
|
|
|
|
|
// they use a blind TTL and could be stale if an object changes twice in a short time span.
|
2017-11-29 04:39:47 +00:00
|
|
|
MediaWikiServices::getInstance()->getMainWANObjectCache()->useInterimHoldOffCaching( false );
|
|
|
|
|
}
|
2015-11-17 18:43:47 +00:00
|
|
|
|
2014-04-13 20:07:50 +00:00
|
|
|
// Useful debug output
|
2021-02-10 22:31:02 +00:00
|
|
|
( static function () {
|
2023-12-19 07:54:55 +00:00
|
|
|
global $wgRequest;
|
2023-09-07 11:46:15 +00:00
|
|
|
|
2020-06-01 05:00:39 +00:00
|
|
|
$logger = LoggerFactory::getInstance( 'wfDebug' );
|
2023-12-19 07:54:55 +00:00
|
|
|
if ( MW_ENTRY_POINT === 'cli' ) {
|
2020-06-01 05:00:39 +00:00
|
|
|
$self = $_SERVER['PHP_SELF'] ?? '';
|
|
|
|
|
$logger->debug( "\n\nStart command line script $self" );
|
|
|
|
|
} else {
|
|
|
|
|
$debug = "\n\nStart request {$wgRequest->getMethod()} {$wgRequest->getRequestURL()}\n";
|
|
|
|
|
$debug .= "IP: " . $wgRequest->getIP() . "\n";
|
|
|
|
|
$debug .= "HTTP HEADERS:\n";
|
|
|
|
|
foreach ( $wgRequest->getAllHeaders() as $name => $value ) {
|
|
|
|
|
$debug .= "$name: $value\n";
|
|
|
|
|
}
|
|
|
|
|
$debug .= "(end headers)";
|
|
|
|
|
$logger->debug( $debug );
|
2010-01-27 17:21:18 +00:00
|
|
|
}
|
2020-06-01 05:00:39 +00:00
|
|
|
} )();
|
2003-08-11 13:53:20 +00:00
|
|
|
|
2014-04-13 20:07:50 +00:00
|
|
|
// Most of the config is out, some might want to run hooks here.
|
2023-05-06 20:01:10 +00:00
|
|
|
( new HookRunner( MediaWikiServices::getInstance()->getHookContainer() ) )->onSetupAfterCache();
|
2008-12-10 23:15:50 +00:00
|
|
|
|
2021-07-26 16:59:05 +00:00
|
|
|
// Now that variant lists may be available, parse any action paths and article paths
|
|
|
|
|
// as query parameters.
|
|
|
|
|
//
|
|
|
|
|
// Skip title interpolation on API queries where it is useless and sometimes harmful (T18019).
|
|
|
|
|
//
|
|
|
|
|
// Optimization: Skip on load.php and all other entrypoints besides index.php to save time.
|
|
|
|
|
//
|
|
|
|
|
// TODO: Figure out if this can be safely done after everything else in Setup.php (e.g. any
|
|
|
|
|
// hooks or other state that would miss this?). If so, move to wfIndexMain or MediaWiki::run.
|
|
|
|
|
if ( MW_ENTRY_POINT === 'index' ) {
|
|
|
|
|
$wgRequest->interpolateTitle();
|
|
|
|
|
}
|
2014-04-01 19:03:00 +00:00
|
|
|
|
2016-02-01 20:44:03 +00:00
|
|
|
/**
|
2023-03-24 02:48:54 +00:00
|
|
|
* @var MediaWiki\Session\SessionId|null $wgInitialSessionId The persistent session ID (if any) loaded at startup
|
2016-02-01 20:44:03 +00:00
|
|
|
*/
|
|
|
|
|
$wgInitialSessionId = null;
|
2023-12-19 15:26:32 +00:00
|
|
|
if ( !defined( 'MW_NO_SESSION' ) && MW_ENTRY_POINT !== 'cli' ) {
|
2016-02-01 20:44:03 +00:00
|
|
|
// If session.auto_start is there, we can't touch session name
|
|
|
|
|
if ( $wgPHPSessionHandling !== 'disable' && !wfIniGetBool( 'session.auto_start' ) ) {
|
2021-01-06 05:23:15 +00:00
|
|
|
HeaderCallback::warnIfHeadersSent();
|
2018-06-11 09:16:48 +00:00
|
|
|
session_name( $wgSessionName ?: $wgCookiePrefix . '_session' );
|
2016-02-01 20:44:03 +00:00
|
|
|
}
|
|
|
|
|
|
2016-02-18 20:56:40 +00:00
|
|
|
// Create the SessionManager singleton and set up our session handler,
|
|
|
|
|
// unless we're specifically asked not to.
|
|
|
|
|
if ( !defined( 'MW_NO_SESSION_HANDLER' ) ) {
|
|
|
|
|
MediaWiki\Session\PHPSessionHandler::install(
|
|
|
|
|
MediaWiki\Session\SessionManager::singleton()
|
|
|
|
|
);
|
|
|
|
|
}
|
2016-02-01 20:44:03 +00:00
|
|
|
|
2020-05-08 18:11:23 +00:00
|
|
|
$contLang = MediaWikiServices::getInstance()->getContentLanguage();
|
|
|
|
|
|
2016-02-01 20:44:03 +00:00
|
|
|
// Initialize the session
|
|
|
|
|
try {
|
|
|
|
|
$session = MediaWiki\Session\SessionManager::getGlobalSession();
|
2019-09-07 14:21:09 +00:00
|
|
|
} catch ( MediaWiki\Session\SessionOverflowException $ex ) {
|
|
|
|
|
// The exception is because the request had multiple possible
|
|
|
|
|
// sessions tied for top priority. Report this to the user.
|
|
|
|
|
$list = [];
|
|
|
|
|
foreach ( $ex->getSessionInfos() as $info ) {
|
2020-05-08 18:11:23 +00:00
|
|
|
$list[] = $info->getProvider()->describe( $contLang );
|
2016-02-01 20:44:03 +00:00
|
|
|
}
|
2020-05-08 18:11:23 +00:00
|
|
|
$list = $contLang->listToText( $list );
|
2019-09-07 14:21:09 +00:00
|
|
|
throw new HttpError( 400,
|
2020-05-08 18:11:23 +00:00
|
|
|
Message::newFromKey( 'sessionmanager-tie', $list )->inLanguage( $contLang )
|
2019-09-07 14:21:09 +00:00
|
|
|
);
|
2016-02-01 20:44:03 +00:00
|
|
|
}
|
|
|
|
|
|
2020-05-08 18:11:23 +00:00
|
|
|
unset( $contLang );
|
|
|
|
|
|
2016-02-01 20:44:03 +00:00
|
|
|
if ( $session->isPersistent() ) {
|
|
|
|
|
$wgInitialSessionId = $session->getSessionId();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$session->renew();
|
|
|
|
|
if ( MediaWiki\Session\PHPSessionHandler::isEnabled() &&
|
2019-01-12 19:16:52 +00:00
|
|
|
( $session->isPersistent() || $session->shouldRememberUser() ) &&
|
|
|
|
|
session_id() !== $session->getId()
|
2016-02-01 20:44:03 +00:00
|
|
|
) {
|
|
|
|
|
// Start the PHP-session for backwards compatibility
|
2019-01-12 19:16:52 +00:00
|
|
|
if ( session_id() !== '' ) {
|
|
|
|
|
wfDebugLog( 'session', 'PHP session {old_id} was already started, changing to {new_id}', 'all', [
|
|
|
|
|
'old_id' => session_id(),
|
|
|
|
|
'new_id' => $session->getId(),
|
|
|
|
|
] );
|
|
|
|
|
session_write_close();
|
|
|
|
|
}
|
2016-02-01 20:44:03 +00:00
|
|
|
session_id( $session->getId() );
|
2019-01-12 19:16:52 +00:00
|
|
|
session_start();
|
2016-02-01 20:44:03 +00:00
|
|
|
}
|
2016-02-18 20:56:40 +00:00
|
|
|
|
|
|
|
|
unset( $session );
|
|
|
|
|
} else {
|
|
|
|
|
// Even if we didn't set up a global Session, still install our session
|
|
|
|
|
// handler unless specifically requested not to.
|
|
|
|
|
if ( !defined( 'MW_NO_SESSION_HANDLER' ) ) {
|
|
|
|
|
MediaWiki\Session\PHPSessionHandler::install(
|
|
|
|
|
MediaWiki\Session\SessionManager::singleton()
|
|
|
|
|
);
|
|
|
|
|
}
|
2016-02-01 20:44:03 +00:00
|
|
|
}
|
|
|
|
|
|
2022-02-21 16:21:36 +00:00
|
|
|
// Explicit globals, so this works with bootstrap.php
|
2019-12-30 06:58:16 +00:00
|
|
|
global $wgUser, $wgLang, $wgOut, $wgTitle;
|
2022-02-21 16:21:36 +00:00
|
|
|
|
2014-04-01 19:03:00 +00:00
|
|
|
/**
|
|
|
|
|
* @var User $wgUser
|
2020-03-21 01:43:22 +00:00
|
|
|
* @deprecated since 1.35, use an available context source when possible, or, as a backup,
|
|
|
|
|
* RequestContext::getMain()
|
2014-04-01 19:03:00 +00:00
|
|
|
*/
|
2021-09-04 19:19:47 +00:00
|
|
|
$wgUser = new StubGlobalUser( RequestContext::getMain()->getUser() ); // BackCompat
|
|
|
|
|
register_shutdown_function( static function () {
|
|
|
|
|
StubGlobalUser::$destructorDeprecationDisarmed = true;
|
|
|
|
|
} );
|
2011-03-24 00:48:22 +00:00
|
|
|
|
2014-02-06 09:04:46 +00:00
|
|
|
/**
|
2020-11-14 07:29:49 +00:00
|
|
|
* @var Language|StubUserLang $wgLang
|
2014-02-06 09:04:46 +00:00
|
|
|
*/
|
|
|
|
|
$wgLang = new StubUserLang;
|
2011-03-24 00:48:22 +00:00
|
|
|
|
2014-02-06 09:04:46 +00:00
|
|
|
/**
|
2023-09-05 17:31:53 +00:00
|
|
|
* @var MediaWiki\Output\OutputPage $wgOut
|
2014-02-06 09:04:46 +00:00
|
|
|
*/
|
2014-04-13 20:07:50 +00:00
|
|
|
$wgOut = RequestContext::getMain()->getOutput(); // BackCompat
|
2007-11-20 10:55:08 +00:00
|
|
|
|
2014-04-01 19:03:00 +00:00
|
|
|
/**
|
2020-11-14 07:29:49 +00:00
|
|
|
* @var Title|null $wgTitle
|
2014-04-01 19:03:00 +00:00
|
|
|
*/
|
2014-02-06 09:04:46 +00:00
|
|
|
$wgTitle = null;
|
2004-05-31 08:43:36 +00:00
|
|
|
|
2022-02-21 16:21:36 +00:00
|
|
|
// Explicit globals, so this works with bootstrap.php
|
|
|
|
|
global $wgFullyInitialised, $wgExtensionFunctions;
|
|
|
|
|
|
2015-10-23 18:50:11 +00:00
|
|
|
// Extension setup functions
|
2014-04-13 20:07:50 +00:00
|
|
|
// Entries should be added to this variable during the inclusion
|
|
|
|
|
// of the extension file. This allows the extension to perform
|
|
|
|
|
// any necessary initialisation in the fully initialised environment
|
2008-12-23 23:34:35 +00:00
|
|
|
foreach ( $wgExtensionFunctions as $func ) {
|
2005-12-14 16:46:27 +00:00
|
|
|
call_user_func( $func );
|
2004-05-15 03:36:39 +00:00
|
|
|
}
|
2020-10-27 00:21:47 +00:00
|
|
|
unset( $func ); // no global pollution; destroy reference
|
2004-05-15 03:36:39 +00:00
|
|
|
|
2016-02-01 20:44:03 +00:00
|
|
|
// If the session user has a 0 id but a valid name, that means we need to
|
|
|
|
|
// autocreate it.
|
2023-12-19 15:26:32 +00:00
|
|
|
if ( !defined( 'MW_NO_SESSION' ) && MW_ENTRY_POINT !== 'cli' ) {
|
2016-02-07 22:46:34 +00:00
|
|
|
$sessionUser = MediaWiki\Session\SessionManager::getGlobalSession()->getUser();
|
2020-08-05 20:20:00 +00:00
|
|
|
if ( $sessionUser->getId() === 0 &&
|
|
|
|
|
MediaWikiServices::getInstance()->getUserNameUtils()->isValid( $sessionUser->getName() )
|
|
|
|
|
) {
|
2020-03-31 18:51:49 +00:00
|
|
|
$res = MediaWikiServices::getInstance()->getAuthManager()->autoCreateUser(
|
2016-04-01 16:49:26 +00:00
|
|
|
$sessionUser,
|
|
|
|
|
MediaWiki\Auth\AuthManager::AUTOCREATE_SOURCE_SESSION,
|
2024-06-09 15:23:35 +00:00
|
|
|
true,
|
|
|
|
|
true,
|
|
|
|
|
$sessionUser
|
2016-04-01 16:49:26 +00:00
|
|
|
);
|
2024-06-13 11:30:09 +00:00
|
|
|
$firstMessage = $res->getMessages( 'error' )[0] ?? $res->getMessages( 'warning' )[0] ?? null;
|
2016-08-10 01:32:28 +00:00
|
|
|
\MediaWiki\Logger\LoggerFactory::getInstance( 'authevents' )->info( 'Autocreation attempt', [
|
2016-02-11 08:12:45 +00:00
|
|
|
'event' => 'autocreate',
|
2023-10-12 13:41:06 +00:00
|
|
|
'successful' => $res->isGood(),
|
2024-06-13 11:30:09 +00:00
|
|
|
'status' => $firstMessage ? $firstMessage->getKey() : '-',
|
2016-02-11 08:12:45 +00:00
|
|
|
] );
|
|
|
|
|
unset( $res );
|
2024-06-13 11:30:09 +00:00
|
|
|
unset( $firstMessage );
|
2016-02-07 22:46:34 +00:00
|
|
|
}
|
|
|
|
|
unset( $sessionUser );
|
2016-02-01 20:44:03 +00:00
|
|
|
}
|
|
|
|
|
|
2023-06-09 14:59:04 +00:00
|
|
|
// Optimization: Avoid overhead from DeferredUpdates and Pingback deps when turned off.
|
2023-12-19 15:26:32 +00:00
|
|
|
if ( MW_ENTRY_POINT !== 'cli' && $wgPingback ) {
|
2023-06-09 14:59:04 +00:00
|
|
|
// NOTE: Do not refactor to inject Config or otherwise make unconditional service call.
|
|
|
|
|
//
|
|
|
|
|
// On a plain install of MediaWiki, Pingback is likely the *only* feature
|
|
|
|
|
// involving DeferredUpdates or DB_PRIMARY on a regular page view.
|
|
|
|
|
// To allow for error recovery and fault isolation, let admins turn this
|
|
|
|
|
// off completely. (T269516)
|
|
|
|
|
DeferredUpdates::addCallableUpdate( static function () {
|
|
|
|
|
MediaWikiServices::getInstance()->getPingback()->run();
|
|
|
|
|
} );
|
2016-06-30 09:29:10 +00:00
|
|
|
}
|
|
|
|
|
|
2022-07-11 16:02:43 +00:00
|
|
|
$settingsWarnings = $wgSettings->getWarnings();
|
|
|
|
|
if ( $settingsWarnings ) {
|
|
|
|
|
$logger = LoggerFactory::getInstance( 'Settings' );
|
|
|
|
|
foreach ( $settingsWarnings as $msg ) {
|
|
|
|
|
$logger->warning( $msg );
|
|
|
|
|
}
|
|
|
|
|
unset( $logger );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unset( $settingsWarnings );
|
|
|
|
|
|
2022-02-21 16:28:35 +00:00
|
|
|
// Explicit globals, so this works with bootstrap.php
|
|
|
|
|
global $wgFullyInitialised;
|
2004-07-18 08:48:43 +00:00
|
|
|
$wgFullyInitialised = true;
|
2016-02-07 19:24:05 +00:00
|
|
|
|
|
|
|
|
// T264370
|
2023-12-19 15:26:32 +00:00
|
|
|
if ( !defined( 'MW_NO_SESSION' ) && MW_ENTRY_POINT !== 'cli' ) {
|
2016-02-07 19:24:05 +00:00
|
|
|
MediaWiki\Session\SessionManager::singleton()->logPotentialSessionLeakage();
|
|
|
|
|
}
|