jenkins-bot has submitted this change and it was merged.

Change subject: Make update.php and install.php use wfPHPVersionError() and 
reorganise it
......................................................................


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
---
M includes/PHPVersionError.php
M maintenance/install.php
M maintenance/update.php
3 files changed, 19 insertions(+), 16 deletions(-)

Approvals:
  Demon: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/includes/PHPVersionError.php b/includes/PHPVersionError.php
index c60c107..6421350 100644
--- a/includes/PHPVersionError.php
+++ b/includes/PHPVersionError.php
@@ -39,19 +39,26 @@
  */
 function wfPHPVersionError( $type ) {
        $mwVersion = '1.21';
-       $phpVersion = PHP_VERSION;
-       $message = "MediaWiki $mwVersion requires at least PHP version 5.3.2, 
you are using PHP $phpVersion.";
-       if( $type == 'index.php' ) {
+       $minimumVersionPHP = '5.3.2';
+
+       $phpVersion = phpversion();
+       $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.";
+       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' ) {
+               $pathinfo = pathinfo( $_SERVER['SCRIPT_NAME'] );
                $encLogo = htmlspecialchars(
-                       str_replace( '//', '/', pathinfo( 
$_SERVER['SCRIPT_NAME'], PATHINFO_DIRNAME ) . '/'
-                       ) . 'skins/common/images/mediawiki.png'
+                       str_replace( '//', '/', $pathinfo['dirname'] . '/' ) .
+                       'skins/common/images/mediawiki.png'
                );
 
-               header( $_SERVER['SERVER_PROTOCOL'] . ' 500 MediaWiki 
configuration Error', true, 500 );
+               header( "$protocol 500 MediaWiki configuration Error" );
                header( 'Content-type: text/html; charset=UTF-8' );
                // Don't cache error pages!  They cause no end of trouble...
                header( 'Cache-control: none' );
-               header( 'Pragma: nocache' );
+               header( 'Pragma: no-cache' );
 
                $finalOutput = <<<HTML
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";>
@@ -103,9 +110,7 @@
        } else {
                // So nothing thinks this is JS or CSS
                $finalOutput = ( $type == 'load.php' ) ? "/* $message */" : 
$message;
-               if( $type != 'cli' ) {
-                       header( $_SERVER['SERVER_PROTOCOL'] . ' 500 MediaWiki 
configuration Error', true, 500 );
-               }
+               header( "$protocol 500 MediaWiki configuration Error" );
        }
        echo( "$finalOutput\n" );
        die( 1 );
diff --git a/maintenance/install.php b/maintenance/install.php
index 39e613f..935a296 100644
--- a/maintenance/install.php
+++ b/maintenance/install.php
@@ -22,9 +22,8 @@
  */
 
 if ( !function_exists( 'version_compare' ) || ( version_compare( phpversion(), 
'5.3.2' ) < 0 ) ) {
-       echo "You are using PHP version " . phpversion() . " but MediaWiki 
needs PHP 5.3.2 or higher. ABORTING.\n" .
-       "Check if you have a newer php executable with a different name, such 
as php5.\n";
-       die( 1 );
+       require_once( dirname( __FILE__ ) . '/../includes/PHPVersionError.php' 
);
+       wfPHPVersionError( 'cli' );
 }
 
 define( 'MW_CONFIG_CALLBACK', 'Installer::overrideConfig' );
diff --git a/maintenance/update.php b/maintenance/update.php
index 159b6b7..f69a9b0 100644
--- a/maintenance/update.php
+++ b/maintenance/update.php
@@ -26,9 +26,8 @@
  */
 
 if ( !function_exists( 'version_compare' ) || ( version_compare( phpversion(), 
'5.3.2' ) < 0 ) ) {
-       echo "You are using PHP version " . phpversion() . " but MediaWiki 
needs PHP 5.3.2 or higher. ABORTING.\n" .
-       "Check if you have a newer php executable with a different name, such 
as php5.\n";
-       die( 1 );
+       require( dirname( __FILE__ ) . '/../includes/PHPVersionError.php' );
+       wfPHPVersionError( 'cli' );
 }
 
 $wgUseMasterForMaintenance = true;

-- 
To view, visit https://gerrit.wikimedia.org/r/51022
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I6294e86a5f3e11b9ea0f62762815e7c71b9037ce
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Platonides <[email protected]>
Gerrit-Reviewer: Demon <[email protected]>
Gerrit-Reviewer: Platonides <[email protected]>
Gerrit-Reviewer: Reedy <[email protected]>
Gerrit-Reviewer: jenkins-bot

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to