From 9880d5b60b6502453c04c7fa69bdc06a5ebc1425 Mon Sep 17 00:00:00 2001 From: aude Date: Sat, 18 Apr 2015 05:37:10 -0400 Subject: [PATCH] Check for dependencies in entry point and Maintenance.php This way, if someone tries to install MediaWiki via either web installer or install.php maintenance script, after obtaining from git, they get some useful information on what to do. Put the checks alongside the php version check, as stuff installed via composer (mustache / lightncandy) is used for NoLocalSettings.php and install.php attempts to use logging stuff. Also tried to make PHPVersionError look slightly nicer, with some

elements and more padding for the

elements. and centralized this code in one place, as much as possible, for improved ease of maintenance. Bug: T90438 Bug: T88951 Change-Id: Iae4eb42c4266dbe9213c5de8a96fccfbeaa9acb0 --- api.php | 10 +-- includes/PHPVersionCheck.php | 157 +++++++++++++++++++++++++++++++++++ includes/PHPVersionError.php | 110 +----------------------- index.php | 13 +-- load.php | 10 +-- maintenance/Maintenance.php | 10 +-- maintenance/update.php | 5 -- mw-config/index.php | 10 +-- 8 files changed, 181 insertions(+), 144 deletions(-) create mode 100644 includes/PHPVersionCheck.php diff --git a/api.php b/api.php index 9721c4f290..a9e56830f3 100644 --- a/api.php +++ b/api.php @@ -35,12 +35,10 @@ use MediaWiki\Logger\LegacyLogger; // So extensions (and other code) can check whether they're running in API mode define( 'MW_API', true ); -// Bail if PHP is too low -if ( !function_exists( 'version_compare' ) || version_compare( PHP_VERSION, '5.3.3' ) < 0 ) { - // We need to use dirname( __FILE__ ) here cause __DIR__ is PHP5.3+ - require dirname( __FILE__ ) . '/includes/PHPVersionError.php'; - wfPHPVersionError( 'api.php' ); -} +// Bail on old versions of PHP, or if composer has not been run yet to install +// dependencies. Using dirname( __FILE__ ) here because __DIR__ is PHP5.3+. +require_once dirname( __FILE__ ) . '/includes/PHPVersionCheck.php'; +wfEntryPointCheck( 'api.php' ); require __DIR__ . '/includes/WebStart.php'; diff --git a/includes/PHPVersionCheck.php b/includes/PHPVersionCheck.php new file mode 100644 index 0000000000..d11d02117b --- /dev/null +++ b/includes/PHPVersionCheck.php @@ -0,0 +1,157 @@ + + + + + MediaWiki {$mwVersion} + + + + The MediaWiki logo +

MediaWiki {$mwVersion} internal error

+
+

+ {$message} +

+

Supported PHP versions

+

+ Please consider upgrading your copy of PHP. + PHP versions less than 5.3.0 are no longer supported by the PHP Group and will not receive + security or bugfix updates. +

+

+ If for some reason you are unable to upgrade your PHP version, you will need to + download an older version + of MediaWiki from our website. See our + compatibility page + for details of which versions are compatible with prior versions of PHP. +

+

External dependencies

+

+ MediaWiki now also has some external dependencies that need to be installed via + composer or from a separate git repo. Please see + mediawiki.org + for help on installing the required components. +

+
+ + +HTML; + // Handle everything that's not index.php + } else { + // So nothing thinks this is JS or CSS + $finalOutput = ( $type == 'load.php' ) ? "/* $message */" : $message; + header( "$protocol 500 MediaWiki configuration Error" ); + } + echo "$finalOutput\n"; + die( 1 ); +} diff --git a/includes/PHPVersionError.php b/includes/PHPVersionError.php index 3a2f9f8cc9..007ea8941e 100644 --- a/includes/PHPVersionError.php +++ b/includes/PHPVersionError.php @@ -1,6 +1,7 @@ - - - - MediaWiki {$mwVersion} - - - - The MediaWiki logo -

MediaWiki {$mwVersion} internal error

-
-

- {$message} -

-

- Please consider upgrading your copy of PHP. - PHP versions less than 5.3.0 are no longer supported by the PHP Group and will not receive - security or bugfix updates. -

-

- If for some reason you are unable to upgrade your PHP version, you will need to - download an older version - of MediaWiki from our website. See our - compatibility page - for details of which versions are compatible with prior versions of PHP. -

-
- - -HTML; - // Handle everything that's not index.php - } else { - // So nothing thinks this is JS or CSS - $finalOutput = ( $type == 'load.php' ) ? "/* $message */" : $message; - header( "$protocol 500 MediaWiki configuration Error" ); - } - echo "$finalOutput\n"; - die( 1 ); -} +require_once dirname( __FILE__ ) . '/PHPVersionCheck.php'; diff --git a/index.php b/index.php index c32bd3aba2..67bd0c9aae 100644 --- a/index.php +++ b/index.php @@ -30,15 +30,10 @@ * @file */ -# Bail on old versions of PHP. Pretty much every other file in the codebase -# has structures (try/catch, foo()->bar(), etc etc) which throw parse errors in -# PHP 4. Setup.php and ObjectCache.php have structures invalid in PHP 5.0 and -# 5.1, respectively. -if ( !function_exists( 'version_compare' ) || version_compare( PHP_VERSION, '5.3.3' ) < 0 ) { - // We need to use dirname( __FILE__ ) here cause __DIR__ is PHP5.3+ - require dirname( __FILE__ ) . '/includes/PHPVersionError.php'; - wfPHPVersionError( 'index.php' ); -} +// Bail on old versions of PHP, or if composer has not been run yet to install +// dependencies. Using dirname( __FILE__ ) here because __DIR__ is PHP5.3+. +require_once dirname( __FILE__ ) . '/includes/PHPVersionCheck.php'; +wfEntryPointCheck( 'index.php' ); require __DIR__ . '/includes/WebStart.php'; diff --git a/load.php b/load.php index d77a689dea..0c7ea62e3f 100644 --- a/load.php +++ b/load.php @@ -22,12 +22,10 @@ * @author Trevor Parscal */ -// Bail if PHP is too low -if ( !function_exists( 'version_compare' ) || version_compare( PHP_VERSION, '5.3.3' ) < 0 ) { - // We need to use dirname( __FILE__ ) here cause __DIR__ is PHP5.3+ - require dirname( __FILE__ ) . '/includes/PHPVersionError.php'; - wfPHPVersionError( 'load.php' ); -} +// Bail on old versions of PHP, or if composer has not been run yet to install +// dependencies. Using dirname( __FILE__ ) here because __DIR__ is PHP5.3+. +require_once dirname( __FILE__ ) . '/includes/PHPVersionCheck.php'; +wfEntryPointCheck( 'load.php' ); require __DIR__ . '/includes/WebStart.php'; diff --git a/maintenance/Maintenance.php b/maintenance/Maintenance.php index c97c6a35f4..e4ac467556 100644 --- a/maintenance/Maintenance.php +++ b/maintenance/Maintenance.php @@ -20,12 +20,10 @@ * @defgroup Maintenance Maintenance */ -// Make sure we're on PHP5.3.3 or better -if ( !function_exists( 'version_compare' ) || version_compare( PHP_VERSION, '5.3.3' ) < 0 ) { - // We need to use dirname( __FILE__ ) here cause __DIR__ is PHP5.3+ - require_once dirname( __FILE__ ) . '/../includes/PHPVersionError.php'; - wfPHPVersionError( 'cli' ); -} +// Bail on old versions of PHP, or if composer has not been run yet to install +// dependencies. Using dirname( __FILE__ ) here because __DIR__ is PHP5.3+. +require_once dirname( __FILE__ ) . '/../includes/PHPVersionCheck.php'; +wfEntryPointCheck( 'cli' ); /** * @defgroup MaintenanceArchive Maintenance archives diff --git a/maintenance/update.php b/maintenance/update.php index b8af5e9c81..3bb722e486 100755 --- a/maintenance/update.php +++ b/maintenance/update.php @@ -26,11 +26,6 @@ * @ingroup Maintenance */ -if ( !function_exists( 'version_compare' ) || ( version_compare( PHP_VERSION, '5.3.3' ) < 0 ) ) { - require dirname( __FILE__ ) . '/../includes/PHPVersionError.php'; - wfPHPVersionError( 'cli' ); -} - $wgUseMasterForMaintenance = true; require_once __DIR__ . '/Maintenance.php'; diff --git a/mw-config/index.php b/mw-config/index.php index ed3e7f4796..be811dc980 100644 --- a/mw-config/index.php +++ b/mw-config/index.php @@ -20,12 +20,10 @@ * @file */ -// Bail if PHP is too low -if ( !function_exists( 'version_compare' ) || version_compare( PHP_VERSION, '5.3.3' ) < 0 ) { - // We need to use dirname( __FILE__ ) here cause __DIR__ is PHP5.3+ - require dirname( dirname( __FILE__ ) ) . '/includes/PHPVersionError.php'; - wfPHPVersionError( 'mw-config/index.php' ); -} +// Bail on old versions of PHP, or if composer has not been run yet to install +// dependencies. Using dirname( __FILE__ ) here because __DIR__ is PHP5.3+. +require_once dirname( __FILE__ ) . '/../includes/PHPVersionCheck.php'; +wfEntryPointCheck( 'mw-config/index.php' ); define( 'MW_CONFIG_CALLBACK', 'Installer::overrideConfig' ); define( 'MEDIAWIKI_INSTALL', true ); -- 2.20.1