Merge "Make update.php file executable"
[lhc/web/wiklou.git] / includes / specials / SpecialSearch.php
index ec8d754..2713a5f 100644 (file)
@@ -41,13 +41,13 @@ class SpecialSearch extends SpecialPage {
        /** @var SearchEngine Search engine */
        protected $searchEngine;
 
-       /** @var String Search engine type, if not default */
+       /** @var string Search engine type, if not default */
        protected $searchEngineType;
 
-       /** @var Array For links */
+       /** @var array For links */
        protected $extraParams = array();
 
-       /** @var String No idea, apparently used by some other classes */
+       /** @var string No idea, apparently used by some other classes */
        protected $mPrefix;
 
        /**
@@ -74,7 +74,7 @@ class SpecialSearch extends SpecialPage {
        /**
         * Entry point
         *
-        * @param string $par or null
+        * @param string $par
         */
        public function execute( $par ) {
                $this->setHeaders();
@@ -162,7 +162,7 @@ class SpecialSearch extends SpecialPage {
        /**
         * If an exact title match can be found, jump straight ahead to it.
         *
-        * @param $term String
+        * @param string $term
         */
        public function goResult( $term ) {
                $this->setupPage( $term );
@@ -177,11 +177,6 @@ class SpecialSearch extends SpecialPage {
                # If there's an exact or very near match, jump right there.
                $title = SearchEngine::getNearMatch( $term );
 
-               if ( !wfRunHooks( 'SpecialSearchGo', array( &$title, &$term ) ) ) {
-                       # Hook requested termination
-                       return;
-               }
-
                if ( !is_null( $title ) ) {
                        $this->getOutput()->redirect( $title->getFullURL() );
 
@@ -205,7 +200,7 @@ class SpecialSearch extends SpecialPage {
        }
 
        /**
-        * @param $term String
+        * @param string $term
         */
        public function showResults( $term ) {
                global $wgDisableTextSearch, $wgSearchForwardUrl, $wgContLang, $wgScript;
@@ -231,7 +226,11 @@ class SpecialSearch extends SpecialPage {
                                $out->addHTML(
                                        Xml::openElement( 'fieldset' ) .
                                        Xml::element( 'legend', null, $this->msg( 'search-external' )->text() ) .
-                                       Xml::element( 'p', array( 'class' => 'mw-searchdisabled' ), $this->msg( 'searchdisabled' )->text() ) .
+                                       Xml::element(
+                                               'p',
+                                               array( 'class' => 'mw-searchdisabled' ),
+                                               $this->msg( 'searchdisabled' )->text()
+                                       ) .
                                        $this->msg( 'googlesearch' )->rawParams(
                                                htmlspecialchars( $term ),
                                                'UTF-8',
@@ -264,8 +263,6 @@ class SpecialSearch extends SpecialPage {
 
                // did you mean... suggestions
                if ( $showSuggestion && $textMatches && !$textStatus && $textMatches->hasSuggestion() ) {
-                       $st = SpecialPage::getTitleFor( 'Search' );
-
                        # mirror Go/Search behavior of original request ..
                        $didYouMeanParams = array( 'search' => $textMatches->getSuggestionQuery() );
 
@@ -285,13 +282,14 @@ class SpecialSearch extends SpecialPage {
                        }
 
                        $suggestLink = Linker::linkKnown(
-                               $st,
+                               $this->getPageTitle(),
                                $suggestionSnippet,
                                array(),
                                $stParams
                        );
 
-                       $this->didYouMeanHtml = '<div class="searchdidyoumean">' . $this->msg( 'search-suggest' )->rawParams( $suggestLink )->text() . '</div>';
+                       $this->didYouMeanHtml = '<div class="searchdidyoumean">'
+                               . $this->msg( 'search-suggest' )->rawParams( $suggestLink )->text() . '</div>';
                }
 
                if ( !wfRunHooks( 'SpecialSearchResultsPrepend', array( $this, $out, $term ) ) ) {
@@ -365,14 +363,19 @@ class SpecialSearch extends SpecialPage {
                $out->addHtml( "<div class='searchresults'>" );
 
                // prev/next links
+               $prevnext = null;
                if ( $num || $this->offset ) {
                        // Show the create link ahead
                        $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
-                       );
-                       //$out->addHTML( "<p class='mw-search-pager-top'>{$prevnext}</p>\n" );
+                       if ( $totalRes > $this->limit || $this->offset ) {
+                               $prevnext = $this->getLanguage()->viewPrevNext(
+                                       $this->getPageTitle(),
+                                       $this->offset,
+                                       $this->limit,
+                                       $this->powerSearchOptions() + array( 'search' => $term ),
+                                       max( $titleMatchesNum, $textMatchesNum ) < $this->limit
+                               );
+                       }
                        wfRunHooks( 'SpecialSearchResults', array( $term, &$titleMatches, &$textMatches ) );
                } else {
                        wfRunHooks( 'SpecialSearchNoResults', array( $term ) );
@@ -391,10 +394,8 @@ class SpecialSearch extends SpecialPage {
                        if ( $numTextMatches > 0 && $numTitleMatches > 0 ) {
                                // if no title matches the heading is redundant
                                $out->wrapWikiMsg( "==$1==\n", 'textmatches' );
-                       } elseif ( $totalRes == 0 ) {
-                               # Don't show the 'no text matches' if we received title matches
-                               # $out->wrapWikiMsg( "==$1==\n", 'notextmatches' );
                        }
+
                        // show interwiki results if any
                        if ( $textMatches->hasInterwikiResults() ) {
                                $out->addHTML( $this->showInterwiki( $textMatches->getInterwikiResults(), $term ) );
@@ -418,17 +419,16 @@ class SpecialSearch extends SpecialPage {
                }
                $out->addHtml( "</div>" );
 
-               if ( $num || $this->offset ) {
+               if ( $prevnext ) {
                        $out->addHTML( "<p class='mw-search-pager-bottom'>{$prevnext}</p>\n" );
                }
-               wfRunHooks( 'SpecialSearchResultsAppend', array( $this, $out, $term ) );
        }
 
        /**
-        * @param $title 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
+        * @param null|SearchResultSet $titleMatches Results from title search
+        * @param null|SearchResultSet $textMatches  Results from text search
         */
        protected function showCreateLink( $title, $num, $titleMatches, $textMatches ) {
                // show direct page/create link if applicable
@@ -452,7 +452,11 @@ class SpecialSearch extends SpecialPage {
                } else {
                        $messageName = 'searchmenu-new-nocreate';
                }
-               $params = array( $messageName, wfEscapeWikiText( $title->getPrefixedText() ), Message::numParam( $num ) );
+               $params = array(
+                       $messageName,
+                       wfEscapeWikiText( $title->getPrefixedText() ),
+                       Message::numParam( $num )
+               );
                wfRunHooks( 'SpecialSearchCreateLink', array( $title, &$params ) );
 
                // Extensions using the hook might still return an empty $messageName
@@ -465,7 +469,7 @@ class SpecialSearch extends SpecialPage {
        }
 
        /**
-        * @param $term string
+        * @param string $term
         */
        protected function setupPage( $term ) {
                # Should advanced UI be used?
@@ -486,8 +490,8 @@ class SpecialSearch extends SpecialPage {
         * Extract "power search" namespace settings from the request object,
         * returning a list of index numbers to search.
         *
-        * @param $request WebRequest
-        * @return Array
+        * @param WebRequest $request
+        * @return array
         */
        protected function powerSearch( &$request ) {
                $arr = array();
@@ -503,7 +507,7 @@ class SpecialSearch extends SpecialPage {
        /**
         * Reconstruct the 'power search' options for links
         *
-        * @return Array
+        * @return array
         */
        protected function powerSearchOptions() {
                $opt = array();
@@ -521,7 +525,7 @@ class SpecialSearch extends SpecialPage {
        /**
         * Show whole set of results
         *
-        * @param $matches SearchResultSet
+        * @param SearchResultSet $matches
         *
         * @return string
         */
@@ -548,8 +552,8 @@ class SpecialSearch extends SpecialPage {
        /**
         * Format a single hit result
         *
-        * @param $result SearchResult
-        * @param array $terms terms to highlight
+        * @param SearchResult $result
+        * @param array $terms Terms to highlight
         *
         * @return string
         */
@@ -557,7 +561,7 @@ class SpecialSearch extends SpecialPage {
                $profile = new ProfileSection( __METHOD__ );
 
                if ( $result->isBrokenTitle() ) {
-                       return "<!-- Broken link in search result -->\n";
+                       return '';
                }
 
                $title = $result->getTitle();
@@ -589,7 +593,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() ) {
-                       return "<!-- missing page " . htmlspecialchars( $title->getPrefixedText() ) . "-->\n";
+                       return '';
                }
 
                // format redirects / relevant sections
@@ -657,7 +661,6 @@ class SpecialSearch extends SpecialPage {
                // link to related articles if supported
                $related = '';
                if ( $result->hasRelated() ) {
-                       $st = SpecialPage::getTitleFor( 'Search' );
                        $stParams = array_merge(
                                $this->powerSearchOptions(),
                                array(
@@ -668,7 +671,7 @@ class SpecialSearch extends SpecialPage {
                        );
 
                        $related = ' -- ' . Linker::linkKnown(
-                               $st,
+                               $this->getPageTitle(),
                                $this->msg( 'search-relatedarticle' )->text(),
                                array(),
                                $stParams
@@ -717,7 +720,8 @@ class SpecialSearch extends SpecialPage {
                        &$score, &$size, &$date, &$related,
                        &$html
                ) ) ) {
-                       $html = "<li><div class='mw-search-result-heading'>{$link} {$redirect} {$section} {$fileMatch}</div> {$extract}\n" .
+                       $html = "<li><div class='mw-search-result-heading'>" .
+                               "{$link} {$redirect} {$section} {$fileMatch}</div> {$extract}\n" .
                                "<div class='mw-search-result-data'>{$score}{$size} - {$date}{$related}</div>" .
                                "</li>\n";
                }
@@ -728,8 +732,8 @@ class SpecialSearch extends SpecialPage {
        /**
         * Show results from other wikis
         *
-        * @param $matches SearchResultSet|array
-        * @param $query String
+        * @param SearchResultSet|array $matches
+        * @param string $query
         *
         * @return string
         */
@@ -743,7 +747,8 @@ class SpecialSearch extends SpecialPage {
 
                // work out custom project captions
                $customCaptions = array();
-               $customLines = explode( "\n", $this->msg( 'search-interwiki-custom' )->text() ); // format per line <iwprefix>:<caption>
+               // format per line <iwprefix>:<caption>
+               $customLines = explode( "\n", $this->msg( 'search-interwiki-custom' )->text() );
                foreach ( $customLines as $line ) {
                        $parts = explode( ":", $line, 2 );
                        if ( count( $parts ) == 2 ) { // validate line
@@ -765,8 +770,7 @@ class SpecialSearch extends SpecialPage {
                        }
                }
 
-
-               // TODO: should support paging in a non-confusing way (not sure how though, maybe via ajax)..
+               // @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
@@ -778,9 +782,9 @@ class SpecialSearch extends SpecialPage {
        /**
         * Show single interwiki link
         *
-        * @param $result SearchResult
-        * @param $lastInterwiki String
-        * @param $query String
+        * @param SearchResult $result
+        * @param string $lastInterwiki
+        * @param string $query
         * @param array $customCaptions iw prefix -> caption
         *
         * @return string
@@ -789,7 +793,7 @@ class SpecialSearch extends SpecialPage {
                $profile = new ProfileSection( __METHOD__ );
 
                if ( $result->isBrokenTitle() ) {
-                       return "<!-- Broken link in search result -->\n";
+                       return '';
                }
 
                $title = $result->getTitle();
@@ -853,9 +857,9 @@ class SpecialSearch extends SpecialPage {
        }
 
        /**
-        * @param $profile
-        * @param $term
-        * @return String
+        * @param string $profile
+        * @param string $term
+        * @return string
         */
        protected function getProfileForm( $profile, $term ) {
                // Hidden stuff
@@ -875,9 +879,9 @@ class SpecialSearch extends SpecialPage {
        /**
         * Generates the power search box at [[Special:Search]]
         *
-        * @param string $term search term
-        * @param $opts array
-        * @return String: HTML form
+        * @param string $term Search term
+        * @param array $opts
+        * @return string HTML form
         */
        protected function powerSearchBox( $term, $opts ) {
                global $wgContLang;
@@ -1004,9 +1008,9 @@ class SpecialSearch extends SpecialPage {
        }
 
        /**
-        * @param $term
-        * @param $resultsShown
-        * @param $totalNum
+        * @param string $term
+        * @param int $resultsShown
+        * @param int $totalNum
         * @return string
         */
        protected function formHeader( $term, $resultsShown, $totalNum ) {
@@ -1078,7 +1082,7 @@ class SpecialSearch extends SpecialPage {
        }
 
        /**
-        * @param $term string
+        * @param string $term
         * @return string
         */
        protected function shortDialog( $term ) {
@@ -1103,12 +1107,12 @@ class SpecialSearch extends SpecialPage {
        /**
         * Make a search link with some target namespaces
         *
-        * @param $term String
-        * @param array $namespaces ignored
-        * @param string $label link's text
-        * @param string $tooltip link's tooltip
-        * @param array $params query string parameters
-        * @return String: HTML fragment
+        * @param string $term
+        * @param array $namespaces Ignored
+        * @param string $label Link's text
+        * @param string $tooltip Link's tooltip
+        * @param array $params Query string parameters
+        * @return string HTML fragment
         */
        protected function makeSearchLink( $term, $namespaces, $label, $tooltip, $params = array() ) {
                $opt = $params;
@@ -1137,8 +1141,8 @@ class SpecialSearch extends SpecialPage {
        /**
         * Check if query starts with image: prefix
         *
-        * @param string $term the string to check
-        * @return Boolean
+        * @param string $term The string to check
+        * @return bool
         */
        protected function startsWithImage( $term ) {
                global $wgContLang;
@@ -1154,8 +1158,8 @@ class SpecialSearch extends SpecialPage {
        /**
         * Check if query starts with all: prefix
         *
-        * @param string $term the string to check
-        * @return Boolean
+        * @param string $term The string to check
+        * @return bool
         */
        protected function startsWithAll( $term ) {
 
@@ -1205,8 +1209,8 @@ class SpecialSearch extends SpecialPage {
         * user navigates search results.
         * @since 1.18
         *
-        * @param $key
-        * @param $value
+        * @param string $key
+        * @param mixed $value
         */
        public function setExtraParam( $key, $value ) {
                $this->extraParams[$key] = $value;