Postgres connection handling gave the caller a way to specify what sort
of domain it needed, whereas the base class was implicitly relying on
the sequence of installer steps to ensure that the current connection
was correctly configured. The PG way of doing this is better for planned
work in this area. Exposing PG-style connection management in the base
class reduces the number of differences between PG and everything else.
Instead of PG's method of having up to three connections open, I am just
holding a single connection open, with state transitions properly
implemented.
Also:
* Deprecate direct access to $this->db.
* Factor out definitelyGetConnection(), a throwing variant of
getConnection().
* Deprecate caling getConnection() with no parameter.
* Remove setupSchemaVars(), since this was a sequence-dependent pattern.
Instead configure schema vars on transition to the create-schema
connection type.
* Use SelectQueryBuilder in databaseExists().
* Remove the pg-commit install step. This commit dates back to
bca55fa58f (March 2007), where in the old installer a commit was
done after all installation. It was moved here in 2010, but now we
have a commit in createTables() serving the same purpose. If we need a
transaction around interwiki insertion, we could do that in the base
class, but that's not what the original code was trying to do.
Change-Id: I073fb57c1b578361ac2a46ecd0cd1312c31747d4
74 lines
2.1 KiB
PHP
74 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace MediaWiki\Installer;
|
|
|
|
use MediaWiki\Html\Html;
|
|
use MediaWiki\Status\Status;
|
|
|
|
/**
|
|
* @internal
|
|
*/
|
|
class MysqlConnectForm extends DatabaseConnectForm {
|
|
/**
|
|
* @return string
|
|
*/
|
|
public function getHtml() {
|
|
return $this->getTextBox(
|
|
'wgDBserver',
|
|
'config-db-host',
|
|
[],
|
|
$this->webInstaller->getHelpBox( 'config-db-host-help' )
|
|
) .
|
|
$this->getCheckBox( 'wgDBssl', 'config-db-ssl' ) .
|
|
"<span class=\"cdx-card\"><span class=\"cdx-card__text\">" .
|
|
Html::element(
|
|
'span',
|
|
[ 'class' => 'cdx-card__text__title' ],
|
|
wfMessage( 'config-db-wiki-settings' )->text()
|
|
) .
|
|
"<span class=\"cdx-card__text__description\">" .
|
|
$this->getTextBox( 'wgDBname', 'config-db-name', [ 'dir' => 'ltr' ],
|
|
$this->webInstaller->getHelpBox( 'config-db-name-help' ) ) .
|
|
$this->getTextBox( 'wgDBprefix', 'config-db-prefix', [ 'dir' => 'ltr' ],
|
|
$this->webInstaller->getHelpBox( 'config-db-prefix-help' ) ) .
|
|
"</span></span></span>" .
|
|
$this->getInstallUserBox();
|
|
}
|
|
|
|
public function submit() {
|
|
// Get variables from the request.
|
|
$newValues = $this->setVarsFromRequest( [ 'wgDBserver', 'wgDBname', 'wgDBprefix', 'wgDBssl' ] );
|
|
|
|
// Validate them.
|
|
$status = Status::newGood();
|
|
if ( !strlen( $newValues['wgDBserver'] ) ) {
|
|
$status->fatal( 'config-missing-db-host' );
|
|
}
|
|
if ( !strlen( $newValues['wgDBname'] ) ) {
|
|
$status->fatal( 'config-missing-db-name' );
|
|
} elseif ( !preg_match( '/^[a-z0-9+_-]+$/i', $newValues['wgDBname'] ) ) {
|
|
$status->fatal( 'config-invalid-db-name', $newValues['wgDBname'] );
|
|
}
|
|
if ( !preg_match( '/^[a-z0-9_-]*$/i', $newValues['wgDBprefix'] ) ) {
|
|
$status->fatal( 'config-invalid-db-prefix', $newValues['wgDBprefix'] );
|
|
}
|
|
if ( !$status->isOK() ) {
|
|
return $status;
|
|
}
|
|
|
|
// Submit user box
|
|
$status = $this->submitInstallUserBox();
|
|
if ( !$status->isOK() ) {
|
|
return $status;
|
|
}
|
|
|
|
// Try to connect
|
|
$status = $this->dbInstaller->getConnection( DatabaseInstaller::CONN_CREATE_DATABASE );
|
|
if ( !$status->isOK() ) {
|
|
return $status;
|
|
}
|
|
|
|
// Check version
|
|
return MysqlInstaller::meetsMinimumRequirement( $status->getDB() );
|
|
}
|
|
}
|