MediaWiki  1.28.0
MagicWordArray Class Reference

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

Public Member Functions

 __construct ($names=[])
 
 add ($name)
 Add a magic word by name. More...
 
 addArray ($names)
 Add a number of magic words by name. More...
 
 getBaseRegex ()
 Get the base regex. More...
 
 getHash ()
 Get a 2-d hashtable for this array. More...
 
 getNames ()
 
 getRegex ()
 Get an unanchored regex that does not match parameters. More...
 
 getRegexStart ()
 Get a regex anchored to the start of the string that does not match parameters. More...
 
 getVariableRegex ()
 Get a regex for matching variables with parameters. More...
 
 getVariableStartToEndRegex ()
 Get an anchored regex for matching variables with parameters. More...
 
 matchAndRemove (&$text)
 Returns an associative array, ID => param value, for all items that match Removes the matched items from the input string (passed by reference) More...
 
 matchStartAndRemove (&$text)
 Return the ID of the magic word at the start of $text, and remove the prefix from $text. More...
 
 matchStartToEnd ($text)
 Match some text, without parameter capture Returns the magic word name, or false if there was no capture. More...
 
 matchVariableStartToEnd ($text)
 Match some text, with parameter capture Returns an array with the magic word name in the first element and the parameter in the second element. More...
 
 parseMatch ($m)
 Parse a match array from preg_match Returns array(magic word ID, parameter value) If there is no parameter value, that element will be false. More...
 

Public Attributes

array $names = []
 

Private Attributes

 $baseRegex
 
array $hash
 
 $regex
 

Detailed Description

Class for handling an array of magic words.

Definition at line 31 of file MagicWordArray.php.

Constructor & Destructor Documentation

MagicWordArray::__construct (   $names = [])
Parameters
array$names

Definition at line 45 of file MagicWordArray.php.

References $names, and names.

Member Function Documentation

MagicWordArray::add (   $name)

Add a magic word by name.

Parameters
string$name

Definition at line 54 of file MagicWordArray.php.

References $name, and names.

MagicWordArray::addArray (   $names)

Add a number of magic words by name.

Parameters
array$names

Definition at line 64 of file MagicWordArray.php.

References names.

MagicWordArray::getBaseRegex ( )

Get the base regex.

Returns
array

Definition at line 95 of file MagicWordArray.php.

References $baseRegex, $name, as, MagicWord\get(), and names.

Referenced by getRegex(), getRegexStart(), and getVariableStartToEndRegex().

MagicWordArray::getHash ( )

Get a 2-d hashtable for this array.

Returns
array

Definition at line 73 of file MagicWordArray.php.

References $hash, $name, $wgContLang, as, MagicWord\get(), global, and names.

Referenced by matchStartToEnd().

MagicWordArray::getNames ( )
Since
1.20
Returns
array

Definition at line 181 of file MagicWordArray.php.

References $names.

MagicWordArray::getRegex ( )

Get an unanchored regex that does not match parameters.

Returns
array

Definition at line 120 of file MagicWordArray.php.

References $base, $regex, and getBaseRegex().

Referenced by getVariableRegex(), and matchAndRemove().

MagicWordArray::getRegexStart ( )

Get a regex anchored to the start of the string that does not match parameters.

Returns
array

Definition at line 148 of file MagicWordArray.php.

References $base, and getBaseRegex().

Referenced by matchStartAndRemove().

MagicWordArray::getVariableRegex ( )

Get a regex for matching variables with parameters.

Returns
string

Definition at line 139 of file MagicWordArray.php.

References getRegex().

MagicWordArray::getVariableStartToEndRegex ( )

Get an anchored regex for matching variables with parameters.

Returns
array

Definition at line 165 of file MagicWordArray.php.

References $base, and getBaseRegex().

Referenced by matchVariableStartToEnd().

MagicWordArray::matchAndRemove ( $text)

Returns an associative array, ID => param value, for all items that match Removes the matched items from the input string (passed by reference)

Parameters
string$text
Returns
array

Definition at line 267 of file MagicWordArray.php.

References $matches, $name, $regex, $res, as, getRegex(), list, and parseMatch().

MagicWordArray::matchStartAndRemove ( $text)

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

Return false if no match found and $text is not modified. Does not match parameters.

Parameters
string$text
Returns
int|bool False on failure

Definition at line 311 of file MagicWordArray.php.

References $regex, as, getRegexStart(), list, and parseMatch().

MagicWordArray::matchStartToEnd (   $text)

Match some text, without parameter capture Returns the magic word name, or false if there was no capture.

Parameters
string$text
Returns
string|bool False on failure

Definition at line 246 of file MagicWordArray.php.

References $wgContLang, getHash(), and global.

MagicWordArray::matchVariableStartToEnd (   $text)

Match some text, with parameter capture Returns an array with the magic word name in the first element and the parameter in the second element.

Both elements are false if there was no match.

Parameters
string$text
Returns
array

Definition at line 225 of file MagicWordArray.php.

References $regex, as, false, getVariableStartToEndRegex(), and parseMatch().

MagicWordArray::parseMatch (   $m)

Parse a match array from preg_match Returns array(magic word ID, parameter value) If there is no parameter value, that element will be false.

Parameters
array$m
Exceptions
MWException
Returns
array

Definition at line 195 of file MagicWordArray.php.

References $value, and list.

Referenced by matchAndRemove(), matchStartAndRemove(), and matchVariableStartToEnd().

Member Data Documentation

MagicWordArray::$baseRegex
private

Definition at line 38 of file MagicWordArray.php.

Referenced by getBaseRegex().

array MagicWordArray::$hash
private

Definition at line 36 of file MagicWordArray.php.

Referenced by getHash().

array MagicWordArray::$names = []

Definition at line 33 of file MagicWordArray.php.

Referenced by __construct(), and getNames().

MagicWordArray::$regex
private

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