Move storing of $db down to SearchEngine
authorPlatonides <platonides@users.mediawiki.org>
Mon, 22 Nov 2010 16:08:12 +0000 (16:08 +0000)
committerPlatonides <platonides@users.mediawiki.org>
Mon, 22 Nov 2010 16:08:12 +0000 (16:08 +0000)
Fixes the r76809 issue of SearchDbTest not being marked as requiring a Database.

includes/search/SearchEngine.php
includes/search/SearchIBM_DB2.php
includes/search/SearchMssql.php
includes/search/SearchMySQL.php
includes/search/SearchOracle.php
includes/search/SearchPostgres.php
includes/search/SearchSqlite.php

index deba774..984322d 100644 (file)
@@ -22,6 +22,14 @@ class SearchEngine {
        var $namespaces = array( NS_MAIN );
        var $showRedirects = false;
 
+       function __construct($db = null) {
+               if ( $db ) {
+                       $this->db = $db;
+               } else {
+                       $this->db = wfGetDB( DB_SLAVE );
+               }
+       }
+
        /**
         * Perform a full text search query and return a result set.
         * If title searches are not supported or disabled, return null.
@@ -383,10 +391,11 @@ class SearchEngine {
         */
        public static function create() {
                global $wgSearchType;
-               $dbr = wfGetDB( DB_SLAVE );
+               $dbr = null;
                if ( $wgSearchType ) {
                        $class = $wgSearchType;
                } else {
+                       $dbr = wfGetDB( DB_SLAVE );
                        $class = $dbr->getSearchEngine();
                }
                $search = new $class( $dbr );
index 97d4825..8cedd6f 100644 (file)
  * @ingroup Search
  */
 class SearchIBM_DB2 extends SearchEngine {
+
+       /**
+        * Creates an instance of this class
+        * @param $db DatabaseIbm_db2: database object
+        */
        function __construct($db) {
-               $this->db = $db;
+               parent::__construct( $db );
        }
 
        /**
index 4177775..8b850fa 100644 (file)
  */
 class SearchMssql extends SearchEngine {
 
+       /**
+        * Creates an instance of this class
+        * @param $db DatabaseMssql: database object
+        */
        function __construct( $db ) {
-               $this->db = $db;
+               parent::__construct( $db );
        }
 
        /**
index bb079c0..b92682a 100644 (file)
@@ -32,9 +32,12 @@ class SearchMySQL extends SearchEngine {
        var $strictMatching = true;
        static $mMinSearchLength;
 
-       /** @todo document */
+       /**
+        * Creates an instance of this class
+        * @param $db DatabaseMysql: database object
+        */
        function __construct( $db ) {
-               $this->db = $db;
+               parent::__construct( $db );
        }
 
        /** 
@@ -410,4 +413,4 @@ class MySQLSearchResultSet extends SqlSearchResultSet {
        function getTotalHits() {
                return $this->mTotalHits;
        }
-}
\ No newline at end of file
+}
index 80fc118..bc5f6b5 100644 (file)
@@ -56,9 +56,13 @@ class SearchOracle extends SearchEngine {
                                                                        'TRSYN' => 1, 
                                                                        'TT' => 1, 
                                                                        'WITHIN' => 1);
-       
+
+       /**
+        * Creates an instance of this class
+        * @param $db DatabasePostgres: database object
+        */
        function __construct($db) {
-               $this->db = $db;
+               parent::__construct( $db );
        }
 
        /**
index c9a2c0b..8c9e293 100644 (file)
  * @ingroup Search
  */
 class SearchPostgres extends SearchEngine {
-
+       /**
+        * Creates an instance of this class
+        * @param $db DatabaseSqlite: database object
+        */
        function __construct( $db ) {
-               $this->db = $db;
+               parent::__construct( $db );
        }
 
        /**
index a7c09ba..6accc31 100644 (file)
@@ -31,7 +31,7 @@ class SearchSqlite extends SearchEngine {
         * @param $db DatabaseSqlite: database object
         */
        function __construct( $db ) {
-               $this->db = $db;
+               parent::__construct( $db );
        }
 
        /**
@@ -331,4 +331,4 @@ class SqliteSearchResultSet extends SqlSearchResultSet {
        function getTotalHits() {
                return $this->mTotalHits;
        }
-}
\ No newline at end of file
+}