Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 39 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| MysqlConnectForm | |
0.00% |
0 / 39 |
|
0.00% |
0 / 2 |
90 | |
0.00% |
0 / 1 |
| getHtml | |
0.00% |
0 / 20 |
|
0.00% |
0 / 1 |
2 | |||
| submit | |
0.00% |
0 / 19 |
|
0.00% |
0 / 1 |
72 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace MediaWiki\Installer; |
| 4 | |
| 5 | use MediaWiki\Html\Html; |
| 6 | use MediaWiki\Status\Status; |
| 7 | |
| 8 | /** |
| 9 | * @internal |
| 10 | */ |
| 11 | class MysqlConnectForm extends DatabaseConnectForm { |
| 12 | /** |
| 13 | * @return string |
| 14 | */ |
| 15 | public function getHtml() { |
| 16 | return $this->getTextBox( |
| 17 | 'wgDBserver', |
| 18 | 'config-db-host', |
| 19 | [], |
| 20 | $this->webInstaller->getHelpBox( 'config-db-host-help' ) |
| 21 | ) . |
| 22 | $this->getCheckBox( 'wgDBssl', 'config-db-ssl' ) . |
| 23 | "<span class=\"cdx-card\"><span class=\"cdx-card__text\">" . |
| 24 | Html::element( |
| 25 | 'span', |
| 26 | [ 'class' => 'cdx-card__text__title' ], |
| 27 | wfMessage( 'config-db-wiki-settings' )->text() |
| 28 | ) . |
| 29 | "<span class=\"cdx-card__text__description\">" . |
| 30 | $this->getTextBox( 'wgDBname', 'config-db-name', [ 'dir' => 'ltr' ], |
| 31 | $this->webInstaller->getHelpBox( 'config-db-name-help' ) ) . |
| 32 | $this->getTextBox( 'wgDBprefix', 'config-db-prefix', [ 'dir' => 'ltr' ], |
| 33 | $this->webInstaller->getHelpBox( 'config-db-prefix-help' ) ) . |
| 34 | "</span></span></span>" . |
| 35 | $this->getInstallUserBox(); |
| 36 | } |
| 37 | |
| 38 | /** @inheritDoc */ |
| 39 | public function submit() { |
| 40 | // Get variables from the request. |
| 41 | $newValues = $this->setVarsFromRequest( [ 'wgDBserver', 'wgDBname', 'wgDBprefix', 'wgDBssl' ] ); |
| 42 | |
| 43 | // Validate them. |
| 44 | $status = Status::newGood(); |
| 45 | if ( ( $newValues['wgDBserver'] ?? '' ) === '' ) { |
| 46 | $status->fatal( 'config-missing-db-host' ); |
| 47 | } |
| 48 | if ( ( $newValues['wgDBname'] ?? '' ) === '' ) { |
| 49 | $status->fatal( 'config-missing-db-name' ); |
| 50 | } elseif ( !preg_match( '/^[a-z0-9+_-]+$/i', $newValues['wgDBname'] ) ) { |
| 51 | $status->fatal( 'config-invalid-db-name', $newValues['wgDBname'] ); |
| 52 | } |
| 53 | if ( !preg_match( '/^[a-z0-9_-]*$/i', $newValues['wgDBprefix'] ) ) { |
| 54 | $status->fatal( 'config-invalid-db-prefix', $newValues['wgDBprefix'] ); |
| 55 | } |
| 56 | if ( !$status->isOK() ) { |
| 57 | return $status; |
| 58 | } |
| 59 | |
| 60 | // Submit user box |
| 61 | $status = $this->submitInstallUserBox(); |
| 62 | if ( !$status->isOK() ) { |
| 63 | return $status; |
| 64 | } |
| 65 | |
| 66 | // Try to connect |
| 67 | $status = $this->dbInstaller->getConnection( DatabaseInstaller::CONN_CREATE_DATABASE ); |
| 68 | if ( !$status->isOK() ) { |
| 69 | return $status; |
| 70 | } |
| 71 | |
| 72 | // Check version |
| 73 | return MysqlInstaller::meetsMinimumRequirement( $status->getDB() ); |
| 74 | } |
| 75 | } |