Merge "SquidUpdate cleanups"
[lhc/web/wiklou.git] / includes / specials / SpecialSearch.php
index d806be3..fc7eeb1 100644 (file)
@@ -115,6 +115,7 @@ class SpecialSearch extends SpecialPage {
                        return;
                }
 
+               $out->addJsConfigVars( array( 'searchTerm' => $search ) );
                $this->searchEngineType = $request->getVal( 'srbackend' );
 
                if ( $request->getVal( 'fulltext' )
@@ -395,7 +396,7 @@ class SpecialSearch extends SpecialPage {
 
                $out->addHtml( "</div>" );
 
-               Hooks::run( 'SpecialSearchResultsAppend', array( $this, $out ) );
+               Hooks::run( 'SpecialSearchResultsAppend', array( $this, $out, $term ) );
 
        }
 
@@ -415,10 +416,7 @@ class SpecialSearch extends SpecialPage {
                        return false;
                }
 
-               // Generate a random number between 0 and 1. If the
-               // number is less than the desired percentages run it.
-               $rand = rand( 0, getrandmax() ) / getrandmax();
-               return $this->getConfig()->get( 'SearchRunSuggestedQueryPercent' ) > $rand;
+               return $this->getConfig()->get( 'SearchRunSuggestedQuery' );
        }
 
        /**
@@ -440,7 +438,7 @@ class SpecialSearch extends SpecialPage {
                        $stParams
                );
 
-               # html of did you mean... search suggestion link
+               # HTML of did you mean... search suggestion link
                return Html::rawElement(
                        'div',
                        array( 'class' => 'searchdidyoumean' ),
@@ -648,8 +646,9 @@ class SpecialSearch extends SpecialPage {
 
                $out = "<ul class='mw-search-results'>\n";
                $result = $matches->next();
+               $pos = $this->offset;
                while ( $result ) {
-                       $out .= $this->showHit( $result, $terms );
+                       $out .= $this->showHit( $result, $terms, ++$pos );
                        $result = $matches->next();
                }
                $out .= "</ul>\n";
@@ -665,10 +664,11 @@ class SpecialSearch extends SpecialPage {
         *
         * @param SearchResult $result
         * @param array $terms Terms to highlight
+        * @param int $position Position within the search results, including offset.
         *
         * @return string
         */
-       protected function showHit( $result, $terms ) {
+       protected function showHit( $result, $terms, $position ) {
 
                if ( $result->isBrokenTitle() ) {
                        return '';
@@ -689,12 +689,13 @@ class SpecialSearch extends SpecialPage {
 
                $link = Linker::linkKnown(
                        $link_t,
-                       $titleSnippet
+                       $titleSnippet,
+                       array( 'data-serp-pos' => $position ) // HTML attributes
                );
 
-               //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 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 ( !$title->userCan( 'read', $this->getUser() ) ) {
                        return "<li>{$link}</li>\n";
                }