25 use Wikimedia\AtEase\AtEase;
88 if ( version_compare( $serverVersion, static::$minimumVersion ) < 0 ) {
90 static::$notMinimumVersionMessage, static::$minimumVersion, $serverVersion
195 if ( $status->isOK() ) {
196 $this->db = $status->value;
198 $this->db->clearFlag(
DBO_TRX );
199 $this->db->commit( __METHOD__ );
213 private function stepApplySourceFile(
216 $tableThatMustNotExist =
false
219 if ( !$status->isOK() ) {
224 if ( $tableThatMustNotExist && $this->db->tableExists( $tableThatMustNotExist, __METHOD__ ) ) {
225 $status->warning(
"config-$stepName-tables-exist" );
232 $this->db->begin( __METHOD__ );
234 $error = $this->db->sourceFile(
235 call_user_func( [ $this, $sourceFileMethod ], $this->db )
237 if ( $error !==
true ) {
238 $this->db->reportQueryError( $error, 0,
'', __METHOD__ );
239 $this->db->rollback( __METHOD__ );
240 $status->fatal(
"config-$stepName-tables-failed", $error );
242 $this->db->commit( __METHOD__ );
245 if ( $status->isOK() ) {
259 return $this->stepApplySourceFile(
'getGeneratedSchemaPath',
'install',
'archive' );
269 return $this->stepApplySourceFile(
'getSchemaPath',
'install-manual' );
279 return $this->stepApplySourceFile(
'getUpdateKeysPath',
'updates',
false );
290 private function getSqlFilePath(
$db, $filename ) {
293 $dbmsSpecificFilePath =
"$IP/maintenance/" .
$db->
getType() .
"/$filename";
294 if ( file_exists( $dbmsSpecificFilePath ) ) {
295 return $dbmsSpecificFilePath;
297 return "$IP/maintenance/$filename";
310 return $this->getSqlFilePath(
$db,
'tables.sql' );
321 return $this->getSqlFilePath(
$db,
'tables-generated.sql' );
333 return $this->getSqlFilePath(
$db,
'update-keys.sql' );
343 if ( !$status->isOK() ) {
349 $updater->setAutoExtensionHookContainer( $this->parent->getAutoExtensionHookContainer() );
350 $updater->doUpdates( [
'extensions' ] );
382 if ( $status->isOK() ) {
386 $msg = __METHOD__ .
': unexpected error while establishing'
387 .
' a database connection with message: '
388 . $status->getMessage()->plain();
400 if ( !$status->isOK() ) {
401 throw new MWException( __METHOD__ .
': unexpected DB connection error' );
403 $connection = $status->value;
405 $this->parent->resetMediaWikiServices(
null, [
406 'DBLoadBalancerFactory' =>
static function () use ( $connection ) {
407 return LBFactorySingle::newFromConnection( $connection );
423 ob_start( [ $this,
'outputHandler' ] );
430 echo
"\nAn error occurred:\n";
433 }
catch ( Exception $e ) {
434 echo
"\nAn error occurred:\n";
435 echo $e->getMessage();
486 return extension_loaded( $name );
508 if ( isset( $GLOBALS[$var] ) ) {
509 $defaults[$var] = $GLOBALS[$var];
529 public function getVar( $var, $default =
null ) {
532 if ( isset( $defaults[$var] ) ) {
533 $default = $defaults[$var];
534 } elseif ( isset( $internal[$var] ) ) {
535 $default = $internal[$var];
538 return $this->parent->getVar( $var, $default );
546 public function setVar( $name, $value ) {
547 $this->parent->setVar( $name, $value );
560 public function getTextBox( $var, $label, $attribs = [], $helpData =
"" ) {
561 $name = $this->
getName() .
'_' . $var;
562 $value = $this->
getVar( $var );
563 if ( !isset( $attribs ) ) {
567 return $this->parent->getTextBox( [
570 'attribs' => $attribs,
571 'controlName' => $name,
589 $name = $this->
getName() .
'_' . $var;
590 $value = $this->
getVar( $var );
591 if ( !isset( $attribs ) ) {
595 return $this->parent->getPasswordBox( [
598 'attribs' => $attribs,
599 'controlName' => $name,
614 public function getCheckBox( $var, $label, $attribs = [], $helpData =
"" ) {
615 $name = $this->
getName() .
'_' . $var;
616 $value = $this->
getVar( $var );
618 return $this->parent->getCheckBox( [
621 'attribs' => $attribs,
622 'controlName' => $name,
641 $params[
'controlName'] = $this->
getName() .
'_' . $params[
'var'];
642 $params[
'value'] = $this->
getVar( $params[
'var'] );
644 return $this->parent->getRadioSet( $params );
655 return $this->parent->setVarsFromRequest( $varNames, $this->
getName() .
'_' );
671 if ( !$status->isOK() ) {
684 return $this->db->tableExists(
'cur', __METHOD__ ) ||
685 $this->db->tableExists(
'revision', __METHOD__ );
694 return Html::openElement(
'fieldset' ) .
695 Html::element(
'legend', [],
wfMessage(
'config-db-install-account' )->text() ) .
699 'config-db-username',
701 $this->parent->getHelpBox(
'config-db-install-username' )
706 'config-db-password',
708 $this->parent->getHelpBox(
'config-db-install-password' )
710 Html::closeElement(
'fieldset' );
731 $wrapperStyle = $this->
getVar(
'_SameAccount' ) ?
'display: none' :
'';
732 $s = Html::openElement(
'fieldset' ) .
733 Html::element(
'legend', [],
wfMessage(
'config-db-web-account' )->text() ) .
735 '_SameAccount',
'config-db-web-account-same',
736 [
'class' =>
'hideShowRadio',
'rel' =>
'dbOtherAccount' ]
738 Html::openElement(
'div', [
'id' =>
'dbOtherAccount',
'style' => $wrapperStyle ] ) .
739 $this->
getTextBox(
'wgDBuser',
'config-db-username' ) .
741 $this->parent->getHelpBox(
'config-db-web-help' );
742 if ( $noCreateMsg ) {
743 $s .= Html::warningBox(
wfMessage( $noCreateMsg )->plain(),
'config-warning-box' );
745 $s .= $this->
getCheckBox(
'_CreateDBAccount',
'config-db-web-create' );
747 $s .= Html::closeElement(
'div' ) . Html::closeElement(
'fieldset' );
759 [
'wgDBuser',
'wgDBpassword',
'_SameAccount',
'_CreateDBAccount' ]
762 if ( $this->
getVar(
'_SameAccount' ) ) {
763 $this->
setVar(
'wgDBuser', $this->
getVar(
'_InstallUser' ) );
764 $this->
setVar(
'wgDBpassword', $this->
getVar(
'_InstallPassword' ) );
767 if ( $this->
getVar(
'_CreateDBAccount' ) && strval( $this->
getVar(
'wgDBpassword' ) ) ==
'' ) {
782 if ( !$status->isOK() ) {
787 if ( $this->db->selectRow(
'interwiki',
'1', [], __METHOD__ ) ) {
788 $status->warning(
'config-install-interwiki-exists' );
793 AtEase::suppressWarnings();
794 $rows = file(
"$IP/maintenance/interwiki.list",
795 FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES );
796 AtEase::restoreWarnings();
801 foreach ( $rows as $row ) {
802 $row = preg_replace(
'/^\s*([^#]*?)\s*(#.*)?$/',
'\\1', $row );
807 $interwikis[] = array_combine(
808 [
'iw_prefix',
'iw_url',
'iw_local',
'iw_api',
'iw_wikiid' ],
812 $this->db->insert(
'interwiki', $interwikis, __METHOD__ );
818 return htmlspecialchars( $string );
834 ( $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.
static meetsMinimumRequirement( $serverVersion)
Whether the provided version meets the necessary requirements for this type.
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.
getRadioSet( $params)
Get a set of labelled radio buttons.
static newForDB(IMaintainableDatabase $db, $shared=false, Maintenance $maintenance=null)
getText()
Format plain text message for the current exception object.
static newFatal( $message,... $parameters)
Factory function for fatal errors.
static newGood( $value=null)
Factory function for good results.
Class to handle database/schema/prefix specifications for IDatabase.
foreach( $mmfl['setupFiles'] as $fileName) if( $queue) if(empty( $mmfl['quiet'])) $s