From 7a31146918cdceef14689bf05d8f1602ec05bfcb Mon Sep 17 00:00:00 2001 From: "coadde [Márcio Alexandre Silva Delgado]" Date: Mon, 4 Jul 2016 16:01:35 -0300 Subject: remove nonfree Database support --- includes/installer/MssqlInstaller.php | 736 --------------------------------- includes/installer/MssqlUpdater.php | 143 ------- includes/installer/OracleInstaller.php | 344 --------------- includes/installer/OracleUpdater.php | 289 ------------- 4 files changed, 1512 deletions(-) delete mode 100644 includes/installer/MssqlInstaller.php delete mode 100644 includes/installer/MssqlUpdater.php delete mode 100644 includes/installer/OracleInstaller.php delete mode 100644 includes/installer/OracleUpdater.php (limited to 'includes/installer') diff --git a/includes/installer/MssqlInstaller.php b/includes/installer/MssqlInstaller.php deleted file mode 100644 index 4d79d966..00000000 --- a/includes/installer/MssqlInstaller.php +++ /dev/null @@ -1,736 +0,0 @@ - 'sa', - '_InstallWindowsAuthentication' => 'sqlauth', - '_WebWindowsAuthentication' => 'sqlauth', - ); - - // SQL Server 2005 RTM - // @todo Are SQL Express version numbers different?) - public $minimumVersion = '9.00.1399'; - - // These are schema-level privs - // Note: the web user will be created will full permissions if possible, this permission - // list is only used if we are unable to grant full permissions. - public $webUserPrivs = array( - 'DELETE', - 'INSERT', - 'SELECT', - 'UPDATE', - 'EXECUTE', - ); - - /** - * @return string - */ - public function getName() { - return 'mssql'; - } - - /** - * @return bool - */ - public function isCompiled() { - return self::checkExtension( 'sqlsrv' ); - } - - /** - * @return string - */ - public function getConnectForm() { - if ( $this->getVar( '_InstallWindowsAuthentication' ) == 'windowsauth' ) { - $displayStyle = 'display: none;'; - } else { - $displayStyle = 'display: block;'; - } - - 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' ), - $this->parent->getHelpBox( 'config-db-name-help' ) ) . - $this->getTextBox( 'wgDBmwschema', 'config-db-schema', array( 'dir' => 'ltr' ), - $this->parent->getHelpBox( 'config-db-schema-help' ) ) . - $this->getTextBox( 'wgDBprefix', 'config-db-prefix', array( 'dir' => 'ltr' ), - $this->parent->getHelpBox( 'config-db-prefix-help' ) ) . - Html::closeElement( 'fieldset' ) . - Html::openElement( 'fieldset' ) . - Html::element( 'legend', array(), wfMessage( 'config-db-install-account' )->text() ) . - $this->getRadioSet( array( - 'var' => '_InstallWindowsAuthentication', - 'label' => 'config-mssql-auth', - 'itemLabelPrefix' => 'config-mssql-', - 'values' => array( 'sqlauth', 'windowsauth' ), - 'itemAttribs' => array( - 'sqlauth' => array( - 'class' => 'showHideRadio', - 'rel' => 'dbCredentialBox', - ), - 'windowsauth' => array( - 'class' => 'hideShowRadio', - 'rel' => 'dbCredentialBox', - ) - ), - 'help' => $this->parent->getHelpBox( 'config-mssql-install-auth' ) - ) ) . - Html::openElement( 'div', array( 'id' => 'dbCredentialBox', 'style' => $displayStyle ) ) . - $this->getTextBox( - '_InstallUser', - 'config-db-username', - array( 'dir' => 'ltr' ), - $this->parent->getHelpBox( 'config-db-install-username' ) - ) . - $this->getPasswordBox( - '_InstallPassword', - 'config-db-password', - array( 'dir' => 'ltr' ), - $this->parent->getHelpBox( 'config-db-install-password' ) - ) . - Html::closeElement( 'div' ) . - Html::closeElement( 'fieldset' ); - } - - public function submitConnectForm() { - // Get variables from the request. - $newValues = $this->setVarsFromRequest( array( - 'wgDBserver', - 'wgDBname', - 'wgDBmwschema', - 'wgDBprefix' - ) ); - - // Validate them. - $status = Status::newGood(); - if ( !strlen( $newValues['wgDBserver'] ) ) { - $status->fatal( 'config-missing-db-host' ); - } - if ( !strlen( $newValues['wgDBname'] ) ) { - $status->fatal( 'config-missing-db-name' ); - } elseif ( !preg_match( '/^[a-z0-9_]+$/i', $newValues['wgDBname'] ) ) { - $status->fatal( 'config-invalid-db-name', $newValues['wgDBname'] ); - } - if ( !preg_match( '/^[a-z0-9_]*$/i', $newValues['wgDBmwschema'] ) ) { - $status->fatal( 'config-invalid-schema', $newValues['wgDBmwschema'] ); - } - if ( !preg_match( '/^[a-z0-9_]*$/i', $newValues['wgDBprefix'] ) ) { - $status->fatal( 'config-invalid-db-prefix', $newValues['wgDBprefix'] ); - } - if ( !$status->isOK() ) { - return $status; - } - - // Check for blank schema and remap to dbo - if ( $newValues['wgDBmwschema'] === '' ) { - $this->setVar( 'wgDBmwschema', 'dbo' ); - } - - // User box - $this->setVarsFromRequest( array( - '_InstallUser', - '_InstallPassword', - '_InstallWindowsAuthentication' - ) ); - - // Try to connect - $status = $this->getConnection(); - if ( !$status->isOK() ) { - return $status; - } - /** - * @var $conn DatabaseBase - */ - $conn = $status->value; - - // Check version - $version = $conn->getServerVersion(); - if ( version_compare( $version, $this->minimumVersion ) < 0 ) { - return Status::newFatal( 'config-mssql-old', $this->minimumVersion, $version ); - } - - return $status; - } - - /** - * @return Status - */ - public function openConnection() { - global $wgDBWindowsAuthentication; - $status = Status::newGood(); - $user = $this->getVar( '_InstallUser' ); - $password = $this->getVar( '_InstallPassword' ); - - if ( $this->getVar( '_InstallWindowsAuthentication' ) == 'windowsauth' ) { - // Use Windows authentication for this connection - $wgDBWindowsAuthentication = true; - } else { - $wgDBWindowsAuthentication = false; - } - - try { - $db = DatabaseBase::factory( 'mssql', array( - 'host' => $this->getVar( 'wgDBserver' ), - 'user' => $user, - 'password' => $password, - 'dbname' => false, - 'flags' => 0, - 'schema' => $this->getVar( 'wgDBmwschema' ), - 'tablePrefix' => $this->getVar( 'wgDBprefix' ) ) ); - $db->prepareStatements( false ); - $db->scrollableCursor( false ); - $status->value = $db; - } catch ( DBConnectionError $e ) { - $status->fatal( 'config-connection-error', $e->getMessage() ); - } - - return $status; - } - - public function preUpgrade() { - global $wgDBuser, $wgDBpassword; - - $status = $this->getConnection(); - if ( !$status->isOK() ) { - $this->parent->showStatusError( $status ); - - return; - } - /** - * @var $conn DatabaseBase - */ - $conn = $status->value; - $conn->selectDB( $this->getVar( 'wgDBname' ) ); - - # Normal user and password are selected after this step, so for now - # just copy these two - $wgDBuser = $this->getVar( '_InstallUser' ); - $wgDBpassword = $this->getVar( '_InstallPassword' ); - } - - /** - * Return true if the install user can create accounts - * - * @return bool - */ - public function canCreateAccounts() { - $status = $this->getConnection(); - if ( !$status->isOK() ) { - return false; - } - /** @var $conn DatabaseBase */ - $conn = $status->value; - - // We need the server-level ALTER ANY LOGIN permission to create new accounts - $res = $conn->query( "SELECT permission_name FROM sys.fn_my_permissions( NULL, 'SERVER' )" ); - $serverPrivs = array( - 'ALTER ANY LOGIN' => false, - 'CONTROL SERVER' => false, - ); - - foreach ( $res as $row ) { - $serverPrivs[$row->permission_name] = true; - } - - if ( !$serverPrivs['ALTER ANY LOGIN'] ) { - return false; - } - - // Check to ensure we can grant everything needed as well - // We can't actually tell if we have WITH GRANT OPTION for a given permission, so we assume we do - // and just check for the permission - // http://technet.microsoft.com/en-us/library/ms178569.aspx - // The following array sets up which permissions imply whatever permissions we specify - $implied = array( - // schema database server - 'DELETE' => array( 'DELETE', 'CONTROL SERVER' ), - 'EXECUTE' => array( 'EXECUTE', 'CONTROL SERVER' ), - 'INSERT' => array( 'INSERT', 'CONTROL SERVER' ), - 'SELECT' => array( 'SELECT', 'CONTROL SERVER' ), - 'UPDATE' => array( 'UPDATE', 'CONTROL SERVER' ), - ); - - $grantOptions = array_flip( $this->webUserPrivs ); - - // Check for schema and db-level permissions, but only if the schema/db exists - $schemaPrivs = $dbPrivs = array( - 'DELETE' => false, - 'EXECUTE' => false, - 'INSERT' => false, - 'SELECT' => false, - 'UPDATE' => false, - ); - - $dbPrivs['ALTER ANY USER'] = false; - - if ( $this->databaseExists( $this->getVar( 'wgDBname' ) ) ) { - $conn->selectDB( $this->getVar( 'wgDBname' ) ); - $res = $conn->query( "SELECT permission_name FROM sys.fn_my_permissions( NULL, 'DATABASE' )" ); - - foreach ( $res as $row ) { - $dbPrivs[$row->permission_name] = true; - } - - // If the db exists, we need ALTER ANY USER privs on it to make a new user - if ( !$dbPrivs['ALTER ANY USER'] ) { - return false; - } - - if ( $this->schemaExists( $this->getVar( 'wgDBmwschema' ) ) ) { - // wgDBmwschema is validated to only contain alphanumeric + underscore, so this is safe - $res = $conn->query( "SELECT permission_name FROM sys.fn_my_permissions( " - . "'{$this->getVar( 'wgDBmwschema' )}', 'SCHEMA' )" ); - - foreach ( $res as $row ) { - $schemaPrivs[$row->permission_name] = true; - } - } - } - - // Now check all the grants we'll need to be doing to see if we can - foreach ( $this->webUserPrivs as $permission ) { - if ( ( isset( $schemaPrivs[$permission] ) && $schemaPrivs[$permission] ) - || ( isset( $dbPrivs[$implied[$permission][0]] ) - && $dbPrivs[$implied[$permission][0]] ) - || ( isset( $serverPrivs[$implied[$permission][1]] ) - && $serverPrivs[$implied[$permission][1]] ) - ) { - unset( $grantOptions[$permission] ); - } - } - - if ( count( $grantOptions ) ) { - // Can't grant everything - return false; - } - - return true; - } - - /** - * @return string - */ - public function getSettingsForm() { - if ( $this->canCreateAccounts() ) { - $noCreateMsg = false; - } else { - $noCreateMsg = 'config-db-web-no-create-privs'; - } - - $wrapperStyle = $this->getVar( '_SameAccount' ) ? 'display: none' : ''; - $displayStyle = $this->getVar( '_WebWindowsAuthentication' ) == 'windowsauth' - ? 'display: none' - : ''; - $s = Html::openElement( 'fieldset' ) . - Html::element( 'legend', array(), wfMessage( 'config-db-web-account' )->text() ) . - $this->getCheckBox( - '_SameAccount', 'config-db-web-account-same', - array( 'class' => 'hideShowRadio', 'rel' => 'dbOtherAccount' ) - ) . - Html::openElement( 'div', array( 'id' => 'dbOtherAccount', 'style' => $wrapperStyle ) ) . - $this->getRadioSet( array( - 'var' => '_WebWindowsAuthentication', - 'label' => 'config-mssql-auth', - 'itemLabelPrefix' => 'config-mssql-', - 'values' => array( 'sqlauth', 'windowsauth' ), - 'itemAttribs' => array( - 'sqlauth' => array( - 'class' => 'showHideRadio', - 'rel' => 'dbCredentialBox', - ), - 'windowsauth' => array( - 'class' => 'hideShowRadio', - 'rel' => 'dbCredentialBox', - ) - ), - 'help' => $this->parent->getHelpBox( 'config-mssql-web-auth' ) - ) ) . - Html::openElement( 'div', array( 'id' => 'dbCredentialBox', 'style' => $displayStyle ) ) . - $this->getTextBox( 'wgDBuser', 'config-db-username' ) . - $this->getPasswordBox( 'wgDBpassword', 'config-db-password' ) . - Html::closeElement( 'div' ); - - if ( $noCreateMsg ) { - $s .= $this->parent->getWarningBox( wfMessage( $noCreateMsg )->plain() ); - } else { - $s .= $this->getCheckBox( '_CreateDBAccount', 'config-db-web-create' ); - } - - $s .= Html::closeElement( 'div' ) . Html::closeElement( 'fieldset' ); - - return $s; - } - - /** - * @return Status - */ - public function submitSettingsForm() { - $this->setVarsFromRequest( array( - 'wgDBuser', - 'wgDBpassword', - '_SameAccount', - '_CreateDBAccount', - '_WebWindowsAuthentication' - ) ); - - if ( $this->getVar( '_SameAccount' ) ) { - $this->setVar( '_WebWindowsAuthentication', $this->getVar( '_InstallWindowsAuthentication' ) ); - $this->setVar( 'wgDBuser', $this->getVar( '_InstallUser' ) ); - $this->setVar( 'wgDBpassword', $this->getVar( '_InstallPassword' ) ); - } - - if ( $this->getVar( '_WebWindowsAuthentication' ) == 'windowsauth' ) { - $this->setVar( 'wgDBuser', '' ); - $this->setVar( 'wgDBpassword', '' ); - $this->setVar( 'wgDBWindowsAuthentication', true ); - } else { - $this->setVar( 'wgDBWindowsAuthentication', false ); - } - - if ( $this->getVar( '_CreateDBAccount' ) - && $this->getVar( '_WebWindowsAuthentication' ) == 'sqlauth' - && strval( $this->getVar( 'wgDBpassword' ) ) == '' - ) { - return Status::newFatal( 'config-db-password-empty', $this->getVar( 'wgDBuser' ) ); - } - - // Validate the create checkbox - $canCreate = $this->canCreateAccounts(); - if ( !$canCreate ) { - $this->setVar( '_CreateDBAccount', false ); - $create = false; - } else { - $create = $this->getVar( '_CreateDBAccount' ); - } - - if ( !$create ) { - // Test the web account - $user = $this->getVar( 'wgDBuser' ); - $password = $this->getVar( 'wgDBpassword' ); - - if ( $this->getVar( '_WebWindowsAuthentication' ) == 'windowsauth' ) { - $user = 'windowsauth'; - $password = 'windowsauth'; - } - - try { - DatabaseBase::factory( 'mssql', array( - 'host' => $this->getVar( 'wgDBserver' ), - 'user' => $user, - 'password' => $password, - 'dbname' => false, - 'flags' => 0, - 'tablePrefix' => $this->getVar( 'wgDBprefix' ), - 'schema' => $this->getVar( 'wgDBmwschema' ), - ) ); - } catch ( DBConnectionError $e ) { - return Status::newFatal( 'config-connection-error', $e->getMessage() ); - } - } - - return Status::newGood(); - } - - public function preInstall() { - # Add our user callback to installSteps, right before the tables are created. - $callback = array( - 'name' => 'user', - 'callback' => array( $this, 'setupUser' ), - ); - $this->parent->addInstallStep( $callback, 'tables' ); - } - - /** - * @return Status - */ - public function setupDatabase() { - $status = $this->getConnection(); - if ( !$status->isOK() ) { - return $status; - } - /** @var DatabaseBase $conn */ - $conn = $status->value; - $dbName = $this->getVar( 'wgDBname' ); - $schemaName = $this->getVar( 'wgDBmwschema' ); - if ( !$this->databaseExists( $dbName ) ) { - $conn->query( - "CREATE DATABASE " . $conn->addIdentifierQuotes( $dbName ), - __METHOD__ - ); - $conn->selectDB( $dbName ); - if ( !$this->schemaExists( $schemaName ) ) { - $conn->query( - "CREATE SCHEMA " . $conn->addIdentifierQuotes( $schemaName ), - __METHOD__ - ); - } - if ( !$this->catalogExists( $schemaName ) ) { - $conn->query( - "CREATE FULLTEXT CATALOG " . $conn->addIdentifierQuotes( $schemaName ), - __METHOD__ - ); - } - } - $this->setupSchemaVars(); - - return $status; - } - - /** - * @return Status - */ - public function setupUser() { - $dbUser = $this->getVar( 'wgDBuser' ); - if ( $dbUser == $this->getVar( '_InstallUser' ) - || ( $this->getVar( '_InstallWindowsAuthentication' ) == 'windowsauth' - && $this->getVar( '_WebWindowsAuthentication' ) == 'windowsauth' ) ) { - return Status::newGood(); - } - $status = $this->getConnection(); - if ( !$status->isOK() ) { - return $status; - } - - $this->setupSchemaVars(); - $dbName = $this->getVar( 'wgDBname' ); - $this->db->selectDB( $dbName ); - $password = $this->getVar( 'wgDBpassword' ); - $schemaName = $this->getVar( 'wgDBmwschema' ); - - if ( $this->getVar( '_WebWindowsAuthentication' ) == 'windowsauth' ) { - $dbUser = 'windowsauth'; - $password = 'windowsauth'; - } - - if ( $this->getVar( '_CreateDBAccount' ) ) { - $tryToCreate = true; - } else { - $tryToCreate = false; - } - - $escUser = $this->db->addIdentifierQuotes( $dbUser ); - $escDb = $this->db->addIdentifierQuotes( $dbName ); - $escSchema = $this->db->addIdentifierQuotes( $schemaName ); - $grantableNames = array(); - if ( $tryToCreate ) { - $escPass = $this->db->addQuotes( $password ); - - if ( !$this->loginExists( $dbUser ) ) { - try { - $this->db->begin(); - $this->db->selectDB( 'master' ); - $logintype = $this->getVar( '_WebWindowsAuthentication' ) == 'windowsauth' - ? 'FROM WINDOWS' - : "WITH PASSWORD = $escPass"; - $this->db->query( "CREATE LOGIN $escUser $logintype" ); - $this->db->selectDB( $dbName ); - $this->db->query( "CREATE USER $escUser FOR LOGIN $escUser WITH DEFAULT_SCHEMA = $escSchema" ); - $this->db->commit(); - $grantableNames[] = $dbUser; - } catch ( DBQueryError $dqe ) { - $this->db->rollback(); - $status->warning( 'config-install-user-create-failed', $dbUser, $dqe->getText() ); - } - } elseif ( !$this->userExists( $dbUser ) ) { - try { - $this->db->begin(); - $this->db->selectDB( $dbName ); - $this->db->query( "CREATE USER $escUser FOR LOGIN $escUser WITH DEFAULT_SCHEMA = $escSchema" ); - $this->db->commit(); - $grantableNames[] = $dbUser; - } catch ( DBQueryError $dqe ) { - $this->db->rollback(); - $status->warning( 'config-install-user-create-failed', $dbUser, $dqe->getText() ); - } - } else { - $status->warning( 'config-install-user-alreadyexists', $dbUser ); - $grantableNames[] = $dbUser; - } - } - - // Try to grant to all the users we know exist or we were able to create - $this->db->selectDB( $dbName ); - foreach ( $grantableNames as $name ) { - try { - // First try to grant full permissions - $fullPrivArr = array( - 'BACKUP DATABASE', 'BACKUP LOG', 'CREATE FUNCTION', 'CREATE PROCEDURE', - 'CREATE TABLE', 'CREATE VIEW', 'CREATE FULLTEXT CATALOG', 'SHOWPLAN' - ); - $fullPrivList = implode( ', ', $fullPrivArr ); - $this->db->begin(); - $this->db->query( "GRANT $fullPrivList ON DATABASE :: $escDb TO $escUser", __METHOD__ ); - $this->db->query( "GRANT CONTROL ON SCHEMA :: $escSchema TO $escUser", __METHOD__ ); - $this->db->commit(); - } catch ( DBQueryError $dqe ) { - // If that fails, try to grant the limited subset specified in $this->webUserPrivs - try { - $privList = implode( ', ', $this->webUserPrivs ); - $this->db->rollback(); - $this->db->begin(); - $this->db->query( "GRANT $privList ON SCHEMA :: $escSchema TO $escUser", __METHOD__ ); - $this->db->commit(); - } catch ( DBQueryError $dqe ) { - $this->db->rollback(); - $status->fatal( 'config-install-user-grant-failed', $dbUser, $dqe->getText() ); - } - // Also try to grant SHOWPLAN on the db, but don't fail if we can't - // (just makes a couple things in mediawiki run slower since - // we have to run SELECT COUNT(*) instead of getting the query plan) - try { - $this->db->query( "GRANT SHOWPLAN ON DATABASE :: $escDb TO $escUser", __METHOD__ ); - } catch ( DBQueryError $dqe ) { - } - } - } - - return $status; - } - - public function createTables() { - $status = parent::createTables(); - - // Do last-minute stuff like fulltext indexes (since they can't be inside a transaction) - if ( $status->isOk() ) { - $searchindex = $this->db->tableName( 'searchindex' ); - $schema = $this->db->addIdentifierQuotes( $this->getVar( 'wgDBmwschema' ) ); - try { - $this->db->query( "CREATE FULLTEXT INDEX ON $searchindex (si_title, si_text) " - . "KEY INDEX si_page ON $schema" ); - } catch ( DBQueryError $dqe ) { - $status->fatal( 'config-install-tables-failed', $dqe->getText() ); - } - } - - return $status; - } - - public function getGlobalDefaults() { - // The default $wgDBmwschema is null, which breaks Postgres and other DBMSes that require - // the use of a schema, so we need to set it here - return array_merge( parent::getGlobalDefaults(), array( - 'wgDBmwschema' => 'mediawiki', - ) ); - } - - /** - * Try to see if the login exists - * @param string $user Username to check - * @return bool - */ - private function loginExists( $user ) { - $res = $this->db->selectField( 'sys.sql_logins', 1, array( 'name' => $user ) ); - return (bool)$res; - } - - /** - * Try to see if the user account exists - * We assume we already have the appropriate database selected - * @param string $user Username to check - * @return bool - */ - private function userExists( $user ) { - $res = $this->db->selectField( 'sys.sysusers', 1, array( 'name' => $user ) ); - return (bool)$res; - } - - /** - * Try to see if a given database exists - * @param string $dbName Database name to check - * @return bool - */ - private function databaseExists( $dbName ) { - $res = $this->db->selectField( 'sys.databases', 1, array( 'name' => $dbName ) ); - return (bool)$res; - } - - /** - * Try to see if a given schema exists - * We assume we already have the appropriate database selected - * @param string $schemaName Schema name to check - * @return bool - */ - private function schemaExists( $schemaName ) { - $res = $this->db->selectField( 'sys.schemas', 1, array( 'name' => $schemaName ) ); - return (bool)$res; - } - - /** - * Try to see if a given fulltext catalog exists - * We assume we already have the appropriate database selected - * @param string $catalogName Catalog name to check - * @return bool - */ - private function catalogExists( $catalogName ) { - $res = $this->db->selectField( 'sys.fulltext_catalogs', 1, array( 'name' => $catalogName ) ); - return (bool)$res; - } - - /** - * Get variables to substitute into tables.sql and the SQL patch files. - * - * @return array - */ - public function getSchemaVars() { - return array( - 'wgDBname' => $this->getVar( 'wgDBname' ), - 'wgDBmwschema' => $this->getVar( 'wgDBmwschema' ), - 'wgDBuser' => $this->getVar( 'wgDBuser' ), - 'wgDBpassword' => $this->getVar( 'wgDBpassword' ), - ); - } - - public function getLocalSettings() { - $schema = LocalSettingsGenerator::escapePhpString( $this->getVar( 'wgDBmwschema' ) ); - $prefix = LocalSettingsGenerator::escapePhpString( $this->getVar( 'wgDBprefix' ) ); - $windowsauth = $this->getVar( 'wgDBWindowsAuthentication' ) ? 'true' : 'false'; - - return "# MSSQL specific settings -\$wgDBWindowsAuthentication = {$windowsauth}; -\$wgDBmwschema = \"{$schema}\"; -\$wgDBprefix = \"{$prefix}\";"; - } -} diff --git a/includes/installer/MssqlUpdater.php b/includes/installer/MssqlUpdater.php deleted file mode 100644 index 164cfab4..00000000 --- a/includes/installer/MssqlUpdater.php +++ /dev/null @@ -1,143 +0,0 @@ -_ckc - * - * @param string $constraintType - * @param string $table Name of the table to which the field belongs - * @param string $field Name of the field to modify - * @return bool False if patch is skipped. - */ - protected function updateConstraints( $constraintType, $table, $field ) { - global $wgDBname, $wgDBmwschema; - - if ( !$this->doTable( $table ) ) { - return true; - } - - $this->output( "...updating constraints on [$table].[$field] ..." ); - $updateKey = "$field-$constraintType-ck"; - if ( !$this->db->tableExists( $table, __METHOD__ ) ) { - $this->output( "...$table table does not exist, skipping modify field patch.\n" ); - return true; - } elseif ( !$this->db->fieldExists( $table, $field, __METHOD__ ) ) { - $this->output( "...$field field does not exist in $table table, " . - "skipping modify field patch.\n" ); - return true; - } elseif ( $this->updateRowExists( $updateKey ) ) { - $this->output( "...$field in table $table already patched.\n" ); - return true; - } - - # After all checks passed, start the update - $this->insertUpdateRow( $updateKey ); - $path = 'named_constraints.sql'; - $constraintMap = array( - 'category_types' => - "($field in('page', 'subcat', 'file'))", - 'major_mime' => - "($field in('unknown', 'application', 'audio', 'image', 'text', 'video'," . - " 'message', 'model', 'multipart'))", - 'media_type' => - "($field in('UNKNOWN', 'BITMAP', 'DRAWING', 'AUDIO', 'VIDEO', 'MULTIMEDIA'," . - "'OFFICE', 'TEXT', 'EXECUTABLE', 'ARCHIVE'))" - ); - $constraint = $constraintMap[$constraintType]; - - # and hack-in those variables that should be replaced - # in our template file right now - $this->db->setSchemaVars( array( - 'tableName' => $table, - 'fieldName' => $field, - 'checkConstraint' => $constraint, - 'wgDBname' => $wgDBname, - 'wgDBmwschema' => $wgDBmwschema, - ) ); - - # Full path from file name - $path = $this->db->patchPath( $path ); - - # No need for a cursor allowing result-iteration; just apply a patch - # store old value for re-setting later - $wasScrollable = $this->db->scrollableCursor( false ); - - # Apply patch - $this->db->sourceFile( $path ); - - # Reset DB instance to have original state - $this->db->setSchemaVars( false ); - $this->db->scrollableCursor( $wasScrollable ); - - $this->output( "done.\n" ); - - return true; - } -} diff --git a/includes/installer/OracleInstaller.php b/includes/installer/OracleInstaller.php deleted file mode 100644 index 9e692ea4..00000000 --- a/includes/installer/OracleInstaller.php +++ /dev/null @@ -1,344 +0,0 @@ - 'USERS', - '_OracleTempTS' => 'TEMP', - '_InstallUser' => 'SYSTEM', - ); - - public $minimumVersion = '9.0.1'; // 9iR1 - - protected $connError = null; - - public function getName() { - return 'oracle'; - } - - public function isCompiled() { - return self::checkExtension( 'oci8' ); - } - - public function getConnectForm() { - if ( $this->getVar( 'wgDBserver' ) == 'localhost' ) { - $this->parent->setVar( 'wgDBserver', '' ); - } - - return $this->getTextBox( - 'wgDBserver', - 'config-db-host-oracle', - array(), - $this->parent->getHelpBox( 'config-db-host-oracle-help' ) - ) . - Html::openElement( 'fieldset' ) . - Html::element( 'legend', array(), wfMessage( 'config-db-wiki-settings' )->text() ) . - $this->getTextBox( 'wgDBprefix', 'config-db-prefix' ) . - $this->getTextBox( '_OracleDefTS', 'config-oracle-def-ts' ) . - $this->getTextBox( - '_OracleTempTS', - 'config-oracle-temp-ts', - array(), - $this->parent->getHelpBox( 'config-db-oracle-help' ) - ) . - Html::closeElement( 'fieldset' ) . - $this->parent->getWarningBox( wfMessage( 'config-db-account-oracle-warn' )->text() ) . - $this->getInstallUserBox() . - $this->getWebUserBox(); - } - - public function submitInstallUserBox() { - parent::submitInstallUserBox(); - $this->parent->setVar( '_InstallDBname', $this->getVar( '_InstallUser' ) ); - - return Status::newGood(); - } - - public function submitConnectForm() { - // Get variables from the request - $newValues = $this->setVarsFromRequest( array( - 'wgDBserver', - 'wgDBprefix', - 'wgDBuser', - 'wgDBpassword' - ) ); - $this->parent->setVar( 'wgDBname', $this->getVar( 'wgDBuser' ) ); - - // Validate them - $status = Status::newGood(); - if ( !strlen( $newValues['wgDBserver'] ) ) { - $status->fatal( 'config-missing-db-server-oracle' ); - } elseif ( !self::checkConnectStringFormat( $newValues['wgDBserver'] ) ) { - $status->fatal( 'config-invalid-db-server-oracle', $newValues['wgDBserver'] ); - } - if ( !preg_match( '/^[a-zA-Z0-9_]*$/', $newValues['wgDBprefix'] ) ) { - $status->fatal( 'config-invalid-schema', $newValues['wgDBprefix'] ); - } - if ( !$status->isOK() ) { - return $status; - } - - // Submit user box - $status = $this->submitInstallUserBox(); - if ( !$status->isOK() ) { - return $status; - } - - // Try to connect trough multiple scenarios - // Scenario 1: Install with a manually created account - $status = $this->getConnection(); - if ( !$status->isOK() ) { - if ( $this->connError == 28009 ) { - // _InstallUser seems to be a SYSDBA - // Scenario 2: Create user with SYSDBA and install with new user - $status = $this->submitWebUserBox(); - if ( !$status->isOK() ) { - return $status; - } - $status = $this->openSYSDBAConnection(); - if ( !$status->isOK() ) { - return $status; - } - if ( !$this->getVar( '_CreateDBAccount' ) ) { - $status->fatal( 'config-db-sys-create-oracle' ); - } - } else { - return $status; - } - } else { - // check for web user credentials - // Scenario 3: Install with a priviliged user but use a restricted user - $statusIS3 = $this->submitWebUserBox(); - if ( !$statusIS3->isOK() ) { - return $statusIS3; - } - } - - /** - * @var $conn DatabaseBase - */ - $conn = $status->value; - - // Check version - $version = $conn->getServerVersion(); - if ( version_compare( $version, $this->minimumVersion ) < 0 ) { - return Status::newFatal( 'config-oracle-old', $this->minimumVersion, $version ); - } - - return $status; - } - - public function openConnection() { - $status = Status::newGood(); - try { - $db = new DatabaseOracle( - $this->getVar( 'wgDBserver' ), - $this->getVar( '_InstallUser' ), - $this->getVar( '_InstallPassword' ), - $this->getVar( '_InstallDBname' ), - 0, - $this->getVar( 'wgDBprefix' ) - ); - $status->value = $db; - } catch ( DBConnectionError $e ) { - $this->connError = $e->db->lastErrno(); - $status->fatal( 'config-connection-error', $e->getMessage() ); - } - - return $status; - } - - public function openSYSDBAConnection() { - $status = Status::newGood(); - try { - $db = new DatabaseOracle( - $this->getVar( 'wgDBserver' ), - $this->getVar( '_InstallUser' ), - $this->getVar( '_InstallPassword' ), - $this->getVar( '_InstallDBname' ), - DBO_SYSDBA, - $this->getVar( 'wgDBprefix' ) - ); - $status->value = $db; - } catch ( DBConnectionError $e ) { - $this->connError = $e->db->lastErrno(); - $status->fatal( 'config-connection-error', $e->getMessage() ); - } - - return $status; - } - - public function needsUpgrade() { - $tempDBname = $this->getVar( 'wgDBname' ); - $this->parent->setVar( 'wgDBname', $this->getVar( 'wgDBuser' ) ); - $retVal = parent::needsUpgrade(); - $this->parent->setVar( 'wgDBname', $tempDBname ); - - return $retVal; - } - - public function preInstall() { - # Add our user callback to installSteps, right before the tables are created. - $callback = array( - 'name' => 'user', - 'callback' => array( $this, 'setupUser' ) - ); - $this->parent->addInstallStep( $callback, 'database' ); - } - - public function setupDatabase() { - $status = Status::newGood(); - - return $status; - } - - public function setupUser() { - global $IP; - - if ( !$this->getVar( '_CreateDBAccount' ) ) { - return Status::newGood(); - } - - // normaly only SYSDBA users can create accounts - $status = $this->openSYSDBAConnection(); - if ( !$status->isOK() ) { - if ( $this->connError == 1031 ) { - // insufficient privileges (looks like a normal user) - $status = $this->openConnection(); - if ( !$status->isOK() ) { - return $status; - } - } else { - return $status; - } - } - - $this->db = $status->value; - $this->setupSchemaVars(); - - if ( !$this->db->selectDB( $this->getVar( 'wgDBuser' ) ) ) { - $this->db->setFlag( DBO_DDLMODE ); - $error = $this->db->sourceFile( "$IP/maintenance/oracle/user.sql" ); - if ( $error !== true || !$this->db->selectDB( $this->getVar( 'wgDBuser' ) ) ) { - $status->fatal( 'config-install-user-failed', $this->getVar( 'wgDBuser' ), $error ); - } - } elseif ( $this->db->getFlag( DBO_SYSDBA ) ) { - $status->fatal( 'config-db-sys-user-exists-oracle', $this->getVar( 'wgDBuser' ) ); - } - - if ( $status->isOK() ) { - // user created or already existing, switching back to a normal connection - // as the new user has all needed privileges to setup the rest of the schema - // i will be using that user as _InstallUser from this point on - $this->db->close(); - $this->db = false; - $this->parent->setVar( '_InstallUser', $this->getVar( 'wgDBuser' ) ); - $this->parent->setVar( '_InstallPassword', $this->getVar( 'wgDBpassword' ) ); - $this->parent->setVar( '_InstallDBname', $this->getVar( 'wgDBuser' ) ); - $status = $this->getConnection(); - } - - return $status; - } - - /** - * Overload: after this action field info table has to be rebuilt - * @return Status - */ - public function createTables() { - $this->setupSchemaVars(); - $this->db->setFlag( DBO_DDLMODE ); - $this->parent->setVar( 'wgDBname', $this->getVar( 'wgDBuser' ) ); - $status = parent::createTables(); - $this->db->clearFlag( DBO_DDLMODE ); - - $this->db->query( 'BEGIN fill_wiki_info; END;' ); - - return $status; - } - - public function getSchemaVars() { - $varNames = array( - # These variables are used by maintenance/oracle/user.sql - '_OracleDefTS', - '_OracleTempTS', - 'wgDBuser', - 'wgDBpassword', - - # These are used by tables.sql - 'wgDBprefix', - ); - $vars = array(); - foreach ( $varNames as $name ) { - $vars[$name] = $this->getVar( $name ); - } - - return $vars; - } - - public function getLocalSettings() { - $prefix = $this->getVar( 'wgDBprefix' ); - - return "# Oracle specific settings -\$wgDBprefix = \"{$prefix}\"; -"; - } - - /** - * Function checks the format of Oracle connect string - * The actual validity of the string is checked by attempting to connect - * - * Regex should be able to validate all connect string formats - * [//](host|tns_name)[:port][/service_name][:POOLED] - * http://www.orafaq.com/wiki/EZCONNECT - * - * @since 1.22 - * - * @param string $connect_string - * - * @return bool Whether the connection string is valid. - */ - public static function checkConnectStringFormat( $connect_string ) { - // @@codingStandardsIgnoreStart Long lines with regular expressions. - // @todo Very long regular expression. Make more readable? - $isValid = preg_match( '/^[[:alpha:]][\w\-]*(?:\.[[:alpha:]][\w\-]*){0,2}$/', $connect_string ); // TNS name - $isValid |= preg_match( '/^(?:\/\/)?[\w\-\.]+(?::[\d]+)?(?:\/(?:[\w\-\.]+(?::(pooled|dedicated|shared))?)?(?:\/[\w\-\.]+)?)?$/', $connect_string ); // EZConnect - // @@codingStandardsIgnoreEnd - return (bool)$isValid; - } -} diff --git a/includes/installer/OracleUpdater.php b/includes/installer/OracleUpdater.php deleted file mode 100644 index 03dbd1ce..00000000 --- a/includes/installer/OracleUpdater.php +++ /dev/null @@ -1,289 +0,0 @@ -db->fieldInfo( 'page', 'page_namespace' ); - if ( $meta->defaultValue() != null ) { - return; - } - - $this->applyPatch( - 'patch_namespace_defaults.sql', - false, - 'Altering namespace fields with default value' - ); - } - - /** - * Uniform FK names + deferrable state - */ - protected function doFKRenameDeferr() { - $meta = $this->db->query( ' - SELECT COUNT(*) cnt - FROM user_constraints - WHERE constraint_type = \'R\' AND deferrable = \'DEFERRABLE\'' - ); - $row = $meta->fetchRow(); - if ( $row && $row['cnt'] > 0 ) { - return; - } - - $this->applyPatch( 'patch_fk_rename_deferred.sql', false, "Altering foreign keys ... " ); - } - - /** - * Recreate functions to 17 schema layout - */ - protected function doFunctions17() { - $this->applyPatch( 'patch_create_17_functions.sql', false, "Recreating functions" ); - } - - /** - * Schema upgrade 16->17 - * there are no incremental patches prior to this - */ - protected function doSchemaUpgrade17() { - // check if iwlinks table exists which was added in 1.17 - if ( $this->db->tableExists( 'iwlinks' ) ) { - return; - } - $this->applyPatch( 'patch_16_17_schema_changes.sql', false, "Updating schema to 17" ); - } - - /** - * Insert page (page_id = 0) to prevent FK constraint violation - */ - protected function doInsertPage0() { - $this->output( "Inserting page 0 if missing ... " ); - $row = array( - 'page_id' => 0, - 'page_namespace' => 0, - 'page_title' => ' ', - 'page_is_redirect' => 0, - 'page_is_new' => 0, - 'page_random' => 0, - 'page_touched' => $this->db->timestamp(), - 'page_latest' => 0, - 'page_len' => 0 - ); - $this->db->insert( 'page', $row, 'OracleUpdater:doInserPage0', array( 'IGNORE' ) ); - $this->output( "ok\n" ); - } - - /** - * Remove DEFAULT '' NOT NULL constraints from fields as '' is internally - * converted to NULL in Oracle - */ - protected function doRemoveNotNullEmptyDefaults() { - $meta = $this->db->fieldInfo( 'categorylinks', 'cl_sortkey_prefix' ); - if ( $meta->isNullable() ) { - return; - } - $this->applyPatch( - 'patch_remove_not_null_empty_defs.sql', - false, - 'Removing not null empty constraints' - ); - } - - protected function doRemoveNotNullEmptyDefaults2() { - $meta = $this->db->fieldInfo( 'ipblocks', 'ipb_by_text' ); - if ( $meta->isNullable() ) { - return; - } - $this->applyPatch( - 'patch_remove_not_null_empty_defs2.sql', - false, - 'Removing not null empty constraints' - ); - } - - /** - * Removed forcing of invalid state on recentchanges_fk2. - * cascading taken in account in the deleting function - */ - protected function doRecentchangesFK2Cascade() { - $meta = $this->db->query( 'SELECT 1 FROM all_constraints WHERE owner = \'' . - strtoupper( $this->db->getDBname() ) . - '\' AND constraint_name = \'' . - $this->db->tablePrefix() . - 'RECENTCHANGES_FK2\' AND delete_rule = \'CASCADE\'' - ); - $row = $meta->fetchRow(); - if ( $row ) { - return; - } - - $this->applyPatch( 'patch_recentchanges_fk2_cascade.sql', false, "Altering RECENTCHANGES_FK2" ); - } - - /** - * Fixed wrong PK, UK definition - */ - protected function doPageRestrictionsPKUKFix() { - $this->output( "Altering PAGE_RESTRICTIONS keys ... " ); - - $meta = $this->db->query( 'SELECT column_name FROM all_cons_columns WHERE owner = \'' . - strtoupper( $this->db->getDBname() ) . - '\' AND constraint_name = \'' . - $this->db->tablePrefix() . - 'PAGE_RESTRICTIONS_PK\' AND rownum = 1' - ); - $row = $meta->fetchRow(); - if ( $row['column_name'] == 'PR_ID' ) { - $this->output( "seems to be up to date.\n" ); - - return; - } - - $this->applyPatch( 'patch-page_restrictions_pkuk_fix.sql', false ); - $this->output( "ok\n" ); - } - - /** - * rebuilding of the function that duplicates tables for tests - */ - protected function doRebuildDuplicateFunction() { - $this->applyPatch( 'patch_rebuild_dupfunc.sql', false, "Rebuilding duplicate function" ); - } - - /** - * Overload: after this action field info table has to be rebuilt - * - * @param array $what - */ - public function doUpdates( $what = array( 'core', 'extensions', 'purge', 'stats' ) ) { - parent::doUpdates( $what ); - - $this->db->query( 'BEGIN fill_wiki_info; END;' ); - } - - /** - * Overload: because of the DDL_MODE tablename escaping is a bit dodgy - */ - public function purgeCache() { - # We can't guarantee that the user will be able to use TRUNCATE, - # but we know that DELETE is available to us - $this->output( "Purging caches..." ); - $this->db->delete( '/*Q*/' . $this->db->tableName( 'objectcache' ), '*', __METHOD__ ); - $this->output( "done.\n" ); - } -} -- cgit v1.2.3-54-g00ecf