42 private static $functionsExtensionsMapping = [
43 'mb_substr' =>
'mbstring',
44 'xml_parser_create' =>
'xml',
45 'ctype_digit' =>
'ctype',
47 'mime_content_type' =>
'fileinfo',
48 'intl_is_failure' =>
'intl',
65 public function __construct( $format =
'text', $scriptPath =
'/' ) {
66 $this->format = $format;
67 $this->scriptPath = $scriptPath;
73 private function checkRequiredPHPVersion() {
75 $minimumVersion =
'8.3.0';
93 $passes = version_compare( PHP_VERSION, $minimumVersion,
'>=' );
95 $versionString =
"PHP $minimumVersion or higher";
98 if ( count( $knownBad ) ) {
99 $versionString .=
' (and not ' . implode(
', ', array_values( $knownBad ) ) .
')';
101 foreach ( $knownBad as $range ) {
103 if ( strpos( $range,
'-' ) ) {
104 $passes = $passes && !(
105 version_compare( PHP_VERSION, trim( strstr( $range,
'-',
true ) ),
'>=' )
106 && version_compare( PHP_VERSION, trim( substr( strstr( $range,
'-',
false ), 1 ) ),
'<' )
109 $passes = $passes && version_compare( PHP_VERSION, trim( $range ),
'<>' );
115 $mwVersion = self::MW_VERSION;
116 $cliText =
"Error: You are using an unsupported PHP version (PHP " . PHP_VERSION .
").\n"
117 .
"MediaWiki $mwVersion needs $versionString.\n\nCheck if you might have a newer "
118 .
"PHP executable with a different name.\n\n";
121 $web[
'intro'] =
"MediaWiki $mwVersion requires $versionString; you are using PHP "
124 $web[
'longTitle'] =
"Supported PHP versions";
126 $web[
'longHtml'] = <<<HTML
128 Please consider <a href=
"https://www.php.net/downloads.php">upgrading your copy of PHP</a>.
129 PHP versions less than v8.2.0 are no longer <a href=
"https://www.php.net/supported-versions.php">supported</a>
130 by the PHP Group and will not receive security or bugfix updates.
133 If
for some reason you are unable to upgrade your PHP version, you will need to
134 <a href=
"https://www.mediawiki.org/wiki/Download">download</a> an older version of
135 MediaWiki from our website. See our
136 <a href=
"https://www.mediawiki.org/wiki/Compatibility#PHP">compatibility page</a>
137 for details of which versions are compatible with prior versions of PHP.
151 private function checkVendorExistence() {
152 if ( !file_exists( __DIR__ .
'/../vendor/autoload.php' ) ) {
153 $cliText =
"Error: You are missing some dependencies. \n"
154 .
"MediaWiki has dependencies that need to be installed via Composer\n"
155 .
"or from a separate repository. Please see\n"
156 .
"https://www.mediawiki.org/wiki/Download_from_Git#Fetch_external_libraries\n"
157 .
"for help with installing them.";
160 $web[
'intro'] =
"Installing some dependencies is required.";
161 $web[
'longTitle'] =
'Dependencies';
163 $web[
'longHtml'] = <<<HTML
165 MediaWiki has dependencies that need to be installed via Composer
166 or from a separate repository. Please see the
167 <a href=
"https://www.mediawiki.org/wiki/Download_from_Git#Fetch_external_libraries">instructions
168 for installing external libraries</a> on MediaWiki.org.
173 $this->triggerError( $web, $cliText );
180 private function checkExtensionExistence() {
181 $missingExtensions = [];
182 foreach ( self::$functionsExtensionsMapping as $function => $extension ) {
183 if ( !function_exists( $function ) ) {
184 $missingExtensions[] = [ $extension ];
189 if ( PHP_INT_SIZE < 8 && !extension_loaded(
'gmp' ) && !extension_loaded(
'bcmath' ) ) {
190 $missingExtensions[] = [
'bcmath',
'gmp' ];
193 if ( $missingExtensions ) {
194 $missingExtText =
'';
195 $missingExtHtml =
'';
196 $baseUrl =
'https://www.php.net';
197 foreach ( $missingExtensions as $extNames ) {
198 $plaintextLinks = [];
200 foreach ( $extNames as $ext ) {
201 $plaintextLinks[] =
"$ext <$baseUrl/$ext>";
202 $htmlLinks[] =
"<b>$ext</b> (<a href=\"$baseUrl/$ext\">more information</a>)";
205 $missingExtText .=
' * ' . implode(
' or ', $plaintextLinks ) .
"\n";
206 $missingExtHtml .=
"<li>" . implode(
' or ', $htmlLinks ) .
"</li>";
209 $cliText =
"Error: Missing one or more required PHP extensions. Please see\n"
210 .
"https://www.mediawiki.org/wiki/Manual:Installation_requirements#PHP\n"
211 .
"for help with installing them.\n"
212 .
"Please install or enable:\n" . $missingExtText;
215 $web[
'intro'] =
"Installing some PHP extensions is required.";
216 $web[
'longTitle'] =
'Required PHP extensions';
217 $web[
'longHtml'] = <<<HTML
219 You are missing one or more extensions to PHP that MediaWiki
requires to
run. Please see the
220 <a href=
"https://www.mediawiki.org/wiki/Manual:Installation_requirements#PHP">PHP
221 installation requirements</a> on MediaWiki.org.
223 <p>Please install or enable:</p>
229 $this->triggerError( $web, $cliText );
236 private function outputHTMLHeader() {
237 $protocol = isset( $_SERVER[
'SERVER_PROTOCOL'] ) ? $_SERVER[
'SERVER_PROTOCOL'] :
'HTTP/1.0';
239 HttpHeader::send(
"$protocol 500 MediaWiki configuration Error" );
241 HttpHeader::send(
'Cache-Control: no-cache' );
252 private function getIndexErrorOutput( $introText, $longTitle, $longHtml ) {
254 htmlspecialchars( str_replace(
'//',
'/', $this->scriptPath .
'/' ) .
255 'resources/assets/mediawiki.png' );
257 $introHtml = htmlspecialchars( $introText );
258 $longTitleHtml = htmlspecialchars( $longTitle );
260 HttpHeader::send(
'Content-type: text/html; charset=UTF-8' );
262 $mwVersion = self::MW_VERSION;
263 $finalOutput = <<<HTML
265<html lang=
"en" dir=
"ltr">
267 <meta charset=
"UTF-8" />
268 <title>MediaWiki {$mwVersion}</title>
269 <style media=
"screen">
272 background-color: #fff;
273 font-family: sans-serif;
290 <img src=
"{$encLogo}" alt=
"The MediaWiki logo" />
291 <h1>MediaWiki {$mwVersion}
internal error</h1>
295 <h2>{$longTitleHtml}</h2>
316 private function triggerError( array $web, $cliText ) {
317 if ( $this->format ===
'html' ) {
319 $this->outputHTMLHeader();
320 $finalOutput = $this->getIndexErrorOutput(
327 $finalOutput = $cliText;
330 echo
"$finalOutput\n";
341 $this->checkRequiredPHPVersion();
342 $this->checkVendorExistence();
343 $this->checkExtensionExistence();