MediaWiki 1.41.2
WebInstallerDBConnect.php
Go to the documentation of this file.
1<?php
2
5
27
31 public function execute() {
32 if ( $this->getVar( '_ExistingDBSettings' ) ) {
33 return 'skip';
34 }
35
36 $r = $this->parent->request;
37 if ( $r->wasPosted() ) {
38 $status = $this->submit();
39
40 if ( $status->isGood() ) {
41 $this->setVar( '_UpgradeDone', false );
42
43 return 'continue';
44 } else {
45 $this->parent->showStatusBox( $status );
46 }
47 }
48
49 $this->startForm();
50
51 $types = "<ul class=\"config-settings-block\">\n";
52 $settings = '';
53 $defaultType = $this->getVar( 'wgDBtype' );
54
55 // Messages: config-dbsupport-mysql, config-dbsupport-postgres, config-dbsupport-sqlite
56 $dbSupport = '';
57 foreach ( Installer::getDBTypes() as $type ) {
58 $dbSupport .= wfMessage( "config-dbsupport-$type" )->plain() . "\n";
59 }
60 $this->addHTML( $this->parent->getInfoBox(
61 wfMessage( 'config-support-info', trim( $dbSupport ) )->plain() ) );
62
63 // It's possible that the library for the default DB type is not compiled in.
64 // In that case, instead select the first supported DB type in the list.
65 $compiledDBs = $this->parent->getCompiledDBs();
66 if ( !in_array( $defaultType, $compiledDBs ) ) {
67 $defaultType = $compiledDBs[0];
68 }
69
70 foreach ( $compiledDBs as $type ) {
71 $installer = $this->parent->getDBInstaller( $type );
72 $types .=
73 '<li>' .
74 Xml::radioLabel(
75 $installer->getReadableName(),
76 'DBType',
77 $type,
78 "DBType_$type",
79 $type == $defaultType,
80 [ 'class' => 'dbRadio', 'rel' => "DB_wrapper_$type" ]
81 ) .
82 "</li>\n";
83
84 // Messages: config-header-mysql, config-header-postgres, config-header-sqlite
85 $settings .= Html::openElement(
86 'div',
87 [
88 'id' => 'DB_wrapper_' . $type,
89 'class' => 'dbWrapper'
90 ]
91 ) .
92 Html::element( 'h3', [], wfMessage( 'config-header-' . $type )->text() ) .
93 $installer->getConnectForm() .
94 "</div>\n";
95 }
96
97 $types .= "</ul><br style=\"clear: left\"/>\n";
98
99 $this->addHTML( $this->parent->label( 'config-db-type', false, $types ) . $settings );
100 $this->endForm();
101
102 return null;
103 }
104
108 public function submit() {
109 $r = $this->parent->request;
110 $type = $r->getVal( 'DBType' );
111 if ( !$type ) {
112 return Status::newFatal( 'config-invalid-db-type' );
113 }
114 $this->setVar( 'wgDBtype', $type );
115 $installer = $this->parent->getDBInstaller( $type );
116 if ( !$installer ) {
117 return Status::newFatal( 'config-invalid-db-type' );
118 }
119
120 return $installer->submitConnectForm();
121 }
122
123}
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
static getDBTypes()
Get a list of known DB types.
This class is a collection of static functions that serve two purposes:
Definition Html.php:57
Generic operation result class Has warning/error list, boolean status and arbitrary value.
Definition Status.php:58
Abstract class to define pages for the web installer.
setVar( $name, $value)
endForm( $continue='continue', $back='back')
getVar( $var, $default=null)