This removes a bunch of back-compat code in the installer and search code.
Minimum postgres version is now 8.3
/** Mediawiki schema */
$wgDBmwschema = 'mediawiki';
-/** Tsearch2 schema */
-$wgDBts2schema = 'public';
/** To override default SQLite data directory ($docroot/../data) */
$wgSQLiteDataDir = '';
$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;
'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:',
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.
'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',
'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';
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();
}
function submitConnectForm() {
// Get variables from the request
$newValues = $this->setVarsFromRequest( array( 'wgDBserver', 'wgDBport',
- 'wgDBname', 'wgDBmwschema', 'wgDBts2schema' ) );
+ 'wgDBname', 'wgDBmwschema' ) );
// Validate them
$status = Status::newGood();
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() ) {
'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' );
}
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();
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)
}
}
- $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