3 * Check PHP Version, as well as for composer dependencies in entry points,
4 * and display something vaguely comprehensible in the event of a totally
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 * http://www.gnu.org/copyleft/gpl.html
26 * Check php version and that external dependencies are installed, and
27 * display an informative error if either condition is not satisfied.
29 function wfEntryPointCheck( $entryPoint ) {
30 if ( !function_exists( 'version_compare' )
31 ||
version_compare( PHP_VERSION
, '5.3.3' ) < 0
32 ||
!file_exists( dirname( __FILE__
) . '/../vendor/autoload.php' )
34 wfPHPVersionError( $entryPoint );
39 * Display something vaguely comprehensible in the event of a totally unrecoverable error.
40 * Does not assume access to *anything*; no globals, no autoloader, no database, no localisation.
41 * Safe for PHP4 (and putting this here means that WebStart.php and GlobalSettings.php
42 * no longer need to be).
44 * Calling this function kills execution immediately.
46 * @param string $type Which entry point we are protecting. One of:
50 * - mw-config/index.php
53 * @note Since we can't rely on anything, the minimum PHP versions and MW current
54 * version are hardcoded here
56 function wfPHPVersionError( $type ) {
58 $minimumVersionPHP = '5.3.3';
60 $phpVersion = PHP_VERSION
;
61 $protocol = isset( $_SERVER['SERVER_PROTOCOL'] ) ?
$_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0';
62 $message = "MediaWiki $mwVersion requires at least "
63 . "PHP version $minimumVersionPHP, you are using PHP $phpVersion. Installing some "
64 . " external dependencies (e.g. via composer) is also required.";
66 if ( $type == 'cli' ) {
67 $finalOutput = "Error: You are missing some external dependencies or are using on older PHP version. \n"
68 . "MediaWiki $mwVersion needs PHP $minimumVersionPHP or higher.\n\n"
69 . "Check if you have a newer php executable with a different name, such as php5.\n\n"
70 . "MediaWiki now also has some external dependencies that need to be installed\n"
71 . "via composer or from a separate git repo. Please see\n"
72 . "https://www.mediawiki.org/wiki/Download_from_Git#Fetch_external_libraries\n"
73 . "for help on installing the required components.";
74 } elseif ( $type == 'index.php' ||
$type == 'mw-config/index.php' ) {
75 $pathinfo = pathinfo( $_SERVER['SCRIPT_NAME'] );
76 if ( $type == 'mw-config/index.php' ) {
77 $dirname = dirname( $pathinfo['dirname'] );
79 $dirname = $pathinfo['dirname'];
81 $encLogo = htmlspecialchars(
82 str_replace( '//', '/', $dirname . '/' ) .
83 'resources/assets/mediawiki.png'
86 header( "$protocol 500 MediaWiki configuration Error" );
87 header( 'Content-type: text/html; charset=UTF-8' );
88 // Don't cache error pages! They cause no end of trouble...
89 header( 'Cache-control: none' );
90 header( 'Pragma: no-cache' );
92 $finalOutput = <<<HTML
94 <html lang="en" dir="ltr">
96 <meta charset="UTF-8" />
97 <title>MediaWiki {$mwVersion}</title>
98 <style media='screen'>
101 background-color: #fff;
102 font-family: sans-serif;
119 <img src="{$encLogo}" alt='The MediaWiki logo' />
120 <h1>MediaWiki {$mwVersion} internal error</h1>
125 <h2>Supported PHP versions</h2>
127 Please consider <a href="http://www.php.net/downloads.php">upgrading your copy of PHP</a>.
128 PHP versions less than 5.3.0 are no longer supported by the PHP Group and will not receive
129 security or bugfix updates.
132 If for some reason you are unable to upgrade your PHP version, you will need to
133 <a href="https://www.mediawiki.org/wiki/Download">download</a> an older version
134 of MediaWiki from our website. See our
135 <a href="https://www.mediawiki.org/wiki/Compatibility#PHP">compatibility page</a>
136 for details of which versions are compatible with prior versions of PHP.
138 <h2>External dependencies</h2>
140 MediaWiki now also has some external dependencies that need to be installed via
141 composer or from a separate git repo. Please see
142 <a href="https://www.mediawiki.org/wiki/Download_from_Git#Fetch_external_libraries">mediawiki.org</a>
143 for help on installing the required components.
149 // Handle everything that's not index.php
151 // So nothing thinks this is JS or CSS
152 $finalOutput = ( $type == 'load.php' ) ?
"/* $message */" : $message;
153 header( "$protocol 500 MediaWiki configuration Error" );
155 echo "$finalOutput\n";