From: Timo Tijhof Date: Tue, 19 Sep 2017 19:24:19 +0000 (+0100) Subject: Setup: Merge PreConfigSetup into Setup.php X-Git-Tag: 1.31.0-rc.0~1679^2 X-Git-Url: http://git.heureux-cyclage.org/?a=commitdiff_plain;h=8b7bafec2185b66bed68b2e7a211fa6c66ae4288;p=lhc%2Fweb%2Fwiklou.git Setup: Merge PreConfigSetup into Setup.php Follows-up 41ea7e2fefff65. The following previously happened between PreConfigSetup and Setup and must now happen either before it, after it, or moved inside it. * WebStart: Detect missing composer. This must be after Autoloader/Vendor but before the first call to wfDebugLog (or other loggers) so that we can output a more descriptive error instead of a generic "Unknown class" fatal error. Moving it to before Setup is too early, and after is too late. Move it to within Setup.php and make it work in CLI mode. * WebStart: Install header callback Moving it to before Setup is too early, and after is too late. Move it to within Setup.php (no-op in CLI mode). * WebStart/Maintenance: Load LocalSetings. Must be between PreConfigSetup and Setup. Move to Setup.php to maintain execution order. Utilise MW_CONFIG_File for custom handling in Maintenance.php. * WebStart: Initialise output buffering Utilise (new) MW_SETUP_CALLBACK hook. * WebStart: Display NoLocalSettings.php Utilise MW_CONFIG_CALLBACK hook. * Maintenance: Setting $wgLocalisationCacheConf, calling Maintenance::finalSetup. Utilise (new) MW_SETUP_CALLBACK hook. Change-Id: I633a6ff235b4275391c48034c0525d2fbfa3fecd --- diff --git a/includes/NoLocalSettings.php b/includes/NoLocalSettings.php index 50950ef300..b8bfd6a4f0 100644 --- a/includes/NoLocalSettings.php +++ b/includes/NoLocalSettings.php @@ -50,6 +50,7 @@ $templateParser = new TemplateParser(); # Render error page if no LocalSettings file can be found try { + global $wgVersion; echo $templateParser->processTemplate( 'NoLocalSettings', [ diff --git a/includes/PreConfigSetup.php b/includes/PreConfigSetup.php deleted file mode 100644 index bda78865b7..0000000000 --- a/includes/PreConfigSetup.php +++ /dev/null @@ -1,54 +0,0 @@ -PSR-3 logging ' . + "library to be present. This library is not embedded directly in MediaWiki's " . + "git repository and must be installed separately by the end user.\n\n" . + 'Please see mediawiki.org for help on installing ' . + 'the required components.' + ); + echo $message; + trigger_error( $message, E_USER_ERROR ); + die( 1 ); +} + +// Install a header callback +MediaWiki\HeaderCallback::register(); + +/** + * Load LocalSettings.php + */ + +if ( defined( 'MW_CONFIG_CALLBACK' ) ) { + call_user_func( MW_CONFIG_CALLBACK ); +} else { + if ( !defined( 'MW_CONFIG_FILE' ) ) { + define( 'MW_CONFIG_FILE', "$IP/LocalSettings.php" ); + } + require_once MW_CONFIG_FILE; +} + +/** + * Customization point after all loading (constants, functions, classes, + * DefaultSettings, LocalSettings). Specifically, this is before usage of + * settings, before instantiation of Profiler (and other singletons), and + * before any setup functions or hooks run. + */ + +if ( defined( 'MW_SETUP_CALLBACK' ) ) { + call_user_func( MW_SETUP_CALLBACK ); +} + +/** + * Main setup + */ + $fname = 'Setup.php'; $ps_setup = Profiler::instance()->scopedProfileIn( $fname ); diff --git a/includes/WebStart.php b/includes/WebStart.php index 8a58e6f032..e4d93f9a30 100644 --- a/includes/WebStart.php +++ b/includes/WebStart.php @@ -59,56 +59,39 @@ if ( $IP === false ) { $IP = realpath( '.' ) ?: dirname( __DIR__ ); } -require_once "$IP/includes/PreConfigSetup.php"; - -# Assert that composer dependencies were successfully loaded -# Purposely no leading \ due to it breaking HHVM RepoAuthorative mode -# PHP works fine with both versions -# See https://github.com/facebook/hhvm/issues/5833 -if ( !interface_exists( 'Psr\Log\LoggerInterface' ) ) { - $message = ( - 'MediaWiki requires the PSR-3 logging ' . - "library to be present. This library is not embedded directly in MediaWiki's " . - "git repository and must be installed separately by the end user.\n\n" . - 'Please see mediawiki.org for help on installing ' . - 'the required components.' - ); - echo $message; - trigger_error( $message, E_USER_ERROR ); - die( 1 ); -} - -# Install a header callback -MediaWiki\HeaderCallback::register(); - -if ( defined( 'MW_CONFIG_CALLBACK' ) ) { - # Use a callback function to configure MediaWiki - call_user_func( MW_CONFIG_CALLBACK ); -} else { +// If no LocalSettings file exists, try to display an error page +// (use a callback because it depends on TemplateParser) +if ( !defined( 'MW_CONFIG_CALLBACK' ) ) { if ( !defined( 'MW_CONFIG_FILE' ) ) { define( 'MW_CONFIG_FILE', "$IP/LocalSettings.php" ); } - - # LocalSettings.php is the per site customization file. If it does not exist - # the wiki installer needs to be launched or the generated file uploaded to - # the root wiki directory. Give a hint, if it is not readable by the server. if ( !is_readable( MW_CONFIG_FILE ) ) { - require_once "$IP/includes/NoLocalSettings.php"; - die(); + function wfWebStartNoLocalSettings() { + # LocalSettings.php is the per-site customization file. If it does not exist + # the wiki installer needs to be launched or the generated file uploaded to + # the root wiki directory. Give a hint, if it is not readable by the server. + global $IP; + require_once "$IP/includes/NoLocalSettings.php"; + die(); + } + define( 'MW_CONFIG_CALLBACK', 'wfWebStartNoLocalSettings' ); } - - # Include site settings. $IP may be changed (hopefully before the AutoLoader is invoked) - require_once MW_CONFIG_FILE; } -# Initialise output buffering -# Check that there is no previous output or previously set up buffers, because -# that would cause us to potentially mix gzip and non-gzip output, creating a -# big mess. -if ( ob_get_level() == 0 ) { - require_once "$IP/includes/OutputHandler.php"; - ob_start( 'wfOutputHandler' ); +// Custom setup for WebStart entry point +if ( !defined( 'MW_SETUP_CALLBACK' ) ) { + function wfWebStartSetup() { + # Initialise output buffering + # Check that there is no previous output or previously set up buffers, because + # that would cause us to potentially mix gzip and non-gzip output, creating a + # big mess. + global $IP; + if ( ob_get_level() == 0 ) { + require_once "$IP/includes/OutputHandler.php"; + ob_start( 'wfOutputHandler' ); + } + } + define( 'MW_SETUP_CALLBACK', 'wfWebStartSetup' ); } require_once "$IP/includes/Setup.php"; diff --git a/maintenance/doMaintenance.php b/maintenance/doMaintenance.php index e87e024918..b5beef696a 100644 --- a/maintenance/doMaintenance.php +++ b/maintenance/doMaintenance.php @@ -55,27 +55,30 @@ $maintenance->setup(); // to $maintenance->mSelf. Keep that here for b/c $self = $maintenance->getName(); -require_once "$IP/includes/PreConfigSetup.php"; - -if ( defined( 'MW_CONFIG_CALLBACK' ) ) { - # Use a callback function to configure MediaWiki - call_user_func( MW_CONFIG_CALLBACK ); -} else { - // Require the configuration (probably LocalSettings.php) - require $maintenance->loadSettings(); +// Define how settings are loaded (e.g. LocalSettings.php) +if ( !defined( 'MW_CONFIG_CALLBACK' ) && !defined( 'MW_CONFIG_FILE' ) ) { + define( 'MW_CONFIG_FILE', $maintenance->loadSettings() ); } -if ( $maintenance->getDbType() === Maintenance::DB_NONE ) { - if ( $wgLocalisationCacheConf['storeClass'] === false - && ( $wgLocalisationCacheConf['store'] == 'db' - || ( $wgLocalisationCacheConf['store'] == 'detect' && !$wgCacheDirectory ) ) - ) { - $wgLocalisationCacheConf['storeClass'] = 'LCStoreNull'; +// Custom setup for Maintenance entry point +if ( !defined( 'MW_SETUP_CALLBACK' ) ) { + function wfMaintenanceSetup() { + // @codingStandardsIgnoreLine MediaWiki.NamingConventions.ValidGlobalName.wgPrefix + global $maintenance, $wgLocalisationCacheConf, $wgCacheDirectory; + if ( $maintenance->getDbType() === Maintenance::DB_NONE ) { + if ( $wgLocalisationCacheConf['storeClass'] === false + && ( $wgLocalisationCacheConf['store'] == 'db' + || ( $wgLocalisationCacheConf['store'] == 'detect' && !$wgCacheDirectory ) ) + ) { + $wgLocalisationCacheConf['storeClass'] = 'LCStoreNull'; + } + } + + $maintenance->finalSetup(); } + define( 'MW_SETUP_CALLBACK', 'wfMaintenanceSetup' ); } -$maintenance->finalSetup(); -// Some last includes require_once "$IP/includes/Setup.php"; // Initialize main config instance