MediaWiki  1.30.1
PHPVersionCheck.php
Go to the documentation of this file.
1 <?php
2 // @codingStandardsIgnoreFile Generic.Arrays.DisallowLongArraySyntax
3 // @codingStandardsIgnoreFile Generic.Files.LineLength
4 // @codingStandardsIgnoreFile MediaWiki.Usage.DirUsage.FunctionFound
31  /* @var string The number of the MediaWiki version used */
32  var $mwVersion = '1.30';
34  'mb_substr' => 'mbstring',
35  'utf8_encode' => 'xml',
36  'ctype_digit' => 'ctype',
37  'json_decode' => 'json',
38  'iconv' => 'iconv',
39  'mime_content_type' => 'fileinfo',
40  );
41 
50  var $entryPoint = null;
51 
61  function setEntryPoint( $entryPoint ) {
62  $this->entryPoint = $entryPoint;
63  }
64 
81  function getPHPInfo( $impl = false ) {
82  if (
83  ( defined( 'HHVM_VERSION' ) && $impl !== 'PHP' ) ||
84  $impl === 'HHVM'
85  ) {
86  return array(
87  'implementation' => 'HHVM',
88  'version' => defined( 'HHVM_VERSION' ) ? HHVM_VERSION : 'undefined',
89  'vendor' => 'Facebook',
90  'upstreamSupported' => '3.6.5',
91  'minSupported' => '3.6.5',
92  'upgradeURL' => 'https://docs.hhvm.com/hhvm/installation/introduction',
93  );
94  }
95  return array(
96  'implementation' => 'PHP',
97  'version' => PHP_VERSION,
98  'vendor' => 'the PHP Group',
99  'upstreamSupported' => '5.5.0',
100  'minSupported' => '5.5.9',
101  'upgradeURL' => 'https://secure.php.net/downloads.php',
102  );
103  }
104 
111  $phpInfo = $this->getPHPInfo();
112  $minimumVersion = $phpInfo['minSupported'];
113  $otherInfo = $this->getPHPInfo( $phpInfo['implementation'] === 'HHVM' ? 'PHP' : 'HHVM' );
114  if (
115  !function_exists( 'version_compare' )
116  || version_compare( $phpInfo['version'], $minimumVersion ) < 0
117  ) {
118  $shortText = "MediaWiki $this->mwVersion requires at least {$phpInfo['implementation']}"
119  . " version $minimumVersion or {$otherInfo['implementation']} version "
120  . "{$otherInfo['minSupported']}, you are using {$phpInfo['implementation']} "
121  . "{$phpInfo['version']}.";
122 
123  $longText = "Error: You might be using an older {$phpInfo['implementation']} version. \n"
124  . "MediaWiki $this->mwVersion needs {$phpInfo['implementation']}"
125  . " $minimumVersion or higher or {$otherInfo['implementation']} version "
126  . "{$otherInfo['minSupported']}.\n\nCheck if you have a"
127  . " newer php executable with a different name, such as php5.\n\n";
128 
129  $longHtml = <<<HTML
130  Please consider <a href="{$phpInfo['upgradeURL']}">upgrading your copy of
131  {$phpInfo['implementation']}</a>.
132  {$phpInfo['implementation']} versions less than {$phpInfo['upstreamSupported']} are no
133  longer supported by {$phpInfo['vendor']} and will not receive
134  security or bugfix updates.
135  </p>
136  <p>
137  If for some reason you are unable to upgrade your {$phpInfo['implementation']} version,
138  you will need to <a href="https://www.mediawiki.org/wiki/Download">download</a> an
139  older version of MediaWiki from our website.
140  See our <a href="https://www.mediawiki.org/wiki/Compatibility#PHP">compatibility page</a>
141  for details of which versions are compatible with prior versions of {$phpInfo['implementation']}.
142 HTML;
143  $this->triggerError(
144  "Supported {$phpInfo['implementation']} versions",
145  $shortText,
146  $longText,
147  $longHtml
148  );
149  }
150  }
151 
157  function checkVendorExistence() {
158  if ( !file_exists( dirname( __FILE__ ) . '/../vendor/autoload.php' ) ) {
159  $shortText = "Installing some external dependencies (e.g. via composer) is required.";
160 
161  $longText = "Error: You are missing some external dependencies. \n"
162  . "MediaWiki now also has some external dependencies that need to be installed\n"
163  . "via composer or from a separate git repo. Please see\n"
164  . "https://www.mediawiki.org/wiki/Download_from_Git#Fetch_external_libraries\n"
165  . "for help on installing the required components.";
166 
167  $longHtml = <<<HTML
168  MediaWiki now also has some external dependencies that need to be installed via
169  composer or from a separate git repo. Please see
170  <a href="https://www.mediawiki.org/wiki/Download_from_Git#Fetch_external_libraries">mediawiki.org</a>
171  for help on installing the required components.
172 HTML;
173 
174  $this->triggerError( 'External dependencies', $shortText, $longText, $longHtml );
175  }
176  }
177 
184  $missingExtensions = array();
185  foreach ( $this->functionsExtensionsMapping as $function => $extension ) {
186  if ( !function_exists( $function ) ) {
187  $missingExtensions[] = $extension;
188  }
189  }
190 
191  if ( $missingExtensions ) {
192  $shortText = "Installing some PHP extensions is required.";
193 
194  $missingExtText = '';
195  $missingExtHtml = '';
196  $baseUrl = 'https://secure.php.net';
197  foreach ( $missingExtensions as $ext ) {
198  $missingExtText .= " * $ext <$baseUrl/$ext>\n";
199  $missingExtHtml .= "<li><b>$ext</b> "
200  . "(<a href=\"$baseUrl/$ext\">more information</a>)</li>";
201  }
202 
203  $cliText = "Error: Missing one or more required components of PHP.\n"
204  . "You are missing a required extension to PHP that MediaWiki needs.\n"
205  . "Please install:\n" . $missingExtText;
206 
207  $longHtml = <<<HTML
208  You are missing a required extension to PHP that MediaWiki
209  requires to run. Please install:
210  <ul>
211  $missingExtHtml
212  </ul>
213 HTML;
214 
215  $this->triggerError( 'Required components', $shortText, $cliText, $longHtml );
216  }
217  }
218 
222  function outputHTMLHeader() {
223  $protocol = isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0';
224 
225  header( "$protocol 500 MediaWiki configuration Error" );
226  // Don't cache error pages! They cause no end of trouble...
227  header( 'Cache-control: none' );
228  header( 'Pragma: no-cache' );
229  }
230 
239  function getIndexErrorOutput( $title, $longHtml, $shortText ) {
240  $pathinfo = pathinfo( $_SERVER['SCRIPT_NAME'] );
241  if ( $this->entryPoint == 'mw-config/index.php' ) {
242  $dirname = dirname( $pathinfo['dirname'] );
243  } else {
244  $dirname = $pathinfo['dirname'];
245  }
246  $encLogo =
247  htmlspecialchars( str_replace( '//', '/', $dirname . '/' ) .
248  'resources/assets/mediawiki.png' );
249  $shortHtml = htmlspecialchars( $shortText );
250 
251  header( 'Content-type: text/html; charset=UTF-8' );
252 
253  $finalOutput = <<<HTML
254 <!DOCTYPE html>
255 <html lang="en" dir="ltr">
256  <head>
257  <meta charset="UTF-8" />
258  <title>MediaWiki {$this->mwVersion}</title>
259  <style media='screen'>
260  body {
261  color: #000;
262  background-color: #fff;
263  font-family: sans-serif;
264  padding: 2em;
265  text-align: center;
266  }
267  p, img, h1, h2, ul {
268  text-align: left;
269  margin: 0.5em 0 1em;
270  }
271  h1 {
272  font-size: 120%;
273  }
274  h2 {
275  font-size: 110%;
276  }
277  </style>
278  </head>
279  <body>
280  <img src="{$encLogo}" alt='The MediaWiki logo' />
281  <h1>MediaWiki {$this->mwVersion} internal error</h1>
282  <div class='error'>
283  <p>
284  {$shortHtml}
285  </p>
286  <h2>{$title}</h2>
287  <p>
288  {$longHtml}
289  </p>
290  </div>
291  </body>
292 </html>
293 HTML;
294 
295  return $finalOutput;
296  }
297 
311  function triggerError( $title, $shortText, $longText, $longHtml ) {
312  switch ( $this->entryPoint ) {
313  case 'cli':
314  $finalOutput = $longText;
315  break;
316  case 'index.php':
317  case 'mw-config/index.php':
318  $this->outputHTMLHeader();
319  $finalOutput = $this->getIndexErrorOutput( $title, $longHtml, $shortText );
320  break;
321  case 'load.php':
322  $this->outputHTMLHeader();
323  $finalOutput = "/* $shortText */";
324  break;
325  default:
326  $this->outputHTMLHeader();
327  // Handle everything that's not index.php
328  $finalOutput = $shortText;
329  }
330 
331  echo "$finalOutput\n";
332  die( 1 );
333  }
334 }
335 
343 function wfEntryPointCheck( $entryPoint ) {
344  $phpVersionCheck = new PHPVersionCheck();
345  $phpVersionCheck->setEntryPoint( $entryPoint );
346  $phpVersionCheck->checkRequiredPHPVersion();
347  $phpVersionCheck->checkVendorExistence();
348  $phpVersionCheck->checkExtensionExistence();
349 }
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:239
copy
and give any other recipients of the Program a copy of this License along with the Program You may charge a fee for the physical act of transferring a copy
Definition: COPYING.txt:87
you
and give any other recipients of the Program a copy of this License along with the Program You may charge a fee for the physical act of transferring a and you may at your option offer warranty protection in exchange for a fee You may modify your copy or copies of the Program or any portion of thus forming a work based on the and copy and distribute such modifications or work under the terms of Section provided that you also meet all of these that in whole or in part contains or is derived from the Program or any part to be licensed as a whole at no charge to all third parties under the terms of this License c If the modified program normally reads commands interactively when you must cause when started running for such interactive use in the most ordinary to print or display an announcement including an appropriate copyright notice and a notice that there is no and telling the user how to view a copy of this and can be reasonably considered independent and separate works in then this and its do not apply to those sections when you distribute them as separate works But when you distribute the same sections as part of a whole which is a work based on the the distribution of the whole must be on the terms of this whose permissions for other licensees extend to the entire and thus to each and every part regardless of who wrote it it is not the intent of this section to claim rights or contest your rights to work written entirely by you
Definition: COPYING.txt:117
captcha-old.help
help
Definition: captcha-old.py:211
version
Prior to version
Definition: maintenance.txt:1
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:12
captcha-old.font
font
Definition: captcha-old.py:244
PHPVersionCheck\checkVendorExistence
checkVendorExistence()
Displays an error, if the vendor/autoload.php file could not be found.
Definition: PHPVersionCheck.php:157
PHPVersionCheck\checkExtensionExistence
checkExtensionExistence()
Displays an error, if a PHP extension does not exist.
Definition: PHPVersionCheck.php:183
page
target page
Definition: All_system_messages.txt:1267
PHPVersionCheck\$entryPoint
string $entryPoint
Which entry point we are protecting.
Definition: PHPVersionCheck.php:50
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:35
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:279
PHPVersionCheck\triggerError
triggerError( $title, $shortText, $longText, $longHtml)
Display something vaguely comprehensible in the event of a totally unrecoverable error.
Definition: PHPVersionCheck.php:311
title
to move a page</td >< td > &*You are moving the page across *A non empty talk page already exists under the new or *You uncheck the box below In those you will have to move or merge the page manually if desired</td >< td > be sure to &You are responsible for making sure that links continue to point where they are supposed to go Note that the page will &a page at the new title
Definition: All_system_messages.txt:2696
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)
$title
namespace and then decline to actually register it file or subcat img or subcat $title
Definition: hooks.txt:932
a
</source > ! result< div class="mw-highlight mw-content-ltr" dir="ltr">< pre >< span ></span >< span class="kd"> var</span >< span class="nx"> a</span >< span class="p"></span ></pre ></div > ! end ! test Multiline< source/> in lists !input *< source > a b</source > *foo< source > a b</source > ! html< ul >< li >< div class="mw-highlight mw-content-ltr" dir="ltr">< pre > a b</pre ></div ></li ></ul >< ul >< li > foo< div class="mw-highlight mw-content-ltr" dir="ltr">< pre > a b</pre ></div ></li ></ul > ! html tidy< ul >< li >< div class="mw-highlight mw-content-ltr" dir="ltr">< pre > a b</pre ></div ></li ></ul >< ul >< li > foo< div class="mw-highlight mw-content-ltr" dir="ltr">< pre > a b</pre ></div ></li ></ul > ! end ! test Custom attributes !input< source lang="javascript" id="foo" class="bar" dir="rtl" style="font-size: larger;"> var a
Definition: parserTests.txt:89
PHPVersionCheck
Definition: PHPVersionCheck.php:30
PHPVersionCheck\outputHTMLHeader
outputHTMLHeader()
Output headers that prevents error pages to be cached.
Definition: PHPVersionCheck.php:222
not
if not
Definition: COPYING.txt:307
MediaWiki
A helper class for throttling authentication attempts.
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:49
run
and give any other recipients of the Program a copy of this License along with the Program You may charge a fee for the physical act of transferring a and you may at your option offer warranty protection in exchange for a fee You may modify your copy or copies of the Program or any portion of thus forming a work based on the and copy and distribute such modifications or work under the terms of Section provided that you also meet all of these that in whole or in part contains or is derived from the Program or any part to be licensed as a whole at no charge to all third parties under the terms of this License c If the modified program normally reads commands interactively when run
Definition: COPYING.txt:87
will
</td >< td > &</td >< td > t want your writing to be edited mercilessly and redistributed at will
Definition: All_system_messages.txt:914
or
or
Definition: COPYING.txt:140
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:5
PHPVersionCheck\$functionsExtensionsMapping
$functionsExtensionsMapping
Definition: PHPVersionCheck.php:33
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:2
PHPVersionCheck\getPHPInfo
getPHPInfo( $impl=false)
Returns the version of the installed php implementation.
Definition: PHPVersionCheck.php:81
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:84
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
captcha-old.p
p
Definition: captcha-old.py:275
style
Bar style
Definition: parserTests.txt:192
reason
c Accompany it with the information you received as to the offer to distribute corresponding source complete source code means all the source code for all modules it plus any associated interface definition plus the scripts used to control compilation and installation of the executable as a special the source code distributed need not include anything that is normally and so on of the operating system on which the executable unless that component itself accompanies the executable If distribution of executable or object code is made by offering access to copy from a designated then offering equivalent access to copy the source code from the same place counts as distribution of the source even though third parties are not compelled to copy the source along with the object code You may not or distribute the Program except as expressly provided under this License Any attempt otherwise to sublicense or distribute the Program is and will automatically terminate your rights under this License parties who have received or from you under this License will not have their licenses terminated so long as such parties remain in full compliance You are not required to accept this since you have not signed it nothing else grants you permission to modify or distribute the Program or its derivative works These actions are prohibited by law if you do not accept this License by modifying or distributing the you indicate your acceptance of this License to do and all its terms and conditions for distributing or modifying the Program or works based on it Each time you redistribute the the recipient automatically receives a license from the original licensor to distribute or modify the Program subject to these terms and conditions You may not impose any further restrictions on the recipients exercise of the rights granted herein You are not responsible for enforcing compliance by third parties to this License as a consequence of a court judgment or allegation of patent infringement or for any other reason(not limited to patent issues)
and
and that you know you can do these things To protect your we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights These restrictions translate to certain responsibilities for you if you distribute copies of the or if you modify it For if you distribute copies of such a whether gratis or for a you must give the recipients all the rights that you have You must make sure that receive or can get the source code And you must show them these terms so they know their rights We protect your rights with two and(2) offer you this license which gives you legal permission to copy
$ext
$ext
Definition: NoLocalSettings.php:25
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:5
color
in the sidebar</td >< td > font color
Definition: All_system_messages.txt:425
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:9
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:43
PHPVersionCheck\setEntryPoint
setEntryPoint( $entryPoint)
Definition: PHPVersionCheck.php:61
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
Definition: globals.txt:10
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:2581
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:11
PHPVersionCheck\checkRequiredPHPVersion
checkRequiredPHPVersion()
Displays an error, if the installed php version does not meet the minimum requirement.
Definition: PHPVersionCheck.php:110
PHPVersionCheck\$mwVersion
$mwVersion
Definition: PHPVersionCheck.php:32
href
shown</td >< td > a href
Definition: All_system_messages.txt:2667
array
the array() calling protocol came about after MediaWiki 1.4rc1.
If
c Accompany it with the information you received as to the offer to distribute corresponding source complete source code means all the source code for all modules it plus any associated interface definition plus the scripts used to control compilation and installation of the executable as a special the source code distributed need not include anything that is normally and so on of the operating system on which the executable unless that component itself accompanies the executable If distribution of executable or object code is made by offering access to copy from a designated then offering equivalent access to copy the source code from the same place counts as distribution of the source even though third parties are not compelled to copy the source along with the object code You may not or distribute the Program except as expressly provided under this License Any attempt otherwise to sublicense or distribute the Program is and will automatically terminate your rights under this License parties who have received or from you under this License will not have their licenses terminated so long as such parties remain in full compliance You are not required to accept this since you have not signed it nothing else grants you permission to modify or distribute the Program or its derivative works These actions are prohibited by law if you do not accept this License by modifying or distributing the you indicate your acceptance of this License to do and all its terms and conditions for distributing or modifying the Program or works based on it Each time you redistribute the the recipient automatically receives a license from the original licensor to distribute or modify the Program subject to these terms and conditions You may not impose any further restrictions on the recipients exercise of the rights granted herein You are not responsible for enforcing compliance by third parties to this License If
Definition: COPYING.txt:191