| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
namespace MediaWiki\Installer; |
| 24 |
|
| 25 |
use MediaWiki\Html\Html; |
| 26 |
use MediaWiki\Status\Status; |
| 27 |
use MediaWiki\Xml\Xml; |
| 28 |
|
| 29 |
class WebInstallerDBConnect extends WebInstallerPage { |
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 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 |
|
| 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 |
|
| 66 |
|
| 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 .= "<div class=\"cdx-radio\"><div class=\"cdx-radio__wrapper\">"; |
| 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 .= "</div></div>"; |
| 92 |
|
| 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( $this->parent )->getHtml() . |
| 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 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 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->getConnectForm( $this->parent )->submit(); |
| 130 |
} |
| 131 |
|
| 132 |
} |