wiki.techinc.nl/includes/installer/DatabaseInstaller.php

575 lines
15 KiB
PHP
Raw Normal View History

<?php
/**
* DBMS-specific installation helper.
*
* @file
* @ingroup Deployment
*/
/**
* Base class for DBMS-specific installation helper classes.
*
2010-07-29 18:36:39 +00:00
* @ingroup Deployment
* @since 1.17
*/
abstract class DatabaseInstaller {
2010-12-16 11:20:39 +00:00
2010-07-20 11:17:36 +00:00
/**
* The Installer object.
*
2010-07-20 11:17:36 +00:00
* TODO: naming this parent is confusing, 'installer' would be clearer.
*
* @var Installer
2010-07-20 11:17:36 +00:00
*/
2010-07-20 11:00:51 +00:00
public $parent;
2010-07-20 11:17:36 +00:00
/**
* The database connection.
*
2010-07-20 11:17:36 +00:00
* @var DatabaseBase
*/
public $db = null;
2010-07-20 11:17:36 +00:00
/**
* Internal variables for installation.
*
2010-07-20 11:17:36 +00:00
* @var array
*/
protected $internalDefaults = array();
2010-07-20 11:17:36 +00:00
/**
* Array of MW configuration globals this class uses.
*
2010-07-20 11:17:36 +00:00
* @var array
*/
protected $globalNames = array();
/**
2010-07-20 11:00:51 +00:00
* Return the internal name, e.g. 'mysql', or 'sqlite'.
*/
2010-07-20 11:00:51 +00:00
public abstract function getName();
/**
2010-07-20 11:00:51 +00:00
* @return true if the client library is compiled in.
*/
2010-07-20 11:00:51 +00:00
public abstract function isCompiled();
/**
* Get HTML for a web form that configures this database. Configuration
* at this time should be the minimum needed to connect and test
* whether install or upgrade is required.
*
2010-07-20 11:17:36 +00:00
* If this is called, $this->parent can be assumed to be a WebInstaller.
*/
2010-07-20 11:00:51 +00:00
public abstract function getConnectForm();
/**
* Set variables based on the request array, assuming it was submitted
* via the form returned by getConnectForm(). Validate the connection
* settings by attempting to connect with them.
*
2010-07-20 11:17:36 +00:00
* If this is called, $this->parent can be assumed to be a WebInstaller.
*
* @return Status
*/
2010-07-20 11:00:51 +00:00
public abstract function submitConnectForm();
/**
* Get HTML for a web form that retrieves settings used for installation.
* $this->parent can be assumed to be a WebInstaller.
* If the DB type has no settings beyond those already configured with
* getConnectForm(), this should return false.
*/
public function getSettingsForm() {
return false;
}
/**
* Set variables based on the request array, assuming it was submitted via
* the form return by getSettingsForm().
*
* @return Status
*/
public function submitSettingsForm() {
return Status::newGood();
}
/**
* Fixed a bug causing the installer to ignore the "engine" and "charset" settings when installing a MySQL database. * Fixed a bug causing the engine and charset settings to not be properly preserved when adding new tables on upgrade. * Fixed total breakage of SQLite upgrade, by reusing the administrative connection to the SQLite database instead of creating a new one when wfGetDB() is called. Added LBFactory_Single to support this. * Introduced a "schema variable" concept to DatabaseBase to avoid the use of globals for communication between the installer and the Database. Removed a lot of old global variable names from Database::replaceVars(), most were only added on a whim and were never used. * Introduced DatabaseInstaller::getSchemaVars(), to allow schema variables to be supplied by the DatabaseInstaller child classes. * Removed messages config-mysql-egine-mismatch [sic] and config-mysql-charset-mismatch. In the old installer it was possible for users to request a certain character set for an upgrade, but in the new installer the question is never asked. So these warnings were shown whenever a non-default character set or engine was used in the old database. * In MysqlInstaller::preUpgrade(), fixed the incorrect strings used to identify the MySQL character sets: mysql5 instead of utf8 and mysql5-binary instead of binary. * On install, initialise the site_stats table, using code copied from the old installer. Unlike the old installer, use SiteStats to increment the user count when the initial user is added. * Fixed several instances of inappropriate call-by-reference. * Replaced call_user_func_array() with call_user_func() where possible, it is shorter and simpler. * Moved the caching boilerplate for DatabaseInstaller::getConnection() to the base class, and have the derived classes override an uncached function openConnection() instead. Updates r80892. * In MysqlInstaller::getLocalSettings(), escape PHP strings correctly with LocalSettingsGenerator::escapePhpString(). * Reduce timeout for checks in dirIsExecutable() to 3 seconds, so that it doesn't take 30s to run when apache is in single-threaded mode for debugging. * MySQL and SQLite have been tested and they appear to work. PostgreSQL upgrade is totally broken, apparently it was like that before I started. The Oracle code is untested.
2011-01-25 07:37:48 +00:00
* Open a connection to the database using the administrative user/password
* currently defined in the session, without any caching. Returns a status
* object. On success, the status object will contain a Database object in
* its value member.
*
* @return Status
*/
* Fixed a bug causing the installer to ignore the "engine" and "charset" settings when installing a MySQL database. * Fixed a bug causing the engine and charset settings to not be properly preserved when adding new tables on upgrade. * Fixed total breakage of SQLite upgrade, by reusing the administrative connection to the SQLite database instead of creating a new one when wfGetDB() is called. Added LBFactory_Single to support this. * Introduced a "schema variable" concept to DatabaseBase to avoid the use of globals for communication between the installer and the Database. Removed a lot of old global variable names from Database::replaceVars(), most were only added on a whim and were never used. * Introduced DatabaseInstaller::getSchemaVars(), to allow schema variables to be supplied by the DatabaseInstaller child classes. * Removed messages config-mysql-egine-mismatch [sic] and config-mysql-charset-mismatch. In the old installer it was possible for users to request a certain character set for an upgrade, but in the new installer the question is never asked. So these warnings were shown whenever a non-default character set or engine was used in the old database. * In MysqlInstaller::preUpgrade(), fixed the incorrect strings used to identify the MySQL character sets: mysql5 instead of utf8 and mysql5-binary instead of binary. * On install, initialise the site_stats table, using code copied from the old installer. Unlike the old installer, use SiteStats to increment the user count when the initial user is added. * Fixed several instances of inappropriate call-by-reference. * Replaced call_user_func_array() with call_user_func() where possible, it is shorter and simpler. * Moved the caching boilerplate for DatabaseInstaller::getConnection() to the base class, and have the derived classes override an uncached function openConnection() instead. Updates r80892. * In MysqlInstaller::getLocalSettings(), escape PHP strings correctly with LocalSettingsGenerator::escapePhpString(). * Reduce timeout for checks in dirIsExecutable() to 3 seconds, so that it doesn't take 30s to run when apache is in single-threaded mode for debugging. * MySQL and SQLite have been tested and they appear to work. PostgreSQL upgrade is totally broken, apparently it was like that before I started. The Oracle code is untested.
2011-01-25 07:37:48 +00:00
public abstract function openConnection();
2010-12-16 11:20:39 +00:00
/**
* Create the database and return a Status object indicating success or
* failure.
*
* @return Status
*/
2010-07-20 11:00:51 +00:00
public abstract function setupDatabase();
* Fixed a bug causing the installer to ignore the "engine" and "charset" settings when installing a MySQL database. * Fixed a bug causing the engine and charset settings to not be properly preserved when adding new tables on upgrade. * Fixed total breakage of SQLite upgrade, by reusing the administrative connection to the SQLite database instead of creating a new one when wfGetDB() is called. Added LBFactory_Single to support this. * Introduced a "schema variable" concept to DatabaseBase to avoid the use of globals for communication between the installer and the Database. Removed a lot of old global variable names from Database::replaceVars(), most were only added on a whim and were never used. * Introduced DatabaseInstaller::getSchemaVars(), to allow schema variables to be supplied by the DatabaseInstaller child classes. * Removed messages config-mysql-egine-mismatch [sic] and config-mysql-charset-mismatch. In the old installer it was possible for users to request a certain character set for an upgrade, but in the new installer the question is never asked. So these warnings were shown whenever a non-default character set or engine was used in the old database. * In MysqlInstaller::preUpgrade(), fixed the incorrect strings used to identify the MySQL character sets: mysql5 instead of utf8 and mysql5-binary instead of binary. * On install, initialise the site_stats table, using code copied from the old installer. Unlike the old installer, use SiteStats to increment the user count when the initial user is added. * Fixed several instances of inappropriate call-by-reference. * Replaced call_user_func_array() with call_user_func() where possible, it is shorter and simpler. * Moved the caching boilerplate for DatabaseInstaller::getConnection() to the base class, and have the derived classes override an uncached function openConnection() instead. Updates r80892. * In MysqlInstaller::getLocalSettings(), escape PHP strings correctly with LocalSettingsGenerator::escapePhpString(). * Reduce timeout for checks in dirIsExecutable() to 3 seconds, so that it doesn't take 30s to run when apache is in single-threaded mode for debugging. * MySQL and SQLite have been tested and they appear to work. PostgreSQL upgrade is totally broken, apparently it was like that before I started. The Oracle code is untested.
2011-01-25 07:37:48 +00:00
/**
* Connect to the database using the administrative user/password currently
* defined in the session. Returns a status object. On success, the status
* object will contain a Database object in its value member.
*
* This will return a cached connection if one is available.
*
2011-02-03 20:57:56 +00:00
* @return Status
* Fixed a bug causing the installer to ignore the "engine" and "charset" settings when installing a MySQL database. * Fixed a bug causing the engine and charset settings to not be properly preserved when adding new tables on upgrade. * Fixed total breakage of SQLite upgrade, by reusing the administrative connection to the SQLite database instead of creating a new one when wfGetDB() is called. Added LBFactory_Single to support this. * Introduced a "schema variable" concept to DatabaseBase to avoid the use of globals for communication between the installer and the Database. Removed a lot of old global variable names from Database::replaceVars(), most were only added on a whim and were never used. * Introduced DatabaseInstaller::getSchemaVars(), to allow schema variables to be supplied by the DatabaseInstaller child classes. * Removed messages config-mysql-egine-mismatch [sic] and config-mysql-charset-mismatch. In the old installer it was possible for users to request a certain character set for an upgrade, but in the new installer the question is never asked. So these warnings were shown whenever a non-default character set or engine was used in the old database. * In MysqlInstaller::preUpgrade(), fixed the incorrect strings used to identify the MySQL character sets: mysql5 instead of utf8 and mysql5-binary instead of binary. * On install, initialise the site_stats table, using code copied from the old installer. Unlike the old installer, use SiteStats to increment the user count when the initial user is added. * Fixed several instances of inappropriate call-by-reference. * Replaced call_user_func_array() with call_user_func() where possible, it is shorter and simpler. * Moved the caching boilerplate for DatabaseInstaller::getConnection() to the base class, and have the derived classes override an uncached function openConnection() instead. Updates r80892. * In MysqlInstaller::getLocalSettings(), escape PHP strings correctly with LocalSettingsGenerator::escapePhpString(). * Reduce timeout for checks in dirIsExecutable() to 3 seconds, so that it doesn't take 30s to run when apache is in single-threaded mode for debugging. * MySQL and SQLite have been tested and they appear to work. PostgreSQL upgrade is totally broken, apparently it was like that before I started. The Oracle code is untested.
2011-01-25 07:37:48 +00:00
*/
public function getConnection() {
if ( $this->db ) {
return Status::newGood( $this->db );
}
$status = $this->openConnection();
if ( $status->isOK() ) {
$this->db = $status->value;
// Enable autocommit
$this->db->clearFlag( DBO_TRX );
$this->db->commit();
}
return $status;
}
/**
2010-07-20 11:17:36 +00:00
* Create database tables from scratch.
*
* @return Status
*/
public function createTables() {
$status = $this->getConnection();
if ( !$status->isOK() ) {
return $status;
}
$this->db->selectDB( $this->getVar( 'wgDBname' ) );
if( $this->db->tableExists( 'user' ) ) {
$status->warning( 'config-install-tables-exist' );
return $status;
}
$this->db->setFlag( DBO_DDLMODE ); // For Oracle's handling of schema files
$this->db->begin( __METHOD__ );
$error = $this->db->sourceFile( $this->db->getSchema() );
if( $error !== true ) {
2011-01-02 19:04:23 +00:00
$this->db->reportQueryError( $error, 0, '', __METHOD__ );
$this->db->rollback( __METHOD__ );
$status->fatal( 'config-install-tables-failed', $error );
} else {
$this->db->commit( __METHOD__ );
}
// Resume normal operations
if( $status->isOk() ) {
* Fixed a bug causing the installer to ignore the "engine" and "charset" settings when installing a MySQL database. * Fixed a bug causing the engine and charset settings to not be properly preserved when adding new tables on upgrade. * Fixed total breakage of SQLite upgrade, by reusing the administrative connection to the SQLite database instead of creating a new one when wfGetDB() is called. Added LBFactory_Single to support this. * Introduced a "schema variable" concept to DatabaseBase to avoid the use of globals for communication between the installer and the Database. Removed a lot of old global variable names from Database::replaceVars(), most were only added on a whim and were never used. * Introduced DatabaseInstaller::getSchemaVars(), to allow schema variables to be supplied by the DatabaseInstaller child classes. * Removed messages config-mysql-egine-mismatch [sic] and config-mysql-charset-mismatch. In the old installer it was possible for users to request a certain character set for an upgrade, but in the new installer the question is never asked. So these warnings were shown whenever a non-default character set or engine was used in the old database. * In MysqlInstaller::preUpgrade(), fixed the incorrect strings used to identify the MySQL character sets: mysql5 instead of utf8 and mysql5-binary instead of binary. * On install, initialise the site_stats table, using code copied from the old installer. Unlike the old installer, use SiteStats to increment the user count when the initial user is added. * Fixed several instances of inappropriate call-by-reference. * Replaced call_user_func_array() with call_user_func() where possible, it is shorter and simpler. * Moved the caching boilerplate for DatabaseInstaller::getConnection() to the base class, and have the derived classes override an uncached function openConnection() instead. Updates r80892. * In MysqlInstaller::getLocalSettings(), escape PHP strings correctly with LocalSettingsGenerator::escapePhpString(). * Reduce timeout for checks in dirIsExecutable() to 3 seconds, so that it doesn't take 30s to run when apache is in single-threaded mode for debugging. * MySQL and SQLite have been tested and they appear to work. PostgreSQL upgrade is totally broken, apparently it was like that before I started. The Oracle code is untested.
2011-01-25 07:37:48 +00:00
$this->enableLB();
}
return $status;
}
/**
* Create the tables for each extension the user enabled
* @return Status
*/
public function createExtensionTables() {
$status = $this->getConnection();
if ( !$status->isOK() ) {
return $status;
}
$updater = DatabaseUpdater::newForDB( $this->db );
$extensionUpdates = $updater->getNewExtensions();
// No extensions need tables (or haven't updated to new installer support)
if( !count( $extensionUpdates ) ) {
return $status;
}
$ourExtensions = array_map( 'strtolower', $this->getVar( '_Extensions' ) );
foreach( $ourExtensions as $ext ) {
if( isset( $extensionUpdates[$ext] ) ) {
$this->db->begin( __METHOD__ );
$error = $this->db->sourceFile( $extensionUpdates[$ext] );
if( $error !== true ) {
$this->db->rollback( __METHOD__ );
$status->warning( 'config-install-tables-failed', $error );
} else {
$this->db->commit( __METHOD__ );
}
}
}
return $status;
}
2010-07-20 11:17:36 +00:00
/**
* Get the DBMS-specific options for LocalSettings.php generation.
*
2010-07-20 11:17:36 +00:00
* @return String
*/
public abstract function getLocalSettings();
2010-12-16 11:20:39 +00:00
* Fixed a bug causing the installer to ignore the "engine" and "charset" settings when installing a MySQL database. * Fixed a bug causing the engine and charset settings to not be properly preserved when adding new tables on upgrade. * Fixed total breakage of SQLite upgrade, by reusing the administrative connection to the SQLite database instead of creating a new one when wfGetDB() is called. Added LBFactory_Single to support this. * Introduced a "schema variable" concept to DatabaseBase to avoid the use of globals for communication between the installer and the Database. Removed a lot of old global variable names from Database::replaceVars(), most were only added on a whim and were never used. * Introduced DatabaseInstaller::getSchemaVars(), to allow schema variables to be supplied by the DatabaseInstaller child classes. * Removed messages config-mysql-egine-mismatch [sic] and config-mysql-charset-mismatch. In the old installer it was possible for users to request a certain character set for an upgrade, but in the new installer the question is never asked. So these warnings were shown whenever a non-default character set or engine was used in the old database. * In MysqlInstaller::preUpgrade(), fixed the incorrect strings used to identify the MySQL character sets: mysql5 instead of utf8 and mysql5-binary instead of binary. * On install, initialise the site_stats table, using code copied from the old installer. Unlike the old installer, use SiteStats to increment the user count when the initial user is added. * Fixed several instances of inappropriate call-by-reference. * Replaced call_user_func_array() with call_user_func() where possible, it is shorter and simpler. * Moved the caching boilerplate for DatabaseInstaller::getConnection() to the base class, and have the derived classes override an uncached function openConnection() instead. Updates r80892. * In MysqlInstaller::getLocalSettings(), escape PHP strings correctly with LocalSettingsGenerator::escapePhpString(). * Reduce timeout for checks in dirIsExecutable() to 3 seconds, so that it doesn't take 30s to run when apache is in single-threaded mode for debugging. * MySQL and SQLite have been tested and they appear to work. PostgreSQL upgrade is totally broken, apparently it was like that before I started. The Oracle code is untested.
2011-01-25 07:37:48 +00:00
/**
* Override this to provide DBMS-specific schema variables, to be
* substituted into tables.sql and other schema files.
*/
public function getSchemaVars() {
return array();
}
/**
* Set appropriate schema variables in the current database connection.
*
* This should be called after any request data has been imported, but before
* any write operations to the database.
*/
public function setupSchemaVars() {
$status = $this->getConnection();
if ( $status->isOK() ) {
$status->value->setSchemaVars( $this->getSchemaVars() );
} else {
throw new MWException( __METHOD__.': unexpected DB connection error' );
* Fixed a bug causing the installer to ignore the "engine" and "charset" settings when installing a MySQL database. * Fixed a bug causing the engine and charset settings to not be properly preserved when adding new tables on upgrade. * Fixed total breakage of SQLite upgrade, by reusing the administrative connection to the SQLite database instead of creating a new one when wfGetDB() is called. Added LBFactory_Single to support this. * Introduced a "schema variable" concept to DatabaseBase to avoid the use of globals for communication between the installer and the Database. Removed a lot of old global variable names from Database::replaceVars(), most were only added on a whim and were never used. * Introduced DatabaseInstaller::getSchemaVars(), to allow schema variables to be supplied by the DatabaseInstaller child classes. * Removed messages config-mysql-egine-mismatch [sic] and config-mysql-charset-mismatch. In the old installer it was possible for users to request a certain character set for an upgrade, but in the new installer the question is never asked. So these warnings were shown whenever a non-default character set or engine was used in the old database. * In MysqlInstaller::preUpgrade(), fixed the incorrect strings used to identify the MySQL character sets: mysql5 instead of utf8 and mysql5-binary instead of binary. * On install, initialise the site_stats table, using code copied from the old installer. Unlike the old installer, use SiteStats to increment the user count when the initial user is added. * Fixed several instances of inappropriate call-by-reference. * Replaced call_user_func_array() with call_user_func() where possible, it is shorter and simpler. * Moved the caching boilerplate for DatabaseInstaller::getConnection() to the base class, and have the derived classes override an uncached function openConnection() instead. Updates r80892. * In MysqlInstaller::getLocalSettings(), escape PHP strings correctly with LocalSettingsGenerator::escapePhpString(). * Reduce timeout for checks in dirIsExecutable() to 3 seconds, so that it doesn't take 30s to run when apache is in single-threaded mode for debugging. * MySQL and SQLite have been tested and they appear to work. PostgreSQL upgrade is totally broken, apparently it was like that before I started. The Oracle code is untested.
2011-01-25 07:37:48 +00:00
}
}
/**
* Set up LBFactory so that wfGetDB() etc. works.
* We set up a special LBFactory instance which returns the current
* installer connection.
*/
public function enableLB() {
$status = $this->getConnection();
if ( !$status->isOK() ) {
throw new MWException( __METHOD__.': unexpected DB connection error' );
}
LBFactory::setInstance( new LBFactory_Single( array(
'connection' => $status->value ) ) );
}
/**
* Perform database upgrades
*
* @return Boolean
*/
public function doUpgrade() {
* Fixed a bug causing the installer to ignore the "engine" and "charset" settings when installing a MySQL database. * Fixed a bug causing the engine and charset settings to not be properly preserved when adding new tables on upgrade. * Fixed total breakage of SQLite upgrade, by reusing the administrative connection to the SQLite database instead of creating a new one when wfGetDB() is called. Added LBFactory_Single to support this. * Introduced a "schema variable" concept to DatabaseBase to avoid the use of globals for communication between the installer and the Database. Removed a lot of old global variable names from Database::replaceVars(), most were only added on a whim and were never used. * Introduced DatabaseInstaller::getSchemaVars(), to allow schema variables to be supplied by the DatabaseInstaller child classes. * Removed messages config-mysql-egine-mismatch [sic] and config-mysql-charset-mismatch. In the old installer it was possible for users to request a certain character set for an upgrade, but in the new installer the question is never asked. So these warnings were shown whenever a non-default character set or engine was used in the old database. * In MysqlInstaller::preUpgrade(), fixed the incorrect strings used to identify the MySQL character sets: mysql5 instead of utf8 and mysql5-binary instead of binary. * On install, initialise the site_stats table, using code copied from the old installer. Unlike the old installer, use SiteStats to increment the user count when the initial user is added. * Fixed several instances of inappropriate call-by-reference. * Replaced call_user_func_array() with call_user_func() where possible, it is shorter and simpler. * Moved the caching boilerplate for DatabaseInstaller::getConnection() to the base class, and have the derived classes override an uncached function openConnection() instead. Updates r80892. * In MysqlInstaller::getLocalSettings(), escape PHP strings correctly with LocalSettingsGenerator::escapePhpString(). * Reduce timeout for checks in dirIsExecutable() to 3 seconds, so that it doesn't take 30s to run when apache is in single-threaded mode for debugging. * MySQL and SQLite have been tested and they appear to work. PostgreSQL upgrade is totally broken, apparently it was like that before I started. The Oracle code is untested.
2011-01-25 07:37:48 +00:00
$this->setupSchemaVars();
$this->enableLB();
$ret = true;
2010-09-09 15:37:23 +00:00
ob_start( array( $this, 'outputHandler' ) );
try {
$up = DatabaseUpdater::newForDB( $this->db );
$up->doUpdates();
} catch ( MWException $e ) {
echo "\nAn error occured:\n";
echo $e->getText();
$ret = false;
}
ob_end_flush();
return $ret;
}
2010-12-16 11:20:39 +00:00
2010-07-20 11:17:36 +00:00
/**
* Allow DB installers a chance to make last-minute changes before installation
* occurs. This happens before setupDatabase() or createTables() is called, but
* long after the constructor. Helpful for things like modifying setup steps :)
*/
public function preInstall() {
2010-12-16 11:20:39 +00:00
2010-07-20 11:17:36 +00:00
}
/**
* Allow DB installers a chance to make checks before upgrade.
*/
public function preUpgrade() {
2010-12-16 11:20:39 +00:00
}
2010-07-20 11:17:36 +00:00
/**
* Get an array of MW configuration globals that will be configured by this class.
*/
public function getGlobalNames() {
return $this->globalNames;
}
/**
* Construct and initialise parent.
* This is typically only called from Installer::getDBInstaller()
*/
2010-07-20 11:00:51 +00:00
public function __construct( $parent ) {
$this->parent = $parent;
}
/**
2010-07-20 11:17:36 +00:00
* Convenience function.
* Check if a named extension is present.
*
2010-07-20 11:17:36 +00:00
* @see wfDl
*/
protected static function checkExtension( $name ) {
wfSuppressWarnings();
$compiled = wfDl( $name );
wfRestoreWarnings();
return $compiled;
}
/**
2010-07-20 11:17:36 +00:00
* Get the internationalised name for this DBMS.
*/
2010-07-20 11:00:51 +00:00
public function getReadableName() {
return wfMsg( 'config-type-' . $this->getName() );
}
2010-12-16 11:20:39 +00:00
/**
2010-07-20 11:17:36 +00:00
* Get a name=>value map of MW configuration globals that overrides.
* DefaultSettings.php
*/
2010-07-20 11:00:51 +00:00
public function getGlobalDefaults() {
return array();
}
/**
2010-07-20 11:17:36 +00:00
* Get a name=>value map of internal variables used during installation.
*/
public function getInternalDefaults() {
return $this->internalDefaults;
}
/**
2010-07-20 11:17:36 +00:00
* Get a variable, taking local defaults into account.
*/
2010-07-20 11:00:51 +00:00
public function getVar( $var, $default = null ) {
$defaults = $this->getGlobalDefaults();
$internal = $this->getInternalDefaults();
if ( isset( $defaults[$var] ) ) {
$default = $defaults[$var];
} elseif ( isset( $internal[$var] ) ) {
$default = $internal[$var];
}
return $this->parent->getVar( $var, $default );
}
/**
* Convenience alias for $this->parent->setVar()
*/
2010-07-20 11:00:51 +00:00
public function setVar( $name, $value ) {
$this->parent->setVar( $name, $value );
}
/**
2010-07-20 11:17:36 +00:00
* Get a labelled text box to configure a local variable.
*/
public function getTextBox( $var, $label, $attribs = array(), $helpData = "" ) {
$name = $this->getName() . '_' . $var;
$value = $this->getVar( $var );
if ( !isset( $attribs ) ) {
$attribs = array();
}
return $this->parent->getTextBox( array(
'var' => $var,
'label' => $label,
'attribs' => $attribs,
'controlName' => $name,
'value' => $value,
'help' => $helpData
) );
}
/**
2010-07-20 11:17:36 +00:00
* Get a labelled password box to configure a local variable.
* Implements password hiding.
*/
public function getPasswordBox( $var, $label, $attribs = array(), $helpData = "" ) {
$name = $this->getName() . '_' . $var;
$value = $this->getVar( $var );
if ( !isset( $attribs ) ) {
$attribs = array();
}
return $this->parent->getPasswordBox( array(
'var' => $var,
'label' => $label,
'attribs' => $attribs,
'controlName' => $name,
'value' => $value,
'help' => $helpData
) );
}
/**
2010-07-20 11:17:36 +00:00
* Get a labelled checkbox to configure a local boolean variable.
*/
public function getCheckBox( $var, $label, $attribs = array(), $helpData = "" ) {
$name = $this->getName() . '_' . $var;
$value = $this->getVar( $var );
return $this->parent->getCheckBox( array(
'var' => $var,
'label' => $label,
'attribs' => $attribs,
'controlName' => $name,
'value' => $value,
'help' => $helpData
));
}
/**
2010-07-20 11:17:36 +00:00
* Get a set of labelled radio buttons.
*
* @param $params Array:
* Parameters are:
* var: The variable to be configured (required)
* label: The message name for the label (required)
* itemLabelPrefix: The message name prefix for the item labels (required)
* values: List of allowed values (required)
* itemAttribs Array of attribute arrays, outer key is the value name (optional)
*
*/
2010-07-20 11:00:51 +00:00
public function getRadioSet( $params ) {
$params['controlName'] = $this->getName() . '_' . $params['var'];
$params['value'] = $this->getVar( $params['var'] );
return $this->parent->getRadioSet( $params );
}
/**
* Convenience function to set variables based on form data.
* Assumes that variables containing "password" in the name are (potentially
* fake) passwords.
* @param $varNames Array
*/
2010-07-20 11:00:51 +00:00
public function setVarsFromRequest( $varNames ) {
return $this->parent->setVarsFromRequest( $varNames, $this->getName() . '_' );
}
/**
* Determine whether an existing installation of MediaWiki is present in
* the configured administrative connection. Returns true if there is
* such a wiki, false if the database doesn't exist.
*
* Traditionally, this is done by testing for the existence of either
* the revision table or the cur table.
*
* @return Boolean
*/
2010-07-20 11:00:51 +00:00
public function needsUpgrade() {
$status = $this->getConnection();
if ( !$status->isOK() ) {
return false;
}
if ( !$this->db->selectDB( $this->getVar( 'wgDBname' ) ) ) {
return false;
}
return $this->db->tableExists( 'cur' ) || $this->db->tableExists( 'revision' );
}
/**
2010-07-20 11:17:36 +00:00
* Get a standard install-user fieldset.
2011-02-03 23:09:42 +00:00
*
* @return String
*/
2010-07-20 11:00:51 +00:00
public function getInstallUserBox() {
return
Html::openElement( 'fieldset' ) .
Html::element( 'legend', array(), wfMsg( 'config-db-install-account' ) ) .
$this->getTextBox( '_InstallUser', 'config-db-username', array(), $this->parent->getHelpBox( 'config-db-install-username' ) ) .
$this->getPasswordBox( '_InstallPassword', 'config-db-password', array(), $this->parent->getHelpBox( 'config-db-install-password' ) ) .
Html::closeElement( 'fieldset' );
}
/**
2010-07-20 11:17:36 +00:00
* Submit a standard install user fieldset.
*/
2010-07-20 11:00:51 +00:00
public function submitInstallUserBox() {
$this->setVarsFromRequest( array( '_InstallUser', '_InstallPassword' ) );
return Status::newGood();
}
/**
* Get a standard web-user fieldset
* @param $noCreateMsg String: Message to display instead of the creation checkbox.
* Set this to false to show a creation checkbox.
2011-02-03 23:09:42 +00:00
*
* @return String
*/
2010-07-20 11:00:51 +00:00
public function getWebUserBox( $noCreateMsg = false ) {
2010-11-04 23:23:34 +00:00
$s = Html::openElement( 'fieldset' ) .
Html::element( 'legend', array(), wfMsg( 'config-db-web-account' ) ) .
$this->getCheckBox(
'_SameAccount', 'config-db-web-account-same',
array( 'class' => 'hideShowRadio', 'rel' => 'dbOtherAccount' )
) .
Html::openElement( 'div', array( 'id' => 'dbOtherAccount', 'style' => 'display: none;' ) ) .
$this->getTextBox( 'wgDBuser', 'config-db-username' ) .
$this->getPasswordBox( 'wgDBpassword', 'config-db-password' ) .
$this->parent->getHelpBox( 'config-db-web-help' );
if ( $noCreateMsg ) {
$s .= $this->parent->getWarningBox( wfMsgNoTrans( $noCreateMsg ) );
} else {
$s .= $this->getCheckBox( '_CreateDBAccount', 'config-db-web-create' );
}
$s .= Html::closeElement( 'div' ) . Html::closeElement( 'fieldset' );
return $s;
}
/**
* Submit the form from getWebUserBox().
*
* @return Status
*/
2010-07-20 11:00:51 +00:00
public function submitWebUserBox() {
2010-07-20 11:17:36 +00:00
$this->setVarsFromRequest(
array( 'wgDBuser', 'wgDBpassword', '_SameAccount', '_CreateDBAccount' )
);
2010-12-16 11:20:39 +00:00
if ( $this->getVar( '_SameAccount' ) ) {
$this->setVar( 'wgDBuser', $this->getVar( '_InstallUser' ) );
$this->setVar( 'wgDBpassword', $this->getVar( '_InstallPassword' ) );
}
2010-12-16 11:20:39 +00:00
return Status::newGood();
}
/**
2010-07-20 11:17:36 +00:00
* Common function for databases that don't understand the MySQLish syntax of interwiki.sql.
2011-02-03 23:09:42 +00:00
*
* @return Status
*/
public function populateInterwikiTable() {
$status = $this->getConnection();
if ( !$status->isOK() ) {
return $status;
}
$this->db->selectDB( $this->getVar( 'wgDBname' ) );
if( $this->db->selectRow( 'interwiki', '*', array(), __METHOD__ ) ) {
$status->warning( 'config-install-interwiki-exists' );
return $status;
}
global $IP;
wfSuppressWarnings();
$rows = file( "$IP/maintenance/interwiki.list",
FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES );
wfRestoreWarnings();
$interwikis = array();
if ( !$rows ) {
return Status::newFatal( 'config-install-interwiki-list' );
}
foreach( $rows as $row ) {
$row = preg_replace( '/^\s*([^#]*?)\s*(#.*)?$/', '\\1', $row ); // strip comments - whee
if ( $row == "" ) continue;
$row .= "||";
$interwikis[] = array_combine(
array( 'iw_prefix', 'iw_url', 'iw_local', 'iw_api', 'iw_wikiid' ),
explode( '|', $row )
);
}
$this->db->insert( 'interwiki', $interwikis, __METHOD__ );
return Status::newGood();
}
2010-09-01 18:16:05 +00:00
public function outputHandler( $string ) {
return htmlspecialchars( $string );
}
}