Merge "Revert "Use display name in category page subheadings if provided""
[lhc/web/wiklou.git] / includes / installer / PostgresInstaller.php
index c10e81a..6dfa28b 100644 (file)
  */
 class PostgresInstaller extends DatabaseInstaller {
 
-       protected $globalNames = array(
+       protected $globalNames = [
                'wgDBserver',
                'wgDBport',
                'wgDBname',
                'wgDBuser',
                'wgDBpassword',
                'wgDBmwschema',
-       );
+       ];
 
-       protected $internalDefaults = array(
+       protected $internalDefaults = [
                '_InstallUser' => 'postgres',
-       );
+       ];
 
        public $minimumVersion = '8.3';
        public $maxRoleSearchDepth = 5;
 
-       protected $pgConns = array();
+       protected $pgConns = [];
 
        function getName() {
                return 'postgres';
@@ -59,22 +59,22 @@ class PostgresInstaller extends DatabaseInstaller {
                return $this->getTextBox(
                        'wgDBserver',
                        'config-db-host',
-                       array(),
+                       [],
                        $this->parent->getHelpBox( 'config-db-host-help' )
                ) .
                        $this->getTextBox( 'wgDBport', 'config-db-port' ) .
                        Html::openElement( 'fieldset' ) .
-                       Html::element( 'legend', array(), wfMessage( 'config-db-wiki-settings' )->text() ) .
+                       Html::element( 'legend', [], wfMessage( 'config-db-wiki-settings' )->text() ) .
                        $this->getTextBox(
                                'wgDBname',
                                'config-db-name',
-                               array(),
+                               [],
                                $this->parent->getHelpBox( 'config-db-name-help' )
                        ) .
                        $this->getTextBox(
                                'wgDBmwschema',
                                'config-db-schema',
-                               array(),
+                               [],
                                $this->parent->getHelpBox( 'config-db-schema-help' )
                        ) .
                        Html::closeElement( 'fieldset' ) .
@@ -83,12 +83,12 @@ class PostgresInstaller extends DatabaseInstaller {
 
        function submitConnectForm() {
                // Get variables from the request
-               $newValues = $this->setVarsFromRequest( array(
+               $newValues = $this->setVarsFromRequest( [
                        'wgDBserver',
                        'wgDBport',
                        'wgDBname',
                        'wgDBmwschema'
-               ) );
+               ] );
 
                // Validate them
                $status = Status::newGood();
@@ -114,7 +114,7 @@ class PostgresInstaller extends DatabaseInstaller {
                        return $status;
                }
                /**
-                * @var $conn DatabaseBase
+                * @var $conn Database
                 */
                $conn = $status->value;
 
@@ -154,12 +154,12 @@ class PostgresInstaller extends DatabaseInstaller {
        protected function openConnectionWithParams( $user, $password, $dbName, $schema ) {
                $status = Status::newGood();
                try {
-                       $db = DatabaseBase::factory( 'postgres', array(
+                       $db = Database::factory( 'postgres', [
                                'host' => $this->getVar( 'wgDBserver' ),
                                'user' => $user,
                                'password' => $password,
                                'dbname' => $dbName,
-                               'schema' => $schema ) );
+                               'schema' => $schema ] );
                        $status->value = $db;
                } catch ( DBConnectionError $e ) {
                        $status->fatal( 'config-connection-error', $e->getMessage() );
@@ -181,7 +181,7 @@ class PostgresInstaller extends DatabaseInstaller {
 
                if ( $status->isOK() ) {
                        /**
-                        * @var $conn DatabaseBase
+                        * @var $conn Database
                         */
                        $conn = $status->value;
                        $conn->clearFlag( DBO_TRX );
@@ -233,7 +233,7 @@ class PostgresInstaller extends DatabaseInstaller {
                                $status = $this->openPgConnection( 'create-schema' );
                                if ( $status->isOK() ) {
                                        /**
-                                        * @var $conn DatabaseBase
+                                        * @var $conn Database
                                         */
                                        $conn = $status->value;
                                        $safeRole = $conn->addIdentifierQuotes( $this->getVar( 'wgDBuser' ) );
@@ -247,10 +247,10 @@ class PostgresInstaller extends DatabaseInstaller {
        }
 
        public function openConnectionToAnyDB( $user, $password ) {
-               $dbs = array(
+               $dbs = [
                        'template1',
                        'postgres',
-               );
+               ];
                if ( !in_array( $this->getVar( 'wgDBname' ), $dbs ) ) {
                        array_unshift( $dbs, $this->getVar( 'wgDBname' ) );
                }
@@ -258,13 +258,13 @@ class PostgresInstaller extends DatabaseInstaller {
                $status = Status::newGood();
                foreach ( $dbs as $db ) {
                        try {
-                               $p = array(
+                               $p = [
                                        'host' => $this->getVar( 'wgDBserver' ),
                                        'user' => $user,
                                        'password' => $password,
                                        'dbname' => $db
-                               );
-                               $conn = DatabaseBase::factory( 'postgres', $p );
+                               ];
+                               $conn = Database::factory( 'postgres', $p );
                        } catch ( DBConnectionError $error ) {
                                $conn = false;
                                $status->fatal( 'config-pg-test-error', $db,
@@ -287,13 +287,13 @@ class PostgresInstaller extends DatabaseInstaller {
                        return false;
                }
                /**
-                * @var $conn DatabaseBase
+                * @var $conn Database
                 */
                $conn = $status->value;
                $superuser = $this->getVar( '_InstallUser' );
 
                $row = $conn->selectRow( '"pg_catalog"."pg_roles"', '*',
-                       array( 'rolname' => $superuser ), __METHOD__ );
+                       [ 'rolname' => $superuser ], __METHOD__ );
 
                return $row;
        }
@@ -404,16 +404,16 @@ class PostgresInstaller extends DatabaseInstaller {
                }
                $conn = $status->value;
                $installerId = $conn->selectField( '"pg_catalog"."pg_roles"', 'oid',
-                       array( 'rolname' => $this->getVar( '_InstallUser' ) ), __METHOD__ );
+                       [ 'rolname' => $this->getVar( '_InstallUser' ) ], __METHOD__ );
                $webId = $conn->selectField( '"pg_catalog"."pg_roles"', 'oid',
-                       array( 'rolname' => $this->getVar( 'wgDBuser' ) ), __METHOD__ );
+                       [ 'rolname' => $this->getVar( 'wgDBuser' ) ], __METHOD__ );
 
                return $this->isRoleMember( $conn, $installerId, $webId, $this->maxRoleSearchDepth );
        }
 
        /**
         * Recursive helper for canCreateObjectsForWebUser().
-        * @param DatabaseBase $conn
+        * @param Database $conn
         * @param int $targetMember Role ID of the member to look for
         * @param int $group Role ID of the group to look for
         * @param int $maxDepth Maximum recursive search depth
@@ -425,8 +425,8 @@ class PostgresInstaller extends DatabaseInstaller {
                        return true;
                }
                // Get all members of the given group
-               $res = $conn->select( '"pg_catalog"."pg_auth_members"', array( 'member' ),
-                       array( 'roleid' => $group ), __METHOD__ );
+               $res = $conn->select( '"pg_catalog"."pg_auth_members"', [ 'member' ],
+                       [ 'roleid' => $group ], __METHOD__ );
                foreach ( $res as $row ) {
                        if ( $row->member == $targetMember ) {
                                // Found target member
@@ -446,22 +446,22 @@ class PostgresInstaller extends DatabaseInstaller {
        }
 
        public function preInstall() {
-               $createDbAccount = array(
+               $createDbAccount = [
                        'name' => 'user',
-                       'callback' => array( $this, 'setupUser' ),
-               );
-               $commitCB = array(
+                       'callback' => [ $this, 'setupUser' ],
+               ];
+               $commitCB = [
                        'name' => 'pg-commit',
-                       'callback' => array( $this, 'commitChanges' ),
-               );
-               $plpgCB = array(
+                       'callback' => [ $this, 'commitChanges' ],
+               ];
+               $plpgCB = [
                        'name' => 'pg-plpgsql',
-                       'callback' => array( $this, 'setupPLpgSQL' ),
-               );
-               $schemaCB = array(
+                       'callback' => [ $this, 'setupPLpgSQL' ],
+               ];
+               $schemaCB = [
                        'name' => 'schema',
-                       'callback' => array( $this, 'setupSchema' )
-               );
+                       'callback' => [ $this, 'setupSchema' ]
+               ];
 
                if ( $this->getVar( '_CreateDBAccount' ) ) {
                        $this->parent->addInstallStep( $createDbAccount, 'database' );
@@ -481,7 +481,7 @@ class PostgresInstaller extends DatabaseInstaller {
                $dbName = $this->getVar( 'wgDBname' );
 
                $exists = $conn->selectField( '"pg_catalog"."pg_database"', '1',
-                       array( 'datname' => $dbName ), __METHOD__ );
+                       [ 'datname' => $dbName ], __METHOD__ );
                if ( !$exists ) {
                        $safedb = $conn->addIdentifierQuotes( $dbName );
                        $conn->query( "CREATE DATABASE $safedb", __METHOD__ );
@@ -587,9 +587,7 @@ class PostgresInstaller extends DatabaseInstaller {
                        return $status;
                }
 
-               /**
-                * @var $conn DatabaseBase
-                */
+               /** @var $conn DatabasePostgres */
                $conn = $status->value;
 
                if ( $conn->tableExists( 'archive' ) ) {
@@ -606,7 +604,7 @@ class PostgresInstaller extends DatabaseInstaller {
 
                        return $status;
                }
-               $error = $conn->sourceFile( $conn->getSchemaPath() );
+               $error = $conn->sourceFile( $this->getSchemaPath( $conn ) );
                if ( $error !== true ) {
                        $conn->reportQueryError( $error, 0, '', __METHOD__ );
                        $conn->rollback( __METHOD__ );
@@ -615,7 +613,7 @@ class PostgresInstaller extends DatabaseInstaller {
                        $conn->commit( __METHOD__ );
                }
                // Resume normal operations
-               if ( $status->isOk() ) {
+               if ( $status->isOK() ) {
                        $this->enableLB();
                }
 
@@ -625,9 +623,9 @@ class PostgresInstaller extends DatabaseInstaller {
        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(
+               return array_merge( parent::getGlobalDefaults(), [
                        'wgDBmwschema' => 'mediawiki',
-               ) );
+               ] );
        }
 
        public function setupPLpgSQL() {
@@ -638,12 +636,12 @@ class PostgresInstaller extends DatabaseInstaller {
                        return $status;
                }
                /**
-                * @var $conn DatabaseBase
+                * @var $conn Database
                 */
                $conn = $status->value;
 
                $exists = $conn->selectField( '"pg_catalog"."pg_language"', 1,
-                       array( 'lanname' => 'plpgsql' ), __METHOD__ );
+                       [ 'lanname' => 'plpgsql' ], __METHOD__ );
                if ( $exists ) {
                        // Already exists, nothing to do
                        return Status::newGood();
@@ -652,13 +650,13 @@ class PostgresInstaller extends DatabaseInstaller {
                // plpgsql is not installed, but if we have a pg_pltemplate table, we
                // should be able to create it
                $exists = $conn->selectField(
-                       array( '"pg_catalog"."pg_class"', '"pg_catalog"."pg_namespace"' ),
+                       [ '"pg_catalog"."pg_class"', '"pg_catalog"."pg_namespace"' ],
                        1,
-                       array(
+                       [
                                'pg_namespace.oid=relnamespace',
                                'nspname' => 'pg_catalog',
                                'relname' => 'pg_pltemplate',
-                       ),
+                       ],
                        __METHOD__ );
                if ( $exists ) {
                        try {