MediaWiki master
WebInstallerDBConnect.php
Go to the documentation of this file.
1<?php
2
23namespace MediaWiki\Installer;
24
27use Xml;
28
30
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() .
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
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->submitConnectForm();
130 }
131
132}
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
This class is a collection of static functions that serve two purposes:
Definition Html.php:56
static getDBTypes()
Get a list of known DB types.
Abstract class to define pages for the web installer.
endForm( $continue='continue', $back='back')
Generic operation result class Has warning/error list, boolean status and arbitrary value.
Definition Status.php:54
Module of static functions for generating XML.
Definition Xml.php:33
element(SerializerNode $parent, SerializerNode $node, $contents)