jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/378986 )
Change subject: Setup: Merge PreConfigSetup into Setup.php ...................................................................... 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 --- M includes/NoLocalSettings.php D includes/PreConfigSetup.php M includes/Setup.php M includes/WebStart.php M maintenance/doMaintenance.php 5 files changed, 125 insertions(+), 113 deletions(-) Approvals: Tim Starling: Looks good to me, approved jenkins-bot: Verified diff --git a/includes/NoLocalSettings.php b/includes/NoLocalSettings.php index 50950ef..b8bfd6a 100644 --- a/includes/NoLocalSettings.php +++ b/includes/NoLocalSettings.php @@ -50,6 +50,7 @@ # 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 bda7886..0000000 --- a/includes/PreConfigSetup.php +++ /dev/null @@ -1,54 +0,0 @@ -<?php -/** - * File-scope setup actions, loaded before LocalSettings.php, shared by - * WebStart.php and doMaintenance.php - * - * 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 - * - * - * @file - */ - -if ( !defined( 'MEDIAWIKI' ) ) { - // Not an entry point - exit( 1 ); -} - -// Grab profiling functions -require_once "$IP/includes/profiler/ProfilerFunctions.php"; - -// Start the autoloader, so that extensions can derive classes from core files -require_once "$IP/includes/AutoLoader.php"; - -// Load up some global defines. -require_once "$IP/includes/Defines.php"; - -// Start the profiler -$wgProfiler = []; -if ( file_exists( "$IP/StartProfiler.php" ) ) { - require "$IP/StartProfiler.php"; -} - -// Load default settings -require_once "$IP/includes/DefaultSettings.php"; - -// Load global functions -require_once "$IP/includes/GlobalFunctions.php"; - -// Load composer's autoloader if present -if ( is_readable( "$IP/vendor/autoload.php" ) ) { - require_once "$IP/vendor/autoload.php"; -} diff --git a/includes/Setup.php b/includes/Setup.php index d4612dd..e4396ba 100644 --- a/includes/Setup.php +++ b/includes/Setup.php @@ -33,6 +33,85 @@ exit( 1 ); } +/** + * Pre-config setup: Before loading LocalSettings.php + */ + +// Grab profiling functions +require_once "$IP/includes/profiler/ProfilerFunctions.php"; + +// Start the autoloader, so that extensions can derive classes from core files +require_once "$IP/includes/AutoLoader.php"; + +// Load up some global defines +require_once "$IP/includes/Defines.php"; + +// Start the profiler +$wgProfiler = []; +if ( file_exists( "$IP/StartProfiler.php" ) ) { + require "$IP/StartProfiler.php"; +} + +// Load default settings +require_once "$IP/includes/DefaultSettings.php"; + +// Load global functions +require_once "$IP/includes/GlobalFunctions.php"; + +// Load composer's autoloader if present +if ( is_readable( "$IP/vendor/autoload.php" ) ) { + require_once "$IP/vendor/autoload.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 <a href="https://github.com/php-fig/log">PSR-3 logging ' . + "library</a> 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 <a href="https://www.mediawiki.org/wiki/Download_from_Git' . + '#Fetch_external_libraries">mediawiki.org</a> 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 8a58e6f..e4d93f9 100644 --- a/includes/WebStart.php +++ b/includes/WebStart.php @@ -59,56 +59,39 @@ $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 <a href="https://github.com/php-fig/log">PSR-3 logging ' . - "library</a> 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 <a href="https://www.mediawiki.org/wiki/Download_from_Git' . - '#Fetch_external_libraries">mediawiki.org</a> 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 e87e024..b5beef6 100644 --- a/maintenance/doMaintenance.php +++ b/maintenance/doMaintenance.php @@ -55,27 +55,30 @@ // 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 -- To view, visit https://gerrit.wikimedia.org/r/378986 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I633a6ff235b4275391c48034c0525d2fbfa3fecd Gerrit-PatchSet: 20 Gerrit-Project: mediawiki/core Gerrit-Branch: master Gerrit-Owner: Krinkle <krinklem...@gmail.com> Gerrit-Reviewer: Aaron Schulz <asch...@wikimedia.org> Gerrit-Reviewer: Anomie <bjor...@wikimedia.org> Gerrit-Reviewer: Brion VIBBER <br...@wikimedia.org> Gerrit-Reviewer: Krinkle <krinklem...@gmail.com> Gerrit-Reviewer: Legoktm <lego...@member.fsf.org> Gerrit-Reviewer: Parent5446 <tylerro...@gmail.com> Gerrit-Reviewer: Reedy <re...@wikimedia.org> Gerrit-Reviewer: Tim Starling <tstarl...@wikimedia.org> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits