24use Wikimedia\AtEase\AtEase;
87 if ( version_compare( $serverVersion, static::$minimumVersion ) < 0 ) {
88 return Status::newFatal(
89 static::$notMinimumVersionMessage, static::$minimumVersion, $serverVersion
93 return Status::newGood();
113 return Status::newGood();
156 return Status::newGood();
190 return Status::newGood( $this->db );
194 if ( $status->isOK() ) {
195 $this->db = $status->value;
197 $this->db->clearFlag(
DBO_TRX );
198 $this->db->commit( __METHOD__ );
212 private function stepApplySourceFile(
215 $tableThatMustNotExist =
false
218 if ( !$status->isOK() ) {
221 $this->db->selectDB( $this->
getVar(
'wgDBname' ) );
223 if ( $tableThatMustNotExist && $this->db->tableExists( $tableThatMustNotExist, __METHOD__ ) ) {
224 $status->warning(
"config-$stepName-tables-exist" );
231 $this->db->begin( __METHOD__ );
233 $error = $this->db->sourceFile(
234 call_user_func( [ $this, $sourceFileMethod ], $this->db )
236 if ( $error !==
true ) {
237 $this->db->reportQueryError( $error, 0,
'', __METHOD__ );
238 $this->db->rollback( __METHOD__ );
239 $status->fatal(
"config-$stepName-tables-failed", $error );
241 $this->db->commit( __METHOD__ );
244 if ( $status->isOK() ) {
258 return $this->stepApplySourceFile(
'getGeneratedSchemaPath',
'install',
'archive' );
268 return $this->stepApplySourceFile(
'getSchemaPath',
'install-manual' );
278 return $this->stepApplySourceFile(
'getUpdateKeysPath',
'updates',
false );
289 private function getSqlFilePath(
$db, $filename ) {
292 $dbmsSpecificFilePath =
"$IP/maintenance/" .
$db->
getType() .
"/$filename";
293 if ( file_exists( $dbmsSpecificFilePath ) ) {
294 return $dbmsSpecificFilePath;
296 return "$IP/maintenance/$filename";
309 return $this->getSqlFilePath(
$db,
'tables.sql' );
320 return $this->getSqlFilePath(
$db,
'tables-generated.sql' );
332 return $this->getSqlFilePath(
$db,
'update-keys.sql' );
342 if ( !$status->isOK() ) {
347 $updater = DatabaseUpdater::newForDB( $this->db );
348 $updater->setAutoExtensionHookContainer( $this->parent->getAutoExtensionHookContainer() );
349 $updater->doUpdates( [
'extensions' ] );
381 if ( $status->isOK() ) {
385 $msg = __METHOD__ .
': unexpected error while establishing'
386 .
' a database connection with message: '
387 . $status->getMessage()->plain();
399 if ( !$status->isOK() ) {
400 throw new MWException( __METHOD__ .
': unexpected DB connection error' );
402 $connection = $status->value;
404 $this->parent->resetMediaWikiServices(
null, [
405 'DBLoadBalancerFactory' =>
static function () use ( $connection ) {
406 return LBFactorySingle::newFromConnection( $connection );
422 ob_start( [ $this,
'outputHandler' ] );
423 $up = DatabaseUpdater::newForDB( $this->db );
429 echo
"\nAn error occurred:\n";
432 }
catch ( Exception $e ) {
433 echo
"\nAn error occurred:\n";
434 echo $e->getMessage();
485 return extension_loaded( $name );
507 if ( isset( $GLOBALS[$var] ) ) {
508 $defaults[$var] = $GLOBALS[$var];
528 public function getVar( $var, $default =
null ) {
531 if ( isset( $defaults[$var] ) ) {
532 $default = $defaults[$var];
533 } elseif ( isset( $internal[$var] ) ) {
534 $default = $internal[$var];
537 return $this->parent->getVar( $var, $default );
545 public function setVar( $name, $value ) {
546 $this->parent->setVar( $name, $value );
559 public function getTextBox( $var, $label, $attribs = [], $helpData =
"" ) {
560 $name = $this->
getName() .
'_' . $var;
561 $value = $this->
getVar( $var );
562 if ( !isset( $attribs ) ) {
566 return $this->parent->getTextBox( [
569 'attribs' => $attribs,
570 'controlName' => $name,
588 $name = $this->
getName() .
'_' . $var;
589 $value = $this->
getVar( $var );
590 if ( !isset( $attribs ) ) {
594 return $this->parent->getPasswordBox( [
597 'attribs' => $attribs,
598 'controlName' => $name,
613 public function getCheckBox( $var, $label, $attribs = [], $helpData =
"" ) {
614 $name = $this->
getName() .
'_' . $var;
615 $value = $this->
getVar( $var );
617 return $this->parent->getCheckBox( [
620 'attribs' => $attribs,
621 'controlName' => $name,
640 $params[
'controlName'] = $this->
getName() .
'_' . $params[
'var'];
641 $params[
'value'] = $this->
getVar( $params[
'var'] );
643 return $this->parent->getRadioSet( $params );
654 return $this->parent->setVarsFromRequest( $varNames, $this->
getName() .
'_' );
670 if ( !$status->isOK() ) {
675 $this->db->selectDB( $this->
getVar(
'wgDBname' ) );
683 return $this->db->tableExists(
'cur', __METHOD__ ) ||
684 $this->db->tableExists(
'revision', __METHOD__ );
693 return Html::openElement(
'fieldset' ) .
694 Html::element(
'legend', [],
wfMessage(
'config-db-install-account' )->text() ) .
698 'config-db-username',
700 $this->parent->getHelpBox(
'config-db-install-username' )
705 'config-db-password',
707 $this->parent->getHelpBox(
'config-db-install-password' )
709 Html::closeElement(
'fieldset' );
719 return Status::newGood();
730 $wrapperStyle = $this->
getVar(
'_SameAccount' ) ?
'display: none' :
'';
731 $s = Html::openElement(
'fieldset' ) .
732 Html::element(
'legend', [],
wfMessage(
'config-db-web-account' )->text() ) .
734 '_SameAccount',
'config-db-web-account-same',
735 [
'class' =>
'hideShowRadio',
'rel' =>
'dbOtherAccount' ]
737 Html::openElement(
'div', [
'id' =>
'dbOtherAccount',
'style' => $wrapperStyle ] ) .
738 $this->
getTextBox(
'wgDBuser',
'config-db-username' ) .
740 $this->parent->getHelpBox(
'config-db-web-help' );
741 if ( $noCreateMsg ) {
742 $s .= Html::warningBox(
wfMessage( $noCreateMsg )->plain(),
'config-warning-box' );
744 $s .= $this->
getCheckBox(
'_CreateDBAccount',
'config-db-web-create' );
746 $s .= Html::closeElement(
'div' ) . Html::closeElement(
'fieldset' );
758 [
'wgDBuser',
'wgDBpassword',
'_SameAccount',
'_CreateDBAccount' ]
761 if ( $this->
getVar(
'_SameAccount' ) ) {
762 $this->
setVar(
'wgDBuser', $this->
getVar(
'_InstallUser' ) );
763 $this->
setVar(
'wgDBpassword', $this->
getVar(
'_InstallPassword' ) );
766 if ( $this->
getVar(
'_CreateDBAccount' ) && strval( $this->
getVar(
'wgDBpassword' ) ) ==
'' ) {
767 return Status::newFatal(
'config-db-password-empty', $this->
getVar(
'wgDBuser' ) );
770 return Status::newGood();
781 if ( !$status->isOK() ) {
784 $this->db->selectDB( $this->
getVar(
'wgDBname' ) );
786 if ( $this->db->selectRow(
'interwiki',
'1', [], __METHOD__ ) ) {
787 $status->warning(
'config-install-interwiki-exists' );
792 AtEase::suppressWarnings();
793 $rows = file(
"$IP/maintenance/interwiki.list",
794 FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES );
795 AtEase::restoreWarnings();
798 return Status::newFatal(
'config-install-interwiki-list' );
800 foreach ( $rows as $row ) {
801 $row = preg_replace(
'/^\s*([^#]*?)\s*(#.*)?$/',
'\\1', $row );
806 $interwikis[] = array_combine(
807 [
'iw_prefix',
'iw_url',
'iw_local',
'iw_api',
'iw_wikiid' ],
811 $this->db->insert(
'interwiki', $interwikis, __METHOD__ );
813 return Status::newGood();
817 return htmlspecialchars( $string );
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...
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.
foreach( $mmfl['setupFiles'] as $fileName) if($queue) if(empty( $mmfl['quiet'])) $s