1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
|
<?php
namespace MediaWiki\Installer;
use MediaWiki\Html\Html;
use MediaWiki\Status\Status;
/**
* @internal
*/
class PostgresConnectForm extends DatabaseConnectForm {
public function getHtml() {
return $this->getTextBox(
'wgDBserver',
'config-db-host',
[],
$this->webInstaller->getHelpBox( 'config-db-host-help' )
) .
$this->getTextBox( 'wgDBport', 'config-db-port' ) .
$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()
) .
$this->getTextBox(
'wgDBname',
'config-db-name',
[],
$this->webInstaller->getHelpBox( 'config-db-name-help' )
) .
$this->getTextBox(
'wgDBmwschema',
'config-db-schema',
[],
$this->webInstaller->getHelpBox( 'config-db-schema-help' )
) .
"</span></span></span>" .
$this->getInstallUserBox();
}
public function submit() {
// Get variables from the request
$newValues = $this->setVarsFromRequest( [
'wgDBserver',
'wgDBport',
'wgDBssl',
'wgDBname',
'wgDBmwschema'
] );
// Validate them
$status = Status::newGood();
if ( !strlen( $newValues['wgDBname'] ) ) {
$status->fatal( 'config-missing-db-name' );
} elseif ( !preg_match( '/^[a-zA-Z0-9_]+$/', $newValues['wgDBname'] ) ) {
$status->fatal( 'config-invalid-db-name', $newValues['wgDBname'] );
}
if ( !preg_match( '/^[a-zA-Z0-9_]*$/', $newValues['wgDBmwschema'] ) ) {
$status->fatal( 'config-invalid-schema', $newValues['wgDBmwschema'] );
}
// Submit user box
if ( $status->isOK() ) {
$status->merge( $this->submitInstallUserBox() );
}
if ( !$status->isOK() ) {
return $status;
}
$status = $this->getPostgresInstaller()->getConnection( DatabaseInstaller::CONN_CREATE_DATABASE );
if ( !$status->isOK() ) {
return $status;
}
$conn = $status->getDB();
// Check version
$status = PostgresInstaller::meetsMinimumRequirement( $conn );
if ( !$status->isOK() ) {
return $status;
}
$this->setVar( 'wgDBuser', $this->getVar( '_InstallUser' ) );
$this->setVar( 'wgDBpassword', $this->getVar( '_InstallPassword' ) );
return Status::newGood();
}
/**
* Downcast the DatabaseInstaller
* @return PostgresInstaller
*/
private function getPostgresInstaller(): PostgresInstaller {
// @phan-suppress-next-line PhanTypeMismatchReturnSuperType
return $this->dbInstaller;
}
}
|