wiki.techinc.nl/includes/PHPVersionError.php

127 lines
4.1 KiB
PHP
Raw Normal View History

2011-07-06 21:05:29 +00:00
<?php
/**
* Display something vaguely comprehensible in the event of a totally unrecoverable error.
*
* 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
*/
2011-07-06 21:05:29 +00:00
/**
* Display something vaguely comprehensible in the event of a totally unrecoverable error.
* Does not assume access to *anything*; no globals, no autoloader, no database, no localisation.
2011-07-06 21:05:29 +00:00
* Safe for PHP4 (and putting this here means that WebStart.php and GlobalSettings.php
* no longer need to be).
*
* Calling this function kills execution immediately.
*
* @param string $type Which entry point we are protecting. One of:
2011-07-06 21:05:29 +00:00
* - index.php
* - load.php
* - api.php
* - mw-config/index.php
2011-07-06 21:05:29 +00:00
* - cli
*
* @note Since we can't rely on anything, the minimum PHP versions and MW current
* version are hardcoded here
*/
function wfPHPVersionError( $type ) {
$mwVersion = '1.24';
Make update.php and install.php use wfPHPVersionError() and reorganise it update.php and install.php now use wfPHPVersionError() Moved to wfPHPVersionError( cli ) the suggestion of another binary name. Old PHP versions won't have $_SERVER superglobal, hardcode HTTP/1.0 in that case. Store in a variable the minimum version of PHP supported by MediaWiki. Changed PHP_VERSION to phpversion(), although it doesn't matter for the version ranges this works. phpversion() has been present since PHP-2.0 PHP_VERSION was added in PHP 3.0RC5 On its current form in PHP 4 it was moved from Zend/zend_constants.c to main/main.c by Zeev in commits 71dddd7db7e768ae8145e085fcbb6b6db4a1c40a and fb1c77bd4f8a636ba47d720f8ca65fc6baae836d (1999-12-17) It had been commented there since the beginning of svn history (1999-04-07) The earliest version we can target seems to be PHP 4.1.0 PHP 4.0.0 produces a parse error on a require_once not followed by a literal path (although you can use require with an expression), plus its dirname() is quite dumb, and wouldn't provide the right path (would require you to call "php ./update.php" from maintenance folder, not "php update.php" or "php maintenance/update.php" from the main dir) Replacing pathinfo( $_SERVER['SCRIPT_NAME'], PATHINFO_DIRNAME ); into a pathinfo() to another variable since pathinfo( "", PATHINFO_DIRNAME ); core dumps in PHP 4.1.0 (works if $path is not empty) The value of the pragma directive is 'no-cache', not 'nocache'. See section 14.32 of rfc2616: http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.32 Change-Id: I6294e86a5f3e11b9ea0f62762815e7c71b9037ce
2013-02-26 20:55:06 +00:00
$minimumVersionPHP = '5.3.2';
$phpVersion = PHP_VERSION;
Make update.php and install.php use wfPHPVersionError() and reorganise it update.php and install.php now use wfPHPVersionError() Moved to wfPHPVersionError( cli ) the suggestion of another binary name. Old PHP versions won't have $_SERVER superglobal, hardcode HTTP/1.0 in that case. Store in a variable the minimum version of PHP supported by MediaWiki. Changed PHP_VERSION to phpversion(), although it doesn't matter for the version ranges this works. phpversion() has been present since PHP-2.0 PHP_VERSION was added in PHP 3.0RC5 On its current form in PHP 4 it was moved from Zend/zend_constants.c to main/main.c by Zeev in commits 71dddd7db7e768ae8145e085fcbb6b6db4a1c40a and fb1c77bd4f8a636ba47d720f8ca65fc6baae836d (1999-12-17) It had been commented there since the beginning of svn history (1999-04-07) The earliest version we can target seems to be PHP 4.1.0 PHP 4.0.0 produces a parse error on a require_once not followed by a literal path (although you can use require with an expression), plus its dirname() is quite dumb, and wouldn't provide the right path (would require you to call "php ./update.php" from maintenance folder, not "php update.php" or "php maintenance/update.php" from the main dir) Replacing pathinfo( $_SERVER['SCRIPT_NAME'], PATHINFO_DIRNAME ); into a pathinfo() to another variable since pathinfo( "", PATHINFO_DIRNAME ); core dumps in PHP 4.1.0 (works if $path is not empty) The value of the pragma directive is 'no-cache', not 'nocache'. See section 14.32 of rfc2616: http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.32 Change-Id: I6294e86a5f3e11b9ea0f62762815e7c71b9037ce
2013-02-26 20:55:06 +00:00
$protocol = isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0';
$message = "MediaWiki $mwVersion requires at least "
. "PHP version $minimumVersionPHP, you are using PHP $phpVersion.";
Make update.php and install.php use wfPHPVersionError() and reorganise it update.php and install.php now use wfPHPVersionError() Moved to wfPHPVersionError( cli ) the suggestion of another binary name. Old PHP versions won't have $_SERVER superglobal, hardcode HTTP/1.0 in that case. Store in a variable the minimum version of PHP supported by MediaWiki. Changed PHP_VERSION to phpversion(), although it doesn't matter for the version ranges this works. phpversion() has been present since PHP-2.0 PHP_VERSION was added in PHP 3.0RC5 On its current form in PHP 4 it was moved from Zend/zend_constants.c to main/main.c by Zeev in commits 71dddd7db7e768ae8145e085fcbb6b6db4a1c40a and fb1c77bd4f8a636ba47d720f8ca65fc6baae836d (1999-12-17) It had been commented there since the beginning of svn history (1999-04-07) The earliest version we can target seems to be PHP 4.1.0 PHP 4.0.0 produces a parse error on a require_once not followed by a literal path (although you can use require with an expression), plus its dirname() is quite dumb, and wouldn't provide the right path (would require you to call "php ./update.php" from maintenance folder, not "php update.php" or "php maintenance/update.php" from the main dir) Replacing pathinfo( $_SERVER['SCRIPT_NAME'], PATHINFO_DIRNAME ); into a pathinfo() to another variable since pathinfo( "", PATHINFO_DIRNAME ); core dumps in PHP 4.1.0 (works if $path is not empty) The value of the pragma directive is 'no-cache', not 'nocache'. See section 14.32 of rfc2616: http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.32 Change-Id: I6294e86a5f3e11b9ea0f62762815e7c71b9037ce
2013-02-26 20:55:06 +00:00
if ( $type == 'cli' ) {
$finalOutput = "You are using PHP version $phpVersion "
. "but MediaWiki $mwVersion needs PHP $minimumVersionPHP or higher. ABORTING.\n"
. "Check if you have a newer php executable with a different name, such as php5.\n";
} elseif ( $type == 'index.php' || $type == 'mw-config/index.php' ) {
Make update.php and install.php use wfPHPVersionError() and reorganise it update.php and install.php now use wfPHPVersionError() Moved to wfPHPVersionError( cli ) the suggestion of another binary name. Old PHP versions won't have $_SERVER superglobal, hardcode HTTP/1.0 in that case. Store in a variable the minimum version of PHP supported by MediaWiki. Changed PHP_VERSION to phpversion(), although it doesn't matter for the version ranges this works. phpversion() has been present since PHP-2.0 PHP_VERSION was added in PHP 3.0RC5 On its current form in PHP 4 it was moved from Zend/zend_constants.c to main/main.c by Zeev in commits 71dddd7db7e768ae8145e085fcbb6b6db4a1c40a and fb1c77bd4f8a636ba47d720f8ca65fc6baae836d (1999-12-17) It had been commented there since the beginning of svn history (1999-04-07) The earliest version we can target seems to be PHP 4.1.0 PHP 4.0.0 produces a parse error on a require_once not followed by a literal path (although you can use require with an expression), plus its dirname() is quite dumb, and wouldn't provide the right path (would require you to call "php ./update.php" from maintenance folder, not "php update.php" or "php maintenance/update.php" from the main dir) Replacing pathinfo( $_SERVER['SCRIPT_NAME'], PATHINFO_DIRNAME ); into a pathinfo() to another variable since pathinfo( "", PATHINFO_DIRNAME ); core dumps in PHP 4.1.0 (works if $path is not empty) The value of the pragma directive is 'no-cache', not 'nocache'. See section 14.32 of rfc2616: http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.32 Change-Id: I6294e86a5f3e11b9ea0f62762815e7c71b9037ce
2013-02-26 20:55:06 +00:00
$pathinfo = pathinfo( $_SERVER['SCRIPT_NAME'] );
if ( $type == 'mw-config/index.php' ) {
$dirname = dirname( $pathinfo['dirname'] );
} else {
$dirname = $pathinfo['dirname'];
}
2011-07-06 21:05:29 +00:00
$encLogo = htmlspecialchars(
str_replace( '//', '/', $dirname . '/' ) .
Make update.php and install.php use wfPHPVersionError() and reorganise it update.php and install.php now use wfPHPVersionError() Moved to wfPHPVersionError( cli ) the suggestion of another binary name. Old PHP versions won't have $_SERVER superglobal, hardcode HTTP/1.0 in that case. Store in a variable the minimum version of PHP supported by MediaWiki. Changed PHP_VERSION to phpversion(), although it doesn't matter for the version ranges this works. phpversion() has been present since PHP-2.0 PHP_VERSION was added in PHP 3.0RC5 On its current form in PHP 4 it was moved from Zend/zend_constants.c to main/main.c by Zeev in commits 71dddd7db7e768ae8145e085fcbb6b6db4a1c40a and fb1c77bd4f8a636ba47d720f8ca65fc6baae836d (1999-12-17) It had been commented there since the beginning of svn history (1999-04-07) The earliest version we can target seems to be PHP 4.1.0 PHP 4.0.0 produces a parse error on a require_once not followed by a literal path (although you can use require with an expression), plus its dirname() is quite dumb, and wouldn't provide the right path (would require you to call "php ./update.php" from maintenance folder, not "php update.php" or "php maintenance/update.php" from the main dir) Replacing pathinfo( $_SERVER['SCRIPT_NAME'], PATHINFO_DIRNAME ); into a pathinfo() to another variable since pathinfo( "", PATHINFO_DIRNAME ); core dumps in PHP 4.1.0 (works if $path is not empty) The value of the pragma directive is 'no-cache', not 'nocache'. See section 14.32 of rfc2616: http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.32 Change-Id: I6294e86a5f3e11b9ea0f62762815e7c71b9037ce
2013-02-26 20:55:06 +00:00
'skins/common/images/mediawiki.png'
2011-07-06 21:05:29 +00:00
);
Make update.php and install.php use wfPHPVersionError() and reorganise it update.php and install.php now use wfPHPVersionError() Moved to wfPHPVersionError( cli ) the suggestion of another binary name. Old PHP versions won't have $_SERVER superglobal, hardcode HTTP/1.0 in that case. Store in a variable the minimum version of PHP supported by MediaWiki. Changed PHP_VERSION to phpversion(), although it doesn't matter for the version ranges this works. phpversion() has been present since PHP-2.0 PHP_VERSION was added in PHP 3.0RC5 On its current form in PHP 4 it was moved from Zend/zend_constants.c to main/main.c by Zeev in commits 71dddd7db7e768ae8145e085fcbb6b6db4a1c40a and fb1c77bd4f8a636ba47d720f8ca65fc6baae836d (1999-12-17) It had been commented there since the beginning of svn history (1999-04-07) The earliest version we can target seems to be PHP 4.1.0 PHP 4.0.0 produces a parse error on a require_once not followed by a literal path (although you can use require with an expression), plus its dirname() is quite dumb, and wouldn't provide the right path (would require you to call "php ./update.php" from maintenance folder, not "php update.php" or "php maintenance/update.php" from the main dir) Replacing pathinfo( $_SERVER['SCRIPT_NAME'], PATHINFO_DIRNAME ); into a pathinfo() to another variable since pathinfo( "", PATHINFO_DIRNAME ); core dumps in PHP 4.1.0 (works if $path is not empty) The value of the pragma directive is 'no-cache', not 'nocache'. See section 14.32 of rfc2616: http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.32 Change-Id: I6294e86a5f3e11b9ea0f62762815e7c71b9037ce
2013-02-26 20:55:06 +00:00
header( "$protocol 500 MediaWiki configuration Error" );
2011-07-06 21:05:29 +00:00
header( 'Content-type: text/html; charset=UTF-8' );
// Don't cache error pages! They cause no end of trouble...
header( 'Cache-control: none' );
Make update.php and install.php use wfPHPVersionError() and reorganise it update.php and install.php now use wfPHPVersionError() Moved to wfPHPVersionError( cli ) the suggestion of another binary name. Old PHP versions won't have $_SERVER superglobal, hardcode HTTP/1.0 in that case. Store in a variable the minimum version of PHP supported by MediaWiki. Changed PHP_VERSION to phpversion(), although it doesn't matter for the version ranges this works. phpversion() has been present since PHP-2.0 PHP_VERSION was added in PHP 3.0RC5 On its current form in PHP 4 it was moved from Zend/zend_constants.c to main/main.c by Zeev in commits 71dddd7db7e768ae8145e085fcbb6b6db4a1c40a and fb1c77bd4f8a636ba47d720f8ca65fc6baae836d (1999-12-17) It had been commented there since the beginning of svn history (1999-04-07) The earliest version we can target seems to be PHP 4.1.0 PHP 4.0.0 produces a parse error on a require_once not followed by a literal path (although you can use require with an expression), plus its dirname() is quite dumb, and wouldn't provide the right path (would require you to call "php ./update.php" from maintenance folder, not "php update.php" or "php maintenance/update.php" from the main dir) Replacing pathinfo( $_SERVER['SCRIPT_NAME'], PATHINFO_DIRNAME ); into a pathinfo() to another variable since pathinfo( "", PATHINFO_DIRNAME ); core dumps in PHP 4.1.0 (works if $path is not empty) The value of the pragma directive is 'no-cache', not 'nocache'. See section 14.32 of rfc2616: http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.32 Change-Id: I6294e86a5f3e11b9ea0f62762815e7c71b9037ce
2013-02-26 20:55:06 +00:00
header( 'Pragma: no-cache' );
2011-07-06 21:05:29 +00:00
2011-12-06 23:06:50 +00:00
$finalOutput = <<<HTML
<!DOCTYPE html>
<html lang="en" dir="ltr">
2011-07-06 21:05:29 +00:00
<head>
<meta charset="UTF-8" />
2011-07-06 21:05:29 +00:00
<title>MediaWiki {$mwVersion}</title>
<style media='screen'>
2011-07-06 21:05:29 +00:00
body {
color: #000;
background-color: #fff;
font-family: sans-serif;
padding: 2em;
text-align: center;
}
p, img, h1 {
text-align: left;
margin: 0.5em 0;
}
h1 {
font-size: 120%;
}
</style>
</head>
<body>
<img src="{$encLogo}" alt='The MediaWiki logo' />
<h1>MediaWiki {$mwVersion} internal error</h1>
<div class='error'>
<p>
{$message}
</p>
<p>
Please consider <a href="http://www.php.net/downloads.php">upgrading your copy of PHP</a>.
PHP versions less than 5.3.0 are no longer supported by the PHP Group and will not receive
security or bugfix updates.
</p>
<p>
If for some reason you are unable to upgrade your PHP version, you will need to
<a href="https://www.mediawiki.org/wiki/Download">download</a> an older version
2011-07-06 21:05:29 +00:00
of MediaWiki from our website. See our
<a href="https://www.mediawiki.org/wiki/Compatibility#PHP">compatibility page</a>
2011-07-06 21:05:29 +00:00
for details of which versions are compatible with prior versions of PHP.
</p>
</div>
</body>
</html>
HTML;
// Handle everything that's not index.php
} else {
// So nothing thinks this is JS or CSS
$finalOutput = ( $type == 'load.php' ) ? "/* $message */" : $message;
Make update.php and install.php use wfPHPVersionError() and reorganise it update.php and install.php now use wfPHPVersionError() Moved to wfPHPVersionError( cli ) the suggestion of another binary name. Old PHP versions won't have $_SERVER superglobal, hardcode HTTP/1.0 in that case. Store in a variable the minimum version of PHP supported by MediaWiki. Changed PHP_VERSION to phpversion(), although it doesn't matter for the version ranges this works. phpversion() has been present since PHP-2.0 PHP_VERSION was added in PHP 3.0RC5 On its current form in PHP 4 it was moved from Zend/zend_constants.c to main/main.c by Zeev in commits 71dddd7db7e768ae8145e085fcbb6b6db4a1c40a and fb1c77bd4f8a636ba47d720f8ca65fc6baae836d (1999-12-17) It had been commented there since the beginning of svn history (1999-04-07) The earliest version we can target seems to be PHP 4.1.0 PHP 4.0.0 produces a parse error on a require_once not followed by a literal path (although you can use require with an expression), plus its dirname() is quite dumb, and wouldn't provide the right path (would require you to call "php ./update.php" from maintenance folder, not "php update.php" or "php maintenance/update.php" from the main dir) Replacing pathinfo( $_SERVER['SCRIPT_NAME'], PATHINFO_DIRNAME ); into a pathinfo() to another variable since pathinfo( "", PATHINFO_DIRNAME ); core dumps in PHP 4.1.0 (works if $path is not empty) The value of the pragma directive is 'no-cache', not 'nocache'. See section 14.32 of rfc2616: http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.32 Change-Id: I6294e86a5f3e11b9ea0f62762815e7c71b9037ce
2013-02-26 20:55:06 +00:00
header( "$protocol 500 MediaWiki configuration Error" );
2011-07-06 21:05:29 +00:00
}
echo "$finalOutput\n";
2011-07-06 21:05:29 +00:00
die( 1 );
}