DB error log
[lhc/web/wiklou.git] / includes / SearchEngine.php
index dd512e9..53d9e69 100644 (file)
@@ -50,7 +50,7 @@ class SearchEngine {
                        return $wgUser->getOption( "searchNs".$i );
                } else {
                        // User is not logged in so we give him the global default namespaces
-                       return $wgNamespacesToBeSearchedDefault[ $i ];
+                       return !empty($wgNamespacesToBeSearchedDefault[ $i ]);
                }
        }
 
@@ -59,7 +59,8 @@ class SearchEngine {
        function powersearch()
        {
                global $wgUser, $wgOut, $wgLang, $wgTitle, $wgRequest;
-
+               $sk =& $wgUser->getSkin();
+               
                $search                 = $wgRequest->getText( 'search' );
                $searchx                = $wgRequest->getVal( 'searchx' );
                $listredirs             = $wgRequest->getVal( 'redirs' );
@@ -86,7 +87,7 @@ class SearchEngine {
                        if ( !isset( $searchx ) ) {
                                $checkboxValue = $this->initNamespaceCheckbox( $i );
                        } else {
-                               $checkboxValue = $_REQUEST[$formVar];
+                               $checkboxValue = $wgRequest->getVal( $formVar );
                        }
 
                        $checked = "";
@@ -130,9 +131,9 @@ class SearchEngine {
                  wfMsg("powersearch") . "\" />\n";
                $ret = str_replace( "$9", $tempText, $ret );
 
-               global $wgScript;
+               $action = $sk->escapeSearchLink();
                $ret = "<br /><br />\n<form id=\"powersearch\" method=\"get\" " .
-                 "action=\"$wgScript\">\n{$ret}\n</form>\n";
+                 "action=\"$action\">\n{$ret}\n</form>\n";
 
                if ( isset ( $searchx ) ) {
                        if ( ! $listredirs ) { 
@@ -142,23 +143,28 @@ class SearchEngine {
                return $ret;
        }
 
+       function setupPage() {
+               global $wgOut;
+               $wgOut->setPageTitle( wfMsg( "searchresults" ) );
+               $q = wfMsg( "searchquery", htmlspecialchars( $this->mUsertext ) );
+               $wgOut->setSubtitle( $q );
+               $wgOut->setArticleRelated( false );
+               $wgOut->setRobotpolicy( "noindex,nofollow" );
+       }
+
        # Perform the search and construct the results page
        function showResults()
        {
-               global $wgUser, $wgTitle, $wgOut, $wgLang, $wgDisableTextSearch;
-               global $wgInputEncoding;
+               global $wgUser, $wgTitle, $wgOut, $wgLang, $wgRequest;
+               global $wgDisableTextSearch, $wgInputEncoding;
                $fname = "SearchEngine::showResults";
 
-               $search = $_REQUEST['search'];
+               $search = $wgRequest->getText( 'search' );
 
                $powersearch = $this->powersearch(); /* Need side-effects here? */
 
-               $wgOut->setPageTitle( wfMsg( "searchresults" ) );
-               $q = wfMsg( "searchquery", htmlspecialchars( $this->mUsertext ) );
-               $wgOut->setSubtitle( $q );
-               $wgOut->setArticleRelated( false );
-               $wgOut->setRobotpolicy( "noindex,nofollow" );
-
+               $this->setupPage();
+               
                $sk = $wgUser->getSkin();
                $header = wfMsg( "searchresulttext", $sk->makeKnownLink(
                  wfMsg( "searchhelppage" ), wfMsg( "searchingwikipedia" ) ) );
@@ -290,6 +296,8 @@ class SearchEngine {
                        # Use cleaner boolean search if available
                        return $this->parseQuery4();
                }
+               # on non mysql4 database: get list of words we don't want to search for
+               require_once( "FulltextStoplist.php" );
 
                $lc = SearchEngine::legalSearchChars() . "()";
                $q = preg_replace( "/([()])/", " \\1 ", $this->mUsertext );
@@ -418,12 +426,13 @@ class SearchEngine {
 
        function goResult()
        {
-               global $wgOut, $wgDisableTextSearch;
+               global $wgOut, $wgRequest, $wgGoToEdit;
+               global $wgDisableTextSearch;
                $fname = "SearchEngine::goResult";
                
-               $search         = $_REQUEST['search'];
+               $search = trim( $wgRequest->getText( "search" ) );
 
-               # First try to go to page as entered.
+               # Try to go to page as entered.
                #
                $t = Title::newFromText( $search );
 
@@ -433,7 +442,8 @@ class SearchEngine {
                        return;
                }
 
-               if ( 0 != $t->getArticleID() ) {
+               # Exact match? No need to look further.
+               if ( $t->getNamespace() == NS_SPECIAL || 0 != $t->getArticleID() ) {
                        $wgOut->redirect( $t->getFullURL() );
                        return;
                }
@@ -462,9 +472,28 @@ class SearchEngine {
                        return;
                }
 
+               # Entering an IP address goes to the contributions page
+               if ( preg_match( '/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/', $search ) ) {
+                       $title = Title::makeTitle( NS_SPECIAL, "Contributions" );
+                       $wgOut->redirect( $title->getFullUrl( "target=$search" ) );
+                       return;
+               }
+
                # No match, generate an edit URL
                $t = Title::newFromText( $this->mUsertext );
-               $wgOut->addHTML( "<p>" . wfMsg("nogomatch", $t->escapeLocalURL( "action=edit" ) ) . "</p>\n" );
+               
+               # If the feature is enabled, go straight to the edit page
+               if ( $wgGoToEdit ) {
+                       $wgOut->redirect( $t->getFullURL( "action=edit" ) );
+                       return;
+               }
+               
+               if( $t ) {
+                       $editurl = $t->escapeLocalURL( "action=edit" );
+               } else {
+                       $editurl = ""; # ?? 
+               }
+               $wgOut->addHTML( "<p>" . wfMsg("nogomatch", $editurl ) . "</p>\n" );
 
                # Try a fuzzy title search
                $anyhit = false;
@@ -482,6 +511,9 @@ class SearchEngine {
 
        /* static */ function doFuzzyTitleSearch( $search, $namespace ){
                global $wgLang, $wgOut;
+               
+               $this->setupPage();
+               
                $sstr = ucfirst($search);
                $sstr = str_replace(" ", "_", $sstr);
                $fuzzymatches = SearchEngine::fuzzyTitles( $sstr, $namespace );