Move fatal PHP functions checks to initialization
[lhc/web/wiklou.git] / includes / PHPVersionCheck.php
index eaab9c8..018c6f8 100644 (file)
@@ -30,8 +30,8 @@
  * version are hardcoded here
  */
 function wfEntryPointCheck( $entryPoint ) {
-       $mwVersion = '1.27';
-       $minimumVersionPHP = '5.3.3';
+       $mwVersion = '1.28';
+       $minimumVersionPHP = '5.5.9';
        $phpVersion = PHP_VERSION;
 
        if ( !function_exists( 'version_compare' )
@@ -45,6 +45,29 @@ function wfEntryPointCheck( $entryPoint ) {
                // @codingStandardsIgnoreEnd
                wfMissingVendorError( $entryPoint, $mwVersion );
        }
+
+       // List of functions and their associated PHP extension to check for
+       // @codingStandardsIgnoreStart Generic.Arrays.DisallowLongArraySyntax
+       $extensions = array(
+               'mb_substr'   => 'mbstring',
+               'utf8_encode' => 'xml',
+               'ctype_digit' => 'ctype',
+               'json_decode' => 'json',
+               'iconv'       => 'iconv',
+       );
+       // List of extensions we're missing
+       $missingExtensions = array();
+       // @codingStandardsIgnoreEnd
+
+       foreach ( $extensions as $function => $extension ) {
+               if ( !function_exists( $function ) ) {
+                       $missingExtensions[] = $extension;
+               }
+       }
+
+       if ( $missingExtensions ) {
+               wfMissingExtensions( $entryPoint, $mwVersion, $missingExtensions );
+       }
 }
 
 /**
@@ -107,7 +130,7 @@ function wfGenericError( $type, $mwVersion, $title, $shortText, $longText, $long
                                padding: 2em;
                                text-align: center;
                        }
-                       p, img, h1, h2 {
+                       p, img, h1, h2, ul  {
                                text-align: left;
                                margin: 0.5em 0 1em;
                        }
@@ -201,3 +224,38 @@ HTML;
 
        wfGenericError( $type, $mwVersion, 'External dependencies', $shortText, $longText, $longHtml );
 }
+
+/**
+ * Display an error for a PHP extension not existing.
+ *
+ * @param string $type See wfGenericError
+ * @param string $mwVersion See wfGenericError
+ * @param array $missingExts The extensions we're missing
+ */
+function wfMissingExtensions( $type, $mwVersion, $missingExts ) {
+       $shortText = "Installing some PHP extensions is required.";
+
+       $missingExtText = '';
+       $missingExtHtml = '';
+       $baseUrl = 'https://secure.php.net';
+       foreach ( $missingExts as $ext ) {
+               $missingExtText .= " * $ext <$baseUrl/$ext>\n";
+               $missingExtHtml .= "<li><b>$ext</b> "
+                       . "(<a href=\"$baseUrl/$ext\">more information</a>)</li>";
+       }
+
+       $cliText = "Error: Missing one or more required components of PHP.\n"
+               . "You are missing a required extension to PHP that MediaWiki needs.\n"
+               . "Please install:\n" . $missingExtText;
+
+       $longHtml = <<<HTML
+               You are missing a required extension to PHP that MediaWiki
+               requires to run. Please install:
+               <ul>
+               $missingExtHtml
+               </ul>
+HTML;
+
+       wfGenericError( $type, $mwVersion, 'Required components', $shortText,
+               $cliText, $longHtml );
+}