Merge "API: Fix list=allusers with multiple values for augroup"
[lhc/web/wiklou.git] / includes / specials / SpecialSearch.php
index 6419a57..adc248e 100644 (file)
@@ -96,6 +96,16 @@ class SpecialSearch extends SpecialPage {
                $search = str_replace( "\n", " ", $request->getText( 'search', $titleParam ) );
 
                $this->load();
+               if ( !is_null( $request->getVal( 'nsRemember' ) ) ) {
+                       $this->saveNamespaces();
+                       // Remove the token from the URL to prevent the user from inadvertently
+                       // exposing it (e.g. by pasting it into a public wiki page) or undoing
+                       // later settings changes (e.g. by reloading the page).
+                       $query = $request->getValues();
+                       unset( $query['title'], $query['nsRemember'] );
+                       $out->redirect( $this->getPageTitle()->getFullURL( $query ) );
+                       return;
+               }
 
                $this->searchEngineType = $request->getVal( 'srbackend' );
 
@@ -209,7 +219,6 @@ class SpecialSearch extends SpecialPage {
                $search = $this->getSearchEngine();
                $search->setLimitOffset( $this->limit, $this->offset );
                $search->setNamespaces( $this->namespaces );
-               $this->saveNamespaces();
                $search->prefix = $this->mPrefix;
                $term = $search->transformSearchTerm( $term );
 
@@ -358,10 +367,8 @@ class SpecialSearch extends SpecialPage {
                                        $this->limit + $this->offset >= $totalRes
                                );
                        }
-                       wfRunHooks( 'SpecialSearchResults', array( $term, &$titleMatches, &$textMatches ) );
-               } else {
-                       wfRunHooks( 'SpecialSearchNoResults', array( $term ) );
                }
+               wfRunHooks( 'SpecialSearchResults', array( $term, &$titleMatches, &$textMatches ) );
 
                $out->parserOptions()->setEditSection( false );
                if ( $titleMatches ) {
@@ -516,9 +523,8 @@ class SpecialSearch extends SpecialPage {
                $request = $this->getRequest();
 
                if ( $user->isLoggedIn() &&
-                       !is_null( $request->getVal( 'nsRemember' ) ) &&
                        $user->matchEditToken(
-                               $request->getVal( 'nsToken' ),
+                               $request->getVal( 'nsRemember' ),
                                'searchnamespace',
                                $request
                        )
@@ -528,7 +534,7 @@ class SpecialSearch extends SpecialPage {
                        foreach ( MWNamespace::getValidNamespaces() as $n ) {
                                $user->setOption( 'searchNs' . $n, false );
                        }
-                       // The request parameters include all the namespaces we just searched.
+                       // The request parameters include all the namespaces to be searched.
                        // Even if they're the same as an existing profile, they're not eaten.
                        foreach ( $this->namespaces as $n ) {
                                $user->setOption( 'searchNs' . $n, true );
@@ -667,26 +673,6 @@ class SpecialSearch extends SpecialPage {
 
                $date = $lang->userTimeAndDate( $timestamp, $this->getUser() );
 
-               // link to related articles if supported
-               $related = '';
-               if ( $result->hasRelated() ) {
-                       $stParams = array_merge(
-                               $this->powerSearchOptions(),
-                               array(
-                                       'search' => $this->msg( 'searchrelated' )->inContentLanguage()->text() .
-                                               ':' . $title->getPrefixedText(),
-                                       'fulltext' => $this->msg( 'search' )->text()
-                               )
-                       );
-
-                       $related = ' -- ' . Linker::linkKnown(
-                               $this->getPageTitle(),
-                               $this->msg( 'search-relatedarticle' )->text(),
-                               array(),
-                               $stParams
-                       );
-               }
-
                $fileMatch = '';
                // Include a thumbnail for media files...
                if ( $title->getNamespace() == NS_FILE ) {
@@ -712,7 +698,7 @@ class SpecialSearch extends SpecialPage {
                                                '<td style="vertical-align: top;">' .
                                                "{$link} {$redirect} {$section} {$fileMatch}" .
                                                $extract .
-                                               "<div class='mw-search-result-data'>{$desc} - {$date}{$related}</div>" .
+                                               "<div class='mw-search-result-data'>{$desc} - {$date}</div>" .
                                                '</td>' .
                                                '</tr>' .
                                                '</table>' .
@@ -732,7 +718,7 @@ class SpecialSearch extends SpecialPage {
                ) ) ) {
                        $html = "<li><div class='mw-search-result-heading'>" .
                                "{$link} {$redirect} {$section} {$fileMatch}</div> {$extract}\n" .
-                               "<div class='mw-search-result-data'>{$size} - {$date}{$related}</div>" .
+                               "<div class='mw-search-result-data'>{$size} - {$date}</div>" .
                                "</li>\n";
                }
 
@@ -932,18 +918,17 @@ class SpecialSearch extends SpecialPage {
                $remember = '';
                $user = $this->getUser();
                if ( $user->isLoggedIn() ) {
-                       $remember .= Html::hidden(
-                               'nsToken',
-                               $user->getEditToken(
-                                       'searchnamespace',
-                                       $this->getRequest()
-                               )
-                       ) .
-                       Xml::checkLabel(
+                       $remember .= Xml::checkLabel(
                                wfMessage( 'powersearch-remember' )->text(),
                                'nsRemember',
                                'mw-search-powersearch-remember',
-                               false
+                               false,
+                               // The token goes here rather than in a hidden field so it
+                               // is only sent when necessary (not every form submission).
+                               array( 'value' => $user->getEditToken(
+                                       'searchnamespace',
+                                       $this->getRequest()
+                               ) )
                        );
                }
 
@@ -951,7 +936,7 @@ class SpecialSearch extends SpecialPage {
                return Xml::openElement( 'fieldset', array( 'id' => 'mw-searchoptions' ) ) .
                        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' ) ) .
+                       Xml::element( 'div', array( 'id' => 'mw-search-togglebox' ), '', false ) .
                        Xml::element( 'div', array( 'class' => 'divider' ), '', false ) .
                        implode( Xml::element( 'div', array( 'class' => 'divider' ), '', false ), $showSections ) .
                        $hidden .
@@ -1090,9 +1075,8 @@ class SpecialSearch extends SpecialPage {
 
                // Results-info
                if ( $totalNum > 0 && $this->offset < $totalNum ) {
-                       $top = $this->msg( 'showingresultsheader' )
+                       $top = $this->msg( 'search-showingresults' )
                                ->numParams( $this->offset + 1, $this->offset + $resultsShown, $totalNum )
-                               ->params( wfEscapeWikiText( $term ) )
                                ->numParams( $resultsShown )
                                ->parse();
                        $out .= Xml::tags( 'div', array( 'class' => 'results-info' ), $top ) .