Make the SQL search subclasses less nerve-wracking to read, by using makeList() inste...
authorTim Starling <tstarling@users.mediawiki.org>
Mon, 22 Dec 2008 12:31:15 +0000 (12:31 +0000)
committerTim Starling <tstarling@users.mediawiki.org>
Mon, 22 Dec 2008 12:31:15 +0000 (12:31 +0000)
includes/SearchMySQL.php
includes/SearchOracle.php
includes/SearchPostgres.php

index 984fcd8..5fc0679 100644 (file)
@@ -34,7 +34,10 @@ class SearchMySQL extends SearchEngine {
                $this->db = $db;
        }
 
-       /** @todo document */
+       /** 
+        * Parse the user's query and transform it into an SQL fragment which will 
+        * become part of a WHERE clause
+        */
        function parseQuery( $filteredText, $fulltext ) {
                global $wgContLang;
                $lc = SearchEngine::legalSearchChars(); // Minus format chars
@@ -126,9 +129,10 @@ class SearchMySQL extends SearchEngine {
        function queryNamespaces() {
                if( is_null($this->namespaces) )
                        return '';  # search all
-               $namespaces = implode( ',', $this->namespaces );
-               if ($namespaces == '') {
+               if ( !count( $this->namespaces ) ) {
                        $namespaces = '0';
+               } else {
+                       $namespaces = $this->db->makeList( $this->namespaces );
                }
                return 'AND page_namespace IN (' . $namespaces . ')';
        }
index bf9368d..b48d5e6 100644 (file)
@@ -77,9 +77,10 @@ class SearchOracle extends SearchEngine {
        function queryNamespaces() {
                if( is_null($this->namespaces) )
                        return '';
-               $namespaces = implode(',', $this->namespaces);
-               if ($namespaces == '') {
+               if ( !count( $this->namespaces ) ) {
                        $namespaces = '0';
+               } else {
+                       $namespaces = $this->db->makeList( $this->namespaces );
                }
                return 'AND page_namespace IN (' . $namespaces . ')';
        }
@@ -144,7 +145,10 @@ class SearchOracle extends SearchEngine {
                        'WHERE page_id=si_page AND ' . $match;
        }
 
-       /** @todo document */
+       /** 
+        * Parse a user input search string, and return an SQL fragment to be used 
+        * as part of a WHERE clause
+        */
        function parseQuery($filteredText, $fulltext) {
                global $wgContLang;
                $lc = SearchEngine::legalSearchChars();
@@ -170,9 +174,9 @@ class SearchOracle extends SearchEngine {
                        }
                }
 
-               $searchon = $this->db->strencode(join(',', $q));
+               $searchon = $this->db->addQuotes(join(',', $q));
                $field = $this->getIndexField($fulltext);
-               return " CONTAINS($field, '$searchon', 1) > 0 ";
+               return " CONTAINS($field, $searchon, 1) > 0 ";
        }
 
        /**
index 7f15f67..4862a44 100644 (file)
@@ -66,6 +66,7 @@ class SearchPostgres extends SearchEngine {
 
        /*
         * Transform the user's search string into a better form for tsearch2
+        * Returns an SQL fragment consisting of quoted text to search for.
        */
        function parseQuery( $term ) {
 
@@ -142,6 +143,7 @@ class SearchPostgres extends SearchEngine {
                }
                $prefix = $wgDBversion < 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
@@ -183,7 +185,7 @@ class SearchPostgres extends SearchEngine {
                        if ( count($this->namespaces) < 1)
                                $query .= ' AND page_namespace = 0';
                        else {
-                               $namespaces = implode( ',', $this->namespaces );
+                               $namespaces = $this->db->makeList( $this->namespaces );
                                $query .= " AND page_namespace IN ($namespaces)";
                        }
                }
@@ -202,8 +204,8 @@ 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 = $pageid ".
-                               "ORDER BY rev_text_id DESC OFFSET 1)";
+                               "(SELECT rev_text_id FROM revision WHERE rev_page = " . intval( $pageid ) . 
+                               " ORDER BY rev_text_id DESC OFFSET 1)";
                $this->db->doQuery($SQL);
                return true;
        }