Per comment on bug 26612, we should drop the pre-Postgres 8.3 support with the TSearc...
authorChad Horohoe <demon@users.mediawiki.org>
Fri, 28 Jan 2011 14:12:26 +0000 (14:12 +0000)
committerChad Horohoe <demon@users.mediawiki.org>
Fri, 28 Jan 2011 14:12:26 +0000 (14:12 +0000)
This removes a bunch of back-compat code in the installer and search code.
Minimum postgres version is now 8.3

includes/DefaultSettings.php
includes/db/DatabasePostgres.php
includes/installer/Installer.i18n.php
includes/installer/PostgresInstaller.php
includes/search/SearchPostgres.php

index 7bcc54b..7d9af50 100644 (file)
@@ -1180,8 +1180,6 @@ $wgSQLMode = '';
 
 /** Mediawiki schema */
 $wgDBmwschema       = 'mediawiki';
-/** Tsearch2 schema */
-$wgDBts2schema      = 'public';
 
 /** To override default SQLite data directory ($docroot/../data) */
 $wgSQLiteDataDir    = '';
index 151f632..6b453cd 100644 (file)
@@ -193,13 +193,12 @@ class DatabasePostgres extends DatabaseBase {
                $this->doQuery( "SET client_encoding='UTF8'" );
 
                global $wgDBmwschema, $wgDBts2schema;
-               if ( isset( $wgDBmwschema ) && isset( $wgDBts2schema )
+               if ( isset( $wgDBmwschema )
                        && $wgDBmwschema !== 'mediawiki'
                        && preg_match( '/^\w+$/', $wgDBmwschema )
-                       && preg_match( '/^\w+$/', $wgDBts2schema )
                ) {
                        $safeschema = $this->addIdentifierQuotes( $wgDBmwschema );
-                       $this->doQuery( "SET search_path = $safeschema, $wgDBts2schema, public" );
+                       $this->doQuery( "SET search_path = $safeschema, public" );
                }
 
                return $this->mConn;
index 3074350..d71a322 100644 (file)
@@ -195,7 +195,6 @@ but it will not let you store characters above the [http://en.wikipedia.org/wiki
        'config-mysql-old'                => 'MySQL $1 or later is required, you have $2.',
        'config-db-port'                  => 'Database port:',
        'config-db-schema'                => 'Schema for MediaWiki',
-       'config-db-ts2-schema'            => 'Schema for tsearch2',
        'config-db-schema-help'           => 'The above schemas are usually correct.
 Only change them if you know you need to.',
        'config-sqlite-dir'               => 'SQLite data directory:',
@@ -242,8 +241,6 @@ Use only ASCII letters (a-z, A-Z), numbers (0-9), underscores (_) and hyphens (-
 
 Check the host, username and password below and try again.',
        'config-invalid-schema'           => 'Invalid schema for MediaWiki "$1".
-Use only ASCII letters (a-z, A-Z), numbers (0-9) and underscores (_).',
-       'config-invalid-ts2schema'        => 'Invalid schema for TSearch2 "$1".
 Use only ASCII letters (a-z, A-Z), numbers (0-9) and underscores (_).',
        'config-postgres-old'             => 'PostgreSQL $1 or later is required, you have $2.',
        'config-sqlite-name-help'         => 'Choose a name that identifies your wiki.
@@ -450,9 +447,6 @@ Make sure that the user "$1" can write to the schema "$2".',
        'config-install-pg-commit'        => 'Committing changes',
        'config-install-pg-plpgsql'       => 'Checking for language PL/pgSQL',
        'config-pg-no-plpgsql'            => 'You need to install the language PL/pgSQL in the database $1',
-       'config-install-pg-ts2'           => 'Checking for tsearch2',
-       'config-install-pg-ts2-failed'    => "'''FAILED''' tsearch2 must be installed in the database $1.
-Please read [$2 these instructions] or ask on #postgresql on irc.freenode.net",
        'config-install-user'             => 'Creating database user',
        'config-install-user-failed'      => 'Granting permission to user "$1" failed: $2',
        'config-install-tables'           => 'Creating tables',
index 6202364..23a67b6 100644 (file)
@@ -24,8 +24,7 @@ class PostgresInstaller extends DatabaseInstaller {
                'wgDBts2schema',
        );
 
-       var $minimumVersion = '8.1';
-       private $ts2MaxVersion = '8.3'; // Doing ts2 is not necessary in PG > 8.3
+       var $minimumVersion = '8.3';
 
        function getName() {
                return 'postgres';
@@ -43,7 +42,6 @@ class PostgresInstaller extends DatabaseInstaller {
                        Html::element( 'legend', array(), wfMsg( 'config-db-wiki-settings' ) ) .
                        $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' ) ) .
-                       $this->getTextBox( 'wgDBts2schema', 'config-db-ts2-schema' ) .
                        Html::closeElement( 'fieldset' ) .
                        $this->getInstallUserBox();
        }
@@ -51,7 +49,7 @@ class PostgresInstaller extends DatabaseInstaller {
        function submitConnectForm() {
                // Get variables from the request
                $newValues = $this->setVarsFromRequest( array( 'wgDBserver', 'wgDBport',
-                       'wgDBname', 'wgDBmwschema', 'wgDBts2schema' ) );
+                       'wgDBname', 'wgDBmwschema' ) );
 
                // Validate them
                $status = Status::newGood();
@@ -63,9 +61,6 @@ class PostgresInstaller extends DatabaseInstaller {
                if ( !preg_match( '/^[a-zA-Z0-9_]*$/', $newValues['wgDBmwschema'] ) ) {
                        $status->fatal( 'config-invalid-schema', $newValues['wgDBmwschema'] );
                }
-               if ( !preg_match( '/^[a-zA-Z0-9_]*$/', $newValues['wgDBts2schema'] ) ) {
-                       $status->fatal( 'config-invalid-ts2schema', $newValues['wgDBts2schema'] );
-               }
 
                // Submit user box
                if ( $status->isOK() ) {
@@ -196,17 +191,12 @@ class PostgresInstaller extends DatabaseInstaller {
                        'name' => 'user',
                        'callback' => array( $this, 'setupUser' ),
                );
-               $ts2CB = array(
-                       'name' => 'pg-ts2',
-                       'callback' => array( $this, 'setupTs2' ),
-               );
                $plpgCB = array(
                        'name' => 'pg-plpgsql',
                        'callback' => array( $this, 'setupPLpgSQL' ),
                );
                $this->parent->addInstallStep( $commitCB, 'interwiki' );
                $this->parent->addInstallStep( $userCB );
-               $this->parent->addInstallStep( $ts2CB, 'database' );
                $this->parent->addInstallStep( $plpgCB, 'database' );
        }
 
@@ -266,36 +256,6 @@ class PostgresInstaller extends DatabaseInstaller {
                return $status;
        }
 
-       /**
-        * Ts2 isn't needed in newer versions of Postgres, so wrap it in a nice big
-        * version check and skip it if we're new. Maybe we can bump $minimumVersion
-        * one day and render this obsolete :)
-        *
-        * @return Status
-        */
-       function setupTs2() {
-               $status = $this->getConnection();
-               if ( !$status->isOK() ) {
-                       return $status;
-               }
-
-               if( version_compare( $this->db->getServerVersion(), $this->ts2MaxVersion, '<' ) ) {
-                       if ( !$this->db->tableExists( 'pg_ts_cfg', $this->getVar( 'wgDBts2schema' ) ) ) {
-                               return Status::newFatal( 
-                                       'config-install-pg-ts2-failed',
-                                       $this->getVar( 'wgDBname' ),
-                                       'http://www.devx.com/opensource/Article/21674/0/page/2'
-                               );
-                       }
-                       $safeuser = $this->db->addQuotes( $this->getVar( 'wgDBuser' ) );
-                       foreach ( array( 'cfg', 'cfgmap', 'dict', 'parser' ) as $table ) {
-                               $sql = "GRANT SELECT ON pg_ts_$table TO $safeuser";
-                               $this->db->query( $sql, __METHOD__ );
-                       }
-               }
-               return Status::newGood();
-       }
-
        function commitChanges() {
                $this->db->query( 'COMMIT' );
                return Status::newGood();
index 639d0a2..70997f3 100644 (file)
@@ -141,13 +141,11 @@ class SearchPostgres extends SearchEngine {
        function searchQuery( $term, $fulltext, $colname ) {
                $postgresVersion = $this->db->getServerVersion();
 
-               $prefix = $postgresVersion < 8.3 ? "'default'," : '';
-
                # Get the SQL fragment for the given term
                $searchstring = $this->parseQuery( $term );
 
                ## We need a separate query here so gin does not complain about empty searches
-               $SQL = "SELECT to_tsquery($prefix $searchstring)";
+               $SQL = "SELECT to_tsquery($searchstring)";
                $res = $this->db->doQuery($SQL);
                if (!$res) {
                        ## TODO: Better output (example to catch: one 'two)
@@ -168,12 +166,10 @@ class SearchPostgres extends SearchEngine {
                                }
                        }
 
-                       $rankscore = $postgresVersion > 8.2 ? 5 : 1;
-                       $rank = $postgresVersion < 8.3 ? 'rank' : 'ts_rank';
                        $query = "SELECT page_id, page_namespace, page_title, ".
-                       "$rank($fulltext, to_tsquery($prefix $searchstring), $rankscore) AS score ".
+                       "ts_rank($fulltext, to_tsquery($searchstring), 5) AS score ".
                        "FROM page p, revision r, pagecontent c WHERE p.page_latest = r.rev_id " .
-                       "AND r.rev_text_id = c.old_id AND $fulltext @@ to_tsquery($prefix $searchstring)";
+                       "AND r.rev_text_id = c.old_id AND $fulltext @@ to_tsquery($searchstring)";
                }
 
                ## Redirects