Merge "Normalise documentation in tests/selenium"
[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 autloader, 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.21';
42 $phpVersion = PHP_VERSION;
43 $message = "MediaWiki $mwVersion requires at least PHP version 5.3.2, you are using PHP $phpVersion.";
44 if( $type == 'index.php' ) {
45 $encLogo = htmlspecialchars(
46 str_replace( '//', '/', pathinfo( $_SERVER['SCRIPT_NAME'], PATHINFO_DIRNAME ) . '/'
47 ) . 'skins/common/images/mediawiki.png'
48 );
49
50 header( $_SERVER['SERVER_PROTOCOL'] . ' 500 MediaWiki configuration Error', true, 500 );
51 header( 'Content-type: text/html; charset=UTF-8' );
52 // Don't cache error pages! They cause no end of trouble...
53 header( 'Cache-control: none' );
54 header( 'Pragma: nocache' );
55
56 $finalOutput = <<<HTML
57 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
58 <html xmlns='http://www.w3.org/1999/xhtml' lang='en'>
59 <head>
60 <title>MediaWiki {$mwVersion}</title>
61 <meta http-equiv='Content-Type' content='text/html; charset=utf-8' />
62 <style type='text/css' media='screen'>
63 body {
64 color: #000;
65 background-color: #fff;
66 font-family: sans-serif;
67 padding: 2em;
68 text-align: center;
69 }
70 p, img, h1 {
71 text-align: left;
72 margin: 0.5em 0;
73 }
74 h1 {
75 font-size: 120%;
76 }
77 </style>
78 </head>
79 <body>
80 <img src="{$encLogo}" alt='The MediaWiki logo' />
81 <h1>MediaWiki {$mwVersion} internal error</h1>
82 <div class='error'>
83 <p>
84 {$message}
85 </p>
86 <p>
87 Please consider <a href="http://www.php.net/downloads.php">upgrading your copy of PHP</a>.
88 PHP versions less than 5.3.0 are no longer supported by the PHP Group and will not receive
89 security or bugfix updates.
90 </p>
91 <p>
92 If for some reason you are unable to upgrade your PHP version, you will need to
93 <a href="http://www.mediawiki.org/wiki/Download">download</a> an older version
94 of MediaWiki from our website. See our
95 <a href="http://www.mediawiki.org/wiki/Compatibility#PHP">compatibility page</a>
96 for details of which versions are compatible with prior versions of PHP.
97 </p>
98 </div>
99 </body>
100 </html>
101 HTML;
102 // Handle everything that's not index.php
103 } else {
104 // So nothing thinks this is JS or CSS
105 $finalOutput = ( $type == 'load.php' ) ? "/* $message */" : $message;
106 if( $type != 'cli' ) {
107 header( $_SERVER['SERVER_PROTOCOL'] . ' 500 MediaWiki configuration Error', true, 500 );
108 }
109 }
110 echo( "$finalOutput\n" );
111 die( 1 );
112 }