Merge "Add tests for API's assert={user|bot}"
[lhc/web/wiklou.git] / includes / PHPVersionError.php
1 <?php
2 /**
3 * Display something vaguely comprehensible in the event of a totally unrecoverable error.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
19 *
20 * @file
21 */
22
23 /**
24 * Display something vaguely comprehensible in the event of a totally unrecoverable error.
25 * Does not assume access to *anything*; no globals, no autoloader, no database, no localisation.
26 * Safe for PHP4 (and putting this here means that WebStart.php and GlobalSettings.php
27 * no longer need to be).
28 *
29 * Calling this function kills execution immediately.
30 *
31 * @param string $type Which entry point we are protecting. One of:
32 * - index.php
33 * - load.php
34 * - api.php
35 * - cli
36 *
37 * @note Since we can't rely on anything, the minimum PHP versions and MW current
38 * version are hardcoded here
39 */
40 function wfPHPVersionError( $type ) {
41 $mwVersion = '1.24';
42 $minimumVersionPHP = '5.3.2';
43
44 $phpVersion = phpversion();
45 $protocol = isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0';
46 $message = "MediaWiki $mwVersion requires at least "
47 . "PHP version $minimumVersionPHP, you are using PHP $phpVersion.";
48
49 if ( $type == 'cli' ) {
50 $finalOutput = "You are using PHP version $phpVersion "
51 . "but MediaWiki $mwVersion needs PHP $minimumVersionPHP or higher. ABORTING.\n"
52 . "Check if you have a newer php executable with a different name, such as php5.\n";
53 } elseif ( $type == 'index.php' ) {
54 $pathinfo = pathinfo( $_SERVER['SCRIPT_NAME'] );
55 $encLogo = htmlspecialchars(
56 str_replace( '//', '/', $pathinfo['dirname'] . '/' ) .
57 'skins/common/images/mediawiki.png'
58 );
59
60 header( "$protocol 500 MediaWiki configuration Error" );
61 header( 'Content-type: text/html; charset=UTF-8' );
62 // Don't cache error pages! They cause no end of trouble...
63 header( 'Cache-control: none' );
64 header( 'Pragma: no-cache' );
65
66 $finalOutput = <<<HTML
67 <!DOCTYPE html>
68 <html lang="en" dir="ltr">
69 <head>
70 <meta charset="UTF-8" />
71 <title>MediaWiki {$mwVersion}</title>
72 <style media='screen'>
73 body {
74 color: #000;
75 background-color: #fff;
76 font-family: sans-serif;
77 padding: 2em;
78 text-align: center;
79 }
80 p, img, h1 {
81 text-align: left;
82 margin: 0.5em 0;
83 }
84 h1 {
85 font-size: 120%;
86 }
87 </style>
88 </head>
89 <body>
90 <img src="{$encLogo}" alt='The MediaWiki logo' />
91 <h1>MediaWiki {$mwVersion} internal error</h1>
92 <div class='error'>
93 <p>
94 {$message}
95 </p>
96 <p>
97 Please consider <a href="http://www.php.net/downloads.php">upgrading your copy of PHP</a>.
98 PHP versions less than 5.3.0 are no longer supported by the PHP Group and will not receive
99 security or bugfix updates.
100 </p>
101 <p>
102 If for some reason you are unable to upgrade your PHP version, you will need to
103 <a href="https://www.mediawiki.org/wiki/Download">download</a> an older version
104 of MediaWiki from our website. See our
105 <a href="https://www.mediawiki.org/wiki/Compatibility#PHP">compatibility page</a>
106 for details of which versions are compatible with prior versions of PHP.
107 </p>
108 </div>
109 </body>
110 </html>
111 HTML;
112 // Handle everything that's not index.php
113 } else {
114 // So nothing thinks this is JS or CSS
115 $finalOutput = ( $type == 'load.php' ) ? "/* $message */" : $message;
116 header( "$protocol 500 MediaWiki configuration Error" );
117 }
118 echo "$finalOutput\n";
119 die( 1 );
120 }