coding style tweaks + removed some PHP4-isms
[lhc/web/wiklou.git] / index.php
1 <?php
2 /**
3 * This is the main web entry point for MediaWiki.
4 *
5 * If you are reading this in your web browser, your server is probably
6 * not configured correctly to run PHP applications!
7 *
8 * See the README, INSTALL, and UPGRADE files for basic setup instructions
9 * and pointers to the online documentation.
10 *
11 * http://www.mediawiki.org/
12 *
13 * ----------
14 *
15 * Copyright (C) 2001-2011 Magnus Manske, Brion Vibber, Lee Daniel Crocker,
16 * Tim Starling, Erik Möller, Gabriel Wicke, Ævar Arnfjörð Bjarmason,
17 * Niklas Laxström, Domas Mituzas, Rob Church, Yuri Astrakhan, Aryeh Gregor,
18 * Aaron Schulz, Andrew Garrett, Raimond Spekking, Alexandre Emsenhuber
19 * Siebrand Mazeland, Chad Horohoe, Roan Kattouw and others.
20 *
21 * This program is free software; you can redistribute it and/or modify
22 * it under the terms of the GNU General Public License as published by
23 * the Free Software Foundation; either version 2 of the License, or
24 * (at your option) any later version.
25 *
26 * This program is distributed in the hope that it will be useful,
27 * but WITHOUT ANY WARRANTY; without even the implied warranty of
28 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29 * GNU General Public License for more details.
30 *
31 * You should have received a copy of the GNU General Public License along
32 * with this program; if not, write to the Free Software Foundation, Inc.,
33 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
34 * http://www.gnu.org/copyleft/gpl.html
35 *
36 * @file
37 */
38
39 // Bail on old versions of PHP. Pretty much every other file in the codebase
40 // has structures (try/catch, foo()->bar(), etc etc) which throw parse errors in PHP 4.
41 // Setup.php and ObjectCache.php have structures invalid in PHP 5.0 and 5.1, respectively.
42 if ( !function_exists( 'version_compare' ) || version_compare( phpversion(), '5.2.3' ) < 0 ) {
43 $phpversion = htmlspecialchars( phpversion() );
44 $errorMsg = <<<ENDL
45 <p>
46 MediaWiki requires PHP 5.2.3 or higher. You are running PHP $phpversion.
47 </p>
48 <p>
49 Please consider <a href="http://www.php.net/downloads.php">upgrading your copy of PHP</a>.
50 PHP versions less than 5.3.0 are no longer supported by the PHP Group and will not receive
51 security or bugfix updates.
52 </p>
53 <p>
54 If for some reason you are unable to upgrade your PHP version, you will need to
55 <a href="http://www.mediawiki.org/wiki/Download">download</a> an older version
56 of MediaWiki from our website. See our
57 <a href="http://www.mediawiki.org/wiki/Compatibility#PHP">compatibility page</a>
58 for details of which versions are compatible with prior versions of PHP.
59 </p>
60 ENDL;
61 wfDie( $errorMsg );
62 }
63
64 # Initialise common code. This gives us access to GlobalFunctions, the AutoLoader, and
65 # the globals $wgRequest, $wgOut, $wgUser, $wgLang and $wgContLang, amongst others; it
66 # does *not* load $wgTitle
67 if ( isset( $_SERVER['MW_COMPILED'] ) ) {
68 require ( 'phase3/includes/WebStart.php' );
69 } else {
70 require ( dirname( __FILE__ ) . '/includes/WebStart.php' );
71 }
72
73 $mediaWiki = new MediaWiki();
74 $mediaWiki->run();
75
76 /**
77 * Display something vaguely comprehensible in the event of a totally unrecoverable error.
78 * Does not assume access to *anything*; no globals, no autloader, no database, no localisation.
79 * Safe for PHP4 (and putting this here means that WebStart.php and GlobalSettings.php
80 * no longer need to be).
81 *
82 * Calling this function kills execution immediately.
83 *
84 * @param $errorMsg String fully-escaped HTML
85 */
86 function wfDie( $errorMsg ){
87 // Use the version set in DefaultSettings if possible, but don't rely on it
88 global $wgVersion, $wgLogo;
89 $version = isset( $wgVersion ) && $wgVersion
90 ? htmlspecialchars( $wgVersion )
91 : '';
92
93 $script = $_SERVER['SCRIPT_NAME'];
94 $path = pathinfo( $script, PATHINFO_DIRNAME ) . '/';
95 $path = str_replace( '//', '/', $path );
96
97 $logo = isset( $wgLogo ) && $wgLogo
98 ? $wgLogo
99 : $path . 'skins/common/images/mediawiki.png';
100 $encLogo = htmlspecialchars( $logo );
101
102 header( $_SERVER['SERVER_PROTOCOL'] . ' 500 MediaWiki configuration Error', true, 500 );
103 header( 'Content-type: text/html; charset=UTF-8' );
104 // Don't cache error pages! They cause no end of trouble...
105 header( 'Cache-control: none' );
106 header( 'Pragma: nocache' );
107
108 ?>
109 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
110 <html xmlns='http://www.w3.org/1999/xhtml' lang='en'>
111 <head>
112 <title>MediaWiki <?php echo $version; ?></title>
113 <meta http-equiv='Content-Type' content='text/html; charset=utf-8' />
114 <style type='text/css' media='screen'>
115 body {
116 color: #000;
117 background-color: #fff;
118 font-family: sans-serif;
119 padding: 2em;
120 text-align: center;
121 }
122 p, img, h1 {
123 text-align: left;
124 margin: 0.5em 0;
125 }
126 h1 {
127 font-size: 120%;
128 }
129 </style>
130 </head>
131 <body>
132 <img src="<?php echo $encLogo; ?>" alt='The MediaWiki logo' />
133 <h1>MediaWiki <?php echo $version; ?> internal error</h1>
134 <div class='error'> <?php echo $errorMsg; ?> </div>
135 </body>
136 </html>
137 <?php
138 die( 1 );
139 }