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

Change subject: Rework PHP and vendor check
......................................................................


Rework PHP and vendor check

* separate warnings for PHP version and vendor

* new wfGenericError() function

* minimum PHP version in a single place

Bug: T102094
Change-Id: I7ae0369e4bab279d5e1bc754fe1a0bc8543bb2ed
---
M includes/PHPVersionCheck.php
1 file changed, 94 insertions(+), 52 deletions(-)

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



diff --git a/includes/PHPVersionCheck.php b/includes/PHPVersionCheck.php
index d11d021..9dec950 100644
--- a/includes/PHPVersionCheck.php
+++ b/includes/PHPVersionCheck.php
@@ -25,13 +25,23 @@
 /**
  * Check php version and that external dependencies are installed, and
  * display an informative error if either condition is not satisfied.
+ *
+ * @note Since we can't rely on anything, the minimum PHP versions and MW 
current
+ * version are hardcoded here
  */
 function wfEntryPointCheck( $entryPoint ) {
+       $mwVersion = '1.26';
+       $minimumVersionPHP = '5.3.3';
+       $phpVersion = PHP_VERSION;
+
        if ( !function_exists( 'version_compare' )
-               || version_compare( PHP_VERSION, '5.3.3' ) < 0
-               || !file_exists( dirname( __FILE__ ) . 
'/../vendor/autoload.php' )
+               || version_compare( $phpVersion, $minimumVersionPHP ) < 0
        ) {
-               wfPHPVersionError( $entryPoint );
+               wfPHPVersionError( $entryPoint, $mwVersion, $minimumVersionPHP, 
$phpVersion );
+       }
+
+       if ( !file_exists( dirname( __FILE__ ) . '/../vendor/autoload.php' ) ) {
+               wfMissingVendorError( $entryPoint, $mwVersion );
        }
 }
 
@@ -49,47 +59,39 @@
  *   - api.php
  *   - mw-config/index.php
  *   - cli
- *
- * @note Since we can't rely on anything, the minimum PHP versions and MW 
current
- * version are hardcoded here
+ * @param string $mwVersion The number of the MediaWiki version used
+ * @param string $title HTML code to be put within an <h2> tag
+ * @param string $shortText
+ * @param string $longText
+ * @param string $longHtml
  */
-function wfPHPVersionError( $type ) {
-       $mwVersion = '1.26';
-       $minimumVersionPHP = '5.3.3';
-
-       $phpVersion = PHP_VERSION;
+function wfGenericError( $type, $mwVersion, $title, $shortText, $longText, 
$longHtml ) {
        $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. Installing some "
-               . " external dependencies (e.g. via composer) is also 
required.";
 
        if ( $type == 'cli' ) {
-               $finalOutput = "Error: You are missing some external 
dependencies or are using on older PHP version. \n"
-                       . "MediaWiki $mwVersion needs PHP $minimumVersionPHP or 
higher.\n\n"
-                       . "Check if you have a newer php executable with a 
different name, such as php5.\n\n"
-                       . "MediaWiki now also has some external dependencies 
that need to be installed\n"
-                       . "via composer or from a separate git repo. Please 
see\n"
-                       . 
"https://www.mediawiki.org/wiki/Download_from_Git#Fetch_external_libraries\n";
-                       . "for help on installing the required components.";
-       } elseif ( $type == 'index.php' || $type == 'mw-config/index.php' ) {
-               $pathinfo = pathinfo( $_SERVER['SCRIPT_NAME'] );
-               if ( $type == 'mw-config/index.php' ) {
-                       $dirname = dirname( $pathinfo['dirname'] );
-               } else {
-                       $dirname = $pathinfo['dirname'];
-               }
-               $encLogo = htmlspecialchars(
-                       str_replace( '//', '/', $dirname . '/' ) .
-                       'resources/assets/mediawiki.png'
-               );
-
+               $finalOutput = $longText;
+       } else {
                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: no-cache' );
 
-               $finalOutput = <<<HTML
+               if ( $type == 'index.php' || $type == 'mw-config/index.php' ) {
+                       $pathinfo = pathinfo( $_SERVER['SCRIPT_NAME'] );
+                       if ( $type == 'mw-config/index.php' ) {
+                               $dirname = dirname( $pathinfo['dirname'] );
+                       } else {
+                               $dirname = $pathinfo['dirname'];
+                       }
+                       $encLogo = htmlspecialchars(
+                               str_replace( '//', '/', $dirname . '/' ) .
+                               'resources/assets/mediawiki.png'
+                       );
+                       $shortHtml = htmlspecialchars( $shortText );
+
+                       header( 'Content-type: text/html; charset=UTF-8' );
+
+                       $finalOutput = <<<HTML
 <!DOCTYPE html>
 <html lang="en" dir="ltr">
        <head>
@@ -120,10 +122,43 @@
                <h1>MediaWiki {$mwVersion} internal error</h1>
                <div class='error'>
                <p>
-                       {$message}
+                       {$shortHtml}
                </p>
-               <h2>Supported PHP versions</h2>
+               <h2>{$title}</h2>
                <p>
+                       {$longHtml}
+               </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' ) ? "/* $shortText 
*/" : $shortText;
+               }
+       }
+       echo "$finalOutput\n";
+       die( 1 );
+}
+
+/**
+ * Display an error for the minimum PHP version requirement not being 
satisfied.
+ *
+ * @param string $type See wfGenericError
+ * @param string $mwVersion See wfGenericError
+ * @param string $minimumVersionPHP The minimum PHP version supported by 
MediaWiki
+ * @param string $phpVersion The current PHP version
+ */
+function wfPHPVersionError( $type, $mwVersion, $minimumVersionPHP, $phpVersion 
) {
+       $shortText = "MediaWiki $mwVersion requires at least "
+               . "PHP version $minimumVersionPHP, you are using PHP 
$phpVersion.";
+
+       $longText = "Error: You might be using on older PHP version. \n"
+               . "MediaWiki $mwVersion needs PHP $minimumVersionPHP or 
higher.\n\n"
+               . "Check if you have a newer php executable with a different 
name, such as php5.\n\n";
+
+       $longHtml = <<<HTML
                        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.
@@ -134,24 +169,31 @@
                        of MediaWiki from our website.  See our
                        <a 
href="https://www.mediawiki.org/wiki/Compatibility#PHP";>compatibility page</a>
                        for details of which versions are compatible with prior 
versions of PHP.
-               </p>
-               <h2>External dependencies</h2>
-               <p>
+HTML;
+       wfGenericError( $type, $mwVersion, 'Supported PHP versions', 
$shortText, $longText, $longHtml );
+}
+
+/**
+ * Display an error for the vendor/autoload.php file not being found.
+ *
+ * @param string $type See wfGenericError
+ * @param string $mwVersion See wfGenericError
+ */
+function wfMissingVendorError( $type, $mwVersion ) {
+       $shortText = "Installing some external dependencies (e.g. via composer) 
is also required.";
+
+       $longText = "Error: You are missing some external dependencies. \n"
+               . "MediaWiki now also has some external dependencies that need 
to be installed\n"
+               . "via composer or from a separate git repo. Please see\n"
+               . 
"https://www.mediawiki.org/wiki/Download_from_Git#Fetch_external_libraries\n";
+               . "for help on installing the required components.";
+
+       $longHtml = <<<HTML
                        MediaWiki now also has some external dependencies that 
need to be installed via
                        composer or from a separate git repo. Please see
                        <a 
href="https://www.mediawiki.org/wiki/Download_from_Git#Fetch_external_libraries";>mediawiki.org</a>
                        for help on installing the required components.
-               </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;
-               header( "$protocol 500 MediaWiki configuration Error" );
-       }
-       echo "$finalOutput\n";
-       die( 1 );
+
+       wfGenericError( $type, $mwVersion, 'External dependencies', $shortText, 
$longText, $longHtml );
 }

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I7ae0369e4bab279d5e1bc754fe1a0bc8543bb2ed
Gerrit-PatchSet: 29
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Paladox <[email protected]>
Gerrit-Reviewer: Addshore <[email protected]>
Gerrit-Reviewer: Bartosz DziewoƄski <[email protected]>
Gerrit-Reviewer: Brian Wolff <[email protected]>
Gerrit-Reviewer: Florianschmidtwelzow <[email protected]>
Gerrit-Reviewer: Ori.livneh <[email protected]>
Gerrit-Reviewer: Ottomata <[email protected]>
Gerrit-Reviewer: Ricordisamoa <[email protected]>
Gerrit-Reviewer: TheDJ <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to