Remove DB logic from SearchEngine. New method in Database and associated subclasses...
authorChad Horohoe <demon@users.mediawiki.org>
Mon, 18 Aug 2008 15:22:00 +0000 (15:22 +0000)
committerChad Horohoe <demon@users.mediawiki.org>
Mon, 18 Aug 2008 15:22:00 +0000 (15:22 +0000)
includes/SearchEngine.php
includes/db/Database.php
includes/db/DatabaseOracle.php
includes/db/DatabasePostgres.php

index 916e1fd..cfa560d 100644 (file)
@@ -282,19 +282,14 @@ class SearchEngine {
         * @return SearchEngine
         */
        public static function create() {
-               global $wgDBtype, $wgSearchType;
+               global $wgSearchType;
+               $dbr = wfGetDB( DB_SLAVE );
                if( $wgSearchType ) {
                        $class = $wgSearchType;
-               } elseif( $wgDBtype == 'mysql' ) {
-                       $class = 'SearchMySQL';
-               } else if ( $wgDBtype == 'postgres' ) {
-                       $class = 'SearchPostgres';
-               } else if ( $wgDBtype == 'oracle' ) {
-                       $class = 'SearchOracle';
                } else {
-                       $class = 'SearchEngineDummy';
+                       $class = $dbr->getSearchEngine();
                }
-               $search = new $class( wfGetDB( DB_SLAVE ) );
+               $search = new $class( $dbr );
                $search->setLimitOffset(0,0);
                return $search;
        }
index 2e3e0ed..5b39564 100644 (file)
@@ -2271,6 +2271,16 @@ class Database {
                $result = $this->query( "SELECT RELEASE_LOCK($lockName)", $method );
                $this->freeResult( $result );
        }
+       
+       /**
+        * Get search engine class. All subclasses of this
+        * need to implement this if they wish to use searching.
+        * 
+        * @return string
+        */
+       public function getSearchEngine() {
+               return "SearchMySQL";
+       }
 }
 
 /**
index f4dbac7..67c8fff 100644 (file)
@@ -716,5 +716,9 @@ echo "error!\n";
        public function unlock( $lockName, $method ) {
                return true;
        }
+       
+       public function getSearchEngine() {
+               return "SearchOracle";
+       }
 
 } // end DatabaseOracle class
index 065ad56..bf948c9 100644 (file)
@@ -1390,5 +1390,9 @@ END;
        public function unlock( $lockName, $method ) {
                return true;
        }
+       
+       public function getSearchEngine() {
+               return "SearchPostgres";
+       }
 
 } // end DatabasePostgres class