| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
class PHPVersionCheck { |
| 36 |
|
| 37 |
var $mwVersion = '1.43'; |
| 38 |
|
| 39 |
|
| 40 |
var $functionsExtensionsMapping = array( |
| 41 |
'mb_substr' => 'mbstring', |
| 42 |
'xml_parser_create' => 'xml', |
| 43 |
'ctype_digit' => 'ctype', |
| 44 |
'json_decode' => 'json', |
| 45 |
'iconv' => 'iconv', |
| 46 |
'mime_content_type' => 'fileinfo', |
| 47 |
'intl_is_failure' => 'intl', |
| 48 |
); |
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
var $format = 'text'; |
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
var $scriptPath = '/'; |
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
function setFormat( $format ) { |
| 66 |
$this->format = $format; |
| 67 |
} |
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
function setScriptPath( $scriptPath ) { |
| 75 |
$this->scriptPath = $scriptPath; |
| 76 |
} |
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
function checkRequiredPHPVersion() { |
| 82 |
|
| 83 |
|
| 84 |
$minimumVersion = '8.1.0'; |
| 85 |
|
| 86 |
|
| 87 |
r: |
| 88 |
|
| 89 |
|
| 90 |
e. |
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
$knownBad = array( |
| 100 |
); |
| 101 |
|
| 102 |
$passes = version_compare( PHP_VERSION, $minimumVersion, '>=' ); |
| 103 |
|
| 104 |
$versionString = "PHP $minimumVersion or higher"; |
| 105 |
|
| 106 |
|
| 107 |
if ( count( $knownBad ) ) { |
| 108 |
$versionString .= ' (and not ' . implode( ', ', array_values( $knownBad ) ) . ')'; |
| 109 |
|
| 110 |
foreach ( $knownBad as $range ) { |
| 111 |
|
| 112 |
if ( strpos( $range, '-' ) ) { |
| 113 |
$passes = $passes && !( |
| 114 |
version_compare( PHP_VERSION, trim( strstr( $range, '-', true ) ), '>=' ) |
| 115 |
&& version_compare( PHP_VERSION, trim( substr( strstr( $range, '-', false ), 1 ) ), '<' ) |
| 116 |
); |
| 117 |
} else { |
| 118 |
$passes = $passes && version_compare( PHP_VERSION, trim( $range ), '<>' ); |
| 119 |
} |
| 120 |
} |
| 121 |
} |
| 122 |
|
| 123 |
if ( !$passes ) { |
| 124 |
$cliText = "Error: You are using an unsupported PHP version (PHP " . PHP_VERSION . ").\n" |
| 125 |
. "MediaWiki $this->mwVersion needs $versionString.\n\nCheck if you might have a newer " |
| 126 |
. "PHP executable with a different name.\n\n"; |
| 127 |
|
| 128 |
$web = array(); |
| 129 |
$web['intro'] = "MediaWiki $this->mwVersion requires $versionString; you are using PHP " |
| 130 |
. PHP_VERSION . "."; |
| 131 |
|
| 132 |
$web['longTitle'] = "Supported PHP versions"; |
| 133 |
|
| 134 |
$web['longHtml'] = <<<HTML |
| 135 |
<p> |
| 136 |
Please consider <a href="https://www.php.net/downloads.php">upgrading your copy of PHP</a>. |
| 137 |
PHP versions less than v8.1.0 are no longer <a href="https://www.php.net/supported-versions.php">supported</a> |
| 138 |
by the PHP Group and will not receive security or bugfix updates. |
| 139 |
</p> |
| 140 |
<p> |
| 141 |
If for some reason you are unable to upgrade your PHP version, you will need to |
| 142 |
<a href="https://www.mediawiki.org/wiki/Download">download</a> an older version of |
| 143 |
MediaWiki from our website. See our |
| 144 |
<a href="https://www.mediawiki.org/wiki/Compatibility#PHP">compatibility page</a> |
| 145 |
for details of which versions are compatible with prior versions of PHP. |
| 146 |
</p> |
| 147 |
HTML; |
| 148 |
|
| 149 |
$this->triggerError( |
| 150 |
$web, |
| 151 |
$cliText |
| 152 |
); |
| 153 |
} |
| 154 |
} |
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
function checkVendorExistence() { |
| 160 |
if ( !file_exists( dirname( __FILE__ ) . '/../vendor/autoload.php' ) ) { |
| 161 |
$cliText = "Error: You are missing some dependencies. \n" |
| 162 |
. "MediaWiki has dependencies that need to be installed via Composer\n" |
| 163 |
. "or from a separate repository. Please see\n" |
| 164 |
. "https://www.mediawiki.org/wiki/Download_from_Git#Fetch_external_libraries\n" |
| 165 |
. "for help with installing them."; |
| 166 |
|
| 167 |
$web = array(); |
| 168 |
$web['intro'] = "Installing some dependencies is required."; |
| 169 |
$web['longTitle'] = 'Dependencies'; |
| 170 |
|
| 171 |
$web['longHtml'] = <<<HTML |
| 172 |
<p> |
| 173 |
MediaWiki has dependencies that need to be installed via Composer |
| 174 |
or from a separate repository. Please see the |
| 175 |
<a href="https://www.mediawiki.org/wiki/Download_from_Git#Fetch_external_libraries">instructions |
| 176 |
for installing external libraries</a> on MediaWiki.org. |
| 177 |
</p> |
| 178 |
HTML; |
| 179 |
|
| 180 |
|
| 181 |
$this->triggerError( $web, $cliText ); |
| 182 |
} |
| 183 |
} |
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
function checkExtensionExistence() { |
| 189 |
$missingExtensions = array(); |
| 190 |
foreach ( $this->functionsExtensionsMapping as $function => $extension ) { |
| 191 |
if ( !function_exists( $function ) ) { |
| 192 |
$missingExtensions[] = array( $extension ); |
| 193 |
} |
| 194 |
} |
| 195 |
|
| 196 |
|
| 197 |
if ( PHP_INT_SIZE < 8 && !extension_loaded( 'gmp' ) && !extension_loaded( 'bcmath' ) ) { |
| 198 |
$missingExtensions[] = array( 'bcmath', 'gmp' ); |
| 199 |
} |
| 200 |
|
| 201 |
if ( $missingExtensions ) { |
| 202 |
$missingExtText = ''; |
| 203 |
$missingExtHtml = ''; |
| 204 |
$baseUrl = 'https://www.php.net'; |
| 205 |
foreach ( $missingExtensions as $extNames ) { |
| 206 |
$plaintextLinks = array(); |
| 207 |
$htmlLinks = array(); |
| 208 |
foreach ( $extNames as $ext ) { |
| 209 |
$plaintextLinks[] = "$ext <$baseUrl/$ext>"; |
| 210 |
$htmlLinks[] = "<b>$ext</b> (<a href=\"$baseUrl/$ext\">more information</a>)"; |
| 211 |
} |
| 212 |
|
| 213 |
$missingExtText .= ' * ' . implode( ' or ', $plaintextLinks ) . "\n"; |
| 214 |
$missingExtHtml .= "<li>" . implode( ' or ', $htmlLinks ) . "</li>"; |
| 215 |
} |
| 216 |
|
| 217 |
$cliText = "Error: Missing one or more required PHP extensions. Please see\n" |
| 218 |
. "https://www.mediawiki.org/wiki/Manual:Installation_requirements#PHP\n" |
| 219 |
. "for help with installing them.\n" |
| 220 |
. "Please install or enable:\n" . $missingExtText; |
| 221 |
|
| 222 |
$web = array(); |
| 223 |
$web['intro'] = "Installing some PHP extensions is required."; |
| 224 |
$web['longTitle'] = 'Required PHP extensions'; |
| 225 |
$web['longHtml'] = <<<HTML |
| 226 |
<p> |
| 227 |
You are missing one or more extensions to PHP that MediaWiki requires to run. Please see the |
| 228 |
<a href="https://www.mediawiki.org/wiki/Manual:Installation_requirements#PHP">PHP |
| 229 |
installation requirements</a> on MediaWiki.org. |
| 230 |
</p> |
| 231 |
<p>Please install or enable:</p> |
| 232 |
<ul> |
| 233 |
$missingExtHtml |
| 234 |
</ul> |
| 235 |
HTML; |
| 236 |
|
| 237 |
$this->triggerError( $web, $cliText ); |
| 238 |
} |
| 239 |
} |
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
function outputHTMLHeader() { |
| 245 |
$protocol = isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0'; |
| 246 |
|
| 247 |
header( "$protocol 500 MediaWiki configuration Error" ); |
| 248 |
|
| 249 |
header( 'Cache-Control: no-cache' ); |
| 250 |
} |
| 251 |
|
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
|
| 257 |
|
| 258 |
|
| 259 |
|
| 260 |
function getIndexErrorOutput( $introText, $longTitle, $longHtml ) { |
| 261 |
$encLogo = |
| 262 |
htmlspecialchars( str_replace( '//', '/', $this->scriptPath . '/' ) . |
| 263 |
'resources/assets/mediawiki.png' ); |
| 264 |
|
| 265 |
$introHtml = htmlspecialchars( $introText ); |
| 266 |
$longTitleHtml = htmlspecialchars( $longTitle ); |
| 267 |
|
| 268 |
header( 'Content-type: text/html; charset=UTF-8' ); |
| 269 |
|
| 270 |
$finalOutput = <<<HTML |
| 271 |
<!DOCTYPE html> |
| 272 |
<html lang="en" dir="ltr"> |
| 273 |
<head> |
| 274 |
<meta charset="UTF-8" /> |
| 275 |
<title>MediaWiki {$this->mwVersion}</title> |
| 276 |
<style media="screen"> |
| 277 |
body { |
| 278 |
color: #000; |
| 279 |
background-color: #fff; |
| 280 |
font-family: sans-serif; |
| 281 |
padding: 2em; |
| 282 |
text-align: center; |
| 283 |
} |
| 284 |
p, img, h1, h2, ul { |
| 285 |
text-align: left; |
| 286 |
margin: 0.5em 0 1em; |
| 287 |
} |
| 288 |
h1 { |
| 289 |
font-size: 120%; |
| 290 |
} |
| 291 |
h2 { |
| 292 |
font-size: 110%; |
| 293 |
} |
| 294 |
</style> |
| 295 |
</head> |
| 296 |
<body> |
| 297 |
<img src="{$encLogo}" alt="The MediaWiki logo" /> |
| 298 |
<h1>MediaWiki {$this->mwVersion} internal error</h1> |
| 299 |
<p> |
| 300 |
{$introHtml} |
| 301 |
</p> |
| 302 |
<h2>{$longTitleHtml}</h2> |
| 303 |
{$longHtml} |
| 304 |
</body> |
| 305 |
</html> |
| 306 |
HTML; |
| 307 |
|
| 308 |
return $finalOutput; |
| 309 |
} |
| 310 |
|
| 311 |
|
| 312 |
|
| 313 |
|
| 314 |
|
| 315 |
|
| 316 |
|
| 317 |
|
| 318 |
|
| 319 |
|
| 320 |
|
| 321 |
|
| 322 |
|
| 323 |
|
| 324 |
|
| 325 |
function triggerError( $web, $cliText ) { |
| 326 |
if ( $this->format === 'html' ) { |
| 327 |
|
| 328 |
$this->outputHTMLHeader(); |
| 329 |
$finalOutput = $this->getIndexErrorOutput( |
| 330 |
$web['intro'], |
| 331 |
$web['longTitle'], |
| 332 |
$web['longHtml'] |
| 333 |
); |
| 334 |
} else { |
| 335 |
|
| 336 |
$finalOutput = $cliText; |
| 337 |
} |
| 338 |
|
| 339 |
echo "$finalOutput\n"; |
| 340 |
die( 1 ); |
| 341 |
} |
| 342 |
} |
| 343 |
|
| 344 |
|
| 345 |
|
| 346 |
|
| 347 |
|
| 348 |
|
| 349 |
|
| 350 |
|
| 351 |
function wfEntryPointCheck( $format = 'text', $scriptPath = '/' ) { |
| 352 |
$phpVersionCheck = new PHPVersionCheck(); |
| 353 |
$phpVersionCheck->setFormat( $format ); |
| 354 |
$phpVersionCheck->setScriptPath( $scriptPath ); |
| 355 |
$phpVersionCheck->checkRequiredPHPVersion(); |
| 356 |
$phpVersionCheck->checkVendorExistence(); |
| 357 |
$phpVersionCheck->checkExtensionExistence(); |
| 358 |
} |