Disable Special:Sitesettings, as it is far far far from working.
[lhc/web/wiklou.git] / includes / SearchEngine.php
index 58b8cf2..e1de0bb 100644 (file)
@@ -4,7 +4,9 @@
  * @package MediaWiki
  */
 
-/** */
+/**
+ * @package MediaWiki
+ */
 class SearchEngine {
        var $limit = 10;
        var $offset = 0;
@@ -40,6 +42,7 @@ class SearchEngine {
         * If an exact title match can be find, or a very slightly close match,
         * return the title. If no match, returns NULL.
         *
+        * @static
         * @param string $term
         * @return Title
         * @access private
@@ -72,12 +75,25 @@ class SearchEngine {
                        return $title;
                }
 
+               $title = Title::newFromText( $term );
+
                # Entering an IP address goes to the contributions page
-               if ( preg_match( '/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/', $term ) ) {
-                       $title = Title::makeTitle( NS_SPECIAL, "Contributions/" . $term );
+               if ( ( $title->getNamespace() == NS_USER && User::isIP($title->getText() ) )
+                       || User::isIP( trim( $term ) ) ) {
+                       return Title::makeTitle( NS_SPECIAL, "Contributions/" . $title->getDbkey() );
+               }
+
+
+               # Entering a user goes to the user page whether it's there or not
+               if ( $title->getNamespace() == NS_USER ) {
                        return $title;
                }
                
+               # Quoted term? Try without the quotes...
+               if( preg_match( '/^"([^"]+)"$/', $term, $matches ) ) {
+                       return SearchEngine::getNearMatch( $matches[1] );
+               }
+               
                return NULL;
        }
        
@@ -118,7 +134,7 @@ class SearchEngine {
                global $wgContLang;
                $arr = array();
                foreach( $wgContLang->getNamespaces() as $ns => $name ) {
-                       if( $ns >= 0 ) {
+                       if( $ns >= NS_MAIN ) {
                                $arr[$ns] = $name;
                        }
                }
@@ -170,7 +186,7 @@ class SearchEngine {
                if ($namespaces == '') {
                        $namespaces = '0';
                }
-               return 'AND cur_namespace IN (' . $namespaces . ')';
+               return 'AND page_namespace IN (' . $namespaces . ')';
        }
        
        /**
@@ -181,6 +197,16 @@ class SearchEngine {
        function queryLimit() {
                return $this->db->limitResult( $this->limit, $this->offset );
        }
+
+       /**
+        * Does not do anything for generic search engine
+        * subclasses may define this though
+        * @return string
+        * @access private
+        */
+       function queryRanking($filteredTerm,$fulltext) {
+               return "";
+       }
        
        /**
         * Construct the full SQL query to do the search.
@@ -193,17 +219,47 @@ class SearchEngine {
                return $this->queryMain( $filteredTerm, $fulltext ) . ' ' .
                        $this->queryRedirect() . ' ' .
                        $this->queryNamespaces() . ' ' .
+                       $this->queryRanking($filteredTerm, $fulltext) . ' ' .
                        $this->queryLimit();
        }
+
+       /**
+        * Load up the appropriate search engine class for the currently
+          * active database backend, and return a configured instance.
+          *
+          * @return SearchEngine
+          * @access private
+       */
+       function create() {
+                global $wgDBtype, $wgDBmysql4, $wgSearchType;
+                if( $wgDBtype == 'mysql' ) {
+                        if( $wgDBmysql4 ) {
+                                $class = 'SearchMySQL4';
+                                require_once( 'SearchMySQL4.php' );
+                        } else {
+                                $class = 'SearchMysql3';
+                                require_once( 'SearchMySQL3.php' );
+                        }
+                } else if ( $wgDBtype == 'PostgreSQL' ) {
+                        $class = 'SearchTsearch2';
+                        require_once( 'SearchTsearch2.php' );
+                } else {
+                        $class = 'SearchEngineDummy';
+                }
+                $search = new $class( wfGetDB( DB_SLAVE ) );
+                $search->setLimitOffset(0,0);
+                return $search;
+       }
+
        
 }
 
-/** */
+/**
+ * @package MediaWiki
+ */
 class SearchEngineDummy {
        function search( $term ) {
                return null;
        }
 }
 
-
-?>