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