MediaWiki
1.30.0
|
This class encapsulates "magic words" such as "#redirect", NOTOC, etc. More...
Public Member Functions | |
__construct ( $id=0, $syn=[], $cs=false) | |
#- 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... | |
Static Public Member Functions | |
static | clearCache () |
Clear the self::$mObjects variable For use in parser tests. More... | |
static & | get ( $id) |
Factory: creates an object representing an ID. More... | |
static | getCacheTTL ( $id) |
Allow external reads of TTL array. More... | |
static | getDoubleUnderscoreArray () |
Get a MagicWordArray of double-underscore entities. More... | |
static | getSubstIDs () |
Get an array of parser substitution modifier IDs. More... | |
static | getVariableIDs () |
Get an array of parser variable IDs. More... | |
Public Attributes | |
bool | $mCaseSensitive |
int | $mId |
#- More... | |
array | $mSynonyms |
Static Public Attributes | |
static | $mCacheTTLs |
static | $mDoubleUnderscoreArray = null |
static | $mDoubleUnderscoreIDs |
static | $mObjects = [] |
static | $mSubstIDs |
static | $mVariableIDs |
static | $mVariableIDsInitialised = false |
Private Attributes | |
string | $mBaseRegex = '' |
bool | $mFound = false |
bool | $mModified = false |
string | $mRegex = '' |
string | $mRegexStart = '' |
string | $mRegexStartToEnd = '' |
string | $mVariableRegex = '' |
string | $mVariableStartToEndRegex = '' |
This class encapsulates "magic words" such as "#redirect", NOTOC, etc.
Possible future improvements:
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 are also Parser variables, add a MagicWordwgVariableIDs hook. Use string keys.
Definition at line 59 of file MagicWord.php.
MagicWord::__construct | ( | $id = 0 , |
|
$syn = [] , |
|||
$cs = false |
|||
) |
MagicWord::addToArray | ( | & | $array, |
$value | |||
) |
Adds all the synonyms of this MagicWord to an array, to allow quick lookup in a list of magic words.
array | &$array | |
string | $value |
Definition at line 656 of file MagicWord.php.
References $value, $wgContLang, as, and global.
|
static |
Clear the self::$mObjects variable For use in parser tests.
Definition at line 320 of file MagicWord.php.
Referenced by ExtraParserTest\setUp(), and WikitextContentHandlerTest\testMakeRedirectContent().
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 376 of file MagicWord.php.
|
static |
Factory: creates an object representing an ID.
int | $id |
Definition at line 258 of file MagicWord.php.
Referenced by MagicWordArray\getBaseRegex(), MagicWordArray\getHash(), WikiEditorHooks\getMagicWords(), WikitextContent\getRedirectTargetAndText(), WikitextContentHandler\makeRedirectContent(), CoreParserFunctions\matchAgainstMagicword(), DoubleRedirectJob\run(), ExtParserFunctions\switchObj(), and JavaScriptContentTest\testMatchMagicWord().
MagicWord::getBaseRegex | ( | ) |
regex without the slashes and what not
Definition at line 445 of file MagicWord.php.
References $mBaseRegex, and initRegex().
|
static |
Allow external reads of TTL array.
int | $id |
Definition at line 295 of file MagicWord.php.
|
static |
Get a MagicWordArray of double-underscore entities.
Definition at line 308 of file MagicWord.php.
References $mDoubleUnderscoreArray, and Hooks\run().
Referenced by InfoAction\pageInfo().
MagicWord::getId | ( | ) |
MagicWord::getRegex | ( | ) |
Gets a regex representing matching the word.
Definition at line 393 of file MagicWord.php.
References $mRegex, and initRegex().
Referenced by match(), matchAndRemove(), and replace().
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 407 of file MagicWord.php.
References initRegex().
MagicWord::getRegexStart | ( | ) |
Gets a regex matching the word, if it is at the string start.
Definition at line 420 of file MagicWord.php.
References $mRegexStart, and initRegex().
Referenced by matchStart(), and matchStartAndRemove().
MagicWord::getRegexStartToEnd | ( | ) |
Gets a regex matching the word from start to end of a string.
Definition at line 433 of file MagicWord.php.
References $mRegexStartToEnd, and initRegex().
Referenced by matchStartToEnd().
|
static |
Get an array of parser substitution modifier IDs.
Definition at line 285 of file MagicWord.php.
References $mSubstIDs.
MagicWord::getSynonym | ( | $i | ) |
Accesses the synonym list directly.
int | $i |
Definition at line 628 of file MagicWord.php.
MagicWord::getSynonyms | ( | ) |
|
static |
Get an array of parser variable IDs.
Definition at line 272 of file MagicWord.php.
References $mVariableIDs, and Hooks\run().
MagicWord::getVariableRegex | ( | ) |
Matches the word, where $1 is a wildcard.
Definition at line 602 of file MagicWord.php.
References $mVariableRegex, and initRegex().
Referenced by substituteCallback().
MagicWord::getVariableStartToEndRegex | ( | ) |
Matches the entire string, where $1 is a wildcard.
Definition at line 614 of file MagicWord.php.
References $mVariableStartToEndRegex, and initRegex().
Referenced by matchVariableStartToEnd().
MagicWord::getWasModified | ( | ) |
Returns true if the last call to replace() or substituteCallback() returned a modified text, otherwise false.
Definition at line 645 of file MagicWord.php.
References $mModified.
MagicWord::initRegex | ( | ) |
Preliminary initialisation.
Definition at line 344 of file MagicWord.php.
References $mSynonyms, and as.
Referenced by getBaseRegex(), getRegex(), getRegexCase(), getRegexStart(), getRegexStartToEnd(), getVariableRegex(), and getVariableStartToEndRegex().
MagicWord::isCaseSensitive | ( | ) |
MagicWord::load | ( | $id | ) |
Initialises this object with an ID.
int | $id |
MWException |
Definition at line 330 of file MagicWord.php.
References $wgContLang, and global.
MagicWord::match | ( | $text | ) |
Returns true if the text contains the word.
string | $text |
Definition at line 459 of file MagicWord.php.
References getRegex().
Referenced by WikitextContent\matchMagicWord().
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 525 of file MagicWord.php.
References $mFound, and getRegex().
MagicWord::matchStart | ( | $text | ) |
Returns true if the text starts with the word.
string | $text |
Definition at line 470 of file MagicWord.php.
References getRegexStart().
MagicWord::matchStartAndRemove | ( | & | $text | ) |
string | &$text |
Definition at line 540 of file MagicWord.php.
References $mFound, and getRegexStart().
MagicWord::matchStartToEnd | ( | $text | ) |
Returns true if the text matched the word.
string | $text |
Definition at line 482 of file MagicWord.php.
References getRegexStartToEnd().
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 496 of file MagicWord.php.
References $matches, captcha-old\count, and getVariableStartToEndRegex().
MagicWord::pregRemoveAndRecord | ( | ) |
MagicWord::replace | ( | $replacement, | |
$subject, | |||
$limit = -1 |
|||
) |
Replaces the word with something else.
string | $replacement | |
string | $subject | |
int | $limit |
Definition at line 570 of file MagicWord.php.
References $res, StringUtils\escapeRegexReplacement(), and getRegex().
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 591 of file MagicWord.php.
References $res, and getVariableRegex().
|
private |
Definition at line 81 of file MagicWord.php.
Referenced by getBaseRegex().
|
static |
Definition at line 178 of file MagicWord.php.
bool MagicWord::$mCaseSensitive |
Definition at line 69 of file MagicWord.php.
Referenced by isCaseSensitive().
|
static |
Definition at line 241 of file MagicWord.php.
Referenced by getDoubleUnderscoreArray().
|
static |
Definition at line 219 of file MagicWord.php.
|
private |
Definition at line 93 of file MagicWord.php.
Referenced by matchAndRemove(), and matchStartAndRemove().
int MagicWord::$mId |
|
private |
Definition at line 90 of file MagicWord.php.
Referenced by getWasModified().
|
static |
Definition at line 240 of file MagicWord.php.
|
private |
Definition at line 72 of file MagicWord.php.
Referenced by getRegex().
|
private |
Definition at line 75 of file MagicWord.php.
Referenced by getRegexStart().
|
private |
Definition at line 78 of file MagicWord.php.
Referenced by getRegexStartToEnd().
|
static |
Definition at line 235 of file MagicWord.php.
Referenced by getSubstIDs().
array MagicWord::$mSynonyms |
Definition at line 66 of file MagicWord.php.
Referenced by getSynonyms(), and initRegex().
|
static |
Definition at line 96 of file MagicWord.php.
Referenced by getVariableIDs().
|
static |
Definition at line 95 of file MagicWord.php.
|
private |
Definition at line 84 of file MagicWord.php.
Referenced by getVariableRegex().
|
private |
Definition at line 87 of file MagicWord.php.
Referenced by getVariableStartToEndRegex().