Rename $t to $title in SpecialSearch
[lhc/web/wiklou.git] / includes / specials / SpecialSearch.php
index b89522d..30039d4 100644 (file)
@@ -60,11 +60,6 @@ class SpecialSearch extends SpecialPage {
         */
        protected $namespaces;
 
-       /**
-        * @var bool
-        */
-       protected $searchRedirects;
-
        /**
         * @var string
         */
@@ -159,9 +154,6 @@ class SpecialSearch extends SpecialPage {
                        }
                }
 
-               // Redirects defaults to true, but we don't know whether it was ticked of or just missing
-               $default = $request->getBool( 'profile' ) ? 0 : 1;
-               $this->searchRedirects = $request->getBool( 'redirs', $default ) ? 1 : 0;
                $this->didYouMeanHtml = ''; # html of did you mean... link
                $this->fulltext = $request->getVal( 'fulltext' );
                $this->profile = $profile;
@@ -175,34 +167,37 @@ class SpecialSearch extends SpecialPage {
        public function goResult( $term ) {
                $this->setupPage( $term );
                # Try to go to page as entered.
-               $t = Title::newFromText( $term );
+               $title = Title::newFromText( $term );
                # If the string cannot be used to create a title
-               if ( is_null( $t ) ) {
+               if ( is_null( $title ) ) {
                        $this->showResults( $term );
+
                        return;
                }
                # If there's an exact or very near match, jump right there.
-               $t = SearchEngine::getNearMatch( $term );
+               $title = SearchEngine::getNearMatch( $term );
 
-               if ( !wfRunHooks( 'SpecialSearchGo', array( &$t, &$term ) ) ) {
+               if ( !wfRunHooks( 'SpecialSearchGo', array( &$title, &$term ) ) ) {
                        # Hook requested termination
                        return;
                }
 
-               if ( !is_null( $t ) ) {
-                       $this->getOutput()->redirect( $t->getFullURL() );
+               if ( !is_null( $title ) ) {
+                       $this->getOutput()->redirect( $title->getFullURL() );
+
                        return;
                }
                # No match, generate an edit URL
-               $t = Title::newFromText( $term );
-               if ( !is_null( $t ) ) {
+               $title = Title::newFromText( $term );
+               if ( !is_null( $title ) ) {
                        global $wgGoToEdit;
-                       wfRunHooks( 'SpecialSearchNogomatch', array( &$t ) );
-                       wfDebugLog( 'nogomatch', $t->getText(), 'private' );
+                       wfRunHooks( 'SpecialSearchNogomatch', array( &$title ) );
+                       wfDebugLog( 'nogomatch', $title->getFullText(), 'private' );
 
                        # If the feature is enabled, go straight to the edit page
                        if ( $wgGoToEdit ) {
-                               $this->getOutput()->redirect( $t->getFullURL( array( 'action' => 'edit' ) ) );
+                               $this->getOutput()->redirect( $title->getFullURL( array( 'action' => 'edit' ) ) );
+
                                return;
                        }
                }
@@ -214,13 +209,11 @@ 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 );
-               $search->showRedirects = $this->searchRedirects; // BC
-               $search->setFeatureData( 'list-redirects', $this->searchRedirects );
                $search->prefix = $this->mPrefix;
                $term = $search->transformSearchTerm( $term );
 
@@ -247,12 +240,12 @@ class SpecialSearch extends SpecialPage {
                                        Xml::closeElement( 'fieldset' )
                                );
                        }
-                       wfProfileOut( __METHOD__ );
+
                        return;
                }
 
-               $t = Title::newFromText( $term );
-               $showSuggestion = $t === null || !$t->isKnown();
+               $title = Title::newFromText( $term );
+               $showSuggestion = $title === null || !$title->isKnown();
                $search->setShowSuggestion( $showSuggestion );
 
                // fetch search results
@@ -303,7 +296,6 @@ class SpecialSearch extends SpecialPage {
 
                if ( !wfRunHooks( 'SpecialSearchResultsPrepend', array( $this, $out, $term ) ) ) {
                        # Hook requested termination
-                       wfProfileOut( __METHOD__ );
                        return;
                }
 
@@ -330,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;
                }
 
@@ -339,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;
                }
 
@@ -375,7 +367,7 @@ class SpecialSearch extends SpecialPage {
                // prev/next links
                if ( $num || $this->offset ) {
                        // Show the create link ahead
-                       $this->showCreateLink( $t, $num, $titleMatches, $textMatches );
+                       $this->showCreateLink( $title, $num, $titleMatches, $textMatches );
                        $prevnext = $this->getLanguage()->viewPrevNext( $this->getPageTitle(), $this->offset, $this->limit,
                                $this->powerSearchOptions() + array( 'search' => $term ),
                                max( $titleMatchesNum, $textMatchesNum ) < $this->limit
@@ -421,7 +413,7 @@ class SpecialSearch extends SpecialPage {
                        } else {
                                $out->wrapWikiMsg( "<p class=\"mw-search-nonefound\">\n$1</p>",
                                        array( 'search-nonefound', wfEscapeWikiText( $term ) ) );
-                               $this->showCreateLink( $t, $num, $titleMatches, $textMatches );
+                               $this->showCreateLink( $title, $num, $titleMatches, $textMatches );
                        }
                }
                $out->addHtml( "</div>" );
@@ -430,37 +422,38 @@ class SpecialSearch extends SpecialPage {
                        $out->addHTML( "<p class='mw-search-pager-bottom'>{$prevnext}</p>\n" );
                }
                wfRunHooks( 'SpecialSearchResultsAppend', array( $this, $out, $term ) );
-               wfProfileOut( __METHOD__ );
        }
 
        /**
-        * @param $t Title
+        * @param $title Title
         * @param int $num The number of search results found
         * @param $titleMatches null|SearchResultSet results from title search
         * @param $textMatches null|SearchResultSet results from text search
         */
-       protected function showCreateLink( $t, $num, $titleMatches, $textMatches ) {
+       protected function showCreateLink( $title, $num, $titleMatches, $textMatches ) {
                // 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( $title ) || $title->getDBkey() === ''
+                       || ( $titleMatches !== null && $titleMatches->searchContainedSyntax() )
+                       || ( $textMatches !== null && $textMatches->searchContainedSyntax() )
+               ) {
                        // invalid title
                        // preserve the paragraph for margins etc...
                        $this->getOutput()->addHtml( '<p></p>' );
+
                        return;
                }
 
-               if ( $t->isKnown() ) {
+               if ( $title->isKnown() ) {
                        $messageName = 'searchmenu-exists';
-               } elseif ( $t->userCan( 'create', $this->getUser() ) ) {
+               } elseif ( $title->userCan( 'create', $this->getUser() ) ) {
                        $messageName = 'searchmenu-new';
                } else {
                        $messageName = 'searchmenu-new-nocreate';
                }
-               $params = array( $messageName, wfEscapeWikiText( $t->getPrefixedText() ), Message::numParam( $num ) );
-               wfRunHooks( 'SpecialSearchCreateLink', array( $t, &$params ) );
+               $params = array( $messageName, wfEscapeWikiText( $title->getPrefixedText() ), Message::numParam( $num ) );
+               wfRunHooks( 'SpecialSearchCreateLink', array( $title, &$params ) );
 
                // Extensions using the hook might still return an empty $messageName
                if ( $messageName ) {
@@ -514,7 +507,6 @@ class SpecialSearch extends SpecialPage {
         */
        protected function powerSearchOptions() {
                $opt = array();
-               $opt['redirs'] = $this->searchRedirects ? 1 : 0;
                if ( $this->profile !== 'advanced' ) {
                        $opt['profile'] = $this->profile;
                } else {
@@ -522,6 +514,7 @@ class SpecialSearch extends SpecialPage {
                                $opt['ns' . $n] = 1;
                        }
                }
+
                return $opt + $this->extraParams;
        }
 
@@ -534,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 );
@@ -553,7 +541,7 @@ class SpecialSearch extends SpecialPage {
 
                // convert the whole thing to desired language variant
                $out = $wgContLang->convert( $out );
-               wfProfileOut( __METHOD__ );
+
                return $out;
        }
 
@@ -566,14 +554,13 @@ 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";
                }
 
-               $t = $result->getTitle();
+               $title = $result->getTitle();
 
                $titleSnippet = $result->getTitleSnippet( $terms );
 
@@ -584,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,
@@ -594,8 +581,7 @@ class SpecialSearch extends SpecialPage {
                //If page content is not readable, just return the title.
                //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__ );
+               if ( !$title->userCan( 'read', $this->getUser() ) ) {
                        return "<li>{$link}</li>\n";
                }
 
@@ -603,8 +589,7 @@ 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";
+                       return "<!-- missing page " . htmlspecialchars( $title->getPrefixedText() ) . "-->\n";
                }
 
                // format redirects / relevant sections
@@ -660,8 +645,8 @@ class SpecialSearch extends SpecialPage {
                $size = $this->msg( 'search-result-size', $lang->formatSize( $byteSize ) )
                        ->numParams( $wordCount )->escaped();
 
-               if ( $t->getNamespace() == NS_CATEGORY ) {
-                       $cat = Category::newFromTitle( $t );
+               if ( $title->getNamespace() == NS_CATEGORY ) {
+                       $cat = Category::newFromTitle( $title );
                        $size = $this->msg( 'search-result-category-size' )
                                ->numParams( $cat->getPageCount(), $cat->getSubcatCount(), $cat->getFileCount() )
                                ->escaped();
@@ -677,7 +662,7 @@ class SpecialSearch extends SpecialPage {
                                $this->powerSearchOptions(),
                                array(
                                        'search' => $this->msg( 'searchrelated' )->inContentLanguage()->text() .
-                                               ':' . $t->getPrefixedText(),
+                                               ':' . $title->getPrefixedText(),
                                        'fulltext' => $this->msg( 'search' )->text()
                                )
                        );
@@ -692,9 +677,9 @@ class SpecialSearch extends SpecialPage {
 
                $fileMatch = '';
                // Include a thumbnail for media files...
-               if ( $t->getNamespace() == NS_FILE ) {
+               if ( $title->getNamespace() == NS_FILE ) {
                        $img = $result->getFile();
-                       $img = $img ?: wfFindFile( $t );
+                       $img = $img ?: wfFindFile( $title );
                        if ( $result->isFileMatch() ) {
                                $fileMatch = "<span class='searchalttitle'>" .
                                        $this->msg( 'search-file-match' )->escaped() . "</span>";
@@ -703,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).
@@ -738,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";
@@ -769,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;
        }
 
@@ -790,36 +780,34 @@ 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";
                }
 
-               $t = $result->getTitle();
+               $title = $result->getTitle();
 
-               $titleSnippet = $result->getTitleSnippet( $terms );
+               $titleSnippet = $result->getTitleSnippet();
 
                if ( $titleSnippet == '' ) {
                        $titleSnippet = null;
                }
 
                $link = Linker::linkKnown(
-                       $t,
+                       $title,
                        $titleSnippet
                );
 
                // format redirect if any
                $redirectTitle = $result->getRedirectTitle();
-               $redirectText = $result->getRedirectSnippet( $terms );
+               $redirectText = $result->getRedirectSnippet();
                $redirect = '';
                if ( !is_null( $redirectTitle ) ) {
                        if ( $redirectText == '' ) {
@@ -834,18 +822,18 @@ class SpecialSearch extends SpecialPage {
 
                $out = "";
                // display project name
-               if ( is_null( $lastInterwiki ) || $lastInterwiki != $t->getInterwiki() ) {
-                       if ( array_key_exists( $t->getInterwiki(), $customCaptions ) ) {
+               if ( is_null( $lastInterwiki ) || $lastInterwiki != $title->getInterwiki() ) {
+                       if ( array_key_exists( $title->getInterwiki(), $customCaptions ) ) {
                                // captions from 'search-interwiki-custom'
-                               $caption = $customCaptions[$t->getInterwiki()];
+                               $caption = $customCaptions[$title->getInterwiki()];
                        } else {
                                // default is to show the hostname of the other wiki which might suck
                                // if there are many wikis on one hostname
-                               $parsed = wfParseUrl( $t->getFullURL() );
+                               $parsed = wfParseUrl( $title->getFullURL() );
                                $caption = $this->msg( 'search-interwiki-default', $parsed['host'] )->text();
                        }
                        // "more results" link (special page stuff could be localized, but we might not know target lang)
-                       $searchTitle = Title::newFromText( $t->getInterwiki() . ":Special:Search" );
+                       $searchTitle = Title::newFromText( $title->getInterwiki() . ":Special:Search" );
                        $searchLink = Linker::linkKnown(
                                $searchTitle,
                                $this->msg( 'search-interwiki-more' )->text(),
@@ -860,7 +848,7 @@ class SpecialSearch extends SpecialPage {
                }
 
                $out .= "<li>{$link} {$redirect}</li>\n";
-               wfProfileOut( __METHOD__ );
+
                return $out;
        }
 
@@ -872,7 +860,6 @@ class SpecialSearch extends SpecialPage {
        protected function getProfileForm( $profile, $term ) {
                // Hidden stuff
                $opts = array();
-               $opts['redirs'] = $this->searchRedirects;
                $opts['profile'] = $this->profile;
 
                if ( $profile === 'advanced' ) {
@@ -880,6 +867,7 @@ class SpecialSearch extends SpecialPage {
                } else {
                        $form = '';
                        wfRunHooks( 'SpecialSearchProfileForm', array( $this, &$form, $profile, $term, $opts ) );
+
                        return $form;
                }
        }
@@ -941,24 +929,18 @@ class SpecialSearch extends SpecialPage {
 
                $showSections = array( 'namespaceTables' => $namespaceTables );
 
-               // Show redirects check only if backend supports it
-               if ( $this->getSearchEngine()->supports( 'list-redirects' ) ) {
-                       $showSections['redirects'] =
-                               Xml::checkLabel( $this->msg( 'powersearch-redir' )->text(), 'redirs', 'redirs', $this->searchRedirects );
-               }
-
                wfRunHooks( 'SpecialSearchPowerBox', array( &$showSections, $term, $opts ) );
 
                $hidden = '';
-               unset( $opts['redirs'] );
                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' ) ) .
@@ -1114,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;
        }
 
@@ -1132,7 +1115,6 @@ class SpecialSearch extends SpecialPage {
                foreach ( $namespaces as $n ) {
                        $opt['ns' . $n] = 1;
                }
-               $opt['redirs'] = $this->searchRedirects;
 
                $stParams = array_merge(
                        array(
@@ -1165,6 +1147,7 @@ class SpecialSearch extends SpecialPage {
                if ( count( $p ) > 1 ) {
                        return $wgContLang->getNsIndex( $p[0] ) == NS_FILE;
                }
+
                return false;
        }
 
@@ -1182,6 +1165,7 @@ class SpecialSearch extends SpecialPage {
                if ( count( $p ) > 1 ) {
                        return $p[0] == $allkeyword;
                }
+
                return false;
        }
 
@@ -1195,6 +1179,7 @@ class SpecialSearch extends SpecialPage {
                        $this->searchEngine = $this->searchEngineType ?
                                SearchEngine::create( $this->searchEngineType ) : SearchEngine::create();
                }
+
                return $this->searchEngine;
        }