MediaWiki  master
SearchHighlighter Class Reference

Highlight bits of wikitext. More...

Public Member Functions

 __construct ($cleanupWikitext=true)
 
 caseCallback ($matches)
 Do manual case conversion for non-ascii chars. More...
 
 extract ($text, $start, $end, &$posStart=null, &$posEnd=null)
 Extract part of the text from start to end, but by not chopping up words. More...
 
 highlightNone ($text, $contextlines, $contextchars)
 Returns the first few lines of the text. More...
 
 highlightSimple ($text, $terms, $contextlines, $contextchars)
 Simple & fast snippet extraction, but gives completely unrelevant snippets. More...
 
 highlightText ($text, $terms, $contextlines, $contextchars)
 Wikitext highlighting when $wgAdvancedSearchHighlighting = true. More...
 
 linkReplace ($matches)
 callback to replace [[target|caption]] kind of links, if the target is category or image, leave it More...
 
 position ($text, $point, $offset=0)
 Find a nonletter near a point (index) in the text. More...
 
 process ($pattern, $extracts, &$linesleft, &$contextchars, &$out, &$offsets)
 Search extracts for a pattern, and return snippets. More...
 
 removeWiki ($text)
 Basic wikitext removal. More...
 
 splitAndAdd (&$extracts, &$count, $text)
 Split text into lines and add it to extracts array. More...
 

Protected Attributes

 $mCleanWikitext = true
 

Detailed Description

Highlight bits of wikitext.

Definition at line 29 of file SearchHighlighter.php.

Constructor & Destructor Documentation

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

Definition at line 36 of file SearchHighlighter.php.

Member Function Documentation

SearchHighlighter::caseCallback (   $matches)

Do manual case conversion for non-ascii chars.

Parameters
array$matches
Returns
string

Definition at line 314 of file SearchHighlighter.php.

References $matches, $wgContLang, and global.

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

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

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

Definition at line 333 of file SearchHighlighter.php.

References position().

Referenced by highlightText(), and process().

SearchHighlighter::highlightNone (   $text,
  $contextlines,
  $contextchars 
)

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

SearchHighlighter::highlightSimple (   $text,
  $terms,
  $contextlines,
  $contextchars 
)

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

Used when $wgAdvancedSearchHighlighting is false.

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

Definition at line 504 of file SearchHighlighter.php.

References $line, $lines, $pre, $wgContLang, as, and global.

SearchHighlighter::highlightText (   $text,
  $terms,
  $contextlines,
  $contextchars 
)

Wikitext highlighting when $wgAdvancedSearchHighlighting = true.

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

Definition at line 50 of file SearchHighlighter.php.

References $key, $last, $line, $matches, $term, $wgContLang, as, extract(), global, NS_FILE, process(), and splitAndAdd().

SearchHighlighter::linkReplace (   $matches)

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

References $matches, $wgContLang, global, NS_CATEGORY, and NS_FILE.

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

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

References $s.

Referenced by extract().

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

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
Access:
protected

Definition at line 406 of file SearchHighlighter.php.

References $line, $out, as, and extract().

Referenced by highlightText().

SearchHighlighter::removeWiki (   $text)

Basic wikitext removal.

Access:
protected
Parameters
string$text
Returns
mixed

Definition at line 449 of file SearchHighlighter.php.

References Sanitizer\escapeHtmlAllowEntities().

Referenced by splitAndAdd().

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

Split text into lines and add it to extracts array.

Parameters
array$extractsIndex -> $line
int$count
string$text

Definition at line 298 of file SearchHighlighter.php.

References $line, as, and removeWiki().

Referenced by highlightText().

Member Data Documentation

SearchHighlighter::$mCleanWikitext = true
protected

Definition at line 30 of file SearchHighlighter.php.


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