85 if ( version_compare( $serverVersion, static::$minimumVersion ) < 0 ) {
86 return Status::newFatal(
87 static::$notMinimumVersionMessage, static::$minimumVersion, $serverVersion
91 return Status::newGood();
110 return Status::newGood();
151 return Status::newGood();
184 return Status::newGood( $this->db );
188 if ( $status->isOK() ) {
189 $this->db = $status->value;
191 $this->db->clearFlag(
DBO_TRX );
192 $this->db->commit( __METHOD__ );
209 $archiveTableMustNotExist =
false
212 if ( !$status->isOK() ) {
215 $this->db->selectDB( $this->
getVar(
'wgDBname' ) );
217 if ( $archiveTableMustNotExist && $this->db->tableExists(
'archive', __METHOD__ ) ) {
218 $status->warning(
"config-$stepName-tables-exist" );
225 $this->db->begin( __METHOD__ );
227 $error = $this->db->sourceFile(
228 call_user_func( [ $this, $sourceFileMethod ], $this->db )
230 if ( $error !==
true ) {
231 $this->db->reportQueryError( $error, 0,
'', __METHOD__ );
232 $this->db->rollback( __METHOD__ );
233 $status->fatal(
"config-$stepName-tables-failed", $error );
235 $this->db->commit( __METHOD__ );
238 if ( $status->isOK() ) {
274 $dbmsSpecificFilePath =
"$IP/maintenance/" .
$db->
getType() .
"/$filename";
275 if ( file_exists( $dbmsSpecificFilePath ) ) {
276 return $dbmsSpecificFilePath;
278 return "$IP/maintenance/$filename";
310 if ( !$status->isOK() ) {
315 DatabaseUpdater::newForDB( $this->db )->doUpdates( [
'extensions' ] );
344 if ( $status->isOK() ) {
348 $msg = __METHOD__ .
': unexpected error while establishing'
349 .
' a database connection with message: '
350 . $status->getMessage()->plain();
362 if ( !$status->isOK() ) {
363 throw new MWException( __METHOD__ .
': unexpected DB connection error' );
366 MediaWikiServices::resetGlobalInstance();
367 $services = MediaWikiServices::getInstance();
369 $connection = $status->value;
370 $services->redefineService(
'DBLoadBalancerFactory',
function () use ( $connection ) {
371 return LBFactorySingle::newFromConnection( $connection );
386 ob_start( [ $this,
'outputHandler' ] );
387 $up = DatabaseUpdater::newForDB( $this->db );
392 echo
"\nAn error occurred:\n";
395 }
catch ( Exception $e ) {
396 echo
"\nAn error occurred:\n";
397 echo $e->getMessage();
444 return extension_loaded( $name );
484 public function getVar( $var, $default =
null ) {
487 if ( isset( $defaults[$var] ) ) {
488 $default = $defaults[$var];
489 } elseif ( isset( $internal[$var] ) ) {
490 $default = $internal[$var];
493 return $this->parent->getVar( $var, $default );
501 public function setVar( $name, $value ) {
502 $this->parent->setVar( $name, $value );
514 public function getTextBox( $var, $label, $attribs = [], $helpData =
"" ) {
515 $name = $this->
getName() .
'_' . $var;
516 $value = $this->
getVar( $var );
517 if ( !isset( $attribs ) ) {
521 return $this->parent->getTextBox( [
524 'attribs' => $attribs,
525 'controlName' => $name,
542 $name = $this->
getName() .
'_' . $var;
543 $value = $this->
getVar( $var );
544 if ( !isset( $attribs ) ) {
548 return $this->parent->getPasswordBox( [
551 'attribs' => $attribs,
552 'controlName' => $name,
567 public function getCheckBox( $var, $label, $attribs = [], $helpData =
"" ) {
568 $name = $this->
getName() .
'_' . $var;
569 $value = $this->
getVar( $var );
571 return $this->parent->getCheckBox( [
574 'attribs' => $attribs,
575 'controlName' => $name,
594 $params[
'controlName'] = $this->
getName() .
'_' . $params[
'var'];
595 $params[
'value'] = $this->
getVar( $params[
'var'] );
597 return $this->parent->getRadioSet( $params );
608 return $this->parent->setVarsFromRequest( $varNames, $this->
getName() .
'_' );
623 if ( !$status->isOK() ) {
628 $this->db->selectDB( $this->
getVar(
'wgDBname' ) );
636 return $this->db->tableExists(
'cur', __METHOD__ ) ||
637 $this->db->tableExists(
'revision', __METHOD__ );
646 return Html::openElement(
'fieldset' ) .
647 Html::element(
'legend', [],
wfMessage(
'config-db-install-account' )->text() ) .
650 'config-db-username',
652 $this->parent->getHelpBox(
'config-db-install-username' )
656 'config-db-password',
658 $this->parent->getHelpBox(
'config-db-install-password' )
660 Html::closeElement(
'fieldset' );
670 return Status::newGood();
681 $wrapperStyle = $this->
getVar(
'_SameAccount' ) ?
'display: none' :
'';
682 $s = Html::openElement(
'fieldset' ) .
683 Html::element(
'legend', [],
wfMessage(
'config-db-web-account' )->text() ) .
685 '_SameAccount',
'config-db-web-account-same',
686 [
'class' =>
'hideShowRadio',
'rel' =>
'dbOtherAccount' ]
688 Html::openElement(
'div', [
'id' =>
'dbOtherAccount',
'style' => $wrapperStyle ] ) .
689 $this->
getTextBox(
'wgDBuser',
'config-db-username' ) .
691 $this->parent->getHelpBox(
'config-db-web-help' );
692 if ( $noCreateMsg ) {
693 $s .= Html::warningBox(
wfMessage( $noCreateMsg )->plain(),
'config-warning-box' );
695 $s .= $this->
getCheckBox(
'_CreateDBAccount',
'config-db-web-create' );
697 $s .= Html::closeElement(
'div' ) . Html::closeElement(
'fieldset' );
709 [
'wgDBuser',
'wgDBpassword',
'_SameAccount',
'_CreateDBAccount' ]
712 if ( $this->
getVar(
'_SameAccount' ) ) {
713 $this->
setVar(
'wgDBuser', $this->
getVar(
'_InstallUser' ) );
714 $this->
setVar(
'wgDBpassword', $this->
getVar(
'_InstallPassword' ) );
717 if ( $this->
getVar(
'_CreateDBAccount' ) && strval( $this->
getVar(
'wgDBpassword' ) ) ==
'' ) {
718 return Status::newFatal(
'config-db-password-empty', $this->
getVar(
'wgDBuser' ) );
721 return Status::newGood();
731 if ( !$status->isOK() ) {
734 $this->db->selectDB( $this->
getVar(
'wgDBname' ) );
736 if ( $this->db->selectRow(
'interwiki',
'1', [], __METHOD__ ) ) {
737 $status->warning(
'config-install-interwiki-exists' );
742 Wikimedia\suppressWarnings();
743 $rows = file(
"$IP/maintenance/interwiki.list",
744 FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES );
745 Wikimedia\restoreWarnings();
748 return Status::newFatal(
'config-install-interwiki-list' );
750 foreach ( $rows as $row ) {
751 $row = preg_replace(
'/^\s*([^#]*?)\s*(#.*)?$/',
'\\1', $row );
756 $interwikis[] = array_combine(
757 [
'iw_prefix',
'iw_url',
'iw_local',
'iw_api',
'iw_wikiid' ],
761 $this->db->insert(
'interwiki', $interwikis, __METHOD__ );
763 return Status::newGood();
767 return htmlspecialchars( $string );
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
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...
Database $db
The database connection.
static meetsMinimumRequirement( $serverVersion)
Whether the provided version meets the necessary requirements for this type.
createExtensionTables()
Create the tables for each extension the user enabled.
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...
getSqlFilePath( $db, $filename)
Return a path to the DBMS-specific SQL file if it exists, otherwise default SQL file.
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.
stepApplySourceFile( $sourceFileMethod, $stepName, $archiveTableMustNotExist=false)
Apply a SQL source file to the database as part of running an installation step.
preInstall()
Allow DB installers a chance to make last-minute changes before installation occurs.
createTables()
Create database tables from scratch.
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.
getInstallUserBox()
Get a standard install-user fieldset.
insertUpdateKeys()
Insert update keys into table to prevent running unneded updates.
setupSchemaVars()
Set appropriate schema variables in the current database connection.
getRadioSet( $params)
Get a set of labelled radio buttons.
getText()
Get the text to display when reporting the error on the command line.
Class for the core installer web interface.