Expose $wgMaxArticleSize in siteinfo query api
[mediawiki.git] / includes / PHPVersionCheck.php
blob018c6f83dcb5214ca2b9313a9d9b352a4d3e9d2b
1 <?php
2 /**
3 * Check PHP Version, as well as for composer dependencies in entry points,
4 * and display something vaguely comprehensible in the event of a totally
5 * unrecoverable error.
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 * http://www.gnu.org/copyleft/gpl.html
22 * @file
25 /**
26 * Check php version and that external dependencies are installed, and
27 * display an informative error if either condition is not satisfied.
29 * @note Since we can't rely on anything, the minimum PHP versions and MW current
30 * version are hardcoded here
32 function wfEntryPointCheck( $entryPoint ) {
33 $mwVersion = '1.28';
34 $minimumVersionPHP = '5.5.9';
35 $phpVersion = PHP_VERSION;
37 if ( !function_exists( 'version_compare' )
38 || version_compare( $phpVersion, $minimumVersionPHP ) < 0
39 ) {
40 wfPHPVersionError( $entryPoint, $mwVersion, $minimumVersionPHP, $phpVersion );
43 // @codingStandardsIgnoreStart MediaWiki.Usage.DirUsage.FunctionFound
44 if ( !file_exists( dirname( __FILE__ ) . '/../vendor/autoload.php' ) ) {
45 // @codingStandardsIgnoreEnd
46 wfMissingVendorError( $entryPoint, $mwVersion );
49 // List of functions and their associated PHP extension to check for
50 // @codingStandardsIgnoreStart Generic.Arrays.DisallowLongArraySyntax
51 $extensions = array(
52 'mb_substr' => 'mbstring',
53 'utf8_encode' => 'xml',
54 'ctype_digit' => 'ctype',
55 'json_decode' => 'json',
56 'iconv' => 'iconv',
58 // List of extensions we're missing
59 $missingExtensions = array();
60 // @codingStandardsIgnoreEnd
62 foreach ( $extensions as $function => $extension ) {
63 if ( !function_exists( $function ) ) {
64 $missingExtensions[] = $extension;
68 if ( $missingExtensions ) {
69 wfMissingExtensions( $entryPoint, $mwVersion, $missingExtensions );
73 /**
74 * Display something vaguely comprehensible in the event of a totally unrecoverable error.
75 * Does not assume access to *anything*; no globals, no autoloader, no database, no localisation.
76 * Safe for PHP4 (and putting this here means that WebStart.php and GlobalSettings.php
77 * no longer need to be).
79 * Calling this function kills execution immediately.
81 * @param string $type Which entry point we are protecting. One of:
82 * - index.php
83 * - load.php
84 * - api.php
85 * - mw-config/index.php
86 * - cli
87 * @param string $mwVersion The number of the MediaWiki version used
88 * @param string $title HTML code to be put within an <h2> tag
89 * @param string $shortText
90 * @param string $longText
91 * @param string $longHtml
93 function wfGenericError( $type, $mwVersion, $title, $shortText, $longText, $longHtml ) {
94 $protocol = isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0';
96 if ( $type == 'cli' ) {
97 $finalOutput = $longText;
98 } else {
99 header( "$protocol 500 MediaWiki configuration Error" );
100 // Don't cache error pages! They cause no end of trouble...
101 header( 'Cache-control: none' );
102 header( 'Pragma: no-cache' );
104 if ( $type == 'index.php' || $type == 'mw-config/index.php' ) {
105 $pathinfo = pathinfo( $_SERVER['SCRIPT_NAME'] );
106 if ( $type == 'mw-config/index.php' ) {
107 $dirname = dirname( $pathinfo['dirname'] );
108 } else {
109 $dirname = $pathinfo['dirname'];
111 $encLogo = htmlspecialchars(
112 str_replace( '//', '/', $dirname . '/' ) .
113 'resources/assets/mediawiki.png'
115 $shortHtml = htmlspecialchars( $shortText );
117 header( 'Content-type: text/html; charset=UTF-8' );
119 $finalOutput = <<<HTML
120 <!DOCTYPE html>
121 <html lang="en" dir="ltr">
122 <head>
123 <meta charset="UTF-8" />
124 <title>MediaWiki {$mwVersion}</title>
125 <style media='screen'>
126 body {
127 color: #000;
128 background-color: #fff;
129 font-family: sans-serif;
130 padding: 2em;
131 text-align: center;
133 p, img, h1, h2, ul {
134 text-align: left;
135 margin: 0.5em 0 1em;
137 h1 {
138 font-size: 120%;
140 h2 {
141 font-size: 110%;
143 </style>
144 </head>
145 <body>
146 <img src="{$encLogo}" alt='The MediaWiki logo' />
147 <h1>MediaWiki {$mwVersion} internal error</h1>
148 <div class='error'>
150 {$shortHtml}
151 </p>
152 <h2>{$title}</h2>
154 {$longHtml}
155 </p>
156 </div>
157 </body>
158 </html>
159 HTML;
160 // Handle everything that's not index.php
161 } else {
162 // So nothing thinks this is JS or CSS
163 $finalOutput = ( $type == 'load.php' ) ? "/* $shortText */" : $shortText;
166 echo "$finalOutput\n";
167 die( 1 );
171 * Display an error for the minimum PHP version requirement not being satisfied.
173 * @param string $type See wfGenericError
174 * @param string $mwVersion See wfGenericError
175 * @param string $minimumVersionPHP The minimum PHP version supported by MediaWiki
176 * @param string $phpVersion The current PHP version
178 function wfPHPVersionError( $type, $mwVersion, $minimumVersionPHP, $phpVersion ) {
179 $shortText = "MediaWiki $mwVersion requires at least "
180 . "PHP version $minimumVersionPHP, you are using PHP $phpVersion.";
182 $longText = "Error: You might be using on older PHP version. \n"
183 . "MediaWiki $mwVersion needs PHP $minimumVersionPHP or higher.\n\n"
184 . "Check if you have a newer php executable with a different name, such as php5.\n\n";
186 $longHtml = <<<HTML
187 Please consider <a href="http://www.php.net/downloads.php">upgrading your copy of PHP</a>.
188 PHP versions less than 5.5.0 are no longer supported by the PHP Group and will not receive
189 security or bugfix updates.
190 </p>
192 If for some reason you are unable to upgrade your PHP version, you will need to
193 <a href="https://www.mediawiki.org/wiki/Download">download</a> an older version
194 of MediaWiki from our website. See our
195 <a href="https://www.mediawiki.org/wiki/Compatibility#PHP">compatibility page</a>
196 for details of which versions are compatible with prior versions of PHP.
197 HTML;
198 wfGenericError( $type, $mwVersion, 'Supported PHP versions', $shortText, $longText, $longHtml );
202 * Display an error for the vendor/autoload.php file not being found.
204 * @param string $type See wfGenericError
205 * @param string $mwVersion See wfGenericError
207 function wfMissingVendorError( $type, $mwVersion ) {
208 $shortText = "Installing some external dependencies (e.g. via composer) is required.";
210 $longText = "Error: You are missing some external dependencies. \n"
211 . "MediaWiki now also has some external dependencies that need to be installed\n"
212 . "via composer or from a separate git repo. Please see\n"
213 . "https://www.mediawiki.org/wiki/Download_from_Git#Fetch_external_libraries\n"
214 . "for help on installing the required components.";
216 // @codingStandardsIgnoreStart Generic.Files.LineLength
217 $longHtml = <<<HTML
218 MediaWiki now also has some external dependencies that need to be installed via
219 composer or from a separate git repo. Please see
220 <a href="https://www.mediawiki.org/wiki/Download_from_Git#Fetch_external_libraries">mediawiki.org</a>
221 for help on installing the required components.
222 HTML;
223 // @codingStandardsIgnoreEnd
225 wfGenericError( $type, $mwVersion, 'External dependencies', $shortText, $longText, $longHtml );
229 * Display an error for a PHP extension not existing.
231 * @param string $type See wfGenericError
232 * @param string $mwVersion See wfGenericError
233 * @param array $missingExts The extensions we're missing
235 function wfMissingExtensions( $type, $mwVersion, $missingExts ) {
236 $shortText = "Installing some PHP extensions is required.";
238 $missingExtText = '';
239 $missingExtHtml = '';
240 $baseUrl = 'https://secure.php.net';
241 foreach ( $missingExts as $ext ) {
242 $missingExtText .= " * $ext <$baseUrl/$ext>\n";
243 $missingExtHtml .= "<li><b>$ext</b> "
244 . "(<a href=\"$baseUrl/$ext\">more information</a>)</li>";
247 $cliText = "Error: Missing one or more required components of PHP.\n"
248 . "You are missing a required extension to PHP that MediaWiki needs.\n"
249 . "Please install:\n" . $missingExtText;
251 $longHtml = <<<HTML
252 You are missing a required extension to PHP that MediaWiki
253 requires to run. Please install:
254 <ul>
255 $missingExtHtml
256 </ul>
257 HTML;
259 wfGenericError( $type, $mwVersion, 'Required components', $shortText,
260 $cliText, $longHtml );