From ca32f08966f1b51fcb19460f0996bb0c4048e6fe Mon Sep 17 00:00:00 2001 From: Pierre Schmitz Date: Sat, 3 Dec 2011 13:29:22 +0100 Subject: Update to MediaWiki 1.18.0 * also update ArchLinux skin to chagnes in MonoBook * Use only css to hide our menu bar when printing --- includes/search/SearchEngine.php | 124 +++++++++++++++++------- includes/search/SearchIBM_DB2.php | 4 +- includes/search/SearchMssql.php | 8 +- includes/search/SearchMySQL.php | 190 ++++++++++++++++++++++--------------- includes/search/SearchOracle.php | 14 ++- includes/search/SearchPostgres.php | 36 +++---- includes/search/SearchSqlite.php | 12 ++- includes/search/SearchUpdate.php | 4 +- 8 files changed, 253 insertions(+), 139 deletions(-) (limited to 'includes/search') diff --git a/includes/search/SearchEngine.php b/includes/search/SearchEngine.php index 17482da2..40b992de 100644 --- a/includes/search/SearchEngine.php +++ b/includes/search/SearchEngine.php @@ -22,6 +22,14 @@ class SearchEngine { var $namespaces = array( NS_MAIN ); var $showRedirects = false; + /// Feature values + protected $features = array(); + + /** + * @var DatabaseBase + */ + protected $db; + function __construct($db = null) { if ( $db ) { $this->db = $db; @@ -54,9 +62,38 @@ class SearchEngine { return null; } - /** If this search backend can list/unlist redirects */ + /** + * If this search backend can list/unlist redirects + * @deprecated since 1.18 Call supports( 'list-redirects' ); + */ function acceptListRedirects() { - return true; + return $this->supports( 'list-redirects' ); + } + + /** + * @since 1.18 + * @param $feature String + * @return Boolean + */ + public function supports( $feature ) { + switch( $feature ) { + case 'list-redirects': + return true; + case 'title-suffix-filter': + default: + return false; + } + } + + /** + * Way to pass custom data for engines + * @since 1.18 + * @param $feature String + * @param $data Mixed + * @return Noolean + */ + public function setFeatureData( $feature, $data ) { + $this->features[$feature] = $data; } /** @@ -95,11 +132,11 @@ class SearchEngine { wfRunHooks( 'SearchGetNearMatchComplete', array( $searchterm, &$title ) ); return $title; } - + /** - * Do a near match (see SearchEngine::getNearMatch) and wrap it into a + * Do a near match (see SearchEngine::getNearMatch) and wrap it into a * SearchResultSet. - * + * * @param $searchterm string * @return SearchResultSet */ @@ -124,19 +161,23 @@ class SearchEngine { return $titleResult; } + $context = new RequestContext; + foreach ( $allSearchTerms as $term ) { # Exact match? No need to look further. $title = Title::newFromText( $term ); - if ( is_null( $title ) ) + if ( is_null( $title ) ){ return null; + } if ( $title->getNamespace() == NS_SPECIAL || $title->isExternal() || $title->exists() ) { return $title; } # See if it still otherwise has content is some sane sense - $article = MediaWiki::articleFromTitle( $title ); + $context->setTitle( $title ); + $article = Article::newFromTitle( $title, $context ); if ( $article->hasViewableContent() ) { return $title; } @@ -259,7 +300,7 @@ class SearchEngine { if ( strncmp( $query, $allkeyword, strlen( $allkeyword ) ) == 0 ) { $this->namespaces = null; $parsed = substr( $query, strlen( $allkeyword ) ); - } else if ( strpos( $query, ':' ) !== false ) { + } elseif ( strpos( $query, ':' ) !== false ) { $prefix = substr( $query, 0, strpos( $query, ':' ) ); $index = $wgContLang->getNsIndex( $prefix ); if ( $index !== false ) { @@ -321,14 +362,11 @@ class SearchEngine { } /** - * Find snippet highlight settings for a given user + * Find snippet highlight settings for all users * - * @param $user User * @return Array contextlines, contextchars */ - public static function userHighlightPrefs( &$user ) { - // $contextlines = $user->getOption( 'contextlines', 5 ); - // $contextchars = $user->getOption( 'contextchars', 50 ); + public static function userHighlightPrefs() { $contextlines = 2; // Hardcode this. Old defaults sucked. :) $contextchars = 75; // same as above.... :P return array( $contextlines, $contextchars ); @@ -434,13 +472,15 @@ class SearchEngine { * @return String */ public static function getOpenSearchTemplate() { - global $wgOpenSearchTemplate, $wgServer; - if ( $wgOpenSearchTemplate ) { + global $wgOpenSearchTemplate, $wgCanonicalServer; + if ( $wgOpenSearchTemplate ) { return $wgOpenSearchTemplate; } else { $ns = implode( '|', SearchEngine::defaultNamespaces() ); - if ( !$ns ) $ns = "0"; - return $wgServer . wfScript( 'api' ) . '?action=opensearch&search={searchTerms}&namespace=' . $ns; + if ( !$ns ) { + $ns = "0"; + } + return $wgCanonicalServer . wfScript( 'api' ) . '?action=opensearch&search={searchTerms}&namespace=' . $ns; } } @@ -575,6 +615,9 @@ class SearchResultSet { * This class is used for different SQL-based search engines shipped with MediaWiki */ class SqlSearchResultSet extends SearchResultSet { + + protected $mResultSet; + function __construct( $resultSet, $terms ) { $this->mResultSet = $resultSet; $this->mTerms = $terms; @@ -598,7 +641,7 @@ class SqlSearchResultSet extends SearchResultSet { $row = $this->mResultSet->fetchObject(); if ( $row === false ) return false; - + return SearchResult::newFromRow( $row ); } @@ -619,19 +662,33 @@ class SearchResultTooMany { /** - * @todo Fixme: This class is horribly factored. It would probably be better to + * @todo FIXME: This class is horribly factored. It would probably be better to * have a useful base class to which you pass some standard information, then * let the fancy self-highlighters extend that. * @ingroup Search */ class SearchResult { + + /** + * @var Revision + */ var $mRevision = null; var $mImage = null; + /** + * @var Title + */ + var $mTitle; + + /** + * @var String + */ + var $mText; + /** * Return a new SearchResult and initializes it with a title. - * - * @param $title Title + * + * @param $title Title * @return SearchResult */ public static function newFromTitle( $title ) { @@ -641,7 +698,7 @@ class SearchResult { } /** * Return a new SearchResult and initializes it with a row. - * + * * @param $row object * @return SearchResult */ @@ -650,28 +707,28 @@ class SearchResult { $result->initFromRow( $row ); return $result; } - + public function __construct( $row = null ) { if ( !is_null( $row ) ) { // Backwards compatibility with pre-1.17 callers $this->initFromRow( $row ); } } - + /** * Initialize from a database row. Makes a Title and passes that to * initFromTitle. - * + * * @param $row object */ protected function initFromRow( $row ) { $this->initFromTitle( Title::makeTitle( $row->page_namespace, $row->page_title ) ); } - + /** * Initialize from a Title and if possible initializes a corresponding * Revision and File. - * + * * @param $title Title */ protected function initFromTitle( $title ) { @@ -788,7 +845,7 @@ class SearchResult { function getTimestamp() { if ( $this->mRevision ) return $this->mRevision->getTimestamp(); - else if ( $this->mImage ) + elseif ( $this->mImage ) return $this->mImage->getTimestamp(); return ''; } @@ -886,7 +943,7 @@ class SearchHighlighter { 2 => '/(\[\[)|(\]\])/', // image 3 => "/(\n\\{\\|)|(\n\\|\\})/" ); // table - // FIXME: this should prolly be a hook or something + // @todo FIXME: This should prolly be a hook or something if ( function_exists( 'wfCite' ) ) { $spat .= '|()'; // references via cite extension $endPatterns[4] = '/()|(<\/ref>)/'; @@ -972,7 +1029,7 @@ class SearchHighlighter { $anyterm = implode( '|', $terms ); $phrase = implode( "$wgSearchHighlightBoundaries+", $terms ); - // FIXME: a hack to scale contextchars, a correct solution + // @todo FIXME: A hack to scale contextchars, a correct solution // would be to have contextchars actually be char and not byte // length, and do proper utf-8 substrings and lengths everywhere, // but PHP is making that very hard and unclean to implement :( @@ -1318,12 +1375,13 @@ class SearchHighlighter { continue; } --$contextlines; - $pre = $wgContLang->truncate( $m[1], - $contextchars ); + // truncate function changes ... to relevant i18n message. + $pre = $wgContLang->truncate( $m[1], - $contextchars, '...', false ); if ( count( $m ) < 3 ) { $post = ''; } else { - $post = $wgContLang->truncate( $m[3], $contextchars ); + $post = $wgContLang->truncate( $m[3], $contextchars, '...', false ); } $found = $m[2]; @@ -1344,7 +1402,7 @@ class SearchHighlighter { /** * Dummy class to be used when non-supported Database engine is present. - * @todo Fixme: dummy class should probably try something at least mildly useful, + * @todo FIXME: Dummy class should probably try something at least mildly useful, * such as a LIKE search through titles. * @ingroup Search */ diff --git a/includes/search/SearchIBM_DB2.php b/includes/search/SearchIBM_DB2.php index 8cedd6f2..c02a009d 100644 --- a/includes/search/SearchIBM_DB2.php +++ b/includes/search/SearchIBM_DB2.php @@ -91,7 +91,7 @@ class SearchIBM_DB2 extends SearchEngine { * Return a LIMIT clause to limit results on the query. * @return String */ - function queryLimit($sql) { + function queryLimit( $sql ) { return $this->db->limitResult($sql, $this->limit, $this->offset); } @@ -151,7 +151,7 @@ class SearchIBM_DB2 extends SearchEngine { $lc = SearchEngine::legalSearchChars(); $this->searchTerms = array(); - # FIXME: This doesn't handle parenthetical expressions. + # @todo FIXME: This doesn't handle parenthetical expressions. $m = array(); $q = array(); diff --git a/includes/search/SearchMssql.php b/includes/search/SearchMssql.php index 8b850fae..ebf19d3a 100644 --- a/includes/search/SearchMssql.php +++ b/includes/search/SearchMssql.php @@ -91,8 +91,9 @@ class SearchMssql extends SearchEngine { /** * Return a LIMIT clause to limit results on the query. * + * @param $sql string + * * @return String - * @private */ function queryLimit( $sql ) { return $this->db->limitResult( $sql, $this->limit, $this->offset ); @@ -103,7 +104,6 @@ class SearchMssql extends SearchEngine { * subclasses may define this though * * @return String - * @private */ function queryRanking( $filteredTerm, $fulltext ) { return ' ORDER BY ftindex.[RANK] DESC'; // return ' ORDER BY score(1)'; @@ -115,7 +115,6 @@ class SearchMssql extends SearchEngine { * * @param $filteredTerm String * @param $fulltext Boolean - * @private */ function getQuery( $filteredTerm, $fulltext ) { return $this->queryLimit( $this->queryMain( $filteredTerm, $fulltext ) . ' ' . @@ -124,7 +123,6 @@ class SearchMssql extends SearchEngine { $this->queryRanking( $filteredTerm, $fulltext ) . ' ' ); } - /** * Picks which field to index on, depending on what type of query. * @@ -159,7 +157,7 @@ class SearchMssql extends SearchEngine { $lc = SearchEngine::legalSearchChars(); $this->searchTerms = array(); - # FIXME: This doesn't handle parenthetical expressions. + # @todo FIXME: This doesn't handle parenthetical expressions. $m = array(); $q = array(); diff --git a/includes/search/SearchMySQL.php b/includes/search/SearchMySQL.php index b92682ad..c52c9e5b 100644 --- a/includes/search/SearchMySQL.php +++ b/includes/search/SearchMySQL.php @@ -40,9 +40,14 @@ class SearchMySQL extends SearchEngine { parent::__construct( $db ); } - /** - * Parse the user's query and transform it into an SQL fragment which will + /** + * Parse the user's query and transform it into an SQL fragment which will * become part of a WHERE clause + * + * @param $filteredText string + * @param $fullText string + * + * @return string */ function parseQuery( $filteredText, $fulltext ) { global $wgContLang; @@ -50,13 +55,13 @@ class SearchMySQL extends SearchEngine { $searchon = ''; $this->searchTerms = array(); - # FIXME: This doesn't handle parenthetical expressions. + # @todo FIXME: This doesn't handle parenthetical expressions. $m = array(); if( preg_match_all( '/([-+<>~]?)(([' . $lc . ']+)(\*?)|"[^"]*")/', $filteredText, $m, PREG_SET_ORDER ) ) { foreach( $m as $bits ) { @list( /* all */, $modifier, $term, $nonQuoted, $wildcard ) = $bits; - + if( $nonQuoted != '' ) { $term = $nonQuoted; $quote = ''; @@ -64,13 +69,13 @@ class SearchMySQL extends SearchEngine { $term = str_replace( '"', '', $term ); $quote = '"'; } - + if( $searchon !== '' ) $searchon .= ' '; if( $this->strictMatching && ($modifier == '') ) { // If we leave this out, boolean op defaults to OR which is rarely helpful. $modifier = '+'; } - + // Some languages such as Serbian store the input form in the search index, // so we may need to search for matches in multiple writing system variants. $convertedVariants = $wgContLang->autoConvertToAllVariants( $term ); @@ -79,7 +84,7 @@ class SearchMySQL extends SearchEngine { } else { $variants = array( $term ); } - + // The low-level search index does some processing on input to work // around problems with minimum lengths and encoding in MySQL's // fulltext engine. @@ -87,12 +92,12 @@ class SearchMySQL extends SearchEngine { $strippedVariants = array_map( array( $wgContLang, 'normalizeForSearch' ), $variants ); - + // Some languages such as Chinese force all variants to a canonical // form when stripping to the low-level search index, so to be sure // let's check our variants list for unique items after stripping. $strippedVariants = array_unique( $strippedVariants ); - + $searchon .= $modifier; if( count( $strippedVariants) > 1 ) $searchon .= '('; @@ -108,7 +113,7 @@ class SearchMySQL extends SearchEngine { } if( count( $strippedVariants) > 1 ) $searchon .= ')'; - + // Match individual terms or quoted phrase in result highlighting... // Note that variants will be introduced in a later stage for highlighting! $regexp = $this->regexTerm( $term, $wildcard ); @@ -124,10 +129,10 @@ class SearchMySQL extends SearchEngine { $field = $this->getIndexField( $fulltext ); return " MATCH($field) AGAINST('$searchon' IN BOOLEAN MODE) "; } - + function regexTerm( $string, $wildcard ) { global $wgContLang; - + $regex = preg_quote( $string, '/' ); if( $wgContLang->hasWordBreaks() ) { if( $wildcard ) { @@ -167,85 +172,112 @@ class SearchMySQL extends SearchEngine { function searchTitle( $term ) { return $this->searchInternal( $term, false ); } - + protected function searchInternal( $term, $fulltext ) { global $wgCountTotalSearchHits; - + + // This seems out of place, why is this called with empty term? + if ( trim( $term ) === '' ) return null; + $filteredTerm = $this->filter( $term ); - $resultSet = $this->db->query( $this->getQuery( $filteredTerm, $fulltext ) ); - + $query = $this->getQuery( $filteredTerm, $fulltext ); + $resultSet = $this->db->select( + $query['tables'], $query['fields'], $query['conds'], + __METHOD__, $query['options'], $query['joins'] + ); + $total = null; if( $wgCountTotalSearchHits ) { - $totalResult = $this->db->query( $this->getCountQuery( $filteredTerm, $fulltext ) ); + $query = $this->getCountQuery( $filteredTerm, $fulltext ); + $totalResult = $this->db->select( + $query['tables'], $query['fields'], $query['conds'], + __METHOD__, $query['options'], $query['joins'] + ); + $row = $totalResult->fetchObject(); if( $row ) { $total = intval( $row->c ); } $totalResult->free(); } - + return new MySQLSearchResultSet( $resultSet, $this->searchTerms, $total ); } - - /** - * Return a partial WHERE clause to exclude redirects, if so set - * @return String - */ - function queryRedirect() { - if( $this->showRedirects ) { - return ''; - } else { - return 'AND page_is_redirect=0'; + public function supports( $feature ) { + switch( $feature ) { + case 'list-redirects': + case 'title-suffix-filter': + return true; + default: + return false; } } /** - * Return a partial WHERE clause to limit the search to the given namespaces - * @return String + * Add special conditions + * @param $query Array + * @since 1.18 */ - function queryNamespaces() { - if( is_null($this->namespaces) ) - return ''; # search all - if ( !count( $this->namespaces ) ) { - $namespaces = '0'; - } else { - $namespaces = $this->db->makeList( $this->namespaces ); + protected function queryFeatures( &$query ) { + foreach ( $this->features as $feature => $value ) { + if ( $feature === 'list-redirects' && !$value ) { + $query['conds']['page_is_redirect'] = 0; + } elseif( $feature === 'title-suffix-filter' && $value ) { + $query['conds'][] = 'page_title' . $this->db->buildLike( $this->db->anyString(), $value ); + } } - return 'AND page_namespace IN (' . $namespaces . ')'; } /** - * Return a LIMIT clause to limit results on the query. - * @return String + * Add namespace conditions + * @param $query Array + * @since 1.18 (changed) */ - function queryLimit() { - return $this->db->limitResult( '', $this->limit, $this->offset ); + function queryNamespaces( &$query ) { + if ( is_array( $this->namespaces ) ) { + if ( count( $this->namespaces ) === 0 ) { + $this->namespaces[] = '0'; + } + $query['conds']['page_namespace'] = $this->namespaces; + } } /** - * Does not do anything for generic search engine - * subclasses may define this though - * @return String + * Add limit options + * @param $query Array + * @since 1.18 */ - function queryRanking( $filteredTerm, $fulltext ) { - return ''; + protected function limitResult( &$query ) { + $query['options']['LIMIT'] = $this->limit; + $query['options']['OFFSET'] = $this->offset; } /** - * Construct the full SQL query to do the search. + * Construct the SQL query to do the search. * The guts shoulds be constructed in queryMain() * @param $filteredTerm String * @param $fulltext Boolean + * @return Array + * @since 1.18 (changed) */ function getQuery( $filteredTerm, $fulltext ) { - return $this->queryMain( $filteredTerm, $fulltext ) . ' ' . - $this->queryRedirect() . ' ' . - $this->queryNamespaces() . ' ' . - $this->queryRanking( $filteredTerm, $fulltext ) . ' ' . - $this->queryLimit(); + $query = array( + 'tables' => array(), + 'fields' => array(), + 'conds' => array(), + 'options' => array(), + 'joins' => array(), + ); + + $this->queryMain( $query, $filteredTerm, $fulltext ); + $this->queryFeatures( $query ); + $this->queryNamespaces( $query ); + $this->limitResult( $query ); + + return $query; } - + /** * Picks which field to index on, depending on what type of query. * @param $fulltext Boolean @@ -257,32 +289,40 @@ class SearchMySQL extends SearchEngine { /** * Get the base part of the search query. - * The actual match syntax will depend on the server - * version; MySQL 3 and MySQL 4 have different capabilities - * in their fulltext search indexes. * * @param $filteredTerm String * @param $fulltext Boolean - * @return String + * @since 1.18 (changed) */ - function queryMain( $filteredTerm, $fulltext ) { + function queryMain( &$query, $filteredTerm, $fulltext ) { $match = $this->parseQuery( $filteredTerm, $fulltext ); - $page = $this->db->tableName( 'page' ); - $searchindex = $this->db->tableName( 'searchindex' ); - return 'SELECT page_id, page_namespace, page_title ' . - "FROM $page,$searchindex " . - 'WHERE page_id=si_page AND ' . $match; + $query['tables'][] = 'page'; + $query['tables'][] = 'searchindex'; + $query['fields'][] = 'page_id'; + $query['fields'][] = 'page_namespace'; + $query['fields'][] = 'page_title'; + $query['conds'][] = 'page_id=si_page'; + $query['conds'][] = $match; } + /** + * @since 1.18 (changed) + */ function getCountQuery( $filteredTerm, $fulltext ) { $match = $this->parseQuery( $filteredTerm, $fulltext ); - $page = $this->db->tableName( 'page' ); - $searchindex = $this->db->tableName( 'searchindex' ); - return "SELECT COUNT(*) AS c " . - "FROM $page,$searchindex " . - 'WHERE page_id=si_page AND ' . $match . - $this->queryRedirect() . ' ' . - $this->queryNamespaces(); + + $query = array( + 'tables' => array( 'page', 'searchindex' ), + 'fields' => array( 'COUNT(*) as c' ), + 'conds' => array( 'page_id=si_page', $match ), + 'options' => array(), + 'joins' => array(), + ); + + $this->queryFeatures( $query ); + $this->queryNamespaces( $query ); + + return $query; } /** @@ -311,7 +351,7 @@ class SearchMySQL extends SearchEngine { * @param $id Integer * @param $title String */ - function updateTitle( $id, $title ) { + function updateTitle( $id, $title ) { $dbw = wfGetDB( DB_MASTER ); $dbw->update( 'searchindex', @@ -329,7 +369,7 @@ class SearchMySQL extends SearchEngine { global $wgContLang; wfProfileIn( __METHOD__ ); - + $out = parent::normalizeText( $string ); // MySQL fulltext index doesn't grok utf-8, so we @@ -363,7 +403,7 @@ class SearchMySQL extends SearchEngine { $out ); wfProfileOut( __METHOD__ ); - + return $out; } @@ -379,7 +419,7 @@ class SearchMySQL extends SearchEngine { /** * Check MySQL server's ft_min_word_len setting so we know * if we need to pad short words... - * + * * @return int */ protected function minSearchLength() { diff --git a/includes/search/SearchOracle.php b/includes/search/SearchOracle.php index 15c386ce..85337ca1 100644 --- a/includes/search/SearchOracle.php +++ b/includes/search/SearchOracle.php @@ -123,18 +123,22 @@ class SearchOracle extends SearchEngine { /** * Return a LIMIT clause to limit results on the query. + * + * @param string + * * @return String */ - function queryLimit($sql) { + function queryLimit( $sql ) { return $this->db->limitResult($sql, $this->limit, $this->offset); } /** * Does not do anything for generic search engine * subclasses may define this though + * * @return String */ - function queryRanking($filteredTerm, $fulltext) { + function queryRanking( $filteredTerm, $fulltext ) { return ' ORDER BY score(1)'; } @@ -186,7 +190,7 @@ class SearchOracle extends SearchEngine { $lc = SearchEngine::legalSearchChars(); $this->searchTerms = array(); - # FIXME: This doesn't handle parenthetical expressions. + # @todo FIXME: This doesn't handle parenthetical expressions. $m = array(); $searchon = ''; if (preg_match_all('/([-+<>~]?)(([' . $lc . ']+)(\*?)|"[^"]*")/', @@ -253,9 +257,9 @@ class SearchOracle extends SearchEngine { // ALTER SESSION SET CURRENT_SCHEMA = ... // was used. $dbw->query( "CALL ctx_ddl.sync_index(" . - $dbw->addQuotes( $dbw->getDBname() . '.' . trim( $dbw->tableName( 'si_text_idx' ), '"' ) ) . ")" ); + $dbw->addQuotes( $dbw->getDBname() . '.' . $dbw->tableName( 'si_text_idx', false ) ) . ")" ); $dbw->query( "CALL ctx_ddl.sync_index(" . - $dbw->addQuotes( $dbw->getDBname() . '.' . trim( $dbw->tableName( 'si_title_idx' ), '"' ) ) . ")" ); + $dbw->addQuotes( $dbw->getDBname() . '.' . $dbw->tableName( 'si_title_idx', false ) ) . ")" ); } /** diff --git a/includes/search/SearchPostgres.php b/includes/search/SearchPostgres.php index 9d6d1539..cfe283b2 100644 --- a/includes/search/SearchPostgres.php +++ b/includes/search/SearchPostgres.php @@ -29,6 +29,11 @@ * @ingroup Search */ class SearchPostgres extends SearchEngine { + + /** + * @var DatabasePostgres + */ + protected $db; /** * Creates an instance of this class * @param $db DatabaseSqlite: database object @@ -56,6 +61,7 @@ class SearchPostgres extends SearchEngine { } return new PostgresSearchResultSet( $resultSet, $this->searchTerms ); } + function searchText( $term ) { $q = $this->searchQuery( $term, 'textvector', 'old_text' ); $olderror = error_reporting(E_ERROR); @@ -67,11 +73,14 @@ class SearchPostgres extends SearchEngine { return new PostgresSearchResultSet( $resultSet, $this->searchTerms ); } - - /* + /** * Transform the user's search string into a better form for tsearch2 * Returns an SQL fragment consisting of quoted text to search for. - */ + * + * @param $term string + * + * @return string + */ function parseQuery( $term ) { wfDebug( "parseQuery received: $term \n" ); @@ -96,10 +105,10 @@ class SearchPostgres extends SearchEngine { if (strtolower($terms[2]) === 'and') { $searchstring .= ' & '; } - else if (strtolower($terms[2]) === 'or' or $terms[2] === '|') { + elseif (strtolower($terms[2]) === 'or' or $terms[2] === '|') { $searchstring .= ' | '; } - else if (strtolower($terms[2]) === 'not') { + elseif (strtolower($terms[2]) === 'not') { $searchstring .= ' & !'; } else { @@ -139,21 +148,18 @@ class SearchPostgres extends SearchEngine { * @param $colname */ 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->query($SQL); if (!$res) { ## TODO: Better output (example to catch: one 'two) die ("Sorry, that was not a valid search string. Please go back and try again"); } - $top = pg_fetch_result($res,0,0); + $top = $res->fetchRow(); + $top = $top[0]; if ($top === "") { ## e.g. if only stopwords are used XXX return something better $query = "SELECT page_id, page_namespace, page_title, 0 AS score ". @@ -168,12 +174,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 @@ -204,7 +208,7 @@ class SearchPostgres extends SearchEngine { function update( $pageid, $title, $text ) { ## We don't want to index older revisions $SQL = "UPDATE pagecontent SET textvector = NULL WHERE old_id IN ". - "(SELECT rev_text_id FROM revision WHERE rev_page = " . intval( $pageid ) . + "(SELECT rev_text_id FROM revision WHERE rev_page = " . intval( $pageid ) . " ORDER BY rev_text_id DESC OFFSET 1)"; $this->db->query($SQL); return true; diff --git a/includes/search/SearchSqlite.php b/includes/search/SearchSqlite.php index 6accc31b..cd59eea9 100644 --- a/includes/search/SearchSqlite.php +++ b/includes/search/SearchSqlite.php @@ -26,6 +26,12 @@ * @ingroup Search */ class SearchSqlite extends SearchEngine { + + /** + * @var DatabaseSqlite + */ + protected $db; + /** * Creates an instance of this class * @param $db DatabaseSqlite: database object @@ -45,6 +51,8 @@ class SearchSqlite extends SearchEngine { /** * Parse the user's query and transform it into an SQL fragment which will * become part of a WHERE clause + * + * @return string */ function parseQuery( $filteredText, $fulltext ) { global $wgContLang; @@ -66,7 +74,9 @@ class SearchSqlite extends SearchEngine { $quote = '"'; } - if( $searchon !== '' ) $searchon .= ' '; + if( $searchon !== '' ) { + $searchon .= ' '; + } // Some languages such as Serbian store the input form in the search index, // so we may need to search for matches in multiple writing system variants. diff --git a/includes/search/SearchUpdate.php b/includes/search/SearchUpdate.php index 5262faa4..77146ebb 100644 --- a/includes/search/SearchUpdate.php +++ b/includes/search/SearchUpdate.php @@ -15,8 +15,8 @@ */ class SearchUpdate { - /* private */ var $mId = 0, $mNamespace, $mTitle, $mText; - /* private */ var $mTitleWords; + private $mId = 0, $mNamespace, $mTitle, $mText; + private $mTitleWords; function __construct( $id, $title, $text = false ) { $nt = Title::newFromText( $title ); -- cgit v1.2.3-54-g00ecf