Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 62
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
WebInstallerDBConnect
0.00% covered (danger)
0.00%
0 / 62
0.00% covered (danger)
0.00%
0 / 2
110
0.00% covered (danger)
0.00%
0 / 1
 execute
0.00% covered (danger)
0.00%
0 / 53
0.00% covered (danger)
0.00%
0 / 1
56
 submit
0.00% covered (danger)
0.00%
0 / 9
0.00% covered (danger)
0.00%
0 / 1
12
1<?php
2
3/**
4 * @license GPL-2.0-or-later
5 * @file
6 * @ingroup Installer
7 */
8
9namespace MediaWiki\Installer;
10
11use MediaWiki\Html\Html;
12use MediaWiki\Status\Status;
13
14class WebInstallerDBConnect extends WebInstallerPage {
15
16    /**
17     * @return string|null When string, "skip" or "continue"
18     */
19    public function execute() {
20        if ( $this->getVar( '_ExistingDBSettings' ) ) {
21            return 'skip';
22        }
23
24        $r = $this->parent->request;
25        if ( $r->wasPosted() ) {
26            $status = $this->submit();
27
28            if ( $status->isGood() ) {
29                $this->setVar( '_UpgradeDone', false );
30
31                return 'continue';
32            } else {
33                $this->parent->showStatusBox( $status );
34            }
35        }
36
37        $this->startForm();
38
39        $types = "<ul class=\"config-settings-block\">\n";
40        $defaultType = $this->getVar( 'wgDBtype' );
41
42        // Messages: config-dbsupport-mysql, config-dbsupport-postgres, config-dbsupport-sqlite
43        $dbSupport = '';
44        foreach ( Installer::getDBTypes() as $type ) {
45            $dbSupport .= wfMessage( "config-dbsupport-$type" )->plain() . "\n";
46        }
47        $this->addHTML( $this->parent->getInfoBox(
48            wfMessage( 'config-support-info', trim( $dbSupport ) )->plain() ) );
49
50        // It's possible that the library for the default DB type is not compiled in.
51        // In that case, instead select the first supported DB type in the list.
52        $compiledDBs = $this->parent->getCompiledDBs();
53        if ( !in_array( $defaultType, $compiledDBs ) ) {
54            $defaultType = $compiledDBs[0];
55        }
56        $types .= "</ul>";
57
58        $settings = '';
59        foreach ( $compiledDBs as $type ) {
60            $installer = $this->parent->getDBInstaller( $type );
61            $types .= "<div class=\"cdx-radio\"><div class=\"cdx-radio__wrapper\">";
62            $id = "DBType_$type";
63            $types .=
64                Html::radio(
65                    'DBType',
66                    $type == $defaultType,
67                    [
68                        'id' => $id,
69                        'class' => [ 'cdx-radio__input', 'dbRadio' ],
70                        'rel' => "DB_wrapper_$type",
71                        'value' => $type,
72                    ]
73                ) .
74                "\u{00A0}<span class=\"cdx-radio__icon\"></span>" .
75                Html::label( $installer->getReadableName(), $id, [ 'class' => 'cdx-radio__label' ] );
76            $types .= "</div></div>";
77            // Messages: config-header-mysql, config-header-postgres, config-header-sqlite
78            $settings .= Html::openElement(
79                    'div',
80                    [
81                        'id' => 'DB_wrapper_' . $type,
82                        'class' => 'dbWrapper'
83                    ]
84                ) .
85                Html::element( 'h3', [], wfMessage( 'config-header-' . $type )->text() ) .
86                $installer->getConnectForm( $this->parent )->getHtml() .
87                "</div>\n";
88
89        }
90
91        $this->addHTML( $this->parent->label( 'config-db-type', false, $types ) . $settings );
92        $this->endForm();
93
94        return null;
95    }
96
97    /**
98     * @return Status
99     */
100    public function submit() {
101        $r = $this->parent->request;
102        $type = $r->getVal( 'DBType' );
103        if ( !$type ) {
104            return Status::newFatal( 'config-invalid-db-type' );
105        }
106        $this->setVar( 'wgDBtype', $type );
107        $installer = $this->parent->getDBInstaller( $type );
108        if ( !$installer ) {
109            return Status::newFatal( 'config-invalid-db-type' );
110        }
111
112        return $installer->getConnectForm( $this->parent )->submit();
113    }
114
115}