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;
7use Wikimedia\Rdbms\Database;
8
9/**
10 * @internal
11 */
12class PostgresConnectForm extends DatabaseConnectForm {
13
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    public function submit() {
46        // Get variables from the request
47        $newValues = $this->setVarsFromRequest( [
48            'wgDBserver',
49            'wgDBport',
50            'wgDBssl',
51            'wgDBname',
52            'wgDBmwschema'
53        ] );
54
55        // Validate them
56        $status = Status::newGood();
57        if ( !strlen( $newValues['wgDBname'] ) ) {
58            $status->fatal( 'config-missing-db-name' );
59        } elseif ( !preg_match( '/^[a-zA-Z0-9_]+$/', $newValues['wgDBname'] ) ) {
60            $status->fatal( 'config-invalid-db-name', $newValues['wgDBname'] );
61        }
62        if ( !preg_match( '/^[a-zA-Z0-9_]*$/', $newValues['wgDBmwschema'] ) ) {
63            $status->fatal( 'config-invalid-schema', $newValues['wgDBmwschema'] );
64        }
65
66        // Submit user box
67        if ( $status->isOK() ) {
68            $status->merge( $this->submitInstallUserBox() );
69        }
70        if ( !$status->isOK() ) {
71            return $status;
72        }
73
74        $status = $this->getPostgresInstaller()->getPgConnection( 'create-db' );
75        if ( !$status->isOK() ) {
76            return $status;
77        }
78        /**
79         * @var Database $conn
80         */
81        $conn = $status->value;
82
83        // Check version
84        $status = PostgresInstaller::meetsMinimumRequirement( $conn );
85        if ( !$status->isOK() ) {
86            return $status;
87        }
88
89        $this->setVar( 'wgDBuser', $this->getVar( '_InstallUser' ) );
90        $this->setVar( 'wgDBpassword', $this->getVar( '_InstallPassword' ) );
91
92        return Status::newGood();
93    }
94
95    /**
96     * Downcast the DatabaseInstaller
97     * @return PostgresInstaller
98     */
99    private function getPostgresInstaller(): PostgresInstaller {
100        // @phan-suppress-next-line PhanTypeMismatchReturnSuperType
101        return $this->dbInstaller;
102    }
103
104}