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