MediaWiki master
WebInstallerDBConnect.php
Go to the documentation of this file.
1<?php
2
23namespace MediaWiki\Installer;
24
27
29
33 public function execute() {
34 if ( $this->getVar( '_ExistingDBSettings' ) ) {
35 return 'skip';
36 }
37
38 $r = $this->parent->request;
39 if ( $r->wasPosted() ) {
40 $status = $this->submit();
41
42 if ( $status->isGood() ) {
43 $this->setVar( '_UpgradeDone', false );
44
45 return 'continue';
46 } else {
47 $this->parent->showStatusBox( $status );
48 }
49 }
50
51 $this->startForm();
52
53 $types = "<ul class=\"config-settings-block\">\n";
54 $defaultType = $this->getVar( 'wgDBtype' );
55
56 // Messages: config-dbsupport-mysql, config-dbsupport-postgres, config-dbsupport-sqlite
57 $dbSupport = '';
58 foreach ( Installer::getDBTypes() as $type ) {
59 $dbSupport .= wfMessage( "config-dbsupport-$type" )->plain() . "\n";
60 }
61 $this->addHTML( $this->parent->getInfoBox(
62 wfMessage( 'config-support-info', trim( $dbSupport ) )->plain() ) );
63
64 // It's possible that the library for the default DB type is not compiled in.
65 // In that case, instead select the first supported DB type in the list.
66 $compiledDBs = $this->parent->getCompiledDBs();
67 if ( !in_array( $defaultType, $compiledDBs ) ) {
68 $defaultType = $compiledDBs[0];
69 }
70 $types .= "</ul>";
71
72 $settings = '';
73 foreach ( $compiledDBs as $type ) {
74 $installer = $this->parent->getDBInstaller( $type );
75 $types .= "<div class=\"cdx-radio\"><div class=\"cdx-radio__wrapper\">";
76 $id = "DBType_$type";
77 $types .=
78 Html::radio(
79 'DBType',
80 $type == $defaultType,
81 [
82 'id' => $id,
83 'class' => [ 'cdx-radio__input', 'dbRadio' ],
84 'rel' => "DB_wrapper_$type",
85 'value' => $type,
86 ]
87 ) .
88 "\u{00A0}<span class=\"cdx-radio__icon\"></span>" .
89 Html::label( $installer->getReadableName(), $id, [ 'class' => 'cdx-radio__label' ] );
90 $types .= "</div></div>";
91 // Messages: config-header-mysql, config-header-postgres, config-header-sqlite
92 $settings .= Html::openElement(
93 'div',
94 [
95 'id' => 'DB_wrapper_' . $type,
96 'class' => 'dbWrapper'
97 ]
98 ) .
99 Html::element( 'h3', [], wfMessage( 'config-header-' . $type )->text() ) .
100 $installer->getConnectForm( $this->parent )->getHtml() .
101 "</div>\n";
102
103 }
104
105 $this->addHTML( $this->parent->label( 'config-db-type', false, $types ) . $settings );
106 $this->endForm();
107
108 return null;
109 }
110
114 public function submit() {
115 $r = $this->parent->request;
116 $type = $r->getVal( 'DBType' );
117 if ( !$type ) {
118 return Status::newFatal( 'config-invalid-db-type' );
119 }
120 $this->setVar( 'wgDBtype', $type );
121 $installer = $this->parent->getDBInstaller( $type );
122 if ( !$installer ) {
123 return Status::newFatal( 'config-invalid-db-type' );
124 }
125
126 return $installer->getConnectForm( $this->parent )->submit();
127 }
128
129}
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:57
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
element(SerializerNode $parent, SerializerNode $node, $contents)