MediaWiki fundraising/REL1_35
SearchHighlighter Class Reference

Highlight bits of wikitext. More...

Public Member Functions

 __construct ( $cleanupWikitext=true)
 Stable to call.
 
 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 unrelevant 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
 

Private Member Functions

 caseCallback ( $matches)
 Do manual case conversion for non-ascii chars.
 
 extract ( $text, $start, $end, &$posStart=null, &$posEnd=null)
 Extract part of the text from start to end, but by not chopping up words.
 
 linkReplace ( $matches)
 callback to replace [[target|caption]] kind of links, if the target is category or image, leave it
 
 position ( $text, $point, $offset=0)
 Find a nonletter near a point (index) in the text.
 
 process ( $pattern, $extracts, &$linesleft, &$contextchars, &$out, &$offsets)
 Search extracts for a pattern, and return snippets.
 
 removeWiki ( $text)
 Basic wikitext removal.
 
 splitAndAdd (&$extracts, &$count, $text)
 Split text into lines and add it to extracts array.
 

Detailed Description

Highlight bits of wikitext.

@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 34 of file SearchHighlighter.php.

Constructor & Destructor Documentation

◆ __construct()

SearchHighlighter::__construct ( $cleanupWikitext = true)

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 46 of file SearchHighlighter.php.

Member Function Documentation

◆ caseCallback()

SearchHighlighter::caseCallback ( $matches)
private

Do manual case conversion for non-ascii chars.

Parameters
array$matches
Returns
string

Definition at line 333 of file SearchHighlighter.php.

References $matches.

◆ extract()

SearchHighlighter::extract ( $text,
$start,
$end,
& $posStart = null,
& $posEnd = null )
private

Extract part of the text from start to end, but by not chopping up words.

Parameters
string$text
int$start
int$end
int | null&$posStart(out) actual start position
int | null&$posEnd(out) actual end position
Returns
string

Definition at line 353 of file SearchHighlighter.php.

References position().

Referenced by highlightText(), and process().

◆ 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 576 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 unrelevant 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 521 of file SearchHighlighter.php.

References $line, and $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 60 of file SearchHighlighter.php.

References $line, $matches, $wgSearchHighlightBoundaries, extract(), NS_FILE, process(), and splitAndAdd().

◆ linkReplace()

SearchHighlighter::linkReplace ( $matches)
private

callback to replace [[target|caption]] kind of links, if the target is category or image, leave it

Parameters
array$matches
Returns
string

Definition at line 495 of file SearchHighlighter.php.

References $matches, NS_CATEGORY, and NS_FILE.

◆ position()

SearchHighlighter::position ( $text,
$point,
$offset = 0 )
private

Find a nonletter near a point (index) in the text.

Parameters
string$text
int$point
int$offsetOffset to found index
Returns
int Nearest nonletter index, or beginning of utf8 char if none

Definition at line 385 of file SearchHighlighter.php.

References $s.

Referenced by extract().

◆ process()

SearchHighlighter::process ( $pattern,
$extracts,
& $linesleft,
& $contextchars,
& $out,
& $offsets )
private

Search extracts for a pattern, and return snippets.

Parameters
string$patternRegexp for matching lines
array$extractsExtracts to search
int&$linesleftNumber of extracts to make
int&$contextcharsLength of snippet
array&$outMap for highlighted snippets
array&$offsetsMap of starting points of snippets

Definition at line 425 of file SearchHighlighter.php.

References $line, and extract().

Referenced by highlightText().

◆ removeWiki()

SearchHighlighter::removeWiki ( $text)
private

Basic wikitext removal.

Parameters
string$text
Returns
mixed

Definition at line 467 of file SearchHighlighter.php.

Referenced by splitAndAdd().

◆ splitAndAdd()

SearchHighlighter::splitAndAdd ( & $extracts,
& $count,
$text )
private

Split text into lines and add it to extracts array.

Parameters
string[]&$extractsIndex -> $line
int&$count
string$text

Definition at line 317 of file SearchHighlighter.php.

References $line, and removeWiki().

Referenced by highlightText().

Member Data Documentation

◆ $mCleanWikitext

SearchHighlighter::$mCleanWikitext = true
protected

Definition at line 38 of file SearchHighlighter.php.

◆ DEFAULT_CONTEXT_CHARS

const SearchHighlighter::DEFAULT_CONTEXT_CHARS = 75

Definition at line 36 of file SearchHighlighter.php.

Referenced by SearchEngine\userHighlightPrefs().

◆ DEFAULT_CONTEXT_LINES

const SearchHighlighter::DEFAULT_CONTEXT_LINES = 2

Definition at line 35 of file SearchHighlighter.php.

Referenced by SearchEngine\userHighlightPrefs().


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