Merge "APIQueryInfo: Allow fetching the canonical url of a page"
[lhc/web/wiklou.git] / includes / search / SearchMySQL.php
index cfe4c29..78eba2d 100644 (file)
@@ -29,8 +29,9 @@
  * @ingroup Search
  */
 class SearchMySQL extends SearchDatabase {
-       var $strictMatching = true;
-       static $mMinSearchLength;
+       protected $strictMatching = true;
+
+       private static $mMinSearchLength;
 
        /**
         * Parse the user's query and transform it into an SQL fragment which will
@@ -43,7 +44,8 @@ class SearchMySQL extends SearchDatabase {
         */
        function parseQuery( $filteredText, $fulltext ) {
                global $wgContLang;
-               $lc = SearchEngine::legalSearchChars(); // Minus format chars
+
+               $lc = $this->legalSearchChars(); // Minus format chars
                $searchon = '';
                $this->searchTerms = array();
 
@@ -52,7 +54,9 @@ class SearchMySQL extends SearchDatabase {
                if ( preg_match_all( '/([-+<>~]?)(([' . $lc . ']+)(\*?)|"[^"]*")/',
                                $filteredText, $m, PREG_SET_ORDER ) ) {
                        foreach ( $m as $bits ) {
-                               @list( /* all */, $modifier, $term, $nonQuoted, $wildcard ) = $bits;
+                               wfSuppressWarnings();
+                               list( /* all */, $modifier, $term, $nonQuoted, $wildcard ) = $bits;
+                               wfRestoreWarnings();
 
                                if ( $nonQuoted != '' ) {
                                        $term = $nonQuoted;
@@ -121,9 +125,9 @@ class SearchMySQL extends SearchDatabase {
                        wfDebug( __METHOD__ . ": Can't understand search query '{$filteredText}'\n" );
                }
 
-               $searchon = $this->db->strencode( $searchon );
+               $searchon = $this->db->addQuotes( $searchon );
                $field = $this->getIndexField( $fulltext );
-               return " MATCH($field) AGAINST('$searchon' IN BOOLEAN MODE) ";
+               return " MATCH($field) AGAINST($searchon IN BOOLEAN MODE) ";
        }
 
        function regexTerm( $string, $wildcard ) {
@@ -153,7 +157,7 @@ class SearchMySQL extends SearchDatabase {
         * Perform a full text search query and return a result set.
         *
         * @param string $term Raw search term
-        * @return MySQLSearchResultSet
+        * @return SqlSearchResultSet
         */
        function searchText( $term ) {
                return $this->searchInternal( $term, true );
@@ -163,15 +167,13 @@ class SearchMySQL extends SearchDatabase {
         * Perform a title-only search query and return a result set.
         *
         * @param string $term Raw search term
-        * @return MySQLSearchResultSet
+        * @return SqlSearchResultSet
         */
        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;
@@ -185,21 +187,19 @@ class SearchMySQL extends SearchDatabase {
                );
 
                $total = null;
-               if ( $wgCountTotalSearchHits ) {
-                       $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();
+               $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 new SqlSearchResultSet( $resultSet, $this->searchTerms, $total );
        }
 
        public function supports( $feature ) {
@@ -303,6 +303,8 @@ class SearchMySQL extends SearchDatabase {
 
        /**
         * @since 1.18 (changed)
+        * @param string $filteredTerm
+        * @param bool $fulltext
         * @return array
         */
        function getCountQuery( $filteredTerm, $fulltext ) {
@@ -374,6 +376,7 @@ class SearchMySQL extends SearchDatabase {
        /**
         * Converts some characters for MySQL's indexing to grok it correctly,
         * and pads short words to overcome limitations.
+        * @param string $string
         * @return mixed|string
         */
        function normalizeText( $string ) {
@@ -422,6 +425,7 @@ class SearchMySQL extends SearchDatabase {
         * Armor a case-folded UTF-8 string to get through MySQL's
         * fulltext search without being mucked up by funny charset
         * settings or anything else of the sort.
+        * @param array $matches
         * @return string
         */
        protected function stripForSearchCallback( $matches ) {
@@ -452,17 +456,3 @@ class SearchMySQL extends SearchDatabase {
                return self::$mMinSearchLength;
        }
 }
-
-/**
- * @ingroup Search
- */
-class MySQLSearchResultSet extends SqlSearchResultSet {
-       function __construct( $resultSet, $terms, $totalHits = null ) {
-               parent::__construct( $resultSet, $terms );
-               $this->mTotalHits = $totalHits;
-       }
-
-       function getTotalHits() {
-               return $this->mTotalHits;
-       }
-}