Umherirrender has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/85221


Change subject: Allow passing a user to SearchEngine::getTextSnippet
......................................................................

Allow passing a user to SearchEngine::getTextSnippet

This avoids use of $wgUser

Change-Id: Iacb247d5962fe77db5a29084ece941261bf306ec
---
M includes/api/ApiQuerySearch.php
M includes/search/SearchEngine.php
M includes/specials/SpecialSearch.php
3 files changed, 11 insertions(+), 4 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/21/85221/1

diff --git a/includes/api/ApiQuerySearch.php b/includes/api/ApiQuerySearch.php
index 36b5597..abc60f6 100644
--- a/includes/api/ApiQuerySearch.php
+++ b/includes/api/ApiQuerySearch.php
@@ -125,6 +125,7 @@
                $titles = array();
                $count = 0;
                $result = $matches->next();
+               $user = $this->getUser();
 
                while ( $result ) {
                        if ( ++ $count > $limit ) {
@@ -145,7 +146,7 @@
                                ApiQueryBase::addTitleInfo( $vals, $title );
 
                                if ( isset( $prop['snippet'] ) ) {
-                                       $vals['snippet'] = 
$result->getTextSnippet( $terms );
+                                       $vals['snippet'] = 
$result->getTextSnippet( $terms, $user );
                                }
                                if ( isset( $prop['size'] ) ) {
                                        $vals['size'] = $result->getByteSize();
diff --git a/includes/search/SearchEngine.php b/includes/search/SearchEngine.php
index e5925fa..b4a25e6 100644
--- a/includes/search/SearchEngine.php
+++ b/includes/search/SearchEngine.php
@@ -874,14 +874,20 @@
 
        /**
         * @param array $terms terms to highlight
+        * @param User $user The user to use or null for $wgUser
         * @return String: highlighted text snippet, null (and not '') if not 
supported
         */
-       function getTextSnippet( $terms ) {
+       function getTextSnippet( $terms, $user = null ) {
                global $wgUser, $wgAdvancedSearchHighlighting;
+
+               if ( !$user ) {
+                       $user = $wgUser;
+               }
+
                $this->initText();
 
                // TODO: make highliter take a content object. Make 
ContentHandler a factory for SearchHighliter.
-               list( $contextlines, $contextchars ) = 
SearchEngine::userHighlightPrefs( $wgUser );
+               list( $contextlines, $contextchars ) = 
SearchEngine::userHighlightPrefs( $user );
                $h = new SearchHighlighter();
                if ( $wgAdvancedSearchHighlighting ) {
                        return $h->highlightText( $this->mText, $terms, 
$contextlines, $contextchars );
diff --git a/includes/specials/SpecialSearch.php 
b/includes/specials/SpecialSearch.php
index 8609c74..22fa8c4 100644
--- a/includes/specials/SpecialSearch.php
+++ b/includes/specials/SpecialSearch.php
@@ -633,7 +633,7 @@
                }
 
                // format text extract
-               $extract = "<div class='searchresult'>" . 
$result->getTextSnippet( $terms ) . "</div>";
+               $extract = "<div class='searchresult'>" . 
$result->getTextSnippet( $terms, $this->getUser() ) . "</div>";
 
                $lang = $this->getLanguage();
 

-- 
To view, visit https://gerrit.wikimedia.org/r/85221
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Iacb247d5962fe77db5a29084ece941261bf306ec
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Umherirrender <umherirrender_de...@web.de>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to