MediaWiki master
MediaWiki\Parser\MagicWordArray Class Reference

Class for handling an array of magic words. More...

Public Member Functions

 __construct ( $names=[], MagicWordFactory $factory=null)
 
 add ( $name)
 Add a magic word by name.
 
 getBaseRegex (bool $capture=true, string $delimiter='/')
 Get the base regex.
 
 getHash ()
 Get a 2-d hashtable for this array.
 
 getNames ()
 
 matchAndRemove (&$text)
 Return an associative array for all items that match.
 
 matchStartAndRemove (&$text)
 Return the ID of the magic word at the start of $text, and remove the prefix from $text.
 
 matchStartToEnd ( $text)
 Match some text, without parameter capture.
 
 matchVariableStartToEnd ( $text)
 Match some text, with parameter capture.
 

Public Attributes

string[] $names = []
 

Detailed Description

Class for handling an array of magic words.

See docs/magicword.md.

Since
1.11

Definition at line 35 of file MagicWordArray.php.

Constructor & Destructor Documentation

◆ __construct()

MediaWiki\Parser\MagicWordArray::__construct ( $names = [],
MagicWordFactory $factory = null )
Parameters
string[]$names
MagicWordFactory | null$factory

Definition at line 54 of file MagicWordArray.php.

References MediaWiki\Parser\MagicWordArray\$names, and MediaWiki\MediaWikiServices\getInstance().

Member Function Documentation

◆ add()

MediaWiki\Parser\MagicWordArray::add ( $name)

Add a magic word by name.

Parameters
string$name

Definition at line 64 of file MagicWordArray.php.

◆ getBaseRegex()

MediaWiki\Parser\MagicWordArray::getBaseRegex ( bool $capture = true,
string $delimiter = '/' )

Get the base regex.

Access: internal
For use in {
See also
Parser} only
Parameters
bool$captureSet to false to suppress the capture groups, which can cause unexpected conflicts when this regexp is embedded in other regexps with similar constructs.
string$delimiterThe delimiter which will be used for the eventual regexp.
Returns
array<int,string>

Definition at line 102 of file MagicWordArray.php.

◆ getHash()

MediaWiki\Parser\MagicWordArray::getHash ( )

Get a 2-d hashtable for this array.

Returns
array<int,array<string,string>>

Definition at line 74 of file MagicWordArray.php.

◆ getNames()

MediaWiki\Parser\MagicWordArray::getNames ( )
Since
1.20
Returns
string[]

Definition at line 194 of file MagicWordArray.php.

◆ matchAndRemove()

MediaWiki\Parser\MagicWordArray::matchAndRemove ( & $text)

Return an associative array for all items that match.

Cannot be used for magic words with parameters. Removes the matched items from the input string (passed by reference)

See also
MagicWord::matchAndRemove
Parameters
string&$text
Returns
array<string,false> Keyed by magic word ID

Definition at line 272 of file MagicWordArray.php.

◆ matchStartAndRemove()

MediaWiki\Parser\MagicWordArray::matchStartAndRemove ( & $text)

Return the ID of the magic word at the start of $text, and remove the prefix from $text.

Does not match parameters.

See also
MagicWord::matchStartAndRemove
Parameters
string&$textUnmodified if no match is found.
Returns
string|false False if no match is found.

Definition at line 325 of file MagicWordArray.php.

◆ matchStartToEnd()

MediaWiki\Parser\MagicWordArray::matchStartToEnd ( $text)

Match some text, without parameter capture.

See also
MagicWord::matchStartToEnd
Parameters
string$text
Returns
string|false The magic word name, or false if there was no capture

Definition at line 253 of file MagicWordArray.php.

◆ matchVariableStartToEnd()

MediaWiki\Parser\MagicWordArray::matchVariableStartToEnd ( $text)

Match some text, with parameter capture.

Parameters
string$text
Returns
(string|false)[] Magic word name in the first element and the parameter in the second element. Both elements are false if there was no match.

Definition at line 235 of file MagicWordArray.php.

Member Data Documentation

◆ $names

string [] MediaWiki\Parser\MagicWordArray::$names = []

Definition at line 38 of file MagicWordArray.php.

Referenced by MediaWiki\Parser\MagicWordArray\__construct().


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