Page MenuHomeWickedGov Phorge

MysqlSettingsForm.php
No OneTemporary

Size
2 KB
Referenced Files
None
Subscribers
None

MysqlSettingsForm.php

<?php
namespace MediaWiki\Installer;
use MediaWiki\MediaWikiServices;
use MediaWiki\Status\Status;
use Wikimedia\Rdbms\DBConnectionError;
/**
* @internal
*/
class MysqlSettingsForm extends DatabaseSettingsForm {
/**
* @return string
*/
public function getHtml() {
if ( $this->getMysqlInstaller()->canCreateAccounts() ) {
$noCreateMsg = false;
} else {
$noCreateMsg = 'config-db-web-no-create-privs';
}
$s = $this->getWebUserBox( $noCreateMsg );
// Do engine selector
$engines = $this->getMysqlInstaller()->getEngines();
// If the current default engine is not supported, use an engine that is
if ( !in_array( $this->getVar( '_MysqlEngine' ), $engines ) ) {
$this->setVar( '_MysqlEngine', reset( $engines ) );
}
// If the current default charset is not supported, use a charset that is
$charsets = $this->getMysqlInstaller()->getCharsets();
if ( !in_array( $this->getVar( '_MysqlCharset' ), $charsets ) ) {
$this->setVar( '_MysqlCharset', reset( $charsets ) );
}
return $s;
}
/**
* @return Status
*/
public function submit() {
$this->setVarsFromRequest( [ '_MysqlEngine', '_MysqlCharset' ] );
$status = $this->submitWebUserBox();
if ( !$status->isOK() ) {
return $status;
}
// Validate the create checkbox
$canCreate = $this->getMysqlInstaller()->canCreateAccounts();
if ( !$canCreate ) {
$this->setVar( '_CreateDBAccount', false );
$create = false;
} else {
$create = $this->getVar( '_CreateDBAccount' );
}
if ( !$create ) {
// Test the web account
try {
MediaWikiServices::getInstance()->getDatabaseFactory()->create( 'mysql', [
'host' => $this->getVar( 'wgDBserver' ),
'user' => $this->getVar( 'wgDBuser' ),
'password' => $this->getVar( 'wgDBpassword' ),
'ssl' => $this->getVar( 'wgDBssl' ),
'dbname' => null,
'flags' => 0,
'tablePrefix' => $this->getVar( 'wgDBprefix' )
] );
} catch ( DBConnectionError $e ) {
return Status::newFatal( 'config-connection-error', $e->getMessage() );
}
}
// Validate engines and charsets
// This is done pre-submit already, so it's just for security
$engines = $this->getMysqlInstaller()->getEngines();
if ( !in_array( $this->getVar( '_MysqlEngine' ), $engines ) ) {
$this->setVar( '_MysqlEngine', reset( $engines ) );
}
$charsets = $this->getMysqlInstaller()->getCharsets();
if ( !in_array( $this->getVar( '_MysqlCharset' ), $charsets ) ) {
$this->setVar( '_MysqlCharset', reset( $charsets ) );
}
return Status::newGood();
}
/**
* Downcast the DatabaseInstaller
* @return MysqlInstaller
*/
private function getMysqlInstaller(): MysqlInstaller {
// @phan-suppress-next-line PhanTypeMismatchReturnSuperType
return $this->dbInstaller;
}
}

File Metadata

Mime Type
text/x-php
Expires
Sun, Oct 26, 14:16 (21 h, 11 m)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
b3/cd/52aad3a3ae6b45f9bab5e2ad5130
Default Alt Text
MysqlSettingsForm.php (2 KB)

Event Timeline