MediaWiki
master
|
This class encapsulates "magic words" such as "#redirect", NOTOC, etc. More...
Public Member Functions | |
__construct ( $id=null, $syn=[], $cs=false, Language $contLang=null) | |
#- More... | |
addToArray (&$array, $value) | |
Adds all the synonyms of this MagicWord to an array, to allow quick lookup in a list of magic words. More... | |
compareStringLength ( $s1, $s2) | |
A comparison function that returns -1, 0 or 1 depending on whether the first string is longer, the same length or shorter than the second string. More... | |
getBaseRegex () | |
regex without the slashes and what not More... | |
getId () | |
getRegex () | |
Gets a regex representing matching the word. More... | |
getRegexCase () | |
Gets the regexp case modifier to use, i.e. More... | |
getRegexStart () | |
Gets a regex matching the word, if it is at the string start. More... | |
getRegexStartToEnd () | |
Gets a regex matching the word from start to end of a string. More... | |
getSynonym ( $i) | |
Accesses the synonym list directly. More... | |
getSynonyms () | |
getVariableRegex () | |
Matches the word, where $1 is a wildcard. More... | |
getVariableStartToEndRegex () | |
Matches the entire string, where $1 is a wildcard. More... | |
getWasModified () | |
Returns true if the last call to replace() or substituteCallback() returned a modified text, otherwise false. More... | |
initRegex () | |
Preliminary initialisation. More... | |
isCaseSensitive () | |
load ( $id) | |
Initialises this object with an ID. More... | |
match ( $text) | |
Returns true if the text contains the word. More... | |
matchAndRemove (&$text) | |
Returns true if the text matches the word, and alters the input string, removing all instances of the word. More... | |
matchStart ( $text) | |
Returns true if the text starts with the word. More... | |
matchStartAndRemove (&$text) | |
matchStartToEnd ( $text) | |
Returns true if the text matched the word. More... | |
matchVariableStartToEnd ( $text) | |
Returns NULL if there's no match, the value of $1 otherwise The return code is the matched string, if there's no variable part in the regex and the matched variable part ($1) if there is one. More... | |
pregRemoveAndRecord () | |
Used in matchAndRemove() More... | |
replace ( $replacement, $subject, $limit=-1) | |
Replaces the word with something else. More... | |
substituteCallback ( $text, $callback) | |
Variable handling: {{SUBST:xxx}} style words Calls back a function to determine what to replace xxx with Input word must contain $1. More... | |
Public Attributes | |
bool | $mCaseSensitive |
string | $mId |
#- More... | |
string[] | $mSynonyms |
This class encapsulates "magic words" such as "#redirect", NOTOC, etc.
Please avoid reading the data out of one of these objects and then writing special case code. If possible, add another match()-like function here.
To add magic words in an extension, use $magicWords in a file listed in $wgExtensionMessagesFiles[].
For magic words which name Parser double underscore names, add a GetDoubleUnderscoreIDs hook. Use string keys.
For magic words which name Parser magic variables, add a GetMagicVariableIDs hook. Use string keys.
Definition at line 65 of file MagicWord.php.
Parser\MagicWord::__construct | ( | $id = null , |
|
$syn = [] , |
|||
$cs = false , |
|||
Language | $contLang = null |
||
) |
#-
Create a new MagicWord object
Use factory instead: MagicWordFactory::get
string | null | $id | The internal name of the magic word |
string[] | string | $syn | synonyms for the magic word |
bool | $cs | If magic word is case sensitive |
Language | null | $contLang | Content language |
Definition at line 116 of file MagicWord.php.
References MediaWiki\MediaWikiServices\getInstance().
Parser\MagicWord::addToArray | ( | & | $array, |
$value | |||
) |
Adds all the synonyms of this MagicWord to an array, to allow quick lookup in a list of magic words.
string[] | &$array | |
string | $value |
Definition at line 451 of file MagicWord.php.
Parser\MagicWord::compareStringLength | ( | $s1, | |
$s2 | |||
) |
A comparison function that returns -1, 0 or 1 depending on whether the first string is longer, the same length or shorter than the second string.
string | $s1 | |
string | $s2 |
Definition at line 177 of file MagicWord.php.
Parser\MagicWord::getBaseRegex | ( | ) |
regex without the slashes and what not
Definition at line 240 of file MagicWord.php.
References Parser\MagicWord\initRegex().
Parser\MagicWord::getId | ( | ) |
Parser\MagicWord::getRegex | ( | ) |
Gets a regex representing matching the word.
Definition at line 188 of file MagicWord.php.
References Parser\MagicWord\initRegex().
Referenced by Parser\MagicWord\match(), Parser\MagicWord\matchAndRemove(), and Parser\MagicWord\replace().
Parser\MagicWord::getRegexCase | ( | ) |
Gets the regexp case modifier to use, i.e.
i or nothing, to be used if one is using MagicWord::getBaseRegex(), otherwise it'll be included in the complete expression
Definition at line 202 of file MagicWord.php.
References Parser\MagicWord\initRegex().
Parser\MagicWord::getRegexStart | ( | ) |
Gets a regex matching the word, if it is at the string start.
Definition at line 215 of file MagicWord.php.
References Parser\MagicWord\initRegex().
Referenced by Parser\MagicWord\matchStart(), and Parser\MagicWord\matchStartAndRemove().
Parser\MagicWord::getRegexStartToEnd | ( | ) |
Gets a regex matching the word from start to end of a string.
Definition at line 228 of file MagicWord.php.
References Parser\MagicWord\initRegex().
Referenced by Parser\MagicWord\matchStartToEnd().
Parser\MagicWord::getSynonym | ( | $i | ) |
Accesses the synonym list directly.
int | $i |
Definition at line 423 of file MagicWord.php.
Parser\MagicWord::getSynonyms | ( | ) |
Definition at line 430 of file MagicWord.php.
References Parser\MagicWord\$mSynonyms.
Parser\MagicWord::getVariableRegex | ( | ) |
Matches the word, where $1 is a wildcard.
Definition at line 397 of file MagicWord.php.
References Parser\MagicWord\initRegex().
Referenced by Parser\MagicWord\substituteCallback().
Parser\MagicWord::getVariableStartToEndRegex | ( | ) |
Matches the entire string, where $1 is a wildcard.
Definition at line 409 of file MagicWord.php.
References Parser\MagicWord\initRegex().
Referenced by Parser\MagicWord\matchVariableStartToEnd().
Parser\MagicWord::getWasModified | ( | ) |
Returns true if the last call to replace() or substituteCallback() returned a modified text, otherwise false.
Definition at line 440 of file MagicWord.php.
Parser\MagicWord::initRegex | ( | ) |
Preliminary initialisation.
Definition at line 142 of file MagicWord.php.
References Parser\MagicWord\$mSynonyms.
Referenced by Parser\MagicWord\getBaseRegex(), Parser\MagicWord\getRegex(), Parser\MagicWord\getRegexCase(), Parser\MagicWord\getRegexStart(), Parser\MagicWord\getRegexStartToEnd(), Parser\MagicWord\getVariableRegex(), and Parser\MagicWord\getVariableStartToEndRegex().
Parser\MagicWord::isCaseSensitive | ( | ) |
Definition at line 460 of file MagicWord.php.
References Parser\MagicWord\$mCaseSensitive.
Parser\MagicWord::load | ( | $id | ) |
Initialises this object with an ID.
string | $id |
MWException |
Definition at line 129 of file MagicWord.php.
Parser\MagicWord::match | ( | $text | ) |
Returns true if the text contains the word.
string | $text |
Definition at line 254 of file MagicWord.php.
References Parser\MagicWord\getRegex().
Referenced by WikitextContent\matchMagicWord().
Parser\MagicWord::matchAndRemove | ( | & | $text | ) |
Returns true if the text matches the word, and alters the input string, removing all instances of the word.
string | &$text |
Definition at line 320 of file MagicWord.php.
References Parser\MagicWord\getRegex().
Parser\MagicWord::matchStart | ( | $text | ) |
Returns true if the text starts with the word.
string | $text |
Definition at line 265 of file MagicWord.php.
References Parser\MagicWord\getRegexStart().
Parser\MagicWord::matchStartAndRemove | ( | & | $text | ) |
string | &$text |
Definition at line 335 of file MagicWord.php.
References Parser\MagicWord\getRegexStart().
Parser\MagicWord::matchStartToEnd | ( | $text | ) |
Returns true if the text matched the word.
string | $text |
Definition at line 277 of file MagicWord.php.
References Parser\MagicWord\getRegexStartToEnd().
Parser\MagicWord::matchVariableStartToEnd | ( | $text | ) |
Returns NULL if there's no match, the value of $1 otherwise The return code is the matched string, if there's no variable part in the regex and the matched variable part ($1) if there is one.
string | $text |
Definition at line 291 of file MagicWord.php.
References $matches, and Parser\MagicWord\getVariableStartToEndRegex().
Parser\MagicWord::pregRemoveAndRecord | ( | ) |
Parser\MagicWord::replace | ( | $replacement, | |
$subject, | |||
$limit = -1 |
|||
) |
Replaces the word with something else.
string | $replacement | |
string | $subject | |
int | $limit |
Definition at line 365 of file MagicWord.php.
References $res, StringUtils\escapeRegexReplacement(), and Parser\MagicWord\getRegex().
Parser\MagicWord::substituteCallback | ( | $text, | |
$callback | |||
) |
Variable handling: {{SUBST:xxx}} style words Calls back a function to determine what to replace xxx with Input word must contain $1.
string | $text | |
callable | $callback |
Definition at line 386 of file MagicWord.php.
References $res, and Parser\MagicWord\getVariableRegex().
bool Parser\MagicWord::$mCaseSensitive |
Definition at line 75 of file MagicWord.php.
Referenced by Parser\MagicWord\isCaseSensitive().
string Parser\MagicWord::$mId |
string [] Parser\MagicWord::$mSynonyms |
Definition at line 72 of file MagicWord.php.
Referenced by Parser\MagicWord\getSynonyms(), and Parser\MagicWord\initRegex().