MediaWiki master
WebInstallerDBConnect.php
Go to the documentation of this file.
1<?php
2
9namespace MediaWiki\Installer;
10
13
15
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
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}
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:44
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:44
element(SerializerNode $parent, SerializerNode $node, $contents)