<?php
+/**
+ * Base code for MediaWiki installer.
+ *
+ * @file
+ * @ingroup Deployment
+ */
/**
* This documentation group collects source code files with deployment functionality.
*
* @var array
*/
- protected $dbTypes = array(
+ protected static $dbTypes = array(
'mysql',
'postgres',
+ 'oracle',
'sqlite',
- 'oracle'
);
/**
* @var array
*/
protected $envChecks = array(
- 'envLatestVersion',
+ 'envCheckMediaWikiVersion',
'envCheckDB',
'envCheckRegisterGlobals',
+ 'envCheckBrokenXML',
+ 'envCheckPHP531',
'envCheckMagicQuotes',
'envCheckMagicSybase',
'envCheckMbstring',
'envCheckDiff3',
'envCheckGraphics',
'envCheckPath',
- 'envCheckWriteableDir',
'envCheckExtension',
'envCheckShellLocale',
'envCheckUploadsDirectory',
/**
* Get a list of known DB types.
*/
- public function getDBTypes() {
- return $this->dbTypes;
+ public static function getDBTypes() {
+ return self::$dbTypes;
}
/**
/**
* Determine if LocalSettings exists. If it does, return an appropriate
- * status for whether we should can upgrade or not.
+ * status for whether upgrading is enabled or not.
*
* @return Status
*/
wfRestoreWarnings();
if( $ls ) {
- if( $this->getDBInstaller()->needsUpgrade() ) {
+ require( "$IP/includes/DefaultSettings.php" );
+ require_once( "$IP/LocalSettings.php" );
+ $vars = get_defined_vars();
+ if( isset( $vars['wgUpgradeKey'] ) && $vars['wgUpgradeKey'] ) {
$status->warning( 'config-localsettings-upgrade' );
- }
- else {
+ $this->setVar( '_UpgradeKey', $vars['wgUpgradeKey' ] );
+ } else {
$status->fatal( 'config-localsettings-noupgrade' );
}
}
* 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
+ * whatever, this function is guarded to catch the attempted DB access and to present
* some fallback text.
*
* @param $text String
/**
* TODO: document
*
- * @param DatabaseInstaller $installer
- *
- * @return Status
- */
- public function installDatabase( DatabaseInstaller &$installer ) {
- if( !$installer ) {
- $type = $this->getVar( 'wgDBtype' );
- $status = Status::newFatal( "config-no-db", $type );
- } else {
- $status = $installer->setupDatabase();
- }
-
- return $status;
- }
-
- /**
- * TODO: document
- *
- * @param DatabaseInstaller $installer
+ * @param $installer DatabaseInstaller
*
* @return Status
*/
if( $status->isOK() ) {
LBFactory::enableBackend();
}
-
+
return $status;
}
- /**
- * TODO: document
- *
- * @param DatabaseInstaller $installer
- *
- * @return Status
- */
- public function installInterwiki( DatabaseInstaller &$installer ) {
- return $installer->populateInterwikiTable();
- }
-
/**
* Exports all wg* variables stored by the installer into global scope.
*/
/**
* Check if we're installing the latest version.
*/
- public function envLatestVersion() {
+ public function envCheckMediaWikiVersion() {
global $wgVersion;
- $latestInfoUrl = 'http://www.mediawiki.org/w/api.php?action=mwreleases&format=json';
- $latestInfo = Http::get( $latestInfoUrl );
-
- if( !$latestInfo ) {
- $this->showMessage( 'config-env-latest-can-not-check', $latestInfoUrl );
+ if( !$this->getVar( '_ExternalHTTP' ) ) {
+ $this->showMessage( 'config-env-latest-disabled' );
return;
}
- $this->setVar( '_ExternalHTTP', true );
- $latestInfo = FormatJson::decode($latestInfo);
+ $repository = wfGetRepository();
+ $currentVersion = $repository->getLatestCoreVersion();
- if ($latestInfo === false || !isset( $latestInfo->mwreleases ) ) {
+ if ( $currentVersion === false ) {
# 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
- $this->showMessage( 'config-env-latest-data-invalid', $latestInfoUrl );
+ $this->showMessage( 'config-env-latest-can-not-check', $repository->getLocation() );
return;
}
- foreach( $latestInfo->mwreleases as $rel ) {
- if( isset( $rel->current ) ) {
- $currentVersion = $rel->version;
- }
- }
-
if( version_compare( $wgVersion, $currentVersion, '<' ) ) {
$this->showMessage( 'config-env-latest-old' );
+ // FIXME: this only works for the web installer!
$this->showHelpBox( 'config-env-latest-help', $wgVersion, $currentVersion );
} elseif( version_compare( $wgVersion, $currentVersion, '>' ) ) {
$this->showMessage( 'config-env-latest-new' );
+ } else {
+ $this->showMessage( 'config-env-latest-ok' );
}
-
- $this->showMessage( 'config-env-latest-ok' );
}
/**
$goodNames = array();
$allNames = array();
- foreach ( $this->dbTypes as $name ) {
+ foreach ( self::getDBTypes() as $name ) {
$db = $this->getDBInstaller( $name );
$readableName = wfMsg( 'config-type-' . $name );
if ( !$compiledDBs ) {
$this->showMessage( 'config-no-db' );
+ // FIXME: this only works for the web installer!
$this->showHelpBox( 'config-no-db-help', $wgLang->commaList( $allNames ) );
return false;
}
- $this->showMessage( 'config-have-db', $wgLang->commaList( $goodNames ) );
+ $this->showMessage( 'config-have-db', $wgLang->listToText( $goodNames ), count( $goodNames ) );
+
+ // Check for FTS3 full-text search module
+ $sqlite = $this->getDBInstaller( 'sqlite' );
+ if ( $sqlite->isCompiled() ) {
+ $db = new DatabaseSqliteStandalone( ':memory:' );
+ $this->showMessage( $db->getFulltextSearchModule() == 'FTS3'
+ ? 'config-have-fts3'
+ : 'config-no-fts3'
+ );
+ }
}
/**
}
}
+ /**
+ * Some versions of libxml+PHP break < and > encoding horribly
+ */
+ public function envCheckBrokenXML() {
+ $test = new PhpXmlBugTester();
+ if ( !$test->ok ) {
+ $this->showMessage( 'config-brokenlibxml' );
+ return false;
+ }
+ }
+
+ /**
+ * Test PHP (probably 5.3.1, but it could regress again) to make sure that
+ * reference parameters to __call() are not converted to null
+ */
+ public function envCheckPHP531() {
+ $test = new PhpRefCallBugTester;
+ $test->execute();
+ if ( !$test->ok ) {
+ $this->showMessage( 'config-using531' );
+ return false;
+ }
+ }
+
/**
* Environment check for magic_quotes_runtime.
*/
$this->showMessage( 'config-pcre' );
return false;
}
+ wfSuppressWarnings();
+ $regexd = preg_replace( '/[\x{0400}-\x{04FF}]/u', '', '-АБВГД-' );
+ wfRestoreWarnings();
+ if ( $regexd != '--' ) {
+ $this->showMessage( 'config-pcre-no-utf8' );
+ return false;
+ }
}
/**
* Search for GNU diff3.
*/
public function envCheckDiff3() {
- $paths = array_merge(
- array(
- "/usr/bin",
- "/usr/local/bin",
- "/opt/csw/bin",
- "/usr/gnu/bin",
- "/usr/sfw/bin"
- ),
- explode( PATH_SEPARATOR, getenv( "PATH" ) )
- );
-
$names = array( "gdiff3", "diff3", "diff3.exe" );
- $versionInfo = array( '$1 --version 2>&1', 'diff3 (GNU diffutils)' );
-
- $haveDiff3 = false;
+ $versionInfo = array( '$1 --version 2>&1', 'GNU diffutils' );
- foreach ( $paths as $path ) {
- $exe = $this->locateExecutable( $path, $names, $versionInfo );
+ $diff3 = $this->locateExecutableInDefaultPaths( $names, $versionInfo );
- if ($exe !== false) {
- $this->setVar( 'wgDiff3', $exe );
- $haveDiff3 = true;
- break;
- }
- }
-
- if ( $haveDiff3 ) {
- $this->showMessage( 'config-diff3-good', $exe );
+ if ( $diff3 ) {
+ $this->showMessage( 'config-diff3-good', $diff3 );
+ $this->setVar( 'wgDiff3', $diff3 );
} else {
$this->setVar( 'wgDiff3', false );
$this->showMessage( 'config-diff3-bad' );
* Environment check for ImageMagick and GD.
*/
public function envCheckGraphics() {
- $imcheck = array( "/usr/bin", "/opt/csw/bin", "/usr/local/bin", "/sw/bin", "/opt/local/bin" );
-
- foreach( $imcheck as $dir ) {
- $im = "$dir/convert";
-
- wfSuppressWarnings();
- $file_exists = file_exists( $im );
- wfRestoreWarnings();
+ $names = array( wfIsWindows() ? 'convert.exe' : 'convert' );
+ $convert = $this->locateExecutableInDefaultPaths( $names, array( '$1 -version', 'ImageMagick' ) );
- if( $file_exists ) {
- $this->showMessage( 'config-imagemagick', $im );
- $this->setVar( 'wgImageMagickConvertCommand', $im );
- return true;
- }
- }
-
- if ( function_exists( 'imagejpeg' ) ) {
+ if ( $convert ) {
+ $this->setVar( 'wgImageMagickConvertCommand', $convert );
+ $this->showMessage( 'config-imagemagick', $convert );
+ return true;
+ } elseif ( function_exists( 'imagejpeg' ) ) {
$this->showMessage( 'config-gd' );
return true;
+ } else {
+ $this->showMessage( 'no-scaling' );
}
-
- $this->showMessage( 'no-scaling' );
}
/**
$this->showMessage( 'config-uri', $uri );
}
- /**
- * Environment check for writable config/ directory.
- */
- public function envCheckWriteableDir() {
- $ipDir = $this->getVar( 'IP' );
- $configDir = $ipDir . '/config';
-
- if( !is_writeable( $configDir ) ) {
- $webserverGroup = self::maybeGetWebserverPrimaryGroup();
-
- if ( $webserverGroup !== null ) {
- $this->showMessage( 'config-dir-not-writable-group', $ipDir, $webserverGroup );
- } else {
- $this->showMessage( 'config-dir-not-writable-nogroup', $ipDir, $webserverGroup );
- }
-
- return false;
- }
- }
-
/**
* Environment check for setting the preferred PHP file extension.
*/
* TODO: document
*/
public function envCheckShellLocale() {
- # Give up now if we're in safe mode or open_basedir.
- # It's theoretically possible but tricky to work with.
- 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
+ $supported = array( 'Linux', 'SunOS', 'HP-UX', 'Darwin' ); # Tested these
if ( !in_array( $os, $supported ) ) {
return true;
}
# Get a list of available locales.
- $lines = $ret = false;
- exec( '/usr/bin/locale -a', $lines, $ret );
+ $ret = false;
+ $lines = wfShellExec( '/usr/bin/locale -a', $ret );
if ( $ret ) {
return true;
}
- $lines = wfArrayMap( 'trim', $lines );
+ $lines = wfArrayMap( 'trim', explode( "\n", $lines ) );
$candidatesByLocale = array();
$candidatesByLang = array();
/**
* Convert a hex string representing a Unicode code point to that code point.
- * @param string $c
+ * @param $c String
* @return string
*/
protected function unicodeChar( $c ) {
* 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
- * points in order to avoid any Unicode-destroying during transite.
+ * points in order to avoid any Unicode-destroying during transit.
*/
$not_normal_c = $this->unicodeChar("FA6C");
$normal_c = $this->unicodeChar("242EE");
- $useNormalizer = 'config-unicode-php';
+ $useNormalizer = 'php';
+ $needsUpdate = false;
/**
* We're going to prefer the pecl extension here unless
* utf8_normalize is more up to date.
*/
if( $utf8 ) {
+ $useNormalizer = 'utf8';
$utf8 = utf8_normalize( $not_normal_c, UNORM_NFC );
- $useNormalizer = 'config-unicode-utf8';
+ if ( $utf8 !== $normal_c ) $needsUpdate = true;
}
if( $intl ) {
+ $useNormalizer = 'intl';
$intl = normalizer_normalize( $not_normal_c, Normalizer::FORM_C );
- $useNormalizer = 'config-unicode-intl';
+ if ( $intl !== $normal_c ) $needsUpdate = true;
}
- $this->showMessage( $useNormalizer );
- if( $useNormalizer === 'config-unicode-php' ) {
+ // Uses messages 'config-unicode-using-php', 'config-unicode-using-utf8', 'config-unicode-using-intl'
+ if( $useNormalizer === 'php' ) {
$this->showMessage( 'config-unicode-pure-php-warning' );
+ } else {
+ $this->showMessage( 'config-unicode-using-' . $useNormalizer );
+ if( $needsUpdate ) {
+ $this->showMessage( 'config-unicode-update-warning' );
+ }
}
}
+ /**
+ * 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 static 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' ) )
+ );
+ }
/**
* Search a path for any of the given executable names. Returns the
* @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
+ * 0 => Command to run for version check, with $1 for the full executable name
* 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 ) {
+ public static function locateExecutable( $path, $names, $versionInfo = false ) {
if ( !is_array( $names ) ) {
$names = array( $names );
}
foreach ( $names as $name ) {
- $command = "$path/$name";
+ $command = $path . DIRECTORY_SEPARATOR . $name;
wfSuppressWarnings();
$file_exists = file_exists( $command );
return $command;
}
+ if ( wfIsWindows() ) {
+ $command = "\"$command\"";
+ }
$file = str_replace( '$1', $command, $versionInfo[0] );
-
- # 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 ) {
+ if ( strstr( wfShellExec( $file ), $versionInfo[1] ) !== false ) {
return $command;
}
}
}
+ return false;
+ }
+ /**
+ * Same as locateExecutable(), but checks in getPossibleBinPaths() by default
+ * @see locateExecutable()
+ */
+ public static function locateExecutableInDefaultPaths( $names, $versionInfo = false ) {
+ foreach( self::getPossibleBinPaths() as $path ) {
+ $exe = self::locateExecutable( $path, $names, $versionInfo );
+ if( $exe !== false ) {
+ return $exe;
+ }
+ }
return false;
}