MediaWiki  1.30.0
PrefixSearch Class Reference

Handles searching prefixes of titles and finding any page names that match. More...

Inheritance diagram for PrefixSearch:

Public Member Functions

 defaultSearchBackend ( $namespaces, $search, $limit, $offset)
 Unless overridden by PrefixSearchBackend hook... More...
 
 search ( $search, $limit, $namespaces=[], $offset=0)
 Do a prefix search of titles and return a list of matching page names. More...
 
 searchWithVariants ( $search, $limit, array $namespaces, $offset=0)
 Do a prefix search for all possible variants of the prefix. More...
 

Static Public Member Functions

static titleSearch ( $search, $limit, $namespaces=[], $offset=0)
 Do a prefix search of titles and return a list of matching page names. More...
 

Protected Member Functions

 extractNamespace ( $input)
 Figure out if given input contains an explicit namespace. More...
 
 searchBackend ( $namespaces, $search, $limit, $offset)
 Do a prefix search of titles and return a list of matching page names. More...
 
 specialSearch ( $search, $limit, $offset)
 Prefix search special-case for Special: namespace. More...
 
 strings (array $strings)
 When implemented in a descendant class, receives an array of titles as strings and returns either an unmodified array or an array of Title objects corresponding to strings received. More...
 
 titles (array $titles)
 When implemented in a descendant class, receives an array of Title objects and returns either an unmodified array or an array of strings corresponding to titles passed to it. More...
 
 validateNamespaces ( $namespaces)
 Validate an array of numerical namespace indexes. More...
 

Private Member Functions

 handleResultFromHook ( $srchres, $namespaces, $search, $limit, $offset)
 

Detailed Description

Handles searching prefixes of titles and finding any page names that match.

Used largely by the OpenSearch implementation.

Deprecated:
Since 1.27, Use SearchEngine::defaultPrefixSearch or SearchEngine::completionSearch

Definition at line 30 of file PrefixSearch.php.

Member Function Documentation

◆ defaultSearchBackend()

PrefixSearch::defaultSearchBackend (   $namespaces,
  $search,
  $limit,
  $offset 
)

Unless overridden by PrefixSearchBackend hook...

This is case-sensitive (First character may be automatically capitalized by Title::secureAndSpit() later on depending on $wgCapitalLinks)

Parameters
array | null$namespacesNamespaces to search in
string$searchTerm
int$limitMax number of items to return
int$offsetNumber of items to skip
Returns
Title[] Array of Title objects

Definition at line 293 of file PrefixSearch.php.

References $dbr, $namespaces, $options, $res, $title, as, DB_REPLICA, LIST_AND, LIST_OR, Title\makeTitleSafe(), TitleArray\newFromResult(), NS_MAIN, NS_SPECIAL, specialSearch(), and wfGetDB().

Referenced by searchBackend(), and SearchEngine\simplePrefixSearch().

◆ extractNamespace()

PrefixSearch::extractNamespace (   $input)
protected

Figure out if given input contains an explicit namespace.

Parameters
string$input
Returns
false|array Array of namespace and remaining text, or false if no namespace given.

Definition at line 79 of file PrefixSearch.php.

References $input, $title, Title\newFromText(), and NS_MAIN.

Referenced by search().

◆ handleResultFromHook()

PrefixSearch::handleResultFromHook (   $srchres,
  $namespaces,
  $search,
  $limit,
  $offset 
)
private

Definition at line 189 of file PrefixSearch.php.

References $namespaces.

Referenced by searchBackend().

◆ search()

PrefixSearch::search (   $search,
  $limit,
  $namespaces = [],
  $offset = 0 
)

Do a prefix search of titles and return a list of matching page names.

Parameters
string$search
int$limit
array$namespacesUsed if query is not explicitly prefixed
int$offsetHow many results to offset from the beginning
Returns
array Array of strings or Title objects

Definition at line 55 of file PrefixSearch.php.

References $namespaces, extractNamespace(), list, Hooks\run(), searchBackend(), and validateNamespaces().

Referenced by SpecialCiteThisPage\prefixSearchSubpages(), searchWithVariants(), PrefixSearchTest\testSearch(), PrefixSearchTest\testSearchBackend(), PrefixSearchTest\testSearchWithOffset(), and titleSearch().

◆ searchBackend()

PrefixSearch::searchBackend (   $namespaces,
  $search,
  $limit,
  $offset 
)
protected

Do a prefix search of titles and return a list of matching page names.

Parameters
array$namespaces
string$search
int$limit
int$offsetHow many results to offset from the beginning
Returns
array Array of strings

Definition at line 169 of file PrefixSearch.php.

References $namespaces, captcha-old\count, defaultSearchBackend(), handleResultFromHook(), NS_FILE, NS_MEDIA, NS_SPECIAL, Hooks\run(), specialSearch(), strings(), and titles().

Referenced by search().

◆ searchWithVariants()

PrefixSearch::searchWithVariants (   $search,
  $limit,
array  $namespaces,
  $offset = 0 
)

Do a prefix search for all possible variants of the prefix.

Parameters
string$search
int$limit
array$namespaces
int$offsetHow many results to offset from the beginning
Returns
array

Definition at line 118 of file PrefixSearch.php.

References $namespaces, $wgContLang, as, captcha-old\count, global, and search().

◆ specialSearch()

PrefixSearch::specialSearch (   $search,
  $limit,
  $offset 
)
protected

Prefix search special-case for Special: namespace.

Parameters
string$searchTerm
int$limitMax number of items to return
int$offsetNumber of items to offset
Returns
array

Definition at line 209 of file PrefixSearch.php.

References $keys, $matches, $special, $wgContLang, as, captcha-old\count, SpecialPageFactory\getNames(), SpecialPageFactory\getPage(), global, Title\makeTitleSafe(), NS_SPECIAL, and use.

Referenced by defaultSearchBackend(), and searchBackend().

◆ strings()

PrefixSearch::strings ( array  $strings)
abstractprotected

When implemented in a descendant class, receives an array of titles as strings and returns either an unmodified array or an array of Title objects corresponding to strings received.

Parameters
array$strings
Returns
array

Reimplemented in StringPrefixSearch, and TitlePrefixSearch.

Referenced by searchBackend().

◆ titles()

PrefixSearch::titles ( array  $titles)
abstractprotected

When implemented in a descendant class, receives an array of Title objects and returns either an unmodified array or an array of strings corresponding to titles passed to it.

Parameters
array$titles
Returns
array

Reimplemented in StringPrefixSearch, and TitlePrefixSearch.

Referenced by searchBackend().

◆ titleSearch()

static PrefixSearch::titleSearch (   $search,
  $limit,
  $namespaces = [],
  $offset = 0 
)
static

Do a prefix search of titles and return a list of matching page names.

Deprecated:
Since 1.23, use TitlePrefixSearch or StringPrefixSearch classes
Parameters
string$search
int$limit
array$namespacesUsed if query is not explicitly prefixed
int$offsetHow many results to offset from the beginning
Returns
array Array of strings

Definition at line 41 of file PrefixSearch.php.

References $namespaces, and search().

◆ validateNamespaces()

PrefixSearch::validateNamespaces (   $namespaces)
protected

Validate an array of numerical namespace indexes.

Parameters
array$namespaces
Returns
array (default: contains only NS_MAIN)

Definition at line 349 of file PrefixSearch.php.

References $namespaces, $wgContLang, as, captcha-old\count, global, and NS_MAIN.

Referenced by search().


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