Localisation updates from https://translatewiki.net.
[mediawiki.git] / includes / installer / WebInstallerDBConnect.php
blob099a8c3922f063a6a7156c7224488ff7a01baf96
1 <?php
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.
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
19 * @file
20 * @ingroup Installer
23 namespace MediaWiki\Installer;
25 use MediaWiki\Html\Html;
26 use MediaWiki\Status\Status;
27 use MediaWiki\Xml\Xml;
29 class WebInstallerDBConnect extends WebInstallerPage {
31 /**
32 * @return string|null When string, "skip" or "continue"
34 public function execute() {
35 if ( $this->getVar( '_ExistingDBSettings' ) ) {
36 return 'skip';
39 $r = $this->parent->request;
40 if ( $r->wasPosted() ) {
41 $status = $this->submit();
43 if ( $status->isGood() ) {
44 $this->setVar( '_UpgradeDone', false );
46 return 'continue';
47 } else {
48 $this->parent->showStatusBox( $status );
52 $this->startForm();
54 $types = "<ul class=\"config-settings-block\">\n";
55 $defaultType = $this->getVar( 'wgDBtype' );
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";
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];
71 $types .= "</ul>";
73 $settings = '';
74 foreach ( $compiledDBs as $type ) {
75 $installer = $this->parent->getDBInstaller( $type );
76 $types .= "<div class=\"cdx-radio\"><div class=\"cdx-radio__wrapper\">";
77 $id = "DBType_$type";
78 $types .=
79 Xml::radio(
80 'DBType',
81 $type,
82 $type == $defaultType,
84 'id' => $id,
85 'class' => 'cdx-radio__input dbRadio',
86 'rel' => "DB_wrapper_$type",
88 ) .
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(
94 'div',
96 'id' => 'DB_wrapper_' . $type,
97 'class' => 'dbWrapper'
99 ) .
100 Html::element( 'h3', [], wfMessage( 'config-header-' . $type )->text() ) .
101 $installer->getConnectForm( $this->parent )->getHtml() .
102 "</div>\n";
106 $types .= "<br style=\"clear: left\"/>\n";
108 $this->addHTML( $this->parent->label( 'config-db-type', false, $types ) . $settings );
109 $this->endForm();
111 return null;
115 * @return Status
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' );
123 $this->setVar( 'wgDBtype', $type );
124 $installer = $this->parent->getDBInstaller( $type );
125 if ( !$installer ) {
126 return Status::newFatal( 'config-invalid-db-type' );
129 return $installer->getConnectForm( $this->parent )->submit();