MediaWiki master
SearchHighlighter Class Reference

Highlight bits of wikitext. More...

Public Member Functions

 __construct ( $cleanupWikitext=true)
 
 highlightNone ( $text, $contextlines=self::DEFAULT_CONTEXT_LINES, $contextchars=self::DEFAULT_CONTEXT_CHARS)
 Returns the first few lines of the text.
 
 highlightSimple ( $text, $terms, $contextlines=self::DEFAULT_CONTEXT_LINES, $contextchars=self::DEFAULT_CONTEXT_CHARS)
 Simple & fast snippet extraction, but gives completely irrelevant snippets.
 
 highlightText ( $text, $terms, $contextlines=self::DEFAULT_CONTEXT_LINES, $contextchars=self::DEFAULT_CONTEXT_CHARS)
 Wikitext highlighting when $wgAdvancedSearchHighlighting = true.
 

Public Attributes

const DEFAULT_CONTEXT_CHARS = 75
 
const DEFAULT_CONTEXT_LINES = 2
 

Protected Attributes

 $mCleanWikitext = true
 

Detailed Description

Highlight bits of wikitext.

Stability: newable
Note
marked as newable in 1.35 for lack of a better alternative, but should use a factory in the future.

Definition at line 36 of file SearchHighlighter.php.

Constructor & Destructor Documentation

◆ __construct()

SearchHighlighter::__construct ( $cleanupWikitext = true)
Stability: stable
to call
Warning
If you pass false to this constructor, then the caller is responsible for HTML escaping.
Parameters
bool$cleanupWikitext

Definition at line 48 of file SearchHighlighter.php.

Member Function Documentation

◆ highlightNone()

SearchHighlighter::highlightNone ( $text,
$contextlines = self::DEFAULT_CONTEXT_LINES,
$contextchars = self::DEFAULT_CONTEXT_CHARS )

Returns the first few lines of the text.

Parameters
string$text
int$contextlinesMax number of returned lines
int$contextcharsAverage number of characters per line
Returns
string

Definition at line 584 of file SearchHighlighter.php.

◆ highlightSimple()

SearchHighlighter::highlightSimple ( $text,
$terms,
$contextlines = self::DEFAULT_CONTEXT_LINES,
$contextchars = self::DEFAULT_CONTEXT_CHARS )

Simple & fast snippet extraction, but gives completely irrelevant snippets.

Used when $wgAdvancedSearchHighlighting is false.

Parameters
string$text
string[]$termsEscaped for regex by SearchDatabase::regexTerm()
int$contextlines
int$contextchars
Returns
string

Definition at line 532 of file SearchHighlighter.php.

References $lines.

◆ highlightText()

SearchHighlighter::highlightText ( $text,
$terms,
$contextlines = self::DEFAULT_CONTEXT_LINES,
$contextchars = self::DEFAULT_CONTEXT_CHARS )

Wikitext highlighting when $wgAdvancedSearchHighlighting = true.

Parameters
string$text
string[]$termsTerms to highlight (not html escaped but regex escaped via SearchDatabase::regexTerm())
int$contextlines
int$contextchars
Returns
string

Definition at line 62 of file SearchHighlighter.php.

References $matches, and NS_FILE.

Member Data Documentation

◆ $mCleanWikitext

SearchHighlighter::$mCleanWikitext = true
protected

Definition at line 40 of file SearchHighlighter.php.

◆ DEFAULT_CONTEXT_CHARS

const SearchHighlighter::DEFAULT_CONTEXT_CHARS = 75

Definition at line 38 of file SearchHighlighter.php.

Referenced by SearchEngine\userHighlightPrefs().

◆ DEFAULT_CONTEXT_LINES

const SearchHighlighter::DEFAULT_CONTEXT_LINES = 2

Definition at line 37 of file SearchHighlighter.php.

Referenced by SearchEngine\userHighlightPrefs().


The documentation for this class was generated from the following file: