MediaWiki  REL1_31
PHPVersionCheck.php
Go to the documentation of this file.
1 <?php
21 // phpcs:disable Generic.Arrays.DisallowLongArraySyntax,PSR2.Classes.PropertyDeclaration,MediaWiki.Usage.DirUsage
29  /* @var string The number of the MediaWiki version used */
30  var $mwVersion = '1.31';
32  'mb_substr' => 'mbstring',
33  'xml_parser_create' => 'xml',
34  'ctype_digit' => 'ctype',
35  'json_decode' => 'json',
36  'iconv' => 'iconv',
37  'mime_content_type' => 'fileinfo',
38  );
39 
48  var $entryPoint = null;
49 
58  function setEntryPoint( $entryPoint ) {
59  $this->entryPoint = $entryPoint;
60  }
61 
78  function getPHPInfo( $impl = false ) {
79  if (
80  ( defined( 'HHVM_VERSION' ) && $impl !== 'PHP' ) ||
81  $impl === 'HHVM'
82  ) {
83  return array(
84  'implementation' => 'HHVM',
85  'version' => defined( 'HHVM_VERSION' ) ? HHVM_VERSION : 'undefined',
86  'vendor' => 'Facebook',
87  'upstreamSupported' => '3.18.5',
88  'minSupported' => '3.18.5',
89  'upgradeURL' => 'https://docs.hhvm.com/hhvm/installation/introduction',
90  );
91  }
92  return array(
93  'implementation' => 'PHP',
94  'version' => PHP_VERSION,
95  'vendor' => 'the PHP Group',
96  'upstreamSupported' => '7.2.0',
97  'minSupported' => '7.0.13',
98  'upgradeURL' => 'https://secure.php.net/downloads.php',
99  );
100  }
101 
106  $phpInfo = $this->getPHPInfo();
107  $minimumVersion = $phpInfo['minSupported'];
108  $otherInfo = $this->getPHPInfo( $phpInfo['implementation'] === 'HHVM' ? 'PHP' : 'HHVM' );
109  if (
110  !function_exists( 'version_compare' )
111  || version_compare( $phpInfo['version'], $minimumVersion ) < 0
112  ) {
113  $shortText = "MediaWiki $this->mwVersion requires at least {$phpInfo['implementation']}"
114  . " version $minimumVersion or {$otherInfo['implementation']} version "
115  . "{$otherInfo['minSupported']}, you are using {$phpInfo['implementation']} "
116  . "{$phpInfo['version']}.";
117 
118  $longText = "Error: You might be using an older {$phpInfo['implementation']} version "
119  . "({$phpInfo['implementation']} {$phpInfo['version']}). \n"
120  . "MediaWiki $this->mwVersion needs {$phpInfo['implementation']}"
121  . " $minimumVersion or higher or {$otherInfo['implementation']} version "
122  . "{$otherInfo['minSupported']}.\n\nCheck if you have a"
123  . " newer php executable with a different name.\n\n";
124 
125  // phpcs:disable Generic.Files.LineLength
126  $longHtml = <<<HTML
127  Please consider <a href="{$phpInfo['upgradeURL']}">upgrading your copy of
128  {$phpInfo['implementation']}</a>.
129  {$phpInfo['implementation']} versions less than {$phpInfo['upstreamSupported']} are no
130  longer supported by {$phpInfo['vendor']} and will not receive
131  security or bugfix updates.
132  </p>
133  <p>
134  If for some reason you are unable to upgrade your {$phpInfo['implementation']} version,
135  you will need to <a href="https://www.mediawiki.org/wiki/Download">download</a> an
136  older version of MediaWiki from our website.
137  See our <a href="https://www.mediawiki.org/wiki/Compatibility#PHP">compatibility page</a>
138  for details of which versions are compatible with prior versions of {$phpInfo['implementation']}.
139 HTML;
140  // phpcs:enable Generic.Files.LineLength
141  $this->triggerError(
142  "Supported {$phpInfo['implementation']} versions",
143  $shortText,
144  $longText,
145  $longHtml
146  );
147  }
148  }
149 
153  function checkVendorExistence() {
154  if ( !file_exists( dirname( __FILE__ ) . '/../vendor/autoload.php' ) ) {
155  $shortText = "Installing some external dependencies (e.g. via composer) is required.";
156 
157  $longText = "Error: You are missing some external dependencies. \n"
158  . "MediaWiki now also has some external dependencies that need to be installed\n"
159  . "via composer or from a separate git repo. Please see\n"
160  . "https://www.mediawiki.org/wiki/Download_from_Git#Fetch_external_libraries\n"
161  . "for help on installing the required components.";
162 
163  // phpcs:disable Generic.Files.LineLength
164  $longHtml = <<<HTML
165  MediaWiki now also has some external dependencies that need to be installed via
166  composer or from a separate git repo. Please see
167  <a href="https://www.mediawiki.org/wiki/Download_from_Git#Fetch_external_libraries">mediawiki.org</a>
168  for help on installing the required components.
169 HTML;
170  // phpcs:enable Generic.Files.LineLength
171 
172  $this->triggerError( 'External dependencies', $shortText, $longText, $longHtml );
173  }
174  }
175 
180  $missingExtensions = array();
181  foreach ( $this->functionsExtensionsMapping as $function => $extension ) {
182  if ( !function_exists( $function ) ) {
183  $missingExtensions[] = $extension;
184  }
185  }
186 
187  if ( $missingExtensions ) {
188  $shortText = "Installing some PHP extensions is required.";
189 
190  $missingExtText = '';
191  $missingExtHtml = '';
192  $baseUrl = 'https://secure.php.net';
193  foreach ( $missingExtensions as $ext ) {
194  $missingExtText .= " * $ext <$baseUrl/$ext>\n";
195  $missingExtHtml .= "<li><b>$ext</b> "
196  . "(<a href=\"$baseUrl/$ext\">more information</a>)</li>";
197  }
198 
199  $cliText = "Error: Missing one or more required components of PHP.\n"
200  . "You are missing a required extension to PHP that MediaWiki needs.\n"
201  . "Please install:\n" . $missingExtText;
202 
203  $longHtml = <<<HTML
204  You are missing a required extension to PHP that MediaWiki
205  requires to run. Please install:
206  <ul>
207  $missingExtHtml
208  </ul>
209 HTML;
210 
211  $this->triggerError( 'Required components', $shortText, $cliText, $longHtml );
212  }
213  }
214 
218  function outputHTMLHeader() {
219  $protocol = isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0';
220 
221  header( "$protocol 500 MediaWiki configuration Error" );
222  // Don't cache error pages! They cause no end of trouble...
223  header( 'Cache-control: none' );
224  header( 'Pragma: no-cache' );
225  }
226 
235  function getIndexErrorOutput( $title, $longHtml, $shortText ) {
236  $pathinfo = pathinfo( $_SERVER['SCRIPT_NAME'] );
237  if ( $this->entryPoint == 'mw-config/index.php' ) {
238  $dirname = dirname( $pathinfo['dirname'] );
239  } else {
240  $dirname = $pathinfo['dirname'];
241  }
242  $encLogo =
243  htmlspecialchars( str_replace( '//', '/', $dirname . '/' ) .
244  'resources/assets/mediawiki.png' );
245  $shortHtml = htmlspecialchars( $shortText );
246 
247  header( 'Content-type: text/html; charset=UTF-8' );
248 
249  $finalOutput = <<<HTML
250 <!DOCTYPE html>
251 <html lang="en" dir="ltr">
252  <head>
253  <meta charset="UTF-8" />
254  <title>MediaWiki {$this->mwVersion}</title>
255  <style media='screen'>
256  body {
257  color: #000;
258  background-color: #fff;
259  font-family: sans-serif;
260  padding: 2em;
261  text-align: center;
262  }
263  p, img, h1, h2, ul {
264  text-align: left;
265  margin: 0.5em 0 1em;
266  }
267  h1 {
268  font-size: 120%;
269  }
270  h2 {
271  font-size: 110%;
272  }
273  </style>
274  </head>
275  <body>
276  <img src="{$encLogo}" alt='The MediaWiki logo' />
277  <h1>MediaWiki {$this->mwVersion} internal error</h1>
278  <div class='error'>
279  <p>
280  {$shortHtml}
281  </p>
282  <h2>{$title}</h2>
283  <p>
284  {$longHtml}
285  </p>
286  </div>
287  </body>
288 </html>
289 HTML;
290 
291  return $finalOutput;
292  }
293 
307  function triggerError( $title, $shortText, $longText, $longHtml ) {
308  switch ( $this->entryPoint ) {
309  case 'cli':
310  $finalOutput = $longText;
311  break;
312  case 'index.php':
313  case 'mw-config/index.php':
314  $this->outputHTMLHeader();
315  $finalOutput = $this->getIndexErrorOutput( $title, $longHtml, $shortText );
316  break;
317  case 'load.php':
318  $this->outputHTMLHeader();
319  $finalOutput = "/* $shortText */";
320  break;
321  default:
322  $this->outputHTMLHeader();
323  // Handle everything that's not index.php
324  $finalOutput = $shortText;
325  }
326 
327  echo "$finalOutput\n";
328  die( 1 );
329  }
330 }
331 
339 function wfEntryPointCheck( $entryPoint ) {
340  $phpVersionCheck = new PHPVersionCheck();
341  $phpVersionCheck->setEntryPoint( $entryPoint );
342  $phpVersionCheck->checkRequiredPHPVersion();
343  $phpVersionCheck->checkVendorExistence();
344  $phpVersionCheck->checkExtensionExistence();
345 }
PHPVersionCheck\getIndexErrorOutput
getIndexErrorOutput( $title, $longHtml, $shortText)
Returns an error page, which is suitable for output to the end user via a web browser.
Definition: PHPVersionCheck.php:235
error
do that in ParserLimitReportFormat instead use this to modify the parameters of the image all existing parser cache entries will be invalid To avoid you ll need to handle that somehow(e.g. with the RejectParserCacheValue hook) because MediaWiki won 't do it for you. & $defaults error
Definition: hooks.txt:2612
array
the array() calling protocol came about after MediaWiki 1.4rc1.
text
design txt This is a brief overview of the new design More thorough and up to date information is available on the documentation wiki at etc Handles the details of getting and saving to the user table of the and dealing with sessions and cookies OutputPage Encapsulates the entire HTML page that will be sent in response to any server request It is used by calling its functions to add text
Definition: design.txt:18
PHPVersionCheck\checkVendorExistence
checkVendorExistence()
Displays an error, if the vendor/autoload.php file could not be found.
Definition: PHPVersionCheck.php:153
PHPVersionCheck\checkExtensionExistence
checkExtensionExistence()
Displays an error, if a PHP extension does not exist.
Definition: PHPVersionCheck.php:179
page
target page
Definition: All_system_messages.txt:1267
PHPVersionCheck\$entryPoint
string $entryPoint
Which entry point we are protecting.
Definition: PHPVersionCheck.php:48
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:37
Makefile.download
def download(url, dest)
Definition: Makefile.py:47
wfEntryPointCheck
wfEntryPointCheck( $entryPoint)
Check php version and that external dependencies are installed, and display an informative error if e...
Definition: PHPVersionCheck.php:339
PHPVersionCheck\triggerError
triggerError( $title, $shortText, $longText, $longHtml)
Display something vaguely comprehensible in the event of a totally unrecoverable error.
Definition: PHPVersionCheck.php:307
updates
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these updates(as a Java servelet could)
PHPVersionCheck
Definition: PHPVersionCheck.php:28
PHPVersionCheck\outputHTMLHeader
outputHTMLHeader()
Output headers that prevents error pages to be cached.
Definition: PHPVersionCheck.php:218
title
title
Definition: parserTests.txt:219
MediaWiki
A helper class for throttling authentication attempts.
version
Prior to version
Definition: maintenance.txt:1
$title
namespace and then decline to actually register it file or subcat img or subcat $title
Definition: hooks.txt:964
div
div
Definition: parserTests.txt:6593
by
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for and distribution as defined by Sections through of this document Licensor shall mean the copyright owner or entity authorized by the copyright owner that is granting the License Legal Entity shall mean the union of the acting entity and all other entities that control are controlled by or are under common control with that entity For the purposes of this definition control direct or to cause the direction or management of such whether by contract or including but not limited to software source documentation and configuration files Object form shall mean any form resulting from mechanical transformation or translation of a Source including but not limited to compiled object generated and conversions to other media types Work shall mean the work of whether in Source or Object made available under the as indicated by a copyright notice that is included in or attached to the whether in Source or Object that is based or other modifications as a an original work of authorship For the purposes of this Derivative Works shall not include works that remain separable or merely the Work and Derivative Works thereof Contribution shall mean any work of including the original version of the Work and any modifications or additions to that Work or Derivative Works that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner For the purposes of this submitted means any form of or written communication sent to the Licensor or its including but not limited to communication on electronic mailing source code control and issue tracking systems that are managed by
Definition: APACHE-LICENSE-2.0.txt:58
will
</td >< td > &</td >< td > t want your writing to be edited mercilessly and redistributed at will
Definition: All_system_messages.txt:914
PHP
The ContentHandler facility adds support for arbitrary content types on wiki instead of relying on wikitext for everything It was introduced in MediaWiki Each kind of and so on Built in content types as usual *javascript user provided javascript code *json simple implementation for use by etc *css user provided css code *text plain text In PHP
Definition: contenthandler.txt:15
PHPVersionCheck\$functionsExtensionsMapping
$functionsExtensionsMapping
Definition: PHPVersionCheck.php:31
style
Bar style
Definition: parserTests.txt:192
see
Some information about database access in MediaWiki By Tim January Database layout For information about the MediaWiki database such as a description of the tables and their please see
Definition: database.txt:18
PHPVersionCheck\getPHPInfo
getPHPInfo( $impl=false)
Returns the version of the installed php implementation.
Definition: PHPVersionCheck.php:78
some
I won t presume to tell you how to I m just describing the methods I chose to use for myself If you do choose to follow these it will probably be easier for you to collaborate with others on the but if you want to contribute without by all means do which work well I also use K &R brace matching style I know that s a religious issue for some
Definition: design.txt:79
copy
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to copy
Definition: LICENSE.txt:11
and
and(b) You must cause any modified files to carry prominent notices stating that You changed the files
on
We ve cleaned up the code here by removing clumps of infrequently used code and moving them off somewhere else It s much easier for someone working with this code to see what s _really_ going on
Definition: hooks.txt:86
are
The ContentHandler facility adds support for arbitrary content types on wiki instead of relying on wikitext for everything It was introduced in MediaWiki Each kind of and so on Built in content types are
Definition: contenthandler.txt:9
color
in the sidebar</td >< td > font color
Definition: All_system_messages.txt:425
or
or
Definition: APACHE-LICENSE-2.0.txt:114
as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:22
from
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for and distribution as defined by Sections through of this document Licensor shall mean the copyright owner or entity authorized by the copyright owner that is granting the License Legal Entity shall mean the union of the acting entity and all other entities that control are controlled by or are under common control with that entity For the purposes of this definition control direct or to cause the direction or management of such whether by contract or including but not limited to software source documentation and configuration files Object form shall mean any form resulting from mechanical transformation or translation of a Source including but not limited to compiled object generated and conversions to other media types Work shall mean the work of whether in Source or Object made available under the as indicated by a copyright notice that is included in or attached to the whether in Source or Object that is based or other modifications as a an original work of authorship For the purposes of this Derivative Works shall not include works that remain separable from
Definition: APACHE-LICENSE-2.0.txt:46
PHPVersionCheck\setEntryPoint
setEntryPoint( $entryPoint)
Definition: PHPVersionCheck.php:58
of
globals txt Globals are evil The original MediaWiki code relied on globals for processing context far too often MediaWiki development since then has been a story of slowly moving context out of global variables and into objects Storing processing context in object member variables allows those objects to be reused in a much more flexible way Consider the elegance of
database rows
Definition: globals.txt:10
that
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these but it might have such a feature in the future We handle these by creating a deferred update object and putting those objects on a global then executing the whole list after the page is displayed We don t do anything smart like collating updates to the same table or such because the list is almost always going to have just one item on if that
Definition: deferred.txt:13
PHPVersionCheck\checkRequiredPHPVersion
checkRequiredPHPVersion()
Displays an error, if the installed php version does not meet the minimum requirement.
Definition: PHPVersionCheck.php:105
PHPVersionCheck\$mwVersion
$mwVersion
Definition: PHPVersionCheck.php:30
$ext
$ext
Definition: router.php:55
href
shown</td >< td > a href
Definition: All_system_messages.txt:2667