Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 63
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 / 63
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 / 54
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 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 * http://www.gnu.org/copyleft/gpl.html
18 *
19 * @file
20 * @ingroup Installer
21 */
22
23namespace MediaWiki\Installer;
24
25use MediaWiki\Html\Html;
26use MediaWiki\Status\Status;
27use MediaWiki\Xml\Xml;
28
29class WebInstallerDBConnect extends WebInstallerPage {
30
31    /**
32     * @return string|null When string, "skip" or "continue"
33     */
34    public function execute() {
35        if ( $this->getVar( '_ExistingDBSettings' ) ) {
36            return 'skip';
37        }
38
39        $r = $this->parent->request;
40        if ( $r->wasPosted() ) {
41            $status = $this->submit();
42
43            if ( $status->isGood() ) {
44                $this->setVar( '_UpgradeDone', false );
45
46                return 'continue';
47            } else {
48                $this->parent->showStatusBox( $status );
49            }
50        }
51
52        $this->startForm();
53
54        $types = "<ul class=\"config-settings-block\">\n";
55        $defaultType = $this->getVar( 'wgDBtype' );
56
57        // Messages: config-dbsupport-mysql, config-dbsupport-postgres, config-dbsupport-sqlite
58        $dbSupport = '';
59        foreach ( Installer::getDBTypes() as $type ) {
60            $dbSupport .= wfMessage( "config-dbsupport-$type" )->plain() . "\n";
61        }
62        $this->addHTML( $this->parent->getInfoBox(
63            wfMessage( 'config-support-info', trim( $dbSupport ) )->plain() ) );
64
65        // It's possible that the library for the default DB type is not compiled in.
66        // In that case, instead select the first supported DB type in the list.
67        $compiledDBs = $this->parent->getCompiledDBs();
68        if ( !in_array( $defaultType, $compiledDBs ) ) {
69            $defaultType = $compiledDBs[0];
70        }
71        $types .= "</ul>";
72
73        $settings = '';
74        foreach ( $compiledDBs as $type ) {
75            $installer = $this->parent->getDBInstaller( $type );
76            $types .= "<span class=\"cdx-radio\">";
77            $id = "DBType_$type";
78            $types .=
79                Xml::radio(
80                    'DBType',
81                    $type,
82                    $type == $defaultType,
83                    [
84                        'id' => $id,
85                        'class' => 'cdx-radio__input dbRadio',
86                        'rel' => "DB_wrapper_$type",
87                    ]
88                ) .
89                "\u{00A0}<span class=\"cdx-radio__icon\"></span>" .
90                Xml::label( $installer->getReadableName(), $id, [ 'class' => 'cdx-radio__label' ] );
91            $types .= "</span>";
92            // Messages: config-header-mysql, config-header-postgres, config-header-sqlite
93            $settings .= Html::openElement(
94                    'div',
95                    [
96                        'id' => 'DB_wrapper_' . $type,
97                        'class' => 'dbWrapper'
98                    ]
99                ) .
100                Html::element( 'h3', [], wfMessage( 'config-header-' . $type )->text() ) .
101                $installer->getConnectForm( $this->parent )->getHtml() .
102                "</div>\n";
103
104        }
105
106        $types .= "<br style=\"clear: left\"/>\n";
107
108        $this->addHTML( $this->parent->label( 'config-db-type', false, $types ) . $settings );
109        $this->endForm();
110
111        return null;
112    }
113
114    /**
115     * @return Status
116     */
117    public function submit() {
118        $r = $this->parent->request;
119        $type = $r->getVal( 'DBType' );
120        if ( !$type ) {
121            return Status::newFatal( 'config-invalid-db-type' );
122        }
123        $this->setVar( 'wgDBtype', $type );
124        $installer = $this->parent->getDBInstaller( $type );
125        if ( !$installer ) {
126            return Status::newFatal( 'config-invalid-db-type' );
127        }
128
129        return $installer->getConnectForm( $this->parent )->submit();
130    }
131
132}