MediaWiki  master
PHPVersionCheck.php
Go to the documentation of this file.
1 <?php
21 // phpcs:disable Generic.Arrays.DisallowLongArraySyntax,PSR2.Classes.PropertyDeclaration,MediaWiki.Usage.DirUsage
22 // phpcs:disable Squiz.Scope.MemberVarScope.Missing,Squiz.Scope.MethodScope.Missing
23 // @phan-file-suppress PhanPluginDuplicateConditionalNullCoalescing
38  /* @var string The number of the MediaWiki version used. */
39  var $mwVersion = '1.34';
40 
41  /* @var array A mapping of PHP functions to PHP extensions. */
43  'mb_substr' => 'mbstring',
44  'xml_parser_create' => 'xml',
45  'ctype_digit' => 'ctype',
46  'json_decode' => 'json',
47  'iconv' => 'iconv',
48  'mime_content_type' => 'fileinfo',
49  );
50 
54  var $format = 'text';
55 
59  var $scriptPath = '/';
60 
66  function setFormat( $format ) {
67  $this->format = $format;
68  }
69 
75  function setScriptPath( $scriptPath ) {
76  $this->scriptPath = $scriptPath;
77  }
78 
95  function getPHPInfo( $impl = false ) {
96  if (
97  ( defined( 'HHVM_VERSION' ) && $impl !== 'PHP' ) ||
98  $impl === 'HHVM'
99  ) {
100  return array(
101  'implementation' => 'HHVM',
102  'version' => defined( 'HHVM_VERSION' ) ? HHVM_VERSION : 'undefined',
103  'vendor' => 'Facebook',
104  'upstreamSupported' => '3.18.5',
105  'minSupported' => '3.18.5',
106  'upgradeURL' => 'https://docs.hhvm.com/hhvm/installation/introduction',
107  );
108  }
109  return array(
110  'implementation' => 'PHP',
111  'version' => PHP_VERSION,
112  'vendor' => 'the PHP Group',
113  'upstreamSupported' => '5.6.0',
114  'minSupported' => '7.0.13',
115  'upgradeURL' => 'https://www.php.net/downloads.php',
116  );
117  }
118 
123  $phpInfo = $this->getPHPInfo();
124  $minimumVersion = $phpInfo['minSupported'];
125  $otherInfo = $this->getPHPInfo( $phpInfo['implementation'] === 'HHVM' ? 'PHP' : 'HHVM' );
126  if ( version_compare( $phpInfo['version'], $minimumVersion ) < 0 ) {
127  $shortText = "MediaWiki $this->mwVersion requires at least {$phpInfo['implementation']}"
128  . " version $minimumVersion or {$otherInfo['implementation']} version "
129  . "{$otherInfo['minSupported']}, you are using {$phpInfo['implementation']} "
130  . "{$phpInfo['version']}.";
131 
132  $longText = "Error: You might be using an older {$phpInfo['implementation']} version "
133  . "({$phpInfo['implementation']} {$phpInfo['version']}). \n"
134  . "MediaWiki $this->mwVersion needs {$phpInfo['implementation']}"
135  . " $minimumVersion or higher or {$otherInfo['implementation']} version "
136  . "{$otherInfo['minSupported']}.\n\nCheck if you have a"
137  . " newer PHP executable with a different name.\n\n";
138 
139  // phpcs:disable Generic.Files.LineLength
140  $longHtml = <<<HTML
141  Please consider <a href="{$phpInfo['upgradeURL']}">upgrading your copy of
142  {$phpInfo['implementation']}</a>.
143  {$phpInfo['implementation']} versions less than {$phpInfo['upstreamSupported']} are no
144  longer supported by {$phpInfo['vendor']} and will not receive
145  security or bugfix updates.
146  </p>
147  <p>
148  If for some reason you are unable to upgrade your {$phpInfo['implementation']} version,
149  you will need to <a href="https://www.mediawiki.org/wiki/Download">download</a> an
150  older version of MediaWiki from our website.
151  See our <a href="https://www.mediawiki.org/wiki/Compatibility#PHP">compatibility page</a>
152  for details of which versions are compatible with prior versions of {$phpInfo['implementation']}.
153 HTML;
154  // phpcs:enable Generic.Files.LineLength
155  $this->triggerError(
156  "Supported {$phpInfo['implementation']} versions",
157  $shortText,
158  $longText,
159  $longHtml
160  );
161  }
162  }
163 
167  function checkVendorExistence() {
168  if ( !file_exists( dirname( __FILE__ ) . '/../vendor/autoload.php' ) ) {
169  $shortText = "Installing some external dependencies (e.g. via composer) is required.";
170 
171  $longText = "Error: You are missing some external dependencies. \n"
172  . "MediaWiki now also has some external dependencies that need to be installed\n"
173  . "via composer or from a separate git repo. Please see\n"
174  . "https://www.mediawiki.org/wiki/Download_from_Git#Fetch_external_libraries\n"
175  . "for help on installing the required components.";
176 
177  // phpcs:disable Generic.Files.LineLength
178  $longHtml = <<<HTML
179  MediaWiki now also has some external dependencies that need to be installed via
180  composer or from a separate git repo. Please see
181  <a href="https://www.mediawiki.org/wiki/Download_from_Git#Fetch_external_libraries">mediawiki.org</a>
182  for help on installing the required components.
183 HTML;
184  // phpcs:enable Generic.Files.LineLength
185 
186  $this->triggerError( 'External dependencies', $shortText, $longText, $longHtml );
187  }
188  }
189 
194  $missingExtensions = array();
195  foreach ( $this->functionsExtensionsMapping as $function => $extension ) {
196  if ( !function_exists( $function ) ) {
197  $missingExtensions[] = $extension;
198  }
199  }
200 
201  if ( $missingExtensions ) {
202  $shortText = "Installing some PHP extensions is required.";
203 
204  $missingExtText = '';
205  $missingExtHtml = '';
206  $baseUrl = 'https://www.php.net';
207  foreach ( $missingExtensions as $ext ) {
208  $missingExtText .= " * $ext <$baseUrl/$ext>\n";
209  $missingExtHtml .= "<li><b>$ext</b> "
210  . "(<a href=\"$baseUrl/$ext\">more information</a>)</li>";
211  }
212 
213  $cliText = "Error: Missing one or more required components of PHP.\n"
214  . "You are missing a required extension to PHP that MediaWiki needs.\n"
215  . "Please install:\n" . $missingExtText;
216 
217  $longHtml = <<<HTML
218  You are missing a required extension to PHP that MediaWiki
219  requires to run. Please install:
220  <ul>
221  $missingExtHtml
222  </ul>
223 HTML;
224 
225  $this->triggerError( 'Required components', $shortText, $cliText, $longHtml );
226  }
227  }
228 
232  function outputHTMLHeader() {
233  $protocol = isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0';
234 
235  header( "$protocol 500 MediaWiki configuration Error" );
236  // Don't cache error pages! They cause no end of trouble...
237  header( 'Cache-control: none' );
238  header( 'Pragma: no-cache' );
239  }
240 
249  function getIndexErrorOutput( $title, $longHtml, $shortText ) {
250  $encLogo =
251  htmlspecialchars( str_replace( '//', '/', $this->scriptPath . '/' ) .
252  'resources/assets/mediawiki.png' );
253  $shortHtml = htmlspecialchars( $shortText );
254 
255  header( 'Content-type: text/html; charset=UTF-8' );
256 
257  $finalOutput = <<<HTML
258 <!DOCTYPE html>
259 <html lang="en" dir="ltr">
260  <head>
261  <meta charset="UTF-8" />
262  <title>MediaWiki {$this->mwVersion}</title>
263  <style media='screen'>
264  body {
265  color: #000;
266  background-color: #fff;
267  font-family: sans-serif;
268  padding: 2em;
269  text-align: center;
270  }
271  p, img, h1, h2, ul {
272  text-align: left;
273  margin: 0.5em 0 1em;
274  }
275  h1 {
276  font-size: 120%;
277  }
278  h2 {
279  font-size: 110%;
280  }
281  </style>
282  </head>
283  <body>
284  <img src="{$encLogo}" alt='The MediaWiki logo' />
285  <h1>MediaWiki {$this->mwVersion} internal error</h1>
286  <div class='error'>
287  <p>
288  {$shortHtml}
289  </p>
290  <h2>{$title}</h2>
291  <p>
292  {$longHtml}
293  </p>
294  </div>
295  </body>
296 </html>
297 HTML;
298 
299  return $finalOutput;
300  }
301 
315  function triggerError( $title, $shortText, $longText, $longHtml ) {
316  if ( $this->format === 'html' ) {
317  // Used by index.php and mw-config/index.php
318  $this->outputHTMLHeader();
319  $finalOutput = $this->getIndexErrorOutput( $title, $longHtml, $shortText );
320  } else {
321  // Used by Maintenance.php (CLI)
322  $finalOutput = $longText;
323  }
324 
325  echo "$finalOutput\n";
326  die( 1 );
327  }
328 }
329 
337 function wfEntryPointCheck( $format = 'text', $scriptPath = '/' ) {
338  $phpVersionCheck = new PHPVersionCheck();
339  $phpVersionCheck->setFormat( $format );
340  $phpVersionCheck->setScriptPath( $scriptPath );
341  $phpVersionCheck->checkRequiredPHPVersion();
342  $phpVersionCheck->checkVendorExistence();
343  $phpVersionCheck->checkExtensionExistence();
344 }
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:10
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:11
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:2621
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
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
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
def download(url, dest)
Definition: Makefile.py:47
wfEntryPointCheck( $format='text', $scriptPath='/')
Check PHP version and that external dependencies are installed, and display an informative error if e...
setScriptPath( $scriptPath)
Set the script path used for images in HTML-formatted errors.
A helper class for throttling authentication attempts.
target page
title
This list may contain false positives That usually means there is additional text with links below the first Each row contains links to the first and second as well as the first line of the second redirect text
outputHTMLHeader()
Output headers that prevents error pages to be cached.
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
Prior to version
Definition: maintenance.txt:1
setFormat( $format)
Set the format used for errors.
getIndexErrorOutput( $title, $longHtml, $shortText)
Returns an error page, which is suitable for output to the end user via a web browser.
shown</td >< td > a href
and(b) You must cause any modified files to carry prominent notices stating that You changed the files
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:2
namespace and then decline to actually register it file or subcat img or subcat $title
Definition: hooks.txt:912
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
checkVendorExistence()
Displays an error, if the vendor/autoload.php file could not be found.
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:9
checkExtensionExistence()
Displays an error, if a PHP extension does not exist.
in the sidebar</td >< td > font color
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:35
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)
Bar style
if(!is_readable( $file)) $ext
Definition: router.php:48
Using a hook running we can avoid having all this option specific stuff in our mainline code Using the function 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:77
</td >< td > &</td >< td > t want your writing to be edited mercilessly and redistributed at will
checkRequiredPHPVersion()
Displays an error, if the installed PHP version does not meet the minimum requirement.
triggerError( $title, $shortText, $longText, $longHtml)
Display something vaguely comprehensible in the event of a totally unrecoverable error.
getPHPInfo( $impl=false)
Return the version of the installed PHP implementation.
if the prop value should be in the metadata multi language array format
Definition: hooks.txt:1623