Various fixes for phan-taint-check
[lhc/web/wiklou.git] / includes / specials / SpecialSearch.php
index 78a54f5..e6d0632 100644 (file)
@@ -76,6 +76,11 @@ class SpecialSearch extends SpecialPage {
         */
        protected $fulltext;
 
+       /**
+        * @var string
+        */
+       protected $sort;
+
        /**
         * @var bool
         */
@@ -162,21 +167,7 @@ class SpecialSearch extends SpecialPage {
                                $url = str_replace( '$1', urlencode( $term ), $searchForwardUrl );
                                $out->redirect( $url );
                        } else {
-                               $out->addHTML(
-                                       "<fieldset>" .
-                                               "<legend>" .
-                                                       $this->msg( 'search-external' )->escaped() .
-                                               "</legend>" .
-                                               "<p class='mw-searchdisabled'>" .
-                                                       $this->msg( 'searchdisabled' )->escaped() .
-                                               "</p>" .
-                                               $this->msg( 'googlesearch' )->rawParams(
-                                                       htmlspecialchars( $term ),
-                                                       'UTF-8',
-                                                       $this->msg( 'searchbutton' )->escaped()
-                                               )->text() .
-                                       "</fieldset>"
-                               );
+                               $this->showGoogleSearch( $term );
                        }
 
                        return;
@@ -185,6 +176,31 @@ class SpecialSearch extends SpecialPage {
                $this->showResults( $term );
        }
 
+       /**
+        * Output a google search form if search is disabled
+        *
+        * @param string $term Search term
+        * @todo FIXME Maybe we should get rid of this raw html message at some future time
+        * @suppress SecurityCheck-XSS
+        */
+       private function showGoogleSearch( $term ) {
+               $this->getOutput()->addHTML(
+                       "<fieldset>" .
+                               "<legend>" .
+                                       $this->msg( 'search-external' )->escaped() .
+                               "</legend>" .
+                               "<p class='mw-searchdisabled'>" .
+                                       $this->msg( 'searchdisabled' )->escaped() .
+                               "</p>" .
+                               $this->msg( 'googlesearch' )->rawParams(
+                                       htmlspecialchars( $term ),
+                                       'UTF-8',
+                                       $this->msg( 'searchbutton' )->escaped()
+                               )->text() .
+                       "</fieldset>"
+               );
+       }
+
        /**
         * Set up basic search parameters from the request and user settings.
         *
@@ -198,17 +214,22 @@ class SpecialSearch extends SpecialPage {
                        $this->setExtraParam( 'prefix', $this->mPrefix );
                }
 
+               $this->sort = $request->getVal( 'sort', SearchEngine::DEFAULT_SORT );
+               if ( $this->sort !== SearchEngine::DEFAULT_SORT ) {
+                       $this->setExtraParam( 'sort', $this->sort );
+               }
+
                $user = $this->getUser();
 
                # Extract manually requested namespaces
                $nslist = $this->powerSearch( $request );
-               if ( !count( $nslist ) ) {
+               if ( $nslist === [] ) {
                        # Fallback to user preference
                        $nslist = $this->searchConfig->userNamespaces( $user );
                }
 
                $profile = null;
-               if ( !count( $nslist ) ) {
+               if ( $nslist === [] ) {
                        $profile = 'default';
                }
 
@@ -301,6 +322,7 @@ class SpecialSearch extends SpecialPage {
                $search->setFeatureData( 'rewrite', $this->runSuggestion );
                $search->setLimitOffset( $this->limit, $this->offset );
                $search->setNamespaces( $this->namespaces );
+               $search->setSort( $this->sort );
                $search->prefix = $this->mPrefix;
 
                Hooks::run( 'SpecialSearchSetupEngine', [ $this, $this->profile, $search ] );
@@ -557,9 +579,9 @@ class SpecialSearch extends SpecialPage {
                                'a',
                                [
                                        'href' => $this->getPageTitle()->getLocalURL( $params ),
-                                       'title' => $this->msg( 'search-filter-title-prefix-reset' ),
+                                       'title' => $this->msg( 'search-filter-title-prefix-reset' )->text(),
                                ],
-                               $this->msg( 'search-filter-title-prefix-reset' )
+                               $this->msg( 'search-filter-title-prefix-reset' )->text()
                        );
                        $subtitle .= ')';
                        $out->setSubtitle( $subtitle );
@@ -709,9 +731,10 @@ class SpecialSearch extends SpecialPage {
         */
        public function getSearchEngine() {
                if ( $this->searchEngine === null ) {
+                       $services = MediaWikiServices::getInstance();
                        $this->searchEngine = $this->searchEngineType ?
-                               MediaWikiServices::getInstance()->getSearchEngineFactory()->create( $this->searchEngineType ) :
-                               MediaWikiServices::getInstance()->newSearchEngine();
+                               $services->getSearchEngineFactory()->create( $this->searchEngineType ) :
+                               $services->newSearchEngine();
                }
 
                return $this->searchEngine;