Setup: Merge PreConfigSetup into Setup.php
authorTimo Tijhof <krinklemail@gmail.com>
Tue, 19 Sep 2017 19:24:19 +0000 (20:24 +0100)
committerKrinkle <krinklemail@gmail.com>
Tue, 24 Oct 2017 23:50:54 +0000 (23:50 +0000)
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

includes/NoLocalSettings.php
includes/PreConfigSetup.php [deleted file]
includes/Setup.php
includes/WebStart.php
maintenance/doMaintenance.php

index 50950ef..b8bfd6a 100644 (file)
@@ -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 (file)
index bda7886..0000000
+++ /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";
-}
index d4612dd..e4396ba 100644 (file)
@@ -33,6 +33,85 @@ if ( !defined( 'MEDIAWIKI' ) ) {
        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 );
 
index 8a58e6f..e4d93f9 100644 (file)
@@ -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 <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";
index e87e024..b5beef6 100644 (file)
@@ -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