| 1 |
<?php |
| 2 |
|
| 3 |
namespace MediaWiki\Installer; |
| 4 |
|
| 5 |
use MediaWiki\Html\Html; |
| 6 |
use MediaWiki\Status\Status; |
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
class PostgresConnectForm extends DatabaseConnectForm { |
| 12 |
|
| 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(); |
| 42 |
} |
| 43 |
|
| 44 |
public function submit() { |
| 45 |
|
| 46 |
$newValues = $this->setVarsFromRequest( [ |
| 47 |
'wgDBserver', |
| 48 |
'wgDBport', |
| 49 |
'wgDBssl', |
| 50 |
'wgDBname', |
| 51 |
'wgDBmwschema' |
| 52 |
] ); |
| 53 |
|
| 54 |
|
| 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'] ); |
| 60 |
} |
| 61 |
if ( !preg_match( '/^[a-zA-Z0-9_]*$/', $newValues['wgDBmwschema'] ) ) { |
| 62 |
$status->fatal( 'config-invalid-schema', $newValues['wgDBmwschema'] ); |
| 63 |
} |
| 64 |
|
| 65 |
|
| 66 |
if ( $status->isOK() ) { |
| 67 |
$status->merge( $this->submitInstallUserBox() ); |
| 68 |
} |
| 69 |
if ( !$status->isOK() ) { |
| 70 |
return $status; |
| 71 |
} |
| 72 |
|
| 73 |
$status = $this->getPostgresInstaller()->getConnection( DatabaseInstaller::CONN_CREATE_DATABASE ); |
| 74 |
if ( !$status->isOK() ) { |
| 75 |
return $status; |
| 76 |
} |
| 77 |
|
| 78 |
$conn = $status->getDB(); |
| 79 |
|
| 80 |
|
| 81 |
$status = PostgresInstaller::meetsMinimumRequirement( $conn ); |
| 82 |
if ( !$status->isOK() ) { |
| 83 |
return $status; |
| 84 |
} |
| 85 |
|
| 86 |
$this->setVar( 'wgDBuser', $this->getVar( '_InstallUser' ) ); |
| 87 |
$this->setVar( 'wgDBpassword', $this->getVar( '_InstallPassword' ) ); |
| 88 |
|
| 89 |
return Status::newGood(); |
| 90 |
} |
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
private function getPostgresInstaller(): PostgresInstaller { |
| 97 |
|
| 98 |
return $this->dbInstaller; |
| 99 |
} |
| 100 |
|
| 101 |
} |