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.
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.
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
23 namespace MediaWiki\Installer
;
25 use MediaWiki\Html\Html
;
26 use MediaWiki\Status\Status
;
27 use MediaWiki\Xml\Xml
;
29 class WebInstallerDBConnect
extends WebInstallerPage
{
32 * @return string|null When string, "skip" or "continue"
34 public function execute() {
35 if ( $this->getVar( '_ExistingDBSettings' ) ) {
39 $r = $this->parent
->request
;
40 if ( $r->wasPosted() ) {
41 $status = $this->submit();
43 if ( $status->isGood() ) {
44 $this->setVar( '_UpgradeDone', false );
48 $this->parent
->showStatusBox( $status );
54 $types = "<ul class=\"config-settings-block\">\n";
55 $defaultType = $this->getVar( 'wgDBtype' );
57 // Messages: config-dbsupport-mysql, config-dbsupport-postgres, config-dbsupport-sqlite
59 foreach ( Installer
::getDBTypes() as $type ) {
60 $dbSupport .= wfMessage( "config-dbsupport-$type" )->plain() . "\n";
62 $this->addHTML( $this->parent
->getInfoBox(
63 wfMessage( 'config-support-info', trim( $dbSupport ) )->plain() ) );
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];
74 foreach ( $compiledDBs as $type ) {
75 $installer = $this->parent
->getDBInstaller( $type );
76 $types .= "<div class=\"cdx-radio\"><div class=\"cdx-radio__wrapper\">";
82 $type == $defaultType,
85 'class' => 'cdx-radio__input dbRadio',
86 'rel' => "DB_wrapper_$type",
89 "\u{00A0}<span class=\"cdx-radio__icon\"></span>" .
90 Xml
::label( $installer->getReadableName(), $id, [ 'class' => 'cdx-radio__label' ] );
91 $types .= "</div></div>";
92 // Messages: config-header-mysql, config-header-postgres, config-header-sqlite
93 $settings .= Html
::openElement(
96 'id' => 'DB_wrapper_' . $type,
97 'class' => 'dbWrapper'
100 Html
::element( 'h3', [], wfMessage( 'config-header-' . $type )->text() ) .
101 $installer->getConnectForm( $this->parent
)->getHtml() .
106 $types .= "<br style=\"clear: left\"/>\n";
108 $this->addHTML( $this->parent
->label( 'config-db-type', false, $types ) . $settings );
117 public function submit() {
118 $r = $this->parent
->request
;
119 $type = $r->getVal( 'DBType' );
121 return Status
::newFatal( 'config-invalid-db-type' );
123 $this->setVar( 'wgDBtype', $type );
124 $installer = $this->parent
->getDBInstaller( $type );
126 return Status
::newFatal( 'config-invalid-db-type' );
129 return $installer->getConnectForm( $this->parent
)->submit();