X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=blobdiff_plain;f=includes%2Finstaller%2FMysqlInstaller.php;h=5ff47e94f0a9348da817917ce5dac8637783863a;hp=cbe51f5137bdcf69be194505cd6235832503ad87;hb=7874fc4bec845ad92960b07e969c65f3c3fe74f2;hpb=b24a0048185fe7c4d86f8b55872ad749c6ab52e6 diff --git a/includes/installer/MysqlInstaller.php b/includes/installer/MysqlInstaller.php index cbe51f5137..5ff47e94f0 100644 --- a/includes/installer/MysqlInstaller.php +++ b/includes/installer/MysqlInstaller.php @@ -29,7 +29,7 @@ */ class MysqlInstaller extends DatabaseInstaller { - protected $globalNames = array( + protected $globalNames = [ 'wgDBserver', 'wgDBname', 'wgDBuser', @@ -37,25 +37,25 @@ class MysqlInstaller extends DatabaseInstaller { 'wgDBprefix', 'wgDBTableOptions', 'wgDBmysql5', - ); + ]; - protected $internalDefaults = array( + protected $internalDefaults = [ '_MysqlEngine' => 'InnoDB', '_MysqlCharset' => 'binary', '_InstallUser' => 'root', - ); + ]; - public $supportedEngines = array( 'InnoDB', 'MyISAM' ); + public $supportedEngines = [ 'InnoDB', 'MyISAM' ]; public $minimumVersion = '5.0.3'; - public $webUserPrivs = array( + public $webUserPrivs = [ 'DELETE', 'INSERT', 'SELECT', 'UPDATE', 'CREATE TEMPORARY TABLES', - ); + ]; /** * @return string @@ -78,14 +78,14 @@ class MysqlInstaller extends DatabaseInstaller { return $this->getTextBox( 'wgDBserver', 'config-db-host', - array(), + [], $this->parent->getHelpBox( 'config-db-host-help' ) ) . Html::openElement( 'fieldset' ) . - Html::element( 'legend', array(), wfMessage( 'config-db-wiki-settings' )->text() ) . - $this->getTextBox( 'wgDBname', 'config-db-name', array( 'dir' => 'ltr' ), + Html::element( 'legend', [], wfMessage( 'config-db-wiki-settings' )->text() ) . + $this->getTextBox( 'wgDBname', 'config-db-name', [ 'dir' => 'ltr' ], $this->parent->getHelpBox( 'config-db-name-help' ) ) . - $this->getTextBox( 'wgDBprefix', 'config-db-prefix', array( 'dir' => 'ltr' ), + $this->getTextBox( 'wgDBprefix', 'config-db-prefix', [ 'dir' => 'ltr' ], $this->parent->getHelpBox( 'config-db-prefix-help' ) ) . Html::closeElement( 'fieldset' ) . $this->getInstallUserBox(); @@ -93,7 +93,7 @@ class MysqlInstaller extends DatabaseInstaller { public function submitConnectForm() { // Get variables from the request. - $newValues = $this->setVarsFromRequest( array( 'wgDBserver', 'wgDBname', 'wgDBprefix' ) ); + $newValues = $this->setVarsFromRequest( [ 'wgDBserver', 'wgDBname', 'wgDBprefix' ] ); // Validate them. $status = Status::newGood(); @@ -124,7 +124,7 @@ class MysqlInstaller extends DatabaseInstaller { return $status; } /** - * @var $conn DatabaseBase + * @var $conn Database */ $conn = $status->value; @@ -143,13 +143,13 @@ class MysqlInstaller extends DatabaseInstaller { public function openConnection() { $status = Status::newGood(); try { - $db = DatabaseBase::factory( 'mysql', array( + $db = Database::factory( 'mysql', [ 'host' => $this->getVar( 'wgDBserver' ), 'user' => $this->getVar( '_InstallUser' ), 'password' => $this->getVar( '_InstallPassword' ), 'dbname' => false, 'flags' => 0, - 'tablePrefix' => $this->getVar( 'wgDBprefix' ) ) ); + 'tablePrefix' => $this->getVar( 'wgDBprefix' ) ] ); $status->value = $db; } catch ( DBConnectionError $e ) { $status->fatal( 'config-connection-error', $e->getMessage() ); @@ -168,7 +168,7 @@ class MysqlInstaller extends DatabaseInstaller { return; } /** - * @var $conn DatabaseBase + * @var $conn Database */ $conn = $status->value; $conn->selectDB( $this->getVar( 'wgDBname' ) ); @@ -226,11 +226,11 @@ class MysqlInstaller extends DatabaseInstaller { $status = $this->getConnection(); /** - * @var $conn DatabaseBase + * @var $conn Database */ $conn = $status->value; - $engines = array(); + $engines = []; $res = $conn->query( 'SHOW ENGINES', __METHOD__ ); foreach ( $res as $row ) { if ( $row->Support == 'YES' || $row->Support == 'DEFAULT' ) { @@ -248,7 +248,7 @@ class MysqlInstaller extends DatabaseInstaller { * @return array */ public function getCharsets() { - return array( 'binary', 'utf8' ); + return [ 'binary', 'utf8' ]; } /** @@ -261,7 +261,7 @@ class MysqlInstaller extends DatabaseInstaller { if ( !$status->isOK() ) { return false; } - /** @var $conn DatabaseBase */ + /** @var $conn Database */ $conn = $status->value; // Get current account name @@ -276,7 +276,7 @@ class MysqlInstaller extends DatabaseInstaller { // The user needs to have INSERT on mysql.* to be able to CREATE USER // The grantee will be double-quoted in this query, as required $res = $conn->select( 'INFORMATION_SCHEMA.USER_PRIVILEGES', '*', - array( 'GRANTEE' => $quotedUser ), __METHOD__ ); + [ 'GRANTEE' => $quotedUser ], __METHOD__ ); $insertMysql = false; $grantOptions = array_flip( $this->webUserPrivs ); foreach ( $res as $row ) { @@ -291,11 +291,11 @@ class MysqlInstaller extends DatabaseInstaller { // Check for DB-specific privs for mysql.* if ( !$insertMysql ) { $row = $conn->selectRow( 'INFORMATION_SCHEMA.SCHEMA_PRIVILEGES', '*', - array( + [ 'GRANTEE' => $quotedUser, 'TABLE_SCHEMA' => 'mysql', 'PRIVILEGE_TYPE' => 'INSERT', - ), __METHOD__ ); + ], __METHOD__ ); if ( $row ) { $insertMysql = true; } @@ -307,10 +307,10 @@ class MysqlInstaller extends DatabaseInstaller { // Check for DB-level grant options $res = $conn->select( 'INFORMATION_SCHEMA.SCHEMA_PRIVILEGES', '*', - array( + [ 'GRANTEE' => $quotedUser, 'IS_GRANTABLE' => 1, - ), __METHOD__ ); + ], __METHOD__ ); foreach ( $res as $row ) { $regex = $conn->likeToRegex( $row->TABLE_SCHEMA ); if ( preg_match( $regex, $this->getVar( 'wgDBname' ) ) ) { @@ -343,9 +343,9 @@ class MysqlInstaller extends DatabaseInstaller { $this->setVar( '_MysqlEngine', reset( $engines ) ); } - $s .= Xml::openElement( 'div', array( + $s .= Xml::openElement( 'div', [ 'id' => 'dbMyisamWarning' - ) ); + ] ); $myisamWarning = 'config-mysql-myisam-dep'; if ( count( $engines ) === 1 ) { $myisamWarning = 'config-mysql-only-myisam-dep'; @@ -363,22 +363,22 @@ class MysqlInstaller extends DatabaseInstaller { // getRadioSet() builds a set of labeled radio buttons. // For grep: The following messages are used as the item labels: // config-mysql-innodb, config-mysql-myisam - $s .= $this->getRadioSet( array( + $s .= $this->getRadioSet( [ 'var' => '_MysqlEngine', 'label' => 'config-mysql-engine', 'itemLabelPrefix' => 'config-mysql-', 'values' => $engines, - 'itemAttribs' => array( - 'MyISAM' => array( + 'itemAttribs' => [ + 'MyISAM' => [ 'class' => 'showHideRadio', 'rel' => 'dbMyisamWarning' - ), - 'InnoDB' => array( + ], + 'InnoDB' => [ 'class' => 'hideShowRadio', 'rel' => 'dbMyisamWarning' - ) - ) - ) ); + ] + ] + ] ); $s .= $this->parent->getHelpBox( 'config-mysql-engine-help' ); } @@ -393,12 +393,12 @@ class MysqlInstaller extends DatabaseInstaller { // getRadioSet() builds a set of labeled radio buttons. // For grep: The following messages are used as the item labels: // config-mysql-binary, config-mysql-utf8 - $s .= $this->getRadioSet( array( + $s .= $this->getRadioSet( [ 'var' => '_MysqlCharset', 'label' => 'config-mysql-charset', 'itemLabelPrefix' => 'config-mysql-', 'values' => $charsets - ) ); + ] ); $s .= $this->parent->getHelpBox( 'config-mysql-charset-help' ); } @@ -409,7 +409,7 @@ class MysqlInstaller extends DatabaseInstaller { * @return Status */ public function submitSettingsForm() { - $this->setVarsFromRequest( array( '_MysqlEngine', '_MysqlCharset' ) ); + $this->setVarsFromRequest( [ '_MysqlEngine', '_MysqlCharset' ] ); $status = $this->submitWebUserBox(); if ( !$status->isOK() ) { return $status; @@ -427,14 +427,14 @@ class MysqlInstaller extends DatabaseInstaller { if ( !$create ) { // Test the web account try { - DatabaseBase::factory( 'mysql', array( + Database::factory( 'mysql', [ 'host' => $this->getVar( 'wgDBserver' ), 'user' => $this->getVar( 'wgDBuser' ), 'password' => $this->getVar( 'wgDBpassword' ), 'dbname' => false, 'flags' => 0, 'tablePrefix' => $this->getVar( 'wgDBprefix' ) - ) ); + ] ); } catch ( DBConnectionError $e ) { return Status::newFatal( 'config-connection-error', $e->getMessage() ); } @@ -456,10 +456,10 @@ class MysqlInstaller extends DatabaseInstaller { public function preInstall() { # Add our user callback to installSteps, right before the tables are created. - $callback = array( + $callback = [ 'name' => 'user', - 'callback' => array( $this, 'setupUser' ), - ); + 'callback' => [ $this, 'setupUser' ], + ]; $this->parent->addInstallStep( $callback, 'tables' ); } @@ -471,7 +471,7 @@ class MysqlInstaller extends DatabaseInstaller { if ( !$status->isOK() ) { return $status; } - /** @var DatabaseBase $conn */ + /** @var Database $conn */ $conn = $status->value; $dbName = $this->getVar( 'wgDBname' ); if ( !$conn->selectDB( $dbName ) ) { @@ -504,19 +504,19 @@ class MysqlInstaller extends DatabaseInstaller { $this->db->selectDB( $dbName ); $server = $this->getVar( 'wgDBserver' ); $password = $this->getVar( 'wgDBpassword' ); - $grantableNames = array(); + $grantableNames = []; if ( $this->getVar( '_CreateDBAccount' ) ) { // Before we blindly try to create a user that already has access, try { // first attempt to connect to the database - DatabaseBase::factory( 'mysql', array( + Database::factory( 'mysql', [ 'host' => $server, 'user' => $dbUser, 'password' => $password, 'dbname' => false, 'flags' => 0, 'tablePrefix' => $this->getVar( 'wgDBprefix' ) - ) ); + ] ); $grantableNames[] = $this->buildFullUserName( $dbUser, $server ); $tryToCreate = false; } catch ( DBConnectionError $e ) { @@ -528,19 +528,19 @@ class MysqlInstaller extends DatabaseInstaller { } if ( $tryToCreate ) { - $createHostList = array( + $createHostList = [ $server, 'localhost', 'localhost.localdomain', '%' - ); + ]; $createHostList = array_unique( $createHostList ); $escPass = $this->db->addQuotes( $password ); foreach ( $createHostList as $host ) { $fullName = $this->buildFullUserName( $dbUser, $host ); - if ( !$this->userDefinitelyExists( $dbUser, $host ) ) { + if ( !$this->userDefinitelyExists( $host, $dbUser ) ) { try { $this->db->begin( __METHOD__ ); $this->db->query( "CREATE USER $fullName IDENTIFIED BY $escPass", __METHOD__ ); @@ -603,8 +603,8 @@ class MysqlInstaller extends DatabaseInstaller { */ private function userDefinitelyExists( $host, $user ) { try { - $res = $this->db->selectRow( 'mysql.user', array( 'Host', 'User' ), - array( 'Host' => $host, 'User' => $user ), __METHOD__ ); + $res = $this->db->selectRow( 'mysql.user', [ 'Host', 'User' ], + [ 'Host' => $host, 'User' => $user ], __METHOD__ ); return (bool)$res; } catch ( DBQueryError $dqe ) { @@ -619,7 +619,7 @@ class MysqlInstaller extends DatabaseInstaller { * @return string */ protected function getTableOptions() { - $options = array(); + $options = []; if ( $this->getVar( '_MysqlEngine' ) !== null ) { $options[] = "ENGINE=" . $this->getVar( '_MysqlEngine' ); } @@ -636,12 +636,12 @@ class MysqlInstaller extends DatabaseInstaller { * @return array */ public function getSchemaVars() { - return array( + return [ 'wgDBTableOptions' => $this->getTableOptions(), 'wgDBname' => $this->getVar( 'wgDBname' ), 'wgDBuser' => $this->getVar( 'wgDBuser' ), 'wgDBpassword' => $this->getVar( 'wgDBpassword' ), - ); + ]; } public function getLocalSettings() {