Merge "Remove "include redirects" option from search"
[lhc/web/wiklou.git] / includes / specials / SpecialSearch.php
index e406a0e..c73ee53 100644 (file)
@@ -171,6 +171,7 @@ class SpecialSearch extends SpecialPage {
                # If the string cannot be used to create a title
                if ( is_null( $t ) ) {
                        $this->showResults( $term );
+
                        return;
                }
                # If there's an exact or very near match, jump right there.
@@ -183,6 +184,7 @@ class SpecialSearch extends SpecialPage {
 
                if ( !is_null( $t ) ) {
                        $this->getOutput()->redirect( $t->getFullURL() );
+
                        return;
                }
                # No match, generate an edit URL
@@ -195,6 +197,7 @@ class SpecialSearch extends SpecialPage {
                        # If the feature is enabled, go straight to the edit page
                        if ( $wgGoToEdit ) {
                                $this->getOutput()->redirect( $t->getFullURL( array( 'action' => 'edit' ) ) );
+
                                return;
                        }
                }
@@ -206,8 +209,8 @@ class SpecialSearch extends SpecialPage {
         */
        public function showResults( $term ) {
                global $wgDisableTextSearch, $wgSearchForwardUrl, $wgContLang, $wgScript;
-               wfProfileIn( __METHOD__ );
 
+               $profile = new ProfileSection( __METHOD__ );
                $search = $this->getSearchEngine();
                $search->setLimitOffset( $this->limit, $this->offset );
                $search->setNamespaces( $this->namespaces );
@@ -237,7 +240,7 @@ class SpecialSearch extends SpecialPage {
                                        Xml::closeElement( 'fieldset' )
                                );
                        }
-                       wfProfileOut( __METHOD__ );
+
                        return;
                }
 
@@ -293,7 +296,6 @@ class SpecialSearch extends SpecialPage {
 
                if ( !wfRunHooks( 'SpecialSearchResultsPrepend', array( $this, $out, $term ) ) ) {
                        # Hook requested termination
-                       wfProfileOut( __METHOD__ );
                        return;
                }
 
@@ -320,7 +322,7 @@ class SpecialSearch extends SpecialPage {
                // Sometimes the search engine knows there are too many hits
                if ( $titleMatches instanceof SearchResultTooMany ) {
                        $out->wrapWikiMsg( "==$1==\n", 'toomanymatches' );
-                       wfProfileOut( __METHOD__ );
+
                        return;
                }
 
@@ -329,8 +331,8 @@ class SpecialSearch extends SpecialPage {
                        $out->addHTML( $this->formHeader( $term, 0, 0 ) );
                        $out->addHtml( $this->getProfileForm( $this->profile, $term ) );
                        $out->addHTML( '</form>' );
+
                        // Empty query -- straight view of search form
-                       wfProfileOut( __METHOD__ );
                        return;
                }
 
@@ -420,7 +422,6 @@ class SpecialSearch extends SpecialPage {
                        $out->addHTML( "<p class='mw-search-pager-bottom'>{$prevnext}</p>\n" );
                }
                wfRunHooks( 'SpecialSearchResultsAppend', array( $this, $out, $term ) );
-               wfProfileOut( __METHOD__ );
        }
 
        /**
@@ -433,12 +434,14 @@ class SpecialSearch extends SpecialPage {
                // show direct page/create link if applicable
 
                // Check DBkey !== '' in case of fragment link only.
-               if ( is_null( $t ) || $t->getDBkey() === '' ||
-                               ( $titleMatches !== null && $titleMatches->searchContainedSyntax() ) ||
-                               ( $textMatches !== null && $textMatches->searchContainedSyntax() ) ) {
+               if ( is_null( $t ) || $t->getDBkey() === ''
+                       || ( $titleMatches !== null && $titleMatches->searchContainedSyntax() )
+                       || ( $textMatches !== null && $textMatches->searchContainedSyntax() )
+               ) {
                        // invalid title
                        // preserve the paragraph for margins etc...
                        $this->getOutput()->addHtml( '<p></p>' );
+
                        return;
                }
 
@@ -511,6 +514,7 @@ class SpecialSearch extends SpecialPage {
                                $opt['ns' . $n] = 1;
                        }
                }
+
                return $opt + $this->extraParams;
        }
 
@@ -523,16 +527,11 @@ class SpecialSearch extends SpecialPage {
         */
        protected function showMatches( &$matches ) {
                global $wgContLang;
-               wfProfileIn( __METHOD__ );
 
+               $profile = new ProfileSection( __METHOD__ );
                $terms = $wgContLang->convertForSearchResult( $matches->termMatches() );
 
-               $out = "";
-               $infoLine = $matches->getInfo();
-               if ( !is_null( $infoLine ) ) {
-                       $out .= "\n<!-- {$infoLine} -->\n";
-               }
-               $out .= "<ul class='mw-search-results'>\n";
+               $out = "<ul class='mw-search-results'>\n";
                $result = $matches->next();
                while ( $result ) {
                        $out .= $this->showHit( $result, $terms );
@@ -542,7 +541,7 @@ class SpecialSearch extends SpecialPage {
 
                // convert the whole thing to desired language variant
                $out = $wgContLang->convert( $out );
-               wfProfileOut( __METHOD__ );
+
                return $out;
        }
 
@@ -555,10 +554,9 @@ class SpecialSearch extends SpecialPage {
         * @return string
         */
        protected function showHit( $result, $terms ) {
-               wfProfileIn( __METHOD__ );
+               $profile = new ProfileSection( __METHOD__ );
 
                if ( $result->isBrokenTitle() ) {
-                       wfProfileOut( __METHOD__ );
                        return "<!-- Broken link in search result -->\n";
                }
 
@@ -573,7 +571,7 @@ class SpecialSearch extends SpecialPage {
                $link_t = clone $t;
 
                wfRunHooks( 'ShowSearchHitTitle',
-                                       array( &$link_t, &$titleSnippet, $result, $terms, $this ) );
+                       array( &$link_t, &$titleSnippet, $result, $terms, $this ) );
 
                $link = Linker::linkKnown(
                        $link_t,
@@ -584,7 +582,6 @@ class SpecialSearch extends SpecialPage {
                //This is not quite safe, but better than showing excerpts from non-readable pages
                //Note that hiding the entry entirely would screw up paging.
                if ( !$t->userCan( 'read', $this->getUser() ) ) {
-                       wfProfileOut( __METHOD__ );
                        return "<li>{$link}</li>\n";
                }
 
@@ -592,7 +589,6 @@ class SpecialSearch extends SpecialPage {
                // The least confusing at this point is to drop the result.
                // You may get less results, but... oh well. :P
                if ( $result->isMissingRevision() ) {
-                       wfProfileOut( __METHOD__ );
                        return "<!-- missing page " . htmlspecialchars( $t->getPrefixedText() ) . "-->\n";
                }
 
@@ -692,7 +688,6 @@ class SpecialSearch extends SpecialPage {
                                $thumb = $img->transform( array( 'width' => 120, 'height' => 120 ) );
                                if ( $thumb ) {
                                        $desc = $this->msg( 'parentheses' )->rawParams( $img->getShortDesc() )->escaped();
-                                       wfProfileOut( __METHOD__ );
                                        // Float doesn't seem to interact well with the bullets.
                                        // Table messes up vertical alignment of the bullets.
                                        // Bullets are therefore disabled (didn't look great anyway).
@@ -727,22 +722,20 @@ class SpecialSearch extends SpecialPage {
                                "</li>\n";
                }
 
-               wfProfileOut( __METHOD__ );
                return $html;
        }
 
        /**
         * Show results from other wikis
         *
-        * @param $matches SearchResultSet
+        * @param $matches SearchResultSet|array
         * @param $query String
         *
         * @return string
         */
        protected function showInterwiki( $matches, $query ) {
                global $wgContLang;
-               wfProfileIn( __METHOD__ );
-               $terms = $wgContLang->convertForSearchResult( $matches->termMatches() );
+               $profile = new ProfileSection( __METHOD__ );
 
                $out = "<div id='mw-search-interwiki'><div id='mw-search-interwiki-caption'>" .
                        $this->msg( 'search-interwiki-caption' )->text() . "</div>\n";
@@ -758,19 +751,27 @@ class SpecialSearch extends SpecialPage {
                        }
                }
 
-               $prev = null;
-               $result = $matches->next();
-               while ( $result ) {
-                       $out .= $this->showInterwikiHit( $result, $prev, $terms, $query, $customCaptions );
-                       $prev = $result->getInterwikiPrefix();
-                       $result = $matches->next();
+               if ( !is_array( $matches ) ) {
+                       $matches = array( $matches );
+               }
+
+               foreach ( $matches as $set ) {
+                       $prev = null;
+                       $result = $set->next();
+                       while ( $result ) {
+                               $out .= $this->showInterwikiHit( $result, $prev, $query, $customCaptions );
+                               $prev = $result->getInterwikiPrefix();
+                               $result = $set->next();
+                       }
                }
+
+
                // TODO: should support paging in a non-confusing way (not sure how though, maybe via ajax)..
                $out .= "</ul></div>\n";
 
                // convert the whole thing to desired language variant
                $out = $wgContLang->convert( $out );
-               wfProfileOut( __METHOD__ );
+
                return $out;
        }
 
@@ -779,17 +780,15 @@ class SpecialSearch extends SpecialPage {
         *
         * @param $result SearchResult
         * @param $lastInterwiki String
-        * @param $terms Array
         * @param $query String
         * @param array $customCaptions iw prefix -> caption
         *
         * @return string
         */
-       protected function showInterwikiHit( $result, $lastInterwiki, $terms, $query, $customCaptions ) {
-               wfProfileIn( __METHOD__ );
+       protected function showInterwikiHit( $result, $lastInterwiki, $query, $customCaptions ) {
+               $profile = new ProfileSection( __METHOD__ );
 
                if ( $result->isBrokenTitle() ) {
-                       wfProfileOut( __METHOD__ );
                        return "<!-- Broken link in search result -->\n";
                }
 
@@ -849,7 +848,7 @@ class SpecialSearch extends SpecialPage {
                }
 
                $out .= "<li>{$link} {$redirect}</li>\n";
-               wfProfileOut( __METHOD__ );
+
                return $out;
        }
 
@@ -868,6 +867,7 @@ class SpecialSearch extends SpecialPage {
                } else {
                        $form = '';
                        wfRunHooks( 'SpecialSearchProfileForm', array( $this, &$form, $profile, $term, $opts ) );
+
                        return $form;
                }
        }
@@ -935,11 +935,12 @@ class SpecialSearch extends SpecialPage {
                foreach ( $opts as $key => $value ) {
                        $hidden .= Html::hidden( $key, $value );
                }
+
                // Return final output
                return Xml::openElement(
-                               'fieldset',
-                               array( 'id' => 'mw-searchoptions', 'style' => 'margin:0em;' )
-                       ) .
+                       'fieldset',
+                       array( 'id' => 'mw-searchoptions', 'style' => 'margin:0em;' )
+               ) .
                        Xml::element( 'legend', null, $this->msg( 'powersearch-legend' )->text() ) .
                        Xml::tags( 'h4', null, $this->msg( 'powersearch-ns' )->parse() ) .
                        Html::element( 'div', array( 'id' => 'mw-search-togglebox' ) ) .
@@ -1095,6 +1096,7 @@ class SpecialSearch extends SpecialPage {
                        $this->msg( 'searchbutton' )->text(),
                        array( 'class' => array( 'mw-ui-button', 'mw-ui-progressive' ) )
                ) . "\n";
+
                return $out . $this->didYouMeanHtml;
        }
 
@@ -1145,6 +1147,7 @@ class SpecialSearch extends SpecialPage {
                if ( count( $p ) > 1 ) {
                        return $wgContLang->getNsIndex( $p[0] ) == NS_FILE;
                }
+
                return false;
        }
 
@@ -1162,6 +1165,7 @@ class SpecialSearch extends SpecialPage {
                if ( count( $p ) > 1 ) {
                        return $p[0] == $allkeyword;
                }
+
                return false;
        }
 
@@ -1175,6 +1179,7 @@ class SpecialSearch extends SpecialPage {
                        $this->searchEngine = $this->searchEngineType ?
                                SearchEngine::create( $this->searchEngineType ) : SearchEngine::create();
                }
+
                return $this->searchEngine;
        }