MediaWiki REL1_29
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
28 /* @var string The number of the MediaWiki version used */
29 var $mwVersion = '1.29';
30 /* @var string The minimum php version for MediaWiki to run */
31 var $minimumVersionPHP = '5.5.9';
33 'mb_substr' => 'mbstring',
34 'utf8_encode' => 'xml',
35 'ctype_digit' => 'ctype',
36 'json_decode' => 'json',
37 'iconv' => 'iconv',
38 );
39
48 var $entryPoint = null;
49
60 $this->entryPoint = $entryPoint;
61 }
62
68 function getPHPImplVersion() {
69 return PHP_VERSION;
70 }
71
78 if (
79 !function_exists( 'version_compare' )
80 || version_compare( $this->getPHPImplVersion(), $this->minimumVersionPHP ) < 0
81 ) {
82 $shortText = "MediaWiki $this->mwVersion requires at least PHP version"
83 . " $this->minimumVersionPHP, you are using PHP {$this->getPHPImplVersion()}.";
84
85 $longText = "Error: You might be using on older PHP version. \n"
86 . "MediaWiki $this->mwVersion needs PHP $this->minimumVersionPHP or higher.\n\n"
87 . "Check if you have a newer php executable with a different name, "
88 . "such as php5.\n\n";
89
90 $longHtml = <<<HTML
91 Please consider <a href="http://www.php.net/downloads.php">upgrading your copy of PHP</a>.
92 PHP versions less than 5.5.0 are no longer supported by the PHP Group and will not receive
93 security or bugfix updates.
94 </p>
95 <p>
96 If for some reason you are unable to upgrade your PHP version, you will need to
97 <a href="https://www.mediawiki.org/wiki/Download">download</a> an older version
98 of MediaWiki from our website. See our
99 <a href="https://www.mediawiki.org/wiki/Compatibility#PHP">compatibility page</a>
100 for details of which versions are compatible with prior versions of PHP.
101HTML;
102 $this->triggerError( 'Supported PHP versions', $shortText, $longText, $longHtml );
103 }
104 }
105
112 if ( !file_exists( dirname( __FILE__ ) . '/../vendor/autoload.php' ) ) {
113 $shortText = "Installing some external dependencies (e.g. via composer) is required.";
114
115 $longText = "Error: You are missing some external dependencies. \n"
116 . "MediaWiki now also has some external dependencies that need to be installed\n"
117 . "via composer or from a separate git repo. Please see\n"
118 . "https://www.mediawiki.org/wiki/Download_from_Git#Fetch_external_libraries\n"
119 . "for help on installing the required components.";
120
121 $longHtml = <<<HTML
122 MediaWiki now also has some external dependencies that need to be installed via
123 composer or from a separate git repo. Please see
124 <a href="https://www.mediawiki.org/wiki/Download_from_Git#Fetch_external_libraries">mediawiki.org</a>
125 for help on installing the required components.
126HTML;
127
128 $this->triggerError( 'External dependencies', $shortText, $longText, $longHtml );
129 }
130 }
131
138 $missingExtensions = array();
139 foreach ( $this->functionsExtensionsMapping as $function => $extension ) {
140 if ( !function_exists( $function ) ) {
141 $missingExtensions[] = $extension;
142 }
143 }
144
145 if ( $missingExtensions ) {
146 $shortText = "Installing some PHP extensions is required.";
147
148 $missingExtText = '';
149 $missingExtHtml = '';
150 $baseUrl = 'https://secure.php.net';
151 foreach ( $missingExtensions as $ext ) {
152 $missingExtText .= " * $ext <$baseUrl/$ext>\n";
153 $missingExtHtml .= "<li><b>$ext</b> "
154 . "(<a href=\"$baseUrl/$ext\">more information</a>)</li>";
155 }
156
157 $cliText = "Error: Missing one or more required components of PHP.\n"
158 . "You are missing a required extension to PHP that MediaWiki needs.\n"
159 . "Please install:\n" . $missingExtText;
160
161 $longHtml = <<<HTML
162 You are missing a required extension to PHP that MediaWiki
163 requires to run. Please install:
164 <ul>
165 $missingExtHtml
166 </ul>
167HTML;
168
169 $this->triggerError( 'Required components', $shortText, $cliText, $longHtml );
170 }
171 }
172
176 function outputHTMLHeader() {
177 $protocol = isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0';
178
179 header( "$protocol 500 MediaWiki configuration Error" );
180 // Don't cache error pages! They cause no end of trouble...
181 header( 'Cache-control: none' );
182 header( 'Pragma: no-cache' );
183 }
184
193 function getIndexErrorOutput( $title, $longHtml, $shortText ) {
194 $pathinfo = pathinfo( $_SERVER['SCRIPT_NAME'] );
195 if ( $this->entryPoint == 'mw-config/index.php' ) {
196 $dirname = dirname( $pathinfo['dirname'] );
197 } else {
198 $dirname = $pathinfo['dirname'];
199 }
200 $encLogo =
201 htmlspecialchars( str_replace( '//', '/', $dirname . '/' ) .
202 'resources/assets/mediawiki.png' );
203 $shortHtml = htmlspecialchars( $shortText );
204
205 header( 'Content-type: text/html; charset=UTF-8' );
206
207 $finalOutput = <<<HTML
208<!DOCTYPE html>
209<html lang="en" dir="ltr">
210 <head>
211 <meta charset="UTF-8" />
212 <title>MediaWiki {$this->mwVersion}</title>
213 <style media='screen'>
214 body {
215 color: #000;
216 background-color: #fff;
217 font-family: sans-serif;
218 padding: 2em;
219 text-align: center;
220 }
221 p, img, h1, h2, ul {
222 text-align: left;
223 margin: 0.5em 0 1em;
224 }
225 h1 {
226 font-size: 120%;
227 }
228 h2 {
229 font-size: 110%;
230 }
231 </style>
232 </head>
233 <body>
234 <img src="{$encLogo}" alt='The MediaWiki logo' />
235 <h1>MediaWiki {$this->mwVersion} internal error</h1>
236 <div class='error'>
237 <p>
238 {$shortHtml}
239 </p>
240 <h2>{$title}</h2>
241 <p>
242 {$longHtml}
243 </p>
244 </div>
245 </body>
246</html>
247HTML;
248
249 return $finalOutput;
250 }
251
265 function triggerError( $title, $shortText, $longText, $longHtml ) {
266 switch ( $this->entryPoint ) {
267 case 'cli':
268 $finalOutput = $longText;
269 break;
270 case 'index.php':
271 case 'mw-config/index.php':
272 $this->outputHTMLHeader();
273 $finalOutput = $this->getIndexErrorOutput( $title, $longHtml, $shortText );
274 break;
275 case 'load.php':
276 $this->outputHTMLHeader();
277 $finalOutput = "/* $shortText */";
278 break;
279 default:
280 $this->outputHTMLHeader();
281 // Handle everything that's not index.php
282 $finalOutput = $shortText;
283 }
284
285 echo "$finalOutput\n";
286 die( 1 );
287 }
288}
289
297function wfEntryPointCheck( $entryPoint ) {
298 $phpVersionCheck = new PHPVersionCheck();
299 $phpVersionCheck->setEntryPoint( $entryPoint );
300 $phpVersionCheck->checkRequiredPHPVersion();
301 $phpVersionCheck->checkVendorExistence();
302 $phpVersionCheck->checkExtensionExistence();
303}
and(b) You must cause any modified files to carry prominent notices stating that You changed the files
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
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
shown</td >< td > a href
in the sidebar</td >< td > font color
</td >< td > &</td >< td > t want your writing to be edited mercilessly and redistributed at will
wfEntryPointCheck( $entryPoint)
Check php version and that external dependencies are installed, and display an informative error if e...
triggerError( $title, $shortText, $longText, $longHtml)
Display something vaguely comprehensible in the event of a totally unrecoverable error.
outputHTMLHeader()
Output headers that prevents error pages to be cached.
getPHPImplVersion()
Returns the version of the installed php implementation.
string $entryPoint
Which entry point we are protecting.
checkExtensionExistence()
Displays an error, if a PHP extension does not exist.
checkRequiredPHPVersion()
Displays an error, if the installed php version does not meet the minimum requirement.
checkVendorExistence()
Displays an error, if the vendor/autoload.php file could not be found.
getIndexErrorOutput( $title, $longHtml, $shortText)
Returns an error page, which is suitable for output to the end user via a web browser.
setEntryPoint( $entryPoint)
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
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
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
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)
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
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
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
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
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
the array() calling protocol came about after MediaWiki 1.4rc1.
namespace and then decline to actually register it file or subcat img or subcat $title
Definition hooks.txt:964
do that in ParserLimitReportFormat instead use this to modify the parameters of the image and a DIV can begin in one section and end in another Make sure your code can handle that case gracefully See the EditSectionClearerLink extension for an example zero but section is usually empty its values are the globals values before the output is cached my talk page
Definition hooks.txt:2579
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:88
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
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
Prior to version
A helper class for throttling authentication attempts.
title
Bar style