wiki.techinc.nl/includes/installer/DatabaseConnectForm.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

71 lines
1.8 KiB
PHP

<?php
namespace MediaWiki\Installer;
use MediaWiki\Html\Html;
use MediaWiki\Status\Status;
/**
* @internal
*/
abstract class DatabaseConnectForm extends DatabaseForm {
/**
* Get HTML for a web form that configures this database. Configuration
* at this time should be the minimum needed to connect and test
* whether install or upgrade is required.
*
* If this is called, $this->parent can be assumed to be a WebInstaller.
*/
abstract public function getHtml();
/**
* Set variables based on the request array, assuming it was submitted
* via the form returned by getConnectForm(). Validate the connection
* settings by attempting to connect with them.
*
* If this is called, $this->parent can be assumed to be a WebInstaller.
*
* @return Status
*/
abstract public function submit();
/**
* Get a standard install-user fieldset.
*
* @return string
*/
protected function getInstallUserBox() {
return "<span class=\"cdx-card\"><span class=\"cdx-card__text\">" .
Html::element(
'span',
[ 'class' => 'cdx-card__text__title' ],
wfMessage( 'config-db-install-account' )->text()
) .
"<span class=\"cdx-card__text__description\">" .
$this->getTextBox(
'_InstallUser',
'config-db-username',
[ 'dir' => 'ltr' ],
$this->webInstaller->getHelpBox( 'config-db-install-username' )
) .
$this->getPasswordBox(
'_InstallPassword',
'config-db-password',
[ 'dir' => 'ltr' ],
$this->webInstaller->getHelpBox( 'config-db-install-password' )
) .
"</span></span></span>";
}
/**
* Submit a standard install user fieldset.
* @return Status
*/
protected function submitInstallUserBox() {
$this->setVarsFromRequest( [ '_InstallUser', '_InstallPassword' ] );
return Status::newGood();
}
}