2010-05-07 12:25:01 +00:00
|
|
|
<?php
|
2010-08-21 18:20:09 +00:00
|
|
|
/**
|
|
|
|
|
* Base code for MediaWiki installer.
|
|
|
|
|
*
|
|
|
|
|
* @file
|
|
|
|
|
* @ingroup Deployment
|
|
|
|
|
*/
|
2010-05-07 12:25:01 +00:00
|
|
|
|
2010-07-29 18:36:39 +00:00
|
|
|
/**
|
|
|
|
|
* This documentation group collects source code files with deployment functionality.
|
|
|
|
|
*
|
|
|
|
|
* @defgroup Deployment Deployment
|
|
|
|
|
*/
|
|
|
|
|
|
2010-05-07 12:25:01 +00:00
|
|
|
/**
|
2010-07-19 02:41:54 +00:00
|
|
|
* Base installer class.
|
2010-07-29 18:18:03 +00:00
|
|
|
*
|
2010-07-22 17:58:26 +00:00
|
|
|
* This class provides the base for installation and update functionality
|
|
|
|
|
* for both MediaWiki core and extensions.
|
2010-07-29 18:18:03 +00:00
|
|
|
*
|
2010-07-29 18:36:39 +00:00
|
|
|
* @ingroup Deployment
|
2010-07-22 17:58:26 +00:00
|
|
|
* @since 1.17
|
2010-05-07 12:25:01 +00:00
|
|
|
*/
|
|
|
|
|
abstract class Installer {
|
2010-07-29 18:18:03 +00:00
|
|
|
|
2010-05-07 12:25:01 +00:00
|
|
|
/**
|
2010-07-22 17:58:26 +00:00
|
|
|
* TODO: make protected?
|
2010-07-29 18:18:03 +00:00
|
|
|
*
|
2010-07-21 17:20:50 +00:00
|
|
|
* @var array
|
2010-05-07 12:25:01 +00:00
|
|
|
*/
|
2010-07-29 18:18:03 +00:00
|
|
|
public $settings;
|
|
|
|
|
|
2010-05-07 12:25:01 +00:00
|
|
|
/**
|
2010-07-22 17:58:26 +00:00
|
|
|
* Cached DB installer instances, access using getDBInstaller().
|
2010-07-29 18:18:03 +00:00
|
|
|
*
|
2010-07-21 17:20:50 +00:00
|
|
|
* @var array
|
2010-05-07 12:25:01 +00:00
|
|
|
*/
|
2010-07-22 17:58:26 +00:00
|
|
|
protected $dbInstallers = array();
|
2010-05-07 12:25:01 +00:00
|
|
|
|
|
|
|
|
/**
|
2010-07-19 02:41:54 +00:00
|
|
|
* Minimum memory size in MB.
|
2010-07-29 18:18:03 +00:00
|
|
|
*
|
2010-07-21 17:20:50 +00:00
|
|
|
* @var integer
|
2010-05-07 12:25:01 +00:00
|
|
|
*/
|
2010-07-29 18:18:03 +00:00
|
|
|
protected $minMemorySize = 50;
|
|
|
|
|
|
2010-05-07 12:25:01 +00:00
|
|
|
/**
|
2010-07-21 17:20:50 +00:00
|
|
|
* Cached Title, used by parse().
|
2010-07-29 18:18:03 +00:00
|
|
|
*
|
2010-07-22 17:58:26 +00:00
|
|
|
* @var Title
|
2010-07-21 17:20:50 +00:00
|
|
|
*/
|
2010-07-22 17:58:26 +00:00
|
|
|
protected $parserTitle;
|
2010-07-29 18:18:03 +00:00
|
|
|
|
2010-07-21 17:20:50 +00:00
|
|
|
/**
|
|
|
|
|
* Cached ParserOptions, used by parse().
|
2010-07-29 18:18:03 +00:00
|
|
|
*
|
2010-07-22 17:58:26 +00:00
|
|
|
* @var ParserOptions
|
2010-07-29 18:18:03 +00:00
|
|
|
*/
|
|
|
|
|
protected $parserOptions;
|
|
|
|
|
|
2010-07-21 17:20:50 +00:00
|
|
|
/**
|
2010-07-22 17:58:26 +00:00
|
|
|
* Known database types. These correspond to the class names <type>Installer,
|
|
|
|
|
* and are also MediaWiki database types valid for $wgDBtype.
|
|
|
|
|
*
|
|
|
|
|
* To add a new type, create a <type>Installer class and a Database<type>
|
|
|
|
|
* class, and add a config-type-<type> message to MessagesEn.php.
|
2010-07-29 18:18:03 +00:00
|
|
|
*
|
2010-07-21 17:20:50 +00:00
|
|
|
* @var array
|
2010-05-07 12:25:01 +00:00
|
|
|
*/
|
2010-08-15 18:55:08 +00:00
|
|
|
protected static $dbTypes = array(
|
2010-07-22 17:58:26 +00:00
|
|
|
'mysql',
|
|
|
|
|
'postgres',
|
|
|
|
|
'sqlite',
|
|
|
|
|
);
|
2010-07-29 18:18:03 +00:00
|
|
|
|
2010-05-07 12:25:01 +00:00
|
|
|
/**
|
2010-07-18 18:52:05 +00:00
|
|
|
* A list of environment check methods called by doEnvironmentChecks().
|
|
|
|
|
* These may output warnings using showMessage(), and/or abort the
|
2010-05-07 12:25:01 +00:00
|
|
|
* installation process by returning false.
|
2010-07-29 18:18:03 +00:00
|
|
|
*
|
2010-07-21 17:20:50 +00:00
|
|
|
* @var array
|
2010-05-07 12:25:01 +00:00
|
|
|
*/
|
2010-07-05 00:29:38 +00:00
|
|
|
protected $envChecks = array(
|
2010-05-07 12:25:01 +00:00
|
|
|
'envLatestVersion',
|
|
|
|
|
'envCheckDB',
|
|
|
|
|
'envCheckRegisterGlobals',
|
|
|
|
|
'envCheckMagicQuotes',
|
|
|
|
|
'envCheckMagicSybase',
|
|
|
|
|
'envCheckMbstring',
|
|
|
|
|
'envCheckZE1',
|
|
|
|
|
'envCheckSafeMode',
|
|
|
|
|
'envCheckXML',
|
|
|
|
|
'envCheckPCRE',
|
|
|
|
|
'envCheckMemory',
|
|
|
|
|
'envCheckCache',
|
|
|
|
|
'envCheckDiff3',
|
|
|
|
|
'envCheckGraphics',
|
|
|
|
|
'envCheckPath',
|
|
|
|
|
'envCheckWriteableDir',
|
|
|
|
|
'envCheckExtension',
|
|
|
|
|
'envCheckShellLocale',
|
|
|
|
|
'envCheckUploadsDirectory',
|
2010-07-29 02:44:23 +00:00
|
|
|
'envCheckLibicu'
|
2010-07-29 18:18:03 +00:00
|
|
|
);
|
|
|
|
|
|
2010-05-07 12:25:01 +00:00
|
|
|
/**
|
2010-07-22 17:58:26 +00:00
|
|
|
* UI interface for displaying a short message
|
|
|
|
|
* The parameters are like parameters to wfMsg().
|
|
|
|
|
* The messages will be in wikitext format, which will be converted to an
|
|
|
|
|
* output format such as HTML or text before being sent to the user.
|
2010-05-07 12:25:01 +00:00
|
|
|
*/
|
2010-07-22 17:58:26 +00:00
|
|
|
public abstract function showMessage( $msg /*, ... */ );
|
2010-07-29 18:18:03 +00:00
|
|
|
|
2010-05-07 12:25:01 +00:00
|
|
|
/**
|
2010-07-22 17:58:26 +00:00
|
|
|
* Constructor, always call this from child classes.
|
2010-05-07 12:25:01 +00:00
|
|
|
*/
|
2010-07-29 18:18:03 +00:00
|
|
|
public function __construct() {
|
2010-06-27 21:48:51 +00:00
|
|
|
// Disable the i18n cache and LoadBalancer
|
|
|
|
|
Language::getLocalisationCache()->disableBackend();
|
|
|
|
|
LBFactory::disableBackend();
|
2010-05-07 12:25:01 +00:00
|
|
|
}
|
2010-07-29 18:18:03 +00:00
|
|
|
|
2010-05-07 12:25:01 +00:00
|
|
|
/**
|
2010-07-19 02:41:54 +00:00
|
|
|
* Get a list of known DB types.
|
2010-05-07 12:25:01 +00:00
|
|
|
*/
|
2010-08-15 18:55:08 +00:00
|
|
|
public static function getDBTypes() {
|
|
|
|
|
return self::$dbTypes;
|
2010-07-29 18:18:03 +00:00
|
|
|
}
|
|
|
|
|
|
2010-05-07 12:25:01 +00:00
|
|
|
/**
|
2010-07-18 18:52:05 +00:00
|
|
|
* Do initial checks of the PHP environment. Set variables according to
|
2010-05-07 12:25:01 +00:00
|
|
|
* the observed environment.
|
|
|
|
|
*
|
|
|
|
|
* It's possible that this may be called under the CLI SAPI, not the SAPI
|
|
|
|
|
* that the wiki will primarily run under. In that case, the subclass should
|
|
|
|
|
* initialise variables such as wgScriptPath, before calling this function.
|
|
|
|
|
*
|
2010-07-18 18:52:05 +00:00
|
|
|
* Under the web subclass, it can already be assumed that PHP 5+ is in use
|
2010-05-07 12:25:01 +00:00
|
|
|
* and that sessions are working.
|
2010-07-29 18:18:03 +00:00
|
|
|
*
|
2010-07-22 17:58:26 +00:00
|
|
|
* @return boolean
|
2010-05-07 12:25:01 +00:00
|
|
|
*/
|
2010-07-19 02:41:54 +00:00
|
|
|
public function doEnvironmentChecks() {
|
2010-05-07 12:25:01 +00:00
|
|
|
$this->showMessage( 'config-env-php', phpversion() );
|
|
|
|
|
|
|
|
|
|
$good = true;
|
2010-07-29 18:18:03 +00:00
|
|
|
|
2010-05-07 12:25:01 +00:00
|
|
|
foreach ( $this->envChecks as $check ) {
|
|
|
|
|
$status = $this->$check();
|
|
|
|
|
if ( $status === false ) {
|
|
|
|
|
$good = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-07-29 18:18:03 +00:00
|
|
|
|
2010-05-07 12:25:01 +00:00
|
|
|
$this->setVar( '_Environment', $good );
|
2010-07-29 18:18:03 +00:00
|
|
|
|
2010-05-07 12:25:01 +00:00
|
|
|
if ( $good ) {
|
|
|
|
|
$this->showMessage( 'config-env-good' );
|
|
|
|
|
} else {
|
|
|
|
|
$this->showMessage( 'config-env-bad' );
|
|
|
|
|
}
|
2010-07-29 18:18:03 +00:00
|
|
|
|
2010-05-07 12:25:01 +00:00
|
|
|
return $good;
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-22 17:58:26 +00:00
|
|
|
/**
|
|
|
|
|
* Set a MW configuration variable, or internal installer configuration variable.
|
2010-07-29 18:18:03 +00:00
|
|
|
*
|
2010-07-22 17:58:26 +00:00
|
|
|
* @param $name String
|
|
|
|
|
* @param $value Mixed
|
|
|
|
|
*/
|
|
|
|
|
public function setVar( $name, $value ) {
|
|
|
|
|
$this->settings[$name] = $value;
|
|
|
|
|
}
|
|
|
|
|
|
2010-05-07 12:25:01 +00:00
|
|
|
/**
|
|
|
|
|
* Get an MW configuration variable, or internal installer configuration variable.
|
|
|
|
|
* The defaults come from $GLOBALS (ultimately DefaultSettings.php).
|
|
|
|
|
* Installer variables are typically prefixed by an underscore.
|
2010-07-29 18:18:03 +00:00
|
|
|
*
|
2010-07-22 17:58:26 +00:00
|
|
|
* @param $name String
|
|
|
|
|
* @param $default Mixed
|
2010-07-29 18:18:03 +00:00
|
|
|
*
|
2010-07-22 17:58:26 +00:00
|
|
|
* @return mixed
|
2010-05-07 12:25:01 +00:00
|
|
|
*/
|
2010-07-19 02:41:54 +00:00
|
|
|
public function getVar( $name, $default = null ) {
|
2010-05-07 12:25:01 +00:00
|
|
|
if ( !isset( $this->settings[$name] ) ) {
|
|
|
|
|
return $default;
|
|
|
|
|
} else {
|
|
|
|
|
return $this->settings[$name];
|
|
|
|
|
}
|
2010-07-29 18:18:03 +00:00
|
|
|
}
|
|
|
|
|
|
2010-05-07 12:25:01 +00:00
|
|
|
/**
|
2010-07-22 17:58:26 +00:00
|
|
|
* Get an instance of DatabaseInstaller for the specified DB type.
|
2010-07-29 18:18:03 +00:00
|
|
|
*
|
2010-07-22 17:58:26 +00:00
|
|
|
* @param $type Mixed: DB installer for which is needed, false to use default.
|
2010-07-29 18:18:03 +00:00
|
|
|
*
|
2010-07-22 17:58:26 +00:00
|
|
|
* @return DatabaseInstaller
|
2010-05-07 12:25:01 +00:00
|
|
|
*/
|
2010-07-22 17:58:26 +00:00
|
|
|
public function getDBInstaller( $type = false ) {
|
|
|
|
|
if ( !$type ) {
|
|
|
|
|
$type = $this->getVar( 'wgDBtype' );
|
|
|
|
|
}
|
2010-07-29 18:18:03 +00:00
|
|
|
|
2010-07-22 17:58:26 +00:00
|
|
|
$type = strtolower( $type );
|
2010-05-07 12:25:01 +00:00
|
|
|
|
2010-07-22 17:58:26 +00:00
|
|
|
if ( !isset( $this->dbInstallers[$type] ) ) {
|
|
|
|
|
$class = ucfirst( $type ). 'Installer';
|
|
|
|
|
$this->dbInstallers[$type] = new $class( $this );
|
|
|
|
|
}
|
2010-07-29 18:18:03 +00:00
|
|
|
|
2010-07-22 17:58:26 +00:00
|
|
|
return $this->dbInstallers[$type];
|
2010-07-29 18:18:03 +00:00
|
|
|
}
|
|
|
|
|
|
2010-05-07 12:25:01 +00:00
|
|
|
/**
|
2010-07-22 17:58:26 +00:00
|
|
|
* Determine if LocalSettings exists. If it does, return an appropriate
|
|
|
|
|
* status for whether we should can upgrade or not.
|
2010-07-29 18:18:03 +00:00
|
|
|
*
|
2010-07-22 17:58:26 +00:00
|
|
|
* @return Status
|
2010-05-07 12:25:01 +00:00
|
|
|
*/
|
2010-07-22 17:58:26 +00:00
|
|
|
public function getLocalSettingsStatus() {
|
|
|
|
|
global $IP;
|
|
|
|
|
|
|
|
|
|
$status = Status::newGood();
|
|
|
|
|
|
|
|
|
|
wfSuppressWarnings();
|
|
|
|
|
$ls = file_exists( "$IP/LocalSettings.php" );
|
|
|
|
|
wfRestoreWarnings();
|
|
|
|
|
|
|
|
|
|
if( $ls ) {
|
|
|
|
|
if( $this->getDBInstaller()->needsUpgrade() ) {
|
|
|
|
|
$status->warning( 'config-localsettings-upgrade' );
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$status->fatal( 'config-localsettings-noupgrade' );
|
2010-05-07 12:25:01 +00:00
|
|
|
}
|
|
|
|
|
}
|
2010-07-29 18:18:03 +00:00
|
|
|
|
2010-07-22 17:58:26 +00:00
|
|
|
return $status;
|
2010-07-29 18:18:03 +00:00
|
|
|
}
|
|
|
|
|
|
2010-05-07 12:25:01 +00:00
|
|
|
/**
|
|
|
|
|
* Get a fake password for sending back to the user in HTML.
|
|
|
|
|
* This is a security mechanism to avoid compromise of the password in the
|
|
|
|
|
* event of session ID compromise.
|
2010-07-29 18:18:03 +00:00
|
|
|
*
|
2010-07-22 17:58:26 +00:00
|
|
|
* @param $realPassword String
|
2010-07-29 18:18:03 +00:00
|
|
|
*
|
2010-07-22 17:58:26 +00:00
|
|
|
* @return string
|
2010-05-07 12:25:01 +00:00
|
|
|
*/
|
2010-07-19 02:41:54 +00:00
|
|
|
public function getFakePassword( $realPassword ) {
|
2010-05-07 12:25:01 +00:00
|
|
|
return str_repeat( '*', strlen( $realPassword ) );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2010-07-18 18:52:05 +00:00
|
|
|
* Set a variable which stores a password, except if the new value is a
|
2010-05-07 12:25:01 +00:00
|
|
|
* fake password in which case leave it as it is.
|
2010-07-29 18:18:03 +00:00
|
|
|
*
|
2010-07-22 17:58:26 +00:00
|
|
|
* @param $name String
|
|
|
|
|
* @param $value Mixed
|
2010-05-07 12:25:01 +00:00
|
|
|
*/
|
2010-07-19 02:41:54 +00:00
|
|
|
public function setPassword( $name, $value ) {
|
2010-05-07 12:25:01 +00:00
|
|
|
if ( !preg_match( '/^\*+$/', $value ) ) {
|
|
|
|
|
$this->setVar( $name, $value );
|
|
|
|
|
}
|
2010-07-29 18:18:03 +00:00
|
|
|
}
|
2010-07-22 17:58:26 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* On POSIX systems return the primary group of the webserver we're running under.
|
|
|
|
|
* On other systems just returns null.
|
|
|
|
|
*
|
|
|
|
|
* This is used to advice the user that he should chgrp his config/data/images directory as the
|
|
|
|
|
* webserver user before he can install.
|
|
|
|
|
*
|
|
|
|
|
* Public because SqliteInstaller needs it, and doesn't subclass Installer.
|
|
|
|
|
*
|
|
|
|
|
* @return mixed
|
|
|
|
|
*/
|
|
|
|
|
public static function maybeGetWebserverPrimaryGroup() {
|
|
|
|
|
if ( !function_exists( 'posix_getegid' ) || !function_exists( 'posix_getpwuid' ) ) {
|
|
|
|
|
# I don't know this, this isn't UNIX.
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# posix_getegid() *not* getmygid() because we want the group of the webserver,
|
|
|
|
|
# not whoever owns the current script.
|
|
|
|
|
$gid = posix_getegid();
|
|
|
|
|
$getpwuid = posix_getpwuid( $gid );
|
|
|
|
|
$group = $getpwuid['name'];
|
|
|
|
|
|
|
|
|
|
return $group;
|
2010-07-29 18:18:03 +00:00
|
|
|
}
|
|
|
|
|
|
2010-07-22 17:58:26 +00:00
|
|
|
/**
|
|
|
|
|
* Convert wikitext $text to HTML.
|
|
|
|
|
*
|
|
|
|
|
* This is potentially error prone since many parser features require a complete
|
|
|
|
|
* installed MW database. The solution is to just not use those features when you
|
|
|
|
|
* write your messages. This appears to work well enough. Basic formatting and
|
|
|
|
|
* external links work just fine.
|
|
|
|
|
*
|
|
|
|
|
* But in case a translator decides to throw in a #ifexist or internal link or
|
|
|
|
|
* whatever, this function is guarded to catch attempted DB access and to present
|
|
|
|
|
* some fallback text.
|
|
|
|
|
*
|
|
|
|
|
* @param $text String
|
|
|
|
|
* @param $lineStart Boolean
|
|
|
|
|
* @return String
|
|
|
|
|
*/
|
|
|
|
|
public function parse( $text, $lineStart = false ) {
|
|
|
|
|
global $wgParser;
|
2010-07-29 18:18:03 +00:00
|
|
|
|
2010-07-22 17:58:26 +00:00
|
|
|
try {
|
|
|
|
|
$out = $wgParser->parse( $text, $this->parserTitle, $this->parserOptions, $lineStart );
|
|
|
|
|
$html = $out->getText();
|
|
|
|
|
} catch ( DBAccessError $e ) {
|
|
|
|
|
$html = '<!--DB access attempted during parse--> ' . htmlspecialchars( $text );
|
2010-07-29 18:18:03 +00:00
|
|
|
|
2010-07-22 17:58:26 +00:00
|
|
|
if ( !empty( $this->debug ) ) {
|
|
|
|
|
$html .= "<!--\n" . $e->getTraceAsString() . "\n-->";
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-07-29 18:18:03 +00:00
|
|
|
|
2010-07-22 17:58:26 +00:00
|
|
|
return $html;
|
2010-07-29 18:18:03 +00:00
|
|
|
}
|
|
|
|
|
|
2010-07-22 17:58:26 +00:00
|
|
|
/**
|
|
|
|
|
* TODO: document
|
2010-07-29 18:18:03 +00:00
|
|
|
*
|
2010-08-21 15:20:23 +00:00
|
|
|
* @param $installer DatabaseInstaller
|
2010-07-29 18:18:03 +00:00
|
|
|
*
|
2010-07-22 17:58:26 +00:00
|
|
|
* @return Status
|
|
|
|
|
*/
|
|
|
|
|
public function installDatabase( DatabaseInstaller &$installer ) {
|
|
|
|
|
if( !$installer ) {
|
|
|
|
|
$type = $this->getVar( 'wgDBtype' );
|
|
|
|
|
$status = Status::newFatal( "config-no-db", $type );
|
|
|
|
|
} else {
|
|
|
|
|
$status = $installer->setupDatabase();
|
|
|
|
|
}
|
2010-07-29 18:18:03 +00:00
|
|
|
|
2010-07-22 17:58:26 +00:00
|
|
|
return $status;
|
2010-05-07 12:25:01 +00:00
|
|
|
}
|
2010-07-18 18:52:05 +00:00
|
|
|
|
2010-07-22 17:58:26 +00:00
|
|
|
/**
|
|
|
|
|
* TODO: document
|
2010-07-29 18:18:03 +00:00
|
|
|
*
|
2010-08-21 15:20:23 +00:00
|
|
|
* @param $installer DatabaseInstaller
|
2010-07-29 18:18:03 +00:00
|
|
|
*
|
2010-07-22 17:58:26 +00:00
|
|
|
* @return Status
|
|
|
|
|
*/
|
|
|
|
|
public function installTables( DatabaseInstaller &$installer ) {
|
|
|
|
|
$status = $installer->createTables();
|
2010-07-29 18:18:03 +00:00
|
|
|
|
2010-07-22 17:58:26 +00:00
|
|
|
if( $status->isOK() ) {
|
|
|
|
|
LBFactory::enableBackend();
|
|
|
|
|
}
|
2010-07-29 18:18:03 +00:00
|
|
|
|
2010-07-22 17:58:26 +00:00
|
|
|
return $status;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* TODO: document
|
2010-07-29 18:18:03 +00:00
|
|
|
*
|
2010-08-21 15:20:23 +00:00
|
|
|
* @param $installer DatabaseInstaller
|
2010-07-29 18:18:03 +00:00
|
|
|
*
|
2010-07-22 17:58:26 +00:00
|
|
|
* @return Status
|
2010-07-29 18:18:03 +00:00
|
|
|
*/
|
2010-07-22 17:58:26 +00:00
|
|
|
public function installInterwiki( DatabaseInstaller &$installer ) {
|
|
|
|
|
return $installer->populateInterwikiTable();
|
2010-07-29 18:18:03 +00:00
|
|
|
}
|
|
|
|
|
|
2010-07-22 17:58:26 +00:00
|
|
|
/**
|
|
|
|
|
* Exports all wg* variables stored by the installer into global scope.
|
|
|
|
|
*/
|
|
|
|
|
public function exportVars() {
|
|
|
|
|
foreach ( $this->settings as $name => $value ) {
|
|
|
|
|
if ( substr( $name, 0, 2 ) == 'wg' ) {
|
|
|
|
|
$GLOBALS[$name] = $value;
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-07-29 18:18:03 +00:00
|
|
|
}
|
|
|
|
|
|
2010-10-16 18:19:00 +00:00
|
|
|
/**
|
|
|
|
|
* Get an array of likely places we can find executables. Check a bunch
|
|
|
|
|
* of known Unix-like defaults, as well as the PATH environment variable
|
|
|
|
|
* (which should maybe make it work for Windows?)
|
|
|
|
|
*
|
|
|
|
|
* @return Array
|
|
|
|
|
*/
|
|
|
|
|
protected function getPossibleBinPaths() {
|
|
|
|
|
return array_merge(
|
|
|
|
|
array( '/usr/bin', '/usr/local/bin', '/opt/csw/bin',
|
|
|
|
|
'/usr/gnu/bin', '/usr/sfw/bin', '/sw/bin', '/opt/local/bin' ),
|
|
|
|
|
explode( PATH_SEPARATOR, getenv( 'PATH' ) )
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-22 17:58:26 +00:00
|
|
|
/**
|
|
|
|
|
* Check if we're installing the latest version.
|
|
|
|
|
*/
|
2010-07-19 02:41:54 +00:00
|
|
|
public function envLatestVersion() {
|
2010-05-07 12:25:01 +00:00
|
|
|
global $wgVersion;
|
2010-07-29 18:18:03 +00:00
|
|
|
|
2010-08-15 10:51:24 +00:00
|
|
|
$repository = wfGetRepository();
|
|
|
|
|
$currentVersion = $repository->getLatestCoreVersion();
|
2010-07-29 18:18:03 +00:00
|
|
|
|
2010-07-10 12:29:15 +00:00
|
|
|
$this->setVar( '_ExternalHTTP', true );
|
2010-07-29 18:18:03 +00:00
|
|
|
|
2010-08-15 10:51:24 +00:00
|
|
|
if ( $currentVersion === false ) {
|
2010-05-07 12:25:01 +00:00
|
|
|
# For when the request is successful but there's e.g. some silly man in
|
|
|
|
|
# the middle firewall blocking us, e.g. one of those annoying airport ones
|
2010-08-15 16:42:43 +00:00
|
|
|
$this->showMessage( 'config-env-latest-can-not-check', $repository->getLocation() );
|
2010-05-07 12:25:01 +00:00
|
|
|
return;
|
|
|
|
|
}
|
2010-07-29 18:18:03 +00:00
|
|
|
|
2010-05-07 12:25:01 +00:00
|
|
|
if( version_compare( $wgVersion, $currentVersion, '<' ) ) {
|
|
|
|
|
$this->showMessage( 'config-env-latest-old' );
|
2010-08-15 16:42:43 +00:00
|
|
|
// FIXME: this only works for the web installer!
|
2010-07-18 18:52:05 +00:00
|
|
|
$this->showHelpBox( 'config-env-latest-help', $wgVersion, $currentVersion );
|
2010-05-07 12:25:01 +00:00
|
|
|
} elseif( version_compare( $wgVersion, $currentVersion, '>' ) ) {
|
|
|
|
|
$this->showMessage( 'config-env-latest-new' );
|
|
|
|
|
}
|
2010-07-29 18:18:03 +00:00
|
|
|
|
2010-05-07 12:25:01 +00:00
|
|
|
$this->showMessage( 'config-env-latest-ok' );
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-22 17:58:26 +00:00
|
|
|
/**
|
|
|
|
|
* Environment check for DB types.
|
|
|
|
|
*/
|
2010-07-19 02:41:54 +00:00
|
|
|
public function envCheckDB() {
|
2010-07-21 17:20:50 +00:00
|
|
|
global $wgLang;
|
2010-07-29 18:18:03 +00:00
|
|
|
|
2010-05-07 12:25:01 +00:00
|
|
|
$compiledDBs = array();
|
|
|
|
|
$goodNames = array();
|
|
|
|
|
$allNames = array();
|
2010-07-29 18:18:03 +00:00
|
|
|
|
2010-08-15 18:55:08 +00:00
|
|
|
foreach ( self::getDBTypes() as $name ) {
|
2010-05-07 12:25:01 +00:00
|
|
|
$db = $this->getDBInstaller( $name );
|
|
|
|
|
$readableName = wfMsg( 'config-type-' . $name );
|
2010-07-29 18:18:03 +00:00
|
|
|
|
2010-07-07 15:05:05 +00:00
|
|
|
if ( $db->isCompiled() ) {
|
2010-05-07 12:25:01 +00:00
|
|
|
$compiledDBs[] = $name;
|
|
|
|
|
$goodNames[] = $readableName;
|
|
|
|
|
}
|
2010-07-29 18:18:03 +00:00
|
|
|
|
2010-05-07 12:25:01 +00:00
|
|
|
$allNames[] = $readableName;
|
|
|
|
|
}
|
2010-07-29 18:18:03 +00:00
|
|
|
|
2010-05-07 12:25:01 +00:00
|
|
|
$this->setVar( '_CompiledDBs', $compiledDBs );
|
2010-07-29 18:18:03 +00:00
|
|
|
|
2010-05-07 12:25:01 +00:00
|
|
|
if ( !$compiledDBs ) {
|
|
|
|
|
$this->showMessage( 'config-no-db' );
|
2010-08-15 16:42:43 +00:00
|
|
|
// FIXME: this only works for the web installer!
|
2010-05-07 12:25:01 +00:00
|
|
|
$this->showHelpBox( 'config-no-db-help', $wgLang->commaList( $allNames ) );
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2010-07-29 18:18:03 +00:00
|
|
|
|
2010-08-18 19:28:41 +00:00
|
|
|
$this->showMessage( 'config-have-db', $wgLang->listToText( $goodNames ), count( $goodNames ) );
|
2010-10-01 21:06:32 +00:00
|
|
|
|
|
|
|
|
// Check for FTS3 full-text search module
|
2010-10-15 14:11:59 +00:00
|
|
|
$sqlite = $this->getDBInstaller( 'sqlite' );
|
2010-10-01 21:06:32 +00:00
|
|
|
if ( $sqlite->isCompiled() ) {
|
|
|
|
|
$db = new DatabaseSqliteStandalone( ':memory:' );
|
|
|
|
|
$this->showMessage( $db->getFulltextSearchModule() == 'FTS3'
|
|
|
|
|
? 'config-have-fts3'
|
|
|
|
|
: 'config-no-fts3'
|
|
|
|
|
);
|
|
|
|
|
}
|
2010-05-07 12:25:01 +00:00
|
|
|
}
|
|
|
|
|
|
2010-07-21 17:20:50 +00:00
|
|
|
/**
|
|
|
|
|
* Environment check for register_globals.
|
|
|
|
|
*/
|
2010-07-19 02:41:54 +00:00
|
|
|
public function envCheckRegisterGlobals() {
|
2010-05-07 12:25:01 +00:00
|
|
|
if( wfIniGetBool( "magic_quotes_runtime" ) ) {
|
|
|
|
|
$this->showMessage( 'config-register-globals' );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-21 17:20:50 +00:00
|
|
|
/**
|
|
|
|
|
* Environment check for magic_quotes_runtime.
|
|
|
|
|
*/
|
2010-07-19 02:41:54 +00:00
|
|
|
public function envCheckMagicQuotes() {
|
2010-05-07 12:25:01 +00:00
|
|
|
if( wfIniGetBool( "magic_quotes_runtime" ) ) {
|
|
|
|
|
$this->showMessage( 'config-magic-quotes-runtime' );
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-21 17:20:50 +00:00
|
|
|
/**
|
|
|
|
|
* Environment check for magic_quotes_sybase.
|
|
|
|
|
*/
|
2010-07-19 02:41:54 +00:00
|
|
|
public function envCheckMagicSybase() {
|
2010-05-07 12:25:01 +00:00
|
|
|
if ( wfIniGetBool( 'magic_quotes_sybase' ) ) {
|
|
|
|
|
$this->showMessage( 'config-magic-quotes-sybase' );
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-21 17:20:50 +00:00
|
|
|
/**
|
|
|
|
|
* Environment check for mbstring.func_overload.
|
|
|
|
|
*/
|
2010-07-19 02:41:54 +00:00
|
|
|
public function envCheckMbstring() {
|
2010-05-07 12:25:01 +00:00
|
|
|
if ( wfIniGetBool( 'mbstring.func_overload' ) ) {
|
|
|
|
|
$this->showMessage( 'config-mbstring' );
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-21 17:20:50 +00:00
|
|
|
/**
|
|
|
|
|
* Environment check for zend.ze1_compatibility_mode.
|
|
|
|
|
*/
|
2010-07-19 02:41:54 +00:00
|
|
|
public function envCheckZE1() {
|
2010-05-07 12:25:01 +00:00
|
|
|
if ( wfIniGetBool( 'zend.ze1_compatibility_mode' ) ) {
|
|
|
|
|
$this->showMessage( 'config-ze1' );
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-21 17:20:50 +00:00
|
|
|
/**
|
|
|
|
|
* Environment check for safe_mode.
|
|
|
|
|
*/
|
2010-07-19 02:41:54 +00:00
|
|
|
public function envCheckSafeMode() {
|
2010-05-07 12:25:01 +00:00
|
|
|
if ( wfIniGetBool( 'safe_mode' ) ) {
|
|
|
|
|
$this->setVar( '_SafeMode', true );
|
|
|
|
|
$this->showMessage( 'config-safe-mode' );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-21 17:20:50 +00:00
|
|
|
/**
|
|
|
|
|
* Environment check for the XML module.
|
|
|
|
|
*/
|
2010-07-19 02:41:54 +00:00
|
|
|
public function envCheckXML() {
|
2010-05-07 12:25:01 +00:00
|
|
|
if ( !function_exists( "utf8_encode" ) ) {
|
|
|
|
|
$this->showMessage( 'config-xml-bad' );
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
$this->showMessage( 'config-xml-good' );
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-21 17:20:50 +00:00
|
|
|
/**
|
|
|
|
|
* Environment check for the PCRE module.
|
|
|
|
|
*/
|
2010-07-19 02:41:54 +00:00
|
|
|
public function envCheckPCRE() {
|
2010-05-07 12:25:01 +00:00
|
|
|
if ( !function_exists( 'preg_match' ) ) {
|
|
|
|
|
$this->showMessage( 'config-pcre' );
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-21 17:20:50 +00:00
|
|
|
/**
|
|
|
|
|
* Environment check for available memory.
|
|
|
|
|
*/
|
2010-07-19 02:41:54 +00:00
|
|
|
public function envCheckMemory() {
|
2010-05-07 12:25:01 +00:00
|
|
|
$limit = ini_get( 'memory_limit' );
|
2010-07-29 18:18:03 +00:00
|
|
|
|
2010-05-07 12:25:01 +00:00
|
|
|
if ( !$limit || $limit == -1 ) {
|
|
|
|
|
$this->showMessage( 'config-memory-none' );
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2010-07-29 18:18:03 +00:00
|
|
|
|
2010-05-07 12:25:01 +00:00
|
|
|
$n = intval( $limit );
|
2010-07-29 18:18:03 +00:00
|
|
|
|
2010-05-07 12:25:01 +00:00
|
|
|
if( preg_match( '/^([0-9]+)[Mm]$/', trim( $limit ), $m ) ) {
|
2010-07-21 17:20:50 +00:00
|
|
|
$n = intval( $m[1] * ( 1024 * 1024 ) );
|
2010-05-07 12:25:01 +00:00
|
|
|
}
|
2010-07-29 18:18:03 +00:00
|
|
|
|
2010-07-21 17:20:50 +00:00
|
|
|
if( $n < $this->minMemorySize * 1024 * 1024 ) {
|
2010-05-07 12:25:01 +00:00
|
|
|
$newLimit = "{$this->minMemorySize}M";
|
2010-07-29 18:18:03 +00:00
|
|
|
|
2010-07-21 17:20:50 +00:00
|
|
|
if( ini_set( "memory_limit", $newLimit ) === false ) {
|
2010-05-07 12:25:01 +00:00
|
|
|
$this->showMessage( 'config-memory-bad', $limit );
|
|
|
|
|
} else {
|
|
|
|
|
$this->showMessage( 'config-memory-raised', $limit, $newLimit );
|
|
|
|
|
$this->setVar( '_RaiseMemory', true );
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
$this->showMessage( 'config-memory-ok', $limit );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-21 17:20:50 +00:00
|
|
|
/**
|
|
|
|
|
* Environment check for compiled object cache types.
|
|
|
|
|
*/
|
2010-07-19 02:41:54 +00:00
|
|
|
public function envCheckCache() {
|
2010-05-07 12:25:01 +00:00
|
|
|
$caches = array();
|
2010-07-29 18:18:03 +00:00
|
|
|
|
2010-05-07 12:25:01 +00:00
|
|
|
foreach ( $this->objectCaches as $name => $function ) {
|
|
|
|
|
if ( function_exists( $function ) ) {
|
|
|
|
|
$caches[$name] = true;
|
|
|
|
|
$this->showMessage( 'config-' . $name );
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-07-29 18:18:03 +00:00
|
|
|
|
2010-05-07 12:25:01 +00:00
|
|
|
if ( !$caches ) {
|
|
|
|
|
$this->showMessage( 'config-no-cache' );
|
|
|
|
|
}
|
2010-07-29 18:18:03 +00:00
|
|
|
|
2010-05-07 12:25:01 +00:00
|
|
|
$this->setVar( '_Caches', $caches );
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-21 17:20:50 +00:00
|
|
|
/**
|
|
|
|
|
* Search for GNU diff3.
|
|
|
|
|
*/
|
2010-07-19 02:41:54 +00:00
|
|
|
public function envCheckDiff3() {
|
2010-05-07 12:25:01 +00:00
|
|
|
$names = array( "gdiff3", "diff3", "diff3.exe" );
|
|
|
|
|
$versionInfo = array( '$1 --version 2>&1', 'diff3 (GNU diffutils)' );
|
2010-07-29 18:18:03 +00:00
|
|
|
|
2010-05-07 12:25:01 +00:00
|
|
|
$haveDiff3 = false;
|
2010-07-29 18:18:03 +00:00
|
|
|
|
2010-10-16 18:19:00 +00:00
|
|
|
foreach ( $this->getPossibleBinPaths() as $path ) {
|
2010-05-07 12:25:01 +00:00
|
|
|
$exe = $this->locateExecutable( $path, $names, $versionInfo );
|
2010-07-29 18:18:03 +00:00
|
|
|
|
2010-05-07 12:25:01 +00:00
|
|
|
if ($exe !== false) {
|
|
|
|
|
$this->setVar( 'wgDiff3', $exe );
|
|
|
|
|
$haveDiff3 = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-07-29 18:18:03 +00:00
|
|
|
|
2010-05-07 12:25:01 +00:00
|
|
|
if ( $haveDiff3 ) {
|
|
|
|
|
$this->showMessage( 'config-diff3-good', $exe );
|
|
|
|
|
} else {
|
|
|
|
|
$this->setVar( 'wgDiff3', false );
|
|
|
|
|
$this->showMessage( 'config-diff3-bad' );
|
2010-07-22 17:58:26 +00:00
|
|
|
}
|
2010-07-29 18:18:03 +00:00
|
|
|
}
|
|
|
|
|
|
2010-07-21 17:20:50 +00:00
|
|
|
/**
|
|
|
|
|
* Environment check for ImageMagick and GD.
|
|
|
|
|
*/
|
2010-07-19 02:41:54 +00:00
|
|
|
public function envCheckGraphics() {
|
2010-10-16 18:19:00 +00:00
|
|
|
$names = array( 'convert', 'convert.exe' );
|
|
|
|
|
$haveConvert = false;
|
2010-07-29 18:18:03 +00:00
|
|
|
|
2010-10-16 18:19:00 +00:00
|
|
|
foreach ( $this->getPossibleBinPaths() as $path ) {
|
|
|
|
|
$exe = $this->locateExecutable( $path, $names );
|
2010-07-29 18:18:03 +00:00
|
|
|
|
2010-10-16 18:19:00 +00:00
|
|
|
if ($exe !== false) {
|
|
|
|
|
$this->setVar( 'wgImageMagickConvertCommand', $exe );
|
|
|
|
|
$haveConvert = true;
|
|
|
|
|
break;
|
2010-05-07 12:25:01 +00:00
|
|
|
}
|
|
|
|
|
}
|
2010-07-29 18:18:03 +00:00
|
|
|
|
2010-10-16 18:19:00 +00:00
|
|
|
if ( $haveConvert ) {
|
|
|
|
|
$this->showMessage( 'config-imagemagick', $exe );
|
|
|
|
|
return true;
|
|
|
|
|
} elseif ( function_exists( 'imagejpeg' ) ) {
|
2010-05-07 12:25:01 +00:00
|
|
|
$this->showMessage( 'config-gd' );
|
|
|
|
|
return true;
|
2010-10-16 18:19:00 +00:00
|
|
|
} else {
|
|
|
|
|
$this->showMessage( 'no-scaling' );
|
2010-05-07 12:25:01 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-21 17:31:00 +00:00
|
|
|
/**
|
|
|
|
|
* Environment check for setting $IP and $wgScriptPath.
|
|
|
|
|
*/
|
2010-07-19 02:41:54 +00:00
|
|
|
public function envCheckPath() {
|
2010-07-25 18:04:41 +00:00
|
|
|
global $IP;
|
2010-05-07 12:25:01 +00:00
|
|
|
$IP = dirname( dirname( dirname( __FILE__ ) ) );
|
2010-07-29 18:18:03 +00:00
|
|
|
|
2010-05-07 12:25:01 +00:00
|
|
|
$this->setVar( 'IP', $IP );
|
|
|
|
|
$this->showMessage( 'config-dir', $IP );
|
|
|
|
|
|
|
|
|
|
// PHP_SELF isn't available sometimes, such as when PHP is CGI but
|
|
|
|
|
// cgi.fix_pathinfo is disabled. In that case, fall back to SCRIPT_NAME
|
|
|
|
|
// to get the path to the current script... hopefully it's reliable. SIGH
|
|
|
|
|
if ( !empty( $_SERVER['PHP_SELF'] ) ) {
|
|
|
|
|
$path = $_SERVER['PHP_SELF'];
|
|
|
|
|
} elseif ( !empty( $_SERVER['SCRIPT_NAME'] ) ) {
|
|
|
|
|
$path = $_SERVER['SCRIPT_NAME'];
|
|
|
|
|
} elseif ( $this->getVar( 'wgScriptPath' ) ) {
|
|
|
|
|
// Some kind soul has set it for us already (e.g. debconf)
|
|
|
|
|
return true;
|
|
|
|
|
} else {
|
|
|
|
|
$this->showMessage( 'config-no-uri' );
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2010-07-29 18:18:03 +00:00
|
|
|
|
2010-05-07 12:25:01 +00:00
|
|
|
$uri = preg_replace( '{^(.*)/config.*$}', '$1', $path );
|
|
|
|
|
$this->setVar( 'wgScriptPath', $uri );
|
|
|
|
|
$this->showMessage( 'config-uri', $uri );
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-21 17:31:00 +00:00
|
|
|
/**
|
|
|
|
|
* Environment check for writable config/ directory.
|
|
|
|
|
*/
|
2010-07-19 02:41:54 +00:00
|
|
|
public function envCheckWriteableDir() {
|
2010-05-07 12:25:01 +00:00
|
|
|
$ipDir = $this->getVar( 'IP' );
|
|
|
|
|
$configDir = $ipDir . '/config';
|
2010-07-29 18:18:03 +00:00
|
|
|
|
2010-05-07 12:25:01 +00:00
|
|
|
if( !is_writeable( $configDir ) ) {
|
|
|
|
|
$webserverGroup = self::maybeGetWebserverPrimaryGroup();
|
2010-07-29 18:18:03 +00:00
|
|
|
|
2010-05-07 12:25:01 +00:00
|
|
|
if ( $webserverGroup !== null ) {
|
|
|
|
|
$this->showMessage( 'config-dir-not-writable-group', $ipDir, $webserverGroup );
|
|
|
|
|
} else {
|
|
|
|
|
$this->showMessage( 'config-dir-not-writable-nogroup', $ipDir, $webserverGroup );
|
|
|
|
|
}
|
2010-07-29 18:18:03 +00:00
|
|
|
|
2010-05-07 12:25:01 +00:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-21 17:31:00 +00:00
|
|
|
/**
|
|
|
|
|
* Environment check for setting the preferred PHP file extension.
|
|
|
|
|
*/
|
2010-07-19 02:41:54 +00:00
|
|
|
public function envCheckExtension() {
|
2010-05-07 12:25:01 +00:00
|
|
|
// FIXME: detect this properly
|
|
|
|
|
if ( defined( 'MW_INSTALL_PHP5_EXT' ) ) {
|
|
|
|
|
$ext = 'php5';
|
|
|
|
|
} else {
|
|
|
|
|
$ext = 'php';
|
|
|
|
|
}
|
2010-07-29 18:18:03 +00:00
|
|
|
|
2010-05-07 12:25:01 +00:00
|
|
|
$this->setVar( 'wgScriptExtension', ".$ext" );
|
|
|
|
|
$this->showMessage( 'config-file-extension', $ext );
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-22 17:58:26 +00:00
|
|
|
/**
|
|
|
|
|
* TODO: document
|
|
|
|
|
*/
|
2010-07-19 02:41:54 +00:00
|
|
|
public function envCheckShellLocale() {
|
2010-07-21 17:31:00 +00:00
|
|
|
# Give up now if we're in safe mode or open_basedir.
|
|
|
|
|
# It's theoretically possible but tricky to work with.
|
2010-05-07 12:25:01 +00:00
|
|
|
if ( wfIniGetBool( "safe_mode" ) || ini_get( 'open_basedir' ) || !function_exists( 'exec' ) ) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$os = php_uname( 's' );
|
|
|
|
|
$supported = array( 'Linux', 'SunOS', 'HP-UX' ); # Tested these
|
2010-07-29 18:18:03 +00:00
|
|
|
|
2010-05-07 12:25:01 +00:00
|
|
|
if ( !in_array( $os, $supported ) ) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-21 17:31:00 +00:00
|
|
|
# Get a list of available locales.
|
2010-05-07 12:25:01 +00:00
|
|
|
$lines = $ret = false;
|
|
|
|
|
exec( '/usr/bin/locale -a', $lines, $ret );
|
2010-07-29 18:18:03 +00:00
|
|
|
|
2010-05-07 12:25:01 +00:00
|
|
|
if ( $ret ) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$lines = wfArrayMap( 'trim', $lines );
|
|
|
|
|
$candidatesByLocale = array();
|
|
|
|
|
$candidatesByLang = array();
|
2010-07-29 18:18:03 +00:00
|
|
|
|
2010-05-07 12:25:01 +00:00
|
|
|
foreach ( $lines as $line ) {
|
|
|
|
|
if ( $line === '' ) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2010-07-29 18:18:03 +00:00
|
|
|
|
2010-05-07 12:25:01 +00:00
|
|
|
if ( !preg_match( '/^([a-zA-Z]+)(_[a-zA-Z]+|)\.(utf8|UTF-8)(@[a-zA-Z_]*|)$/i', $line, $m ) ) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2010-07-29 18:18:03 +00:00
|
|
|
|
2010-05-07 12:25:01 +00:00
|
|
|
list( $all, $lang, $territory, $charset, $modifier ) = $m;
|
2010-07-29 18:18:03 +00:00
|
|
|
|
2010-05-07 12:25:01 +00:00
|
|
|
$candidatesByLocale[$m[0]] = $m;
|
|
|
|
|
$candidatesByLang[$lang][] = $m;
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-21 17:31:00 +00:00
|
|
|
# Try the current value of LANG.
|
2010-05-07 12:25:01 +00:00
|
|
|
if ( isset( $candidatesByLocale[ getenv( 'LANG' ) ] ) ) {
|
|
|
|
|
$this->setVar( 'wgShellLocale', getenv( 'LANG' ) );
|
|
|
|
|
$this->showMessage( 'config-shell-locale', getenv( 'LANG' ) );
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-21 17:31:00 +00:00
|
|
|
# Try the most common ones.
|
2010-05-07 12:25:01 +00:00
|
|
|
$commonLocales = array( 'en_US.UTF-8', 'en_US.utf8', 'de_DE.UTF-8', 'de_DE.utf8' );
|
|
|
|
|
foreach ( $commonLocales as $commonLocale ) {
|
|
|
|
|
if ( isset( $candidatesByLocale[$commonLocale] ) ) {
|
|
|
|
|
$this->setVar( 'wgShellLocale', $commonLocale );
|
|
|
|
|
$this->showMessage( 'config-shell-locale', $commonLocale );
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Is there an available locale in the Wiki's language?
|
|
|
|
|
$wikiLang = $this->getVar( 'wgLanguageCode' );
|
2010-07-29 18:18:03 +00:00
|
|
|
|
2010-05-07 12:25:01 +00:00
|
|
|
if ( isset( $candidatesByLang[$wikiLang] ) ) {
|
|
|
|
|
$m = reset( $candidatesByLang[$wikiLang] );
|
|
|
|
|
$this->setVar( 'wgShellLocale', $m[0] );
|
|
|
|
|
$this->showMessage( 'config-shell-locale', $m[0] );
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Are there any at all?
|
|
|
|
|
if ( count( $candidatesByLocale ) ) {
|
|
|
|
|
$m = reset( $candidatesByLocale );
|
|
|
|
|
$this->setVar( 'wgShellLocale', $m[0] );
|
|
|
|
|
$this->showMessage( 'config-shell-locale', $m[0] );
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-21 17:31:00 +00:00
|
|
|
# Give up.
|
2010-05-07 12:25:01 +00:00
|
|
|
return true;
|
|
|
|
|
}
|
2010-07-18 18:52:05 +00:00
|
|
|
|
2010-07-22 17:58:26 +00:00
|
|
|
/**
|
|
|
|
|
* TODO: document
|
|
|
|
|
*/
|
2010-07-19 02:41:54 +00:00
|
|
|
public function envCheckUploadsDirectory() {
|
2010-05-07 12:25:01 +00:00
|
|
|
global $IP, $wgServer;
|
2010-07-29 18:18:03 +00:00
|
|
|
|
2010-05-07 12:25:01 +00:00
|
|
|
$dir = $IP . '/images/';
|
|
|
|
|
$url = $wgServer . $this->getVar( 'wgScriptPath' ) . '/images/';
|
|
|
|
|
$safe = !$this->dirIsExecutable( $dir, $url );
|
2010-07-29 18:18:03 +00:00
|
|
|
|
2010-05-07 12:25:01 +00:00
|
|
|
if ( $safe ) {
|
|
|
|
|
$this->showMessage( 'config-uploads-safe' );
|
|
|
|
|
} else {
|
|
|
|
|
$this->showMessage( 'config-uploads-not-safe', $dir );
|
|
|
|
|
}
|
2010-07-29 18:18:03 +00:00
|
|
|
}
|
|
|
|
|
|
2010-07-29 02:44:23 +00:00
|
|
|
/**
|
|
|
|
|
* Convert a hex string representing a Unicode code point to that code point.
|
2010-08-21 18:20:09 +00:00
|
|
|
* @param $c String
|
2010-07-29 02:44:23 +00:00
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
protected function unicodeChar( $c ) {
|
|
|
|
|
$c = hexdec($c);
|
|
|
|
|
if ($c <= 0x7F) {
|
|
|
|
|
return chr($c);
|
|
|
|
|
} else if ($c <= 0x7FF) {
|
|
|
|
|
return chr(0xC0 | $c >> 6) . chr(0x80 | $c & 0x3F);
|
|
|
|
|
} else if ($c <= 0xFFFF) {
|
|
|
|
|
return chr(0xE0 | $c >> 12) . chr(0x80 | $c >> 6 & 0x3F)
|
|
|
|
|
. chr(0x80 | $c & 0x3F);
|
|
|
|
|
} else if ($c <= 0x10FFFF) {
|
|
|
|
|
return chr(0xF0 | $c >> 18) . chr(0x80 | $c >> 12 & 0x3F)
|
|
|
|
|
. chr(0x80 | $c >> 6 & 0x3F)
|
|
|
|
|
. chr(0x80 | $c & 0x3F);
|
|
|
|
|
} else {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Check the libicu version
|
|
|
|
|
*/
|
|
|
|
|
public function envCheckLibicu() {
|
|
|
|
|
$utf8 = function_exists( 'utf8_normalize' );
|
|
|
|
|
$intl = function_exists( 'normalizer_normalize' );
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* This needs to be updated something that the latest libicu
|
|
|
|
|
* will properly normalize. This normalization was found at
|
|
|
|
|
* http://www.unicode.org/versions/Unicode5.2.0/#Character_Additions
|
|
|
|
|
* Note that we use the hex representation to create the code
|
2010-07-29 19:28:16 +00:00
|
|
|
* points in order to avoid any Unicode-destroying during transit.
|
2010-07-29 02:44:23 +00:00
|
|
|
*/
|
|
|
|
|
$not_normal_c = $this->unicodeChar("FA6C");
|
|
|
|
|
$normal_c = $this->unicodeChar("242EE");
|
|
|
|
|
|
2010-08-02 11:54:11 +00:00
|
|
|
$useNormalizer = 'php';
|
2010-07-29 19:28:16 +00:00
|
|
|
$needsUpdate = false;
|
2010-07-29 02:44:23 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* We're going to prefer the pecl extension here unless
|
|
|
|
|
* utf8_normalize is more up to date.
|
|
|
|
|
*/
|
|
|
|
|
if( $utf8 ) {
|
2010-08-02 11:54:11 +00:00
|
|
|
$useNormalizer = 'utf8';
|
2010-07-29 19:28:16 +00:00
|
|
|
$utf8 = utf8_normalize( $not_normal_c, UNORM_NFC );
|
|
|
|
|
if ( $utf8 !== $normal_c ) $needsUpdate = true;
|
2010-07-29 02:44:23 +00:00
|
|
|
}
|
|
|
|
|
if( $intl ) {
|
2010-08-02 11:54:11 +00:00
|
|
|
$useNormalizer = 'intl';
|
2010-07-29 19:28:16 +00:00
|
|
|
$intl = normalizer_normalize( $not_normal_c, Normalizer::FORM_C );
|
|
|
|
|
if ( $intl !== $normal_c ) $needsUpdate = true;
|
2010-07-29 02:44:23 +00:00
|
|
|
}
|
|
|
|
|
|
2010-08-02 11:54:11 +00:00
|
|
|
// Uses messages 'config-unicode-using-php', 'config-unicode-using-utf8', 'config-unicode-using-intl'
|
|
|
|
|
$this->showMessage( 'config-unicode-using-' . $useNormalizer );
|
|
|
|
|
if( $useNormalizer === 'php' ) {
|
2010-07-29 02:44:23 +00:00
|
|
|
$this->showMessage( 'config-unicode-pure-php-warning' );
|
2010-07-29 19:28:16 +00:00
|
|
|
} elseif( $needsUpdate ) {
|
|
|
|
|
$this->showMessage( 'config-unicode-update-warning' );
|
2010-07-29 02:44:23 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2010-07-22 17:58:26 +00:00
|
|
|
/**
|
|
|
|
|
* Search a path for any of the given executable names. Returns the
|
|
|
|
|
* executable name if found. Also checks the version string returned
|
|
|
|
|
* by each executable.
|
2010-07-29 18:18:03 +00:00
|
|
|
*
|
2010-07-22 17:58:26 +00:00
|
|
|
* Used only by environment checks.
|
|
|
|
|
*
|
|
|
|
|
* @param $path String: path to search
|
|
|
|
|
* @param $names Array of executable names
|
|
|
|
|
* @param $versionInfo Boolean false or array with two members:
|
|
|
|
|
* 0 => Command to run for version check, with $1 for the path
|
|
|
|
|
* 1 => String to compare the output with
|
|
|
|
|
*
|
|
|
|
|
* If $versionInfo is not false, only executables with a version
|
|
|
|
|
* matching $versionInfo[1] will be returned.
|
|
|
|
|
*/
|
|
|
|
|
protected function locateExecutable( $path, $names, $versionInfo = false ) {
|
|
|
|
|
if ( !is_array( $names ) ) {
|
|
|
|
|
$names = array( $names );
|
|
|
|
|
}
|
2010-05-07 12:25:01 +00:00
|
|
|
|
2010-07-22 17:58:26 +00:00
|
|
|
foreach ( $names as $name ) {
|
|
|
|
|
$command = "$path/$name";
|
2010-07-29 18:18:03 +00:00
|
|
|
|
2010-07-22 17:58:26 +00:00
|
|
|
wfSuppressWarnings();
|
|
|
|
|
$file_exists = file_exists( $command );
|
|
|
|
|
wfRestoreWarnings();
|
2010-07-29 18:18:03 +00:00
|
|
|
|
2010-07-22 17:58:26 +00:00
|
|
|
if ( $file_exists ) {
|
|
|
|
|
if ( !$versionInfo ) {
|
|
|
|
|
return $command;
|
|
|
|
|
}
|
2010-07-29 18:18:03 +00:00
|
|
|
|
2010-07-22 17:58:26 +00:00
|
|
|
$file = str_replace( '$1', $command, $versionInfo[0] );
|
2010-07-29 18:18:03 +00:00
|
|
|
|
2010-07-22 17:58:26 +00:00
|
|
|
# Should maybe be wfShellExec( $file), but runs into a ulimit, see
|
|
|
|
|
# http://www.mediawiki.org/w/index.php?title=New-installer_issues&diff=prev&oldid=335456
|
|
|
|
|
if ( strstr( `$file`, $versionInfo[1]) !== false ) {
|
|
|
|
|
return $command;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-07-29 18:18:03 +00:00
|
|
|
|
2010-07-22 17:58:26 +00:00
|
|
|
return false;
|
2010-07-29 18:18:03 +00:00
|
|
|
}
|
|
|
|
|
|
2010-05-07 12:25:01 +00:00
|
|
|
/**
|
2010-07-19 02:41:54 +00:00
|
|
|
* Checks if scripts located in the given directory can be executed via the given URL.
|
2010-07-29 18:18:03 +00:00
|
|
|
*
|
2010-07-22 17:58:26 +00:00
|
|
|
* Used only by environment checks.
|
2010-05-07 12:25:01 +00:00
|
|
|
*/
|
2010-07-19 02:41:54 +00:00
|
|
|
public function dirIsExecutable( $dir, $url ) {
|
2010-05-07 12:25:01 +00:00
|
|
|
$scriptTypes = array(
|
|
|
|
|
'php' => array(
|
|
|
|
|
"<?php echo 'ex' . 'ec';",
|
|
|
|
|
"#!/var/env php5\n<?php echo 'ex' . 'ec';",
|
|
|
|
|
),
|
|
|
|
|
);
|
2010-07-29 18:18:03 +00:00
|
|
|
|
2010-07-21 17:31:00 +00:00
|
|
|
// it would be good to check other popular languages here, but it'll be slow.
|
2010-05-07 12:25:01 +00:00
|
|
|
|
|
|
|
|
wfSuppressWarnings();
|
2010-07-29 18:18:03 +00:00
|
|
|
|
2010-05-07 12:25:01 +00:00
|
|
|
foreach ( $scriptTypes as $ext => $contents ) {
|
|
|
|
|
foreach ( $contents as $source ) {
|
|
|
|
|
$file = 'exectest.' . $ext;
|
2010-07-29 18:18:03 +00:00
|
|
|
|
2010-05-07 12:25:01 +00:00
|
|
|
if ( !file_put_contents( $dir . $file, $source ) ) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
2010-07-29 18:18:03 +00:00
|
|
|
|
2010-05-07 12:25:01 +00:00
|
|
|
$text = Http::get( $url . $file );
|
|
|
|
|
unlink( $dir . $file );
|
2010-07-29 18:18:03 +00:00
|
|
|
|
2010-05-07 12:25:01 +00:00
|
|
|
if ( $text == 'exec' ) {
|
|
|
|
|
wfRestoreWarnings();
|
|
|
|
|
return $ext;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-07-29 18:18:03 +00:00
|
|
|
|
2010-05-07 12:25:01 +00:00
|
|
|
wfRestoreWarnings();
|
2010-07-29 18:18:03 +00:00
|
|
|
|
2010-05-07 12:25:01 +00:00
|
|
|
return false;
|
2010-07-29 18:18:03 +00:00
|
|
|
}
|
|
|
|
|
|
2010-07-25 18:04:41 +00:00
|
|
|
}
|