wiki.techinc.nl/includes/installer/MysqlConnectForm.php
Tim Starling 3f852f7ddc Split web-specific code out of DatabaseInstaller
DatabaseInstaller had some LSP violations, such as calling undeclared
methods of the supplied Installer object, assuming that it was a
WebInstaller. It was also large.

So, split the web form parts of DatabaseInstaller into separate classes.
We have a class hierarchy for the connect forms, and a class hierarchy
for the settings forms, with a base class DatabaseForm mostly as a place
to put protected helper methods.

Also, have DatabaseInstaller::getConnection() return a special subclass
of Status, so that we can remove many Phan type overrides.

Change-Id: Ie84025f8f70b895fa6882848b9a21ba1750d60e2
2024-03-13 13:04:13 +11:00

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();
if ( !$status->isOK() ) {
return $status;
}
// Check version
return MysqlInstaller::meetsMinimumRequirement( $status->getDB() );
}
}