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 * @note Since we can't rely on anything, the minimum PHP versions and MW current
30 * version are hardcoded here
32 function wfEntryPointCheck( $entryPoint ) {
34 $minimumVersionPHP = '5.3.3';
35 $phpVersion = PHP_VERSION
;
37 if ( !function_exists( 'version_compare' )
38 ||
version_compare( $phpVersion, $minimumVersionPHP ) < 0
40 wfPHPVersionError( $entryPoint, $mwVersion, $minimumVersionPHP, $phpVersion );
43 if ( !file_exists( dirname( __FILE__
) . '/../vendor/autoload.php' ) ) {
44 wfMissingVendorError( $entryPoint, $mwVersion );
49 * Display something vaguely comprehensible in the event of a totally unrecoverable error.
50 * Does not assume access to *anything*; no globals, no autoloader, no database, no localisation.
51 * Safe for PHP4 (and putting this here means that WebStart.php and GlobalSettings.php
52 * no longer need to be).
54 * Calling this function kills execution immediately.
56 * @param string $type Which entry point we are protecting. One of:
60 * - mw-config/index.php
62 * @param string $mwVersion The number of the MediaWiki version used
63 * @param string $title HTML code to be put within an <h2> tag
64 * @param string $shortText
65 * @param string $longText
66 * @param string $longHtml
68 function wfGenericError( $type, $mwVersion, $title, $shortText, $longText, $longHtml ) {
69 $protocol = isset( $_SERVER['SERVER_PROTOCOL'] ) ?
$_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0';
71 if ( $type == 'cli' ) {
72 $finalOutput = $longText;
74 header( "$protocol 500 MediaWiki configuration Error" );
75 // Don't cache error pages! They cause no end of trouble...
76 header( 'Cache-control: none' );
77 header( 'Pragma: no-cache' );
79 if ( $type == 'index.php' ||
$type == 'mw-config/index.php' ) {
80 $pathinfo = pathinfo( $_SERVER['SCRIPT_NAME'] );
81 if ( $type == 'mw-config/index.php' ) {
82 $dirname = dirname( $pathinfo['dirname'] );
84 $dirname = $pathinfo['dirname'];
86 $encLogo = htmlspecialchars(
87 str_replace( '//', '/', $dirname . '/' ) .
88 'resources/assets/mediawiki.png'
90 $shortHtml = htmlspecialchars( $shortText );
92 header( 'Content-type: text/html; charset=UTF-8' );
94 $finalOutput = <<<HTML
96 <html lang="en" dir="ltr">
98 <meta charset="UTF-8" />
99 <title>MediaWiki {$mwVersion}</title>
100 <style media='screen'>
103 background-color: #fff;
104 font-family: sans-serif;
121 <img src="{$encLogo}" alt='The MediaWiki logo' />
122 <h1>MediaWiki {$mwVersion} internal error</h1>
135 // Handle everything that's not index.php
137 // So nothing thinks this is JS or CSS
138 $finalOutput = ( $type == 'load.php' ) ?
"/* $shortText */" : $shortText;
141 echo "$finalOutput\n";
146 * Display an error for the minimum PHP version requirement not being satisfied.
148 * @param string $type See wfGenericError
149 * @param string $mwVersion See wfGenericError
150 * @param string $minimumVersionPHP The minimum PHP version supported by MediaWiki
151 * @param string $phpVersion The current PHP version
153 function wfPHPVersionError( $type, $mwVersion, $minimumVersionPHP, $phpVersion ) {
154 $shortText = "MediaWiki $mwVersion requires at least "
155 . "PHP version $minimumVersionPHP, you are using PHP $phpVersion.";
157 $longText = "Error: You might be using on older PHP version. \n"
158 . "MediaWiki $mwVersion needs PHP $minimumVersionPHP or higher.\n\n"
159 . "Check if you have a newer php executable with a different name, such as php5.\n\n";
162 Please consider <a href="http://www.php.net/downloads.php">upgrading your copy of PHP</a>.
163 PHP versions less than 5.3.0 are no longer supported by the PHP Group and will not receive
164 security or bugfix updates.
167 If for some reason you are unable to upgrade your PHP version, you will need to
168 <a href="https://www.mediawiki.org/wiki/Download">download</a> an older version
169 of MediaWiki from our website. See our
170 <a href="https://www.mediawiki.org/wiki/Compatibility#PHP">compatibility page</a>
171 for details of which versions are compatible with prior versions of PHP.
173 wfGenericError( $type, $mwVersion, 'Supported PHP versions', $shortText, $longText, $longHtml );
177 * Display an error for the vendor/autoload.php file not being found.
179 * @param string $type See wfGenericError
180 * @param string $mwVersion See wfGenericError
182 function wfMissingVendorError( $type, $mwVersion ) {
183 $shortText = "Installing some external dependencies (e.g. via composer) is also required.";
185 $longText = "Error: You are missing some external dependencies. \n"
186 . "MediaWiki now also has some external dependencies that need to be installed\n"
187 . "via composer or from a separate git repo. Please see\n"
188 . "https://www.mediawiki.org/wiki/Download_from_Git#Fetch_external_libraries\n"
189 . "for help on installing the required components.";
192 MediaWiki now also has some external dependencies that need to be installed via
193 composer or from a separate git repo. Please see
194 <a href="https://www.mediawiki.org/wiki/Download_from_Git#Fetch_external_libraries">mediawiki.org</a>
195 for help on installing the required components.
198 wfGenericError( $type, $mwVersion, 'External dependencies', $shortText, $longText, $longHtml );