[ Index ]

PHP Cross Reference of MediaWiki-1.24.0

title

Body

[close]

/includes/ -> PHPVersionError.php (source)

   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   *   - mw-config/index.php
  36   *   - cli
  37   *
  38   * @note Since we can't rely on anything, the minimum PHP versions and MW current
  39   * version are hardcoded here
  40   */
  41  function wfPHPVersionError( $type ) {
  42      $mwVersion = '1.24';
  43      $minimumVersionPHP = '5.3.2';
  44  
  45      $phpVersion = PHP_VERSION;
  46      $protocol = isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0';
  47      $message = "MediaWiki $mwVersion requires at least "
  48          . "PHP version $minimumVersionPHP, you are using PHP $phpVersion.";
  49  
  50      if ( $type == 'cli' ) {
  51          $finalOutput = "You are using PHP version $phpVersion "
  52              . "but MediaWiki $mwVersion needs PHP $minimumVersionPHP or higher. ABORTING.\n"
  53              . "Check if you have a newer php executable with a different name, such as php5.\n";
  54      } elseif ( $type == 'index.php' || $type == 'mw-config/index.php' ) {
  55          $pathinfo = pathinfo( $_SERVER['SCRIPT_NAME'] );
  56          if ( $type == 'mw-config/index.php' ) {
  57              $dirname = dirname( $pathinfo['dirname'] );
  58          } else {
  59              $dirname = $pathinfo['dirname'];
  60          }
  61          $encLogo = htmlspecialchars(
  62              str_replace( '//', '/', $dirname . '/' ) .
  63              'resources/assets/mediawiki.png'
  64          );
  65  
  66          header( "$protocol 500 MediaWiki configuration Error" );
  67          header( 'Content-type: text/html; charset=UTF-8' );
  68          // Don't cache error pages!  They cause no end of trouble...
  69          header( 'Cache-control: none' );
  70          header( 'Pragma: no-cache' );
  71  
  72          $finalOutput = <<<HTML
  73  <!DOCTYPE html>
  74  <html lang="en" dir="ltr">
  75      <head>
  76          <meta charset="UTF-8" />
  77          <title>MediaWiki {$mwVersion}</title>
  78          <style media='screen'>
  79              body {
  80                  color: #000;
  81                  background-color: #fff;
  82                  font-family: sans-serif;
  83                  padding: 2em;
  84                  text-align: center;
  85              }
  86              p, img, h1 {
  87                  text-align: left;
  88                  margin: 0.5em 0;
  89              }
  90              h1 {
  91                  font-size: 120%;
  92              }
  93          </style>
  94      </head>
  95      <body>
  96          <img src="{$encLogo}" alt='The MediaWiki logo' />
  97          <h1>MediaWiki {$mwVersion} internal error</h1>
  98          <div class='error'>
  99          <p>
 100              {$message}
 101          </p>
 102          <p>
 103              Please consider <a href="http://www.php.net/downloads.php">upgrading your copy of PHP</a>.
 104              PHP versions less than 5.3.0 are no longer supported by the PHP Group and will not receive
 105              security or bugfix updates.
 106          </p>
 107          <p>
 108              If for some reason you are unable to upgrade your PHP version, you will need to
 109              <a href="https://www.mediawiki.org/wiki/Download">download</a> an older version
 110              of MediaWiki from our website.  See our
 111              <a href="https://www.mediawiki.org/wiki/Compatibility#PHP">compatibility page</a>
 112              for details of which versions are compatible with prior versions of PHP.
 113          </p>
 114          </div>
 115      </body>
 116  </html>
 117  HTML;
 118      // Handle everything that's not index.php
 119      } else {
 120          // So nothing thinks this is JS or CSS
 121          $finalOutput = ( $type == 'load.php' ) ? "/* $message */" : $message;
 122          header( "$protocol 500 MediaWiki configuration Error" );
 123      }
 124      echo "$finalOutput\n";
 125      die( 1 );
 126  }


Generated: Fri Nov 28 14:03:12 2014 Cross-referenced by PHPXref 0.7.1