| 1 |
<?php |
| 2 |
|
| 3 |
namespace MediaWiki\Installer; |
| 4 |
|
| 5 |
use MediaWiki\MediaWikiServices; |
| 6 |
use MediaWiki\Status\Status; |
| 7 |
use Wikimedia\Rdbms\DBConnectionError; |
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
class MysqlSettingsForm extends DatabaseSettingsForm { |
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
public function getHtml() { |
| 18 |
if ( $this->getMysqlInstaller()->canCreateAccounts() ) { |
| 19 |
$noCreateMsg = false; |
| 20 |
} else { |
| 21 |
$noCreateMsg = 'config-db-web-no-create-privs'; |
| 22 |
} |
| 23 |
$s = $this->getWebUserBox( $noCreateMsg ); |
| 24 |
|
| 25 |
|
| 26 |
$engines = $this->getMysqlInstaller()->getEngines(); |
| 27 |
|
| 28 |
if ( !in_array( $this->getVar( '_MysqlEngine' ), $engines ) ) { |
| 29 |
$this->setVar( '_MysqlEngine', reset( $engines ) ); |
| 30 |
} |
| 31 |
|
| 32 |
|
| 33 |
$charsets = $this->getMysqlInstaller()->getCharsets(); |
| 34 |
if ( !in_array( $this->getVar( '_MysqlCharset' ), $charsets ) ) { |
| 35 |
$this->setVar( '_MysqlCharset', reset( $charsets ) ); |
| 36 |
} |
| 37 |
|
| 38 |
return $s; |
| 39 |
} |
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
public function submit() { |
| 45 |
$this->setVarsFromRequest( [ '_MysqlEngine', '_MysqlCharset' ] ); |
| 46 |
$status = $this->submitWebUserBox(); |
| 47 |
if ( !$status->isOK() ) { |
| 48 |
return $status; |
| 49 |
} |
| 50 |
|
| 51 |
|
| 52 |
$canCreate = $this->getMysqlInstaller()->canCreateAccounts(); |
| 53 |
if ( !$canCreate ) { |
| 54 |
$this->setVar( '_CreateDBAccount', false ); |
| 55 |
$create = false; |
| 56 |
} else { |
| 57 |
$create = $this->getVar( '_CreateDBAccount' ); |
| 58 |
} |
| 59 |
|
| 60 |
if ( !$create ) { |
| 61 |
|
| 62 |
try { |
| 63 |
MediaWikiServices::getInstance()->getDatabaseFactory()->create( 'mysql', [ |
| 64 |
'host' => $this->getVar( 'wgDBserver' ), |
| 65 |
'user' => $this->getVar( 'wgDBuser' ), |
| 66 |
'password' => $this->getVar( 'wgDBpassword' ), |
| 67 |
'ssl' => $this->getVar( 'wgDBssl' ), |
| 68 |
'dbname' => null, |
| 69 |
'flags' => 0, |
| 70 |
'tablePrefix' => $this->getVar( 'wgDBprefix' ) |
| 71 |
] ); |
| 72 |
} catch ( DBConnectionError $e ) { |
| 73 |
return Status::newFatal( 'config-connection-error', $e->getMessage() ); |
| 74 |
} |
| 75 |
} |
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
$engines = $this->getMysqlInstaller()->getEngines(); |
| 80 |
if ( !in_array( $this->getVar( '_MysqlEngine' ), $engines ) ) { |
| 81 |
$this->setVar( '_MysqlEngine', reset( $engines ) ); |
| 82 |
} |
| 83 |
$charsets = $this->getMysqlInstaller()->getCharsets(); |
| 84 |
if ( !in_array( $this->getVar( '_MysqlCharset' ), $charsets ) ) { |
| 85 |
$this->setVar( '_MysqlCharset', reset( $charsets ) ); |
| 86 |
} |
| 87 |
|
| 88 |
return Status::newGood(); |
| 89 |
} |
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
private function getMysqlInstaller(): MysqlInstaller { |
| 96 |
|
| 97 |
return $this->dbInstaller; |
| 98 |
} |
| 99 |
|
| 100 |
} |