Merge "docs: Fix typo"
[mediawiki.git] / includes / installer / PostgresConnectForm.php
blobd5f843bd7f2f8baeecae6625f81269ab5a5fe9b4
1 <?php
3 namespace MediaWiki\Installer;
5 use MediaWiki\Html\Html;
6 use MediaWiki\Status\Status;
8 /**
9 * @internal
11 class PostgresConnectForm extends DatabaseConnectForm {
13 public function getHtml() {
14 return $this->getTextBox(
15 'wgDBserver',
16 'config-db-host',
17 [],
18 $this->webInstaller->getHelpBox( 'config-db-host-help' )
19 ) .
20 $this->getTextBox( 'wgDBport', 'config-db-port' ) .
21 $this->getCheckBox( 'wgDBssl', 'config-db-ssl' ) .
22 "<span class=\"cdx-card\"><span class=\"cdx-card__text\">" .
23 Html::element(
24 'span',
25 [ 'class' => 'cdx-card__text__title' ],
26 wfMessage( 'config-db-wiki-settings' )->text()
27 ) .
28 $this->getTextBox(
29 'wgDBname',
30 'config-db-name',
31 [],
32 $this->webInstaller->getHelpBox( 'config-db-name-help' )
33 ) .
34 $this->getTextBox(
35 'wgDBmwschema',
36 'config-db-schema',
37 [],
38 $this->webInstaller->getHelpBox( 'config-db-schema-help' )
39 ) .
40 "</span></span></span>" .
41 $this->getInstallUserBox();
44 public function submit() {
45 // Get variables from the request
46 $newValues = $this->setVarsFromRequest( [
47 'wgDBserver',
48 'wgDBport',
49 'wgDBssl',
50 'wgDBname',
51 'wgDBmwschema'
52 ] );
54 // Validate them
55 $status = Status::newGood();
56 if ( !strlen( $newValues['wgDBname'] ) ) {
57 $status->fatal( 'config-missing-db-name' );
58 } elseif ( !preg_match( '/^[a-zA-Z0-9_]+$/', $newValues['wgDBname'] ) ) {
59 $status->fatal( 'config-invalid-db-name', $newValues['wgDBname'] );
61 if ( !preg_match( '/^[a-zA-Z0-9_]*$/', $newValues['wgDBmwschema'] ) ) {
62 $status->fatal( 'config-invalid-schema', $newValues['wgDBmwschema'] );
65 // Submit user box
66 if ( $status->isOK() ) {
67 $status->merge( $this->submitInstallUserBox() );
69 if ( !$status->isOK() ) {
70 return $status;
73 $status = $this->getPostgresInstaller()->getConnection( DatabaseInstaller::CONN_CREATE_DATABASE );
74 if ( !$status->isOK() ) {
75 return $status;
78 $conn = $status->getDB();
80 // Check version
81 $status = PostgresInstaller::meetsMinimumRequirement( $conn );
82 if ( !$status->isOK() ) {
83 return $status;
86 $this->setVar( 'wgDBuser', $this->getVar( '_InstallUser' ) );
87 $this->setVar( 'wgDBpassword', $this->getVar( '_InstallPassword' ) );
89 return Status::newGood();
92 /**
93 * Downcast the DatabaseInstaller
95 private function getPostgresInstaller(): PostgresInstaller {
96 // @phan-suppress-next-line PhanTypeMismatchReturnSuperType
97 return $this->dbInstaller;