26use Wikimedia\AtEase\AtEase;
90 if ( version_compare( $serverVersion, static::$minimumVersion ) < 0 ) {
91 return Status::newFatal(
92 static::$notMinimumVersionMessage, static::$minimumVersion, $serverVersion
96 return Status::newGood();
116 return Status::newGood();
159 return Status::newGood();
193 return Status::newGood( $this->db );
197 if ( $status->isOK() ) {
198 $this->db = $status->value;
200 $this->db->clearFlag(
DBO_TRX );
201 $this->db->commit( __METHOD__ );
215 private function stepApplySourceFile(
218 $tableThatMustNotExist =
false
221 if ( !$status->isOK() ) {
226 if ( $tableThatMustNotExist && $this->db->tableExists( $tableThatMustNotExist, __METHOD__ ) ) {
227 $status->warning(
"config-$stepName-tables-exist" );
234 $this->db->begin( __METHOD__ );
236 $error = $this->db->sourceFile(
237 call_user_func( [ $this, $sourceFileMethod ], $this->db )
239 if ( $error !==
true ) {
240 $this->db->reportQueryError( $error, 0,
'', __METHOD__ );
241 $this->db->rollback( __METHOD__ );
242 $status->fatal(
"config-$stepName-tables-failed", $error );
244 $this->db->commit( __METHOD__ );
247 if ( $status->isOK() ) {
261 return $this->stepApplySourceFile(
'getGeneratedSchemaPath',
'install',
'archive' );
271 return $this->stepApplySourceFile(
'getSchemaPath',
'install-manual' );
281 return $this->stepApplySourceFile(
'getUpdateKeysPath',
'updates',
false );
292 private function getSqlFilePath(
$db, $filename ) {
295 $dbmsSpecificFilePath =
"$IP/maintenance/" .
$db->
getType() .
"/$filename";
296 if ( file_exists( $dbmsSpecificFilePath ) ) {
297 return $dbmsSpecificFilePath;
299 return "$IP/maintenance/$filename";
312 return $this->getSqlFilePath(
$db,
'tables.sql' );
323 return $this->getSqlFilePath(
$db,
'tables-generated.sql' );
335 return $this->getSqlFilePath(
$db,
'update-keys.sql' );
345 if ( !$status->isOK() ) {
350 $updater = DatabaseUpdater::newForDB( $this->db );
351 $updater->setAutoExtensionHookContainer( $this->parent->getAutoExtensionHookContainer() );
352 $updater->doUpdates( [
'extensions' ] );
384 if ( $status->isOK() ) {
388 $msg = __METHOD__ .
': unexpected error while establishing'
389 .
' a database connection with message: '
390 . $status->getMessage()->plain();
402 if ( !$status->isOK() ) {
403 throw new MWException( __METHOD__ .
': unexpected DB connection error' );
405 $connection = $status->value;
407 $this->parent->resetMediaWikiServices(
null, [
408 'DBLoadBalancerFactory' =>
static function () use ( $connection ) {
409 return LBFactorySingle::newFromConnection( $connection );
425 ob_start( [ $this,
'outputHandler' ] );
426 $up = DatabaseUpdater::newForDB( $this->db );
432 echo
"\nAn error occurred:\n";
435 }
catch ( Exception $e ) {
436 echo
"\nAn error occurred:\n";
437 echo $e->getMessage();
488 return extension_loaded( $name );
510 if ( isset( $GLOBALS[$var] ) ) {
511 $defaults[$var] = $GLOBALS[$var];
531 public function getVar( $var, $default =
null ) {
534 if ( isset( $defaults[$var] ) ) {
535 $default = $defaults[$var];
536 } elseif ( isset( $internal[$var] ) ) {
537 $default = $internal[$var];
540 return $this->parent->getVar( $var, $default );
548 public function setVar( $name, $value ) {
549 $this->parent->setVar( $name, $value );
562 public function getTextBox( $var, $label, $attribs = [], $helpData =
"" ) {
563 $name = $this->
getName() .
'_' . $var;
564 $value = $this->
getVar( $var );
565 if ( !isset( $attribs ) ) {
569 return $this->parent->getTextBox( [
572 'attribs' => $attribs,
573 'controlName' => $name,
591 $name = $this->
getName() .
'_' . $var;
592 $value = $this->
getVar( $var );
593 if ( !isset( $attribs ) ) {
597 return $this->parent->getPasswordBox( [
600 'attribs' => $attribs,
601 'controlName' => $name,
616 public function getCheckBox( $var, $label, $attribs = [], $helpData =
"" ) {
617 $name = $this->
getName() .
'_' . $var;
618 $value = $this->
getVar( $var );
620 return $this->parent->getCheckBox( [
623 'attribs' => $attribs,
624 'controlName' => $name,
643 $params[
'controlName'] = $this->
getName() .
'_' . $params[
'var'];
644 $params[
'value'] = $this->
getVar( $params[
'var'] );
646 return $this->parent->getRadioSet( $params );
657 return $this->parent->setVarsFromRequest( $varNames, $this->
getName() .
'_' );
673 if ( !$status->isOK() ) {
686 return $this->db->tableExists(
'cur', __METHOD__ ) ||
687 $this->db->tableExists(
'revision', __METHOD__ );
696 return Html::openElement(
'fieldset' ) .
697 Html::element(
'legend', [],
wfMessage(
'config-db-install-account' )->text() ) .
701 'config-db-username',
703 $this->parent->getHelpBox(
'config-db-install-username' )
708 'config-db-password',
710 $this->parent->getHelpBox(
'config-db-install-password' )
712 Html::closeElement(
'fieldset' );
722 return Status::newGood();
733 $wrapperStyle = $this->
getVar(
'_SameAccount' ) ?
'display: none' :
'';
734 $s = Html::openElement(
'fieldset' ) .
735 Html::element(
'legend', [],
wfMessage(
'config-db-web-account' )->text() ) .
737 '_SameAccount',
'config-db-web-account-same',
738 [
'class' =>
'hideShowRadio',
'rel' =>
'dbOtherAccount' ]
740 Html::openElement(
'div', [
'id' =>
'dbOtherAccount',
'style' => $wrapperStyle ] ) .
741 $this->
getTextBox(
'wgDBuser',
'config-db-username' ) .
743 $this->parent->getHelpBox(
'config-db-web-help' );
744 if ( $noCreateMsg ) {
745 $s .= Html::warningBox(
wfMessage( $noCreateMsg )->plain(),
'config-warning-box' );
747 $s .= $this->
getCheckBox(
'_CreateDBAccount',
'config-db-web-create' );
749 $s .= Html::closeElement(
'div' ) . Html::closeElement(
'fieldset' );
761 [
'wgDBuser',
'wgDBpassword',
'_SameAccount',
'_CreateDBAccount' ]
764 if ( $this->
getVar(
'_SameAccount' ) ) {
765 $this->
setVar(
'wgDBuser', $this->
getVar(
'_InstallUser' ) );
766 $this->
setVar(
'wgDBpassword', $this->
getVar(
'_InstallPassword' ) );
769 if ( $this->
getVar(
'_CreateDBAccount' ) && strval( $this->
getVar(
'wgDBpassword' ) ) ==
'' ) {
770 return Status::newFatal(
'config-db-password-empty', $this->
getVar(
'wgDBuser' ) );
773 return Status::newGood();
784 if ( !$status->isOK() ) {
789 if ( $this->db->selectRow(
'interwiki',
'1', [], __METHOD__ ) ) {
790 $status->warning(
'config-install-interwiki-exists' );
795 AtEase::suppressWarnings();
796 $rows = file(
"$IP/maintenance/interwiki.list",
797 FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES );
798 AtEase::restoreWarnings();
801 return Status::newFatal(
'config-install-interwiki-list' );
803 foreach ( $rows as $row ) {
804 $row = preg_replace(
'/^\s*([^#]*?)\s*(#.*)?$/',
'\\1', $row );
809 $interwikis[] = array_combine(
810 [
'iw_prefix',
'iw_url',
'iw_local',
'iw_api',
'iw_wikiid' ],
814 $this->db->insert(
'interwiki', $interwikis, __METHOD__ );
816 return Status::newGood();
820 return htmlspecialchars( $string );
836 ( $schema !==
'' ) ? $schema :
null,
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
if(!defined( 'MEDIAWIKI')) if(ini_get('mbstring.func_overload')) if(!defined( 'MW_ENTRY_POINT')) global $IP
Environment checks.
Base class for DBMS-specific installation helper classes.
getWebUserBox( $noCreateMsg=false)
Get a standard web-user fieldset.
submitWebUserBox()
Submit the form from getWebUserBox().
static checkExtension( $name)
Convenience function.
preUpgrade()
Allow DB installers a chance to make checks before upgrade.
__construct( $parent)
Construct and initialise parent.
enableLB()
Set up LBFactory so that wfGetDB() etc.
getUpdateKeysPath( $db)
Return a path to the DBMS-specific update key file, otherwise default to update-keys....
getGlobalNames()
Get an array of MW configuration globals that will be configured by this class.
getReadableName()
Get the internationalised name for this DBMS.
WebInstaller $parent
The Installer object.
submitSettingsForm()
Set variables based on the request array, assuming it was submitted via the form return by getSetting...
selectDatabase(Database $conn, string $database)
Database $db
The database connection.
createExtensionTables()
Create the tables for each extension the user enabled.
getGeneratedSchemaPath( $db)
Return a path to the DBMS-specific automatically generated schema file.
static string $notMinimumVersionMessage
Set by subclasses.
setupDatabase()
Create the database and return a Status object indicating success or failure.
getPasswordBox( $var, $label, $attribs=[], $helpData="")
Get a labelled password box to configure a local variable.
setVarsFromRequest( $varNames)
Convenience function to set variables based on form data.
getSettingsForm()
Get HTML for a web form that retrieves settings used for installation.
static string $minimumVersion
Set by subclasses.
needsUpgrade()
Determine whether an existing installation of MediaWiki is present in the configured administrative c...
submitConnectForm()
Set variables based on the request array, assuming it was submitted via the form returned by getConne...
getCheckBox( $var, $label, $attribs=[], $helpData="")
Get a labelled checkbox to configure a local boolean variable.
getSchemaPath( $db)
Return a path to the DBMS-specific schema file, otherwise default to tables.sql.
getConnection()
Connect to the database using the administrative user/password currently defined in the session.
getSchemaVars()
Override this to provide DBMS-specific schema variables, to be substituted into tables....
getVar( $var, $default=null)
Get a variable, taking local defaults into account.
getTextBox( $var, $label, $attribs=[], $helpData="")
Get a labelled text box to configure a local variable.
preInstall()
Allow DB installers a chance to make last-minute changes before installation occurs.
createTables()
Create database tables from scratch from the automatically generated file.
populateInterwikiTable()
Common function for databases that don't understand the MySQLish syntax of interwiki....
array $internalDefaults
Internal variables for installation.
doUpgrade()
Perform database upgrades.
checkPrerequisites()
Checks for installation prerequisites other than those checked by isCompiled()
getInternalDefaults()
Get a name=>value map of internal variables used during installation.
setVar( $name, $value)
Convenience alias for $this->parent->setVar()
submitInstallUserBox()
Submit a standard install user fieldset.
getConnectForm()
Get HTML for a web form that configures this database.
openConnection()
Open a connection to the database using the administrative user/password currently defined in the ses...
getName()
Return the internal name, e.g.
array $globalNames
Array of MW configuration globals this class uses.
getLocalSettings()
Get the DBMS-specific options for LocalSettings.php generation.
getGlobalDefaults()
Get a name=>value map of MW configuration globals for the default values.
createManualTables()
Create database tables from scratch.
getInstallUserBox()
Get a standard install-user fieldset.
insertUpdateKeys()
Insert update keys into table to prevent running unneeded updates.
setupSchemaVars()
Set appropriate schema variables in the current database connection.
static meetsMinimumRequirement(IDatabase $conn)
Whether the provided version meets the necessary requirements for this type.
getRadioSet( $params)
Get a set of labelled radio buttons.
getText()
Format plain text message for the current exception object.
Class for the core installer web interface.
Class to handle database/schema/prefix specifications for IDatabase.