[search] Remove more dead code
[lhc/web/wiklou.git] / includes / specials / SpecialSearch.php
index 9690d45..e7a8677 100644 (file)
@@ -100,6 +100,25 @@ class SpecialSearch extends SpecialPage {
         * @param string $par
         */
        public function execute( $par ) {
+               $request = $this->getRequest();
+
+               // Fetch the search term
+               $search = str_replace( "\n", " ", $request->getText( 'search' ) );
+
+               // Historically search terms have been accepted not only in the search query
+               // parameter, but also as part of the primary url. This can have PII implications
+               // in releasing page view data. As such issue a 301 redirect to the correct
+               // URL.
+               if ( strlen( $par ) && !strlen( $search ) ) {
+                       $query = $request->getValues();
+                       unset( $query['title'] );
+                       // Strip underscores from title parameter; most of the time we'll want
+                       // text form here. But don't strip underscores from actual text params!
+                       $query['search'] = str_replace( '_', ' ', $par );
+                       $this->getOutput()->redirect( $this->getPageTitle()->getFullURL( $query ), 301 );
+                       return;
+               }
+
                $this->setHeaders();
                $this->outputHeader();
                $out = $this->getOutput();
@@ -110,15 +129,6 @@ class SpecialSearch extends SpecialPage {
                ] );
                $this->addHelpLink( 'Help:Searching' );
 
-               // Strip underscores from title parameter; most of the time we'll want
-               // text form here. But don't strip underscores from actual text params!
-               $titleParam = str_replace( '_', ' ', $par );
-
-               $request = $this->getRequest();
-
-               // Fetch the search term
-               $search = str_replace( "\n", " ", $request->getText( 'search', $titleParam ) );
-
                $this->load();
                if ( !is_null( $request->getVal( 'nsRemember' ) ) ) {
                        $this->saveNamespaces();
@@ -224,11 +234,6 @@ class SpecialSearch extends SpecialPage {
 
                        return;
                }
-               # No match, generate an edit URL
-               $title = Title::newFromText( $term );
-               if ( !is_null( $title ) ) {
-                       Hooks::run( 'SpecialSearchNogomatch', [ &$title ] );
-               }
                $this->showResults( $term );
        }
 
@@ -393,6 +398,7 @@ class SpecialSearch extends SpecialPage {
 
                        // show results
                        if ( $numTextMatches > 0 ) {
+                               $search->augmentSearchResults( $textMatches );
                                $out->addHTML( $this->showMatches( $textMatches ) );
                        }
 
@@ -444,7 +450,6 @@ class SpecialSearch extends SpecialPage {
                $out->addHTML( "</div>" );
 
                Hooks::run( 'SpecialSearchResultsAppend', [ $this, $out, $term ] );
-
        }
 
        /**
@@ -459,25 +464,6 @@ class SpecialSearch extends SpecialPage {
                return "<p class=\"mw-search-interwiki-header mw-search-visualclear\">\n$wikiMsg</p>";
        }
 
-       /**
-        * Decide if the suggested query should be run, and it's results returned
-        * instead of the provided $textMatches
-        *
-        * @param SearchResultSet $textMatches The results of a users query
-        * @return bool
-        */
-       protected function shouldRunSuggestedQuery( SearchResultSet $textMatches ) {
-               if ( !$this->runSuggestion ||
-                       !$textMatches->hasSuggestion() ||
-                       $textMatches->numRows() > 0 ||
-                       $textMatches->searchContainedSyntax()
-               ) {
-                       return false;
-               }
-
-               return $this->getConfig()->get( 'SearchRunSuggestedQuery' );
-       }
-
        /**
         * Generates HTML shown to the user when we have a suggestion about a query
         * that might give more results than their current query.
@@ -706,7 +692,7 @@ class SpecialSearch extends SpecialPage {
         *
         * @return string
         */
-       protected function showMatches( &$matches, $interwiki = null ) {
+       protected function showMatches( $matches, $interwiki = null ) {
                global $wgContLang;
 
                $terms = $wgContLang->convertForSearchResult( $matches->termMatches() );
@@ -715,7 +701,7 @@ class SpecialSearch extends SpecialPage {
                $pos = $this->offset;
 
                if ( $result && $interwiki ) {
-                       $out .= $this->interwikiHeader( $interwiki, $result );
+                       $out .= $this->interwikiHeader( $interwiki, $matches );
                }
 
                $out .= "<ul class='mw-search-results'>\n";
@@ -740,8 +726,7 @@ class SpecialSearch extends SpecialPage {
         *
         * @return string
         */
-       protected function showHit( $result, $terms, $position ) {
-
+       protected function showHit( SearchResult $result, $terms, $position ) {
                if ( $result->isBrokenTitle() ) {
                        return '';
                }
@@ -961,7 +946,6 @@ class SpecialSearch extends SpecialPage {
         * @return string
         */
        protected function showInterwikiHit( $result, $lastInterwiki, $query ) {
-
                if ( $result->isBrokenTitle() ) {
                        return '';
                }
@@ -1324,24 +1308,6 @@ class SpecialSearch extends SpecialPage {
                return false;
        }
 
-       /**
-        * Check if query starts with all: prefix
-        *
-        * @param string $term The string to check
-        * @return bool
-        */
-       protected function startsWithAll( $term ) {
-
-               $allkeyword = $this->msg( 'searchall' )->inContentLanguage()->text();
-
-               $parts = explode( ':', $term );
-               if ( count( $parts ) > 1 ) {
-                       return $parts[0] == $allkeyword;
-               }
-
-               return false;
-       }
-
        /**
         * @since 1.18
         *