--- /dev/null
+<?php
+
+/**
+ * Test for *.php5 capability in webserver
+ * Used by includes/templates/PHP4.php
+ */
+if ( version_compare( phpversion(), '5.0.0' ) >= 0 ) {
+ echo 'y'.'e'.'s';
+}
+
+?>
* Create a site configuration object
* Not used for much in a default install
*/
-require_once( "$IP/includes/SiteConfiguration.php" );
-$wgConf = new SiteConfiguration;
+if ( !defined( 'MW_PHP4' ) ) {
+ require_once( "$IP/includes/SiteConfiguration.php" );
+ $wgConf = new SiteConfiguration;
+}
/** MediaWiki version number */
$wgVersion = '1.14alpha';
*/
/** database host name or ip address */
$wgDBserver = 'localhost';
-/** database port number */
-$wgDBport = '';
+/** database port number (for PostgreSQL) */
+$wgDBport = 5432;
/** name of the database */
-$wgDBname = 'wikidb';
+$wgDBname = 'my_wiki';
/** */
$wgDBconnection = '';
/** Database username */
# This check may also protect against code injection in
# case of broken installations.
- if(! file_exists( $wgDiff3 ) ){
+ if( !$wgDiff3 || !file_exists( $wgDiff3 ) ) {
wfDebug( "diff3 not found\n" );
return false;
}
$IP = realpath( '.' );
}
+
# Start profiler
require_once( "$IP/StartProfiler.php" );
wfProfileIn( 'WebStart.php-conf' );
# Load up some global defines.
require_once( "$IP/includes/Defines.php" );
-# LocalSettings.php is the per site customization file. If it does not exit
-# the wiki installer need to be launched or the generated file moved from
-# ./config/ to ./
-if( !file_exists( "$IP/LocalSettings.php" ) ) {
- require_once( "$IP/includes/DefaultSettings.php" ); # used for printing the version
- require_once( "$IP/includes/templates/NoLocalSettings.php" );
- die();
+# Check for PHP 5
+if ( !function_exists( 'version_compare' )
+ || version_compare( phpversion(), '5.0.0' ) < 0
+) {
+ define( 'MW_PHP4', '1' );
+ require( "$IP/includes/DefaultSettings.php" );
+ require( "$IP/includes/templates/PHP4.php" );
+ exit;
}
# Start the autoloader, so that extensions can derive classes from core files
require_once( "$IP/includes/AutoLoader.php" );
-# Include site settings. $IP may be changed (hopefully before the AutoLoader is invoked)
-require_once( "$IP/LocalSettings.php" );
+if ( defined( 'MW_CONFIG_CALLBACK' ) ) {
+ # Use a callback function to configure MediaWiki
+ require_once( "$IP/includes/DefaultSettings.php" );
+ call_user_func( MW_CONFIG_CALLBACK );
+} else {
+ # LocalSettings.php is the per site customization file. If it does not exit
+ # the wiki installer need to be launched or the generated file moved from
+ # ./config/ to ./
+ if( !file_exists( "$IP/LocalSettings.php" ) ) {
+ require_once( "$IP/includes/DefaultSettings.php" ); # used for printing the version
+ require_once( "$IP/includes/templates/NoLocalSettings.php" );
+ die();
+ }
+
+ # Include site settings. $IP may be changed (hopefully before the AutoLoader is invoked)
+ require_once( "$IP/LocalSettings.php" );
+}
wfProfileOut( 'WebStart.php-conf' );
wfProfileIn( 'WebStart.php-ob_start' );
protected function installErrorHandler() {
$this->mPHPError = false;
+ $this->htmlErrors = ini_set( 'html_errors', '0' );
set_error_handler( array( $this, 'connectionErrorHandler' ) );
}
protected function restoreErrorHandler() {
restore_error_handler();
- return $this->mPHPError;
+ if ( $this->htmlErrors !== false ) {
+ ini_set( 'html_errors', $this->htmlErrors );
+ }
+ if ( $this->mPHPError ) {
+ $error = preg_replace( '!\[<a.*</a>\]!', '', $this->mPHPError );
+ $error = preg_replace( '!^.*?:(.*)$!', '$1', $error );
+ return $error;
+ } else {
+ return false;
+ }
}
protected function connectionErrorHandler( $errno, $errstr ) {
$failFunction = false, $flags = 0 )
{
- global $wgOut;
- # Can't get a reference if it hasn't been set yet
- if ( !isset( $wgOut ) ) {
- $wgOut = NULL;
- }
- $this->mOut =& $wgOut;
$this->mFailFunction = $failFunction;
$this->mFlags = $flags;
$this->open( $server, $user, $password, $dbName);
global $wgDBport;
- if (!strlen($user)) { ## e.g. the class is being loaded
- return;
- }
-
$this->close();
$this->mServer = $server;
$this->mPort = $port = $wgDBport;
$this->mPassword = $password;
$this->mDBname = $dbName;
- $hstring="";
+ $connectVars = array(
+ 'dbname' => $dbName,
+ 'user' => $user,
+ 'password' => $password );
if ($server!=false && $server!="") {
- $hstring="host=$server ";
+ $connectVars['host'] = $server;
}
if ($port!=false && $port!="") {
- $hstring .= "port=$port ";
+ $connectVars['port'] = $port;
}
+ $connectString = $this->makeConnectionString( $connectVars );
- error_reporting( E_ALL );
- @$this->mConn = pg_connect("$hstring dbname=$dbName user=$user password=$password");
+ $this->installErrorHandler();
+ $this->mConn = pg_connect( $connectString );
+ $phpError = $this->restoreErrorHandler();
if ( $this->mConn == false ) {
wfDebug( "DB connection error\n" );
wfDebug( "Server: $server, Database: $dbName, User: $user, Password: " . substr( $password, 0, 3 ) . "...\n" );
wfDebug( $this->lastError()."\n" );
- return false;
+ if ( !$this->mFailFunction ) {
+ throw new DBConnectionError( $this, $phpError );
+ } else {
+ return false;
+ }
}
$this->mOpened = true;
return $this->mConn;
}
+ function makeConnectionString( $vars ) {
+ $s = '';
+ foreach ( $vars as $name => $value ) {
+ $s .= "$name='" . str_replace( "'", "\\'", $value ) . "' ";
+ }
+ return $s;
+ }
+
function initial_setup($password, $dbName) {
// If this is the initial connection, setup the schema stuff and possibly create the user
print "<li>Checking the version of Postgres...";
$version = $this->getServerVersion();
$PGMINVER = '8.1';
- if ($this->numeric_version < $PGMINVER) {
- print "<b>FAILED</b>. Required version is $PGMINVER. You have $this->numeric_version ($version)</li>\n";
+ if ($version < $PGMINVER) {
+ print "<b>FAILED</b>. Required version is $PGMINVER. You have $version</li>\n";
dieout("</ul>");
}
print "version $this->numeric_version is OK.</li>\n";
$table = $this->tableName( $table );
if (! isset( $wgDBversion ) ) {
- $this->getServerVersion();
- $wgDBversion = $this->numeric_version;
+ $wgDBversion = $this->getServerVersion();
}
if ( !is_array( $options ) )
* @return string Version information from the database
*/
function getServerVersion() {
- $version = pg_fetch_result($this->doQuery("SELECT version()"),0,0);
- $thisver = array();
- if (!preg_match('/PostgreSQL (\d+\.\d+)(\S+)/', $version, $thisver)) {
- die("Could not determine the numeric version from $version!");
- }
- $version = $thisver[1].$thisver[2];
- $this->numeric_version = $thisver[1];
- return $version;
+ $versionInfo = pg_version( $this->mConn );
+ return $versionInfo['server'];
}
-
/**
* Query whether a given relation exists (in the given schema, or the
* default mw one if not given)
global $wgOut,$wgSQLiteDataDir, $wgSQLiteDataDirMode;
if ("$wgSQLiteDataDir" == '') $wgSQLiteDataDir = dirname($_SERVER['DOCUMENT_ROOT']).'/data';
if (!is_dir($wgSQLiteDataDir)) wfMkdirParents( $wgSQLiteDataDir, $wgSQLiteDataDirMode );
- if (!isset($wgOut)) $wgOut = NULL; # Can't get a reference if it hasn't been set yet
- $this->mOut =& $wgOut;
$this->mFailFunction = $failFunction;
$this->mFlags = $flags;
$this->mDatabaseFile = "$wgSQLiteDataDir/$dbName.sqlite";
$this->mConn = false;
if ($dbName) {
$file = $this->mDatabaseFile;
- if ($this->mFlags & DBO_PERSISTENT) $this->mConn = new PDO("sqlite:$file",$user,$pass,array(PDO::ATTR_PERSISTENT => true));
- else $this->mConn = new PDO("sqlite:$file",$user,$pass);
- if ($this->mConn === false) wfDebug("DB connection error: $err\n");;
+ try {
+ if ( $this->mFlags & DBO_PERSISTENT ) {
+ $this->mConn = new PDO( "sqlite:$file", $user, $pass,
+ array( PDO::ATTR_PERSISTENT => true ) );
+ } else {
+ $this->mConn = new PDO( "sqlite:$file", $user, $pass );
+ }
+ } catch ( PDOException $e ) {
+ $err = $e->getMessage();
+ }
+ if ( $this->mConn === false ) {
+ wfDebug( "DB connection error: $err\n" );
+ if ( !$this->mFailFunction ) {
+ throw new DBConnectionError( $this, $err );
+ } else {
+ return false;
+ }
+
+ }
$this->mOpened = $this->mConn;
- $this->mConn->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_SILENT); # set error codes only, dont raise exceptions
+ # set error codes only, don't raise exceptions
+ $this->mConn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_SILENT );
}
return $this->mConn;
}
global $wgMaxTocLevel, $wgContLang;
$doNumberHeadings = $this->mOptions->getNumberHeadings();
- if( !$this->mTitle->quickUserCan( 'edit' ) ) {
+ $showEditLink = $this->mOptions->getEditSection();
+
+ // Do not call quickUserCan unless necessary
+ if( $showEditLink && !$this->mTitle->quickUserCan( 'edit' ) ) {
$showEditLink = 0;
- } else {
- $showEditLink = $this->mOptions->getEditSection();
}
# Inhibit editsection links if requested in the page
--- /dev/null
+<?php
+/**
+ * @file
+ * @ingroup Templates
+ */
+
+if( isset( $_SERVER['REQUEST_URI'] ) ) {
+ $scriptUrl = $_SERVER['REQUEST_URI'];
+} elseif( isset( $_SERVER['SCRIPT_NAME'] ) ) {
+ // Probably IIS; doesn't set REQUEST_URI
+ $scriptUrl = $_SERVER['SCRIPT_NAME'];
+} else {
+ $scriptUrl = '';
+}
+if ( preg_match( '!^(.*)/config/[^/]*.php$!', $scriptUrl, $m ) ) {
+ $baseUrl = $m[1];
+} elseif ( preg_match( '!^(.*)/[^/]*.php$!', $scriptUrl, $m ) ) {
+ $baseUrl = $m[1];
+} else {
+ $baseUrl = dirname( $baseUrl );
+}
+
+?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en' lang='en'>
+ <head>
+ <title>MediaWiki <?php echo htmlspecialchars( $wgVersion ); ?></title>
+ <meta http-equiv='Content-Type' content='text/html; charset=utf-8' />
+ <style type='text/css' media='screen, projection'>
+ html, body {
+ color: #000;
+ background-color: #fff;
+ font-family: sans-serif;
+ text-align: center;
+ }
+
+ p {
+ text-align: left;
+ margin-left: 2em;
+ margin-right: 2em;
+ }
+
+ h1 {
+ font-size: 150%;
+ }
+ </style>
+ </head>
+ <body>
+ <img src="<?php echo htmlspecialchars( $baseUrl ) ?>/skins/common/images/mediawiki.png" alt='The MediaWiki logo' />
+
+ <h1>MediaWiki <?php echo htmlspecialchars( $wgVersion ); ?></h1>
+ <div class='error'>
+<p>
+ MediaWiki requires PHP 5.0.0 or higher. You are running PHP
+ <?php echo htmlspecialchars( phpversion() ); ?>.
+</p>
+<?php
+flush();
+/**
+ * Test the *.php5 extension
+ */
+$downloadOther = true;
+if ( $baseUrl ) {
+ $testUrl = "$wgServer$baseUrl/extension-test.php5";
+ ini_set( 'allow_url_fopen', '1' );
+ $s = file_get_contents( $testUrl );
+
+ if ( strpos( $s, 'yes' ) !== false ) {
+ $encUrl = htmlspecialchars( str_replace( '.php', '.php5', $scriptUrl ) );
+ echo "<p>You may be able to use MediaWiki using a <a href=\"$encUrl\">.php5</a> file extension.</p>";
+ $downloadOther = false;
+ }
+}
+if ( $downloadOther ) {
+?>
+<p>Please consider upgrading your copy of PHP. PHP 4 is at the end of its
+lifecycle and will not receive further security updates.</p>
+<p>If for some reason you really really need to run MediaWiki on PHP 4, you will need to
+<a href="http://www.mediawiki.org/wiki/Download">download version 1.6.x</a>
+from our website. </p>
+<?php
+}
+?>
+
+ </div>
+ </body>
+</html>