MediaWiki REL1_33
|
This class encapsulates "magic words" such as "#redirect", NOTOC, etc. More...
Public Member Functions | |
__construct ( $id=null, $syn=[], $cs=false, Language $contLang=null) | |
#- | |
addToArray (&$array, $value) | |
Adds all the synonyms of this MagicWord to an array, to allow quick lookup in a list of magic words. | |
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. | |
getBaseRegex () | |
regex without the slashes and what not | |
getId () | |
getRegex () | |
Gets a regex representing matching the word. | |
getRegexCase () | |
Gets the regexp case modifier to use, i.e. | |
getRegexStart () | |
Gets a regex matching the word, if it is at the string start. | |
getRegexStartToEnd () | |
Gets a regex matching the word from start to end of a string. | |
getSynonym ( $i) | |
Accesses the synonym list directly. | |
getSynonyms () | |
getVariableRegex () | |
Matches the word, where $1 is a wildcard. | |
getVariableStartToEndRegex () | |
Matches the entire string, where $1 is a wildcard. | |
getWasModified () | |
Returns true if the last call to replace() or substituteCallback() returned a modified text, otherwise false. | |
initRegex () | |
Preliminary initialisation. | |
isCaseSensitive () | |
load ( $id) | |
Initialises this object with an ID. | |
match ( $text) | |
Returns true if the text contains the word. | |
matchAndRemove (&$text) | |
Returns true if the text matches the word, and alters the input string, removing all instances of the word. | |
matchStart ( $text) | |
Returns true if the text starts with the word. | |
matchStartAndRemove (&$text) | |
matchStartToEnd ( $text) | |
Returns true if the text matched the word. | |
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. | |
pregRemoveAndRecord () | |
Used in matchAndRemove() | |
replace ( $replacement, $subject, $limit=-1) | |
Replaces the word with something else. | |
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. | |
Static Public Member Functions | |
static | get ( $id) |
Factory: creates an object representing an ID. | |
static | getCacheTTL ( $id) |
Allow external reads of TTL array. | |
static | getDoubleUnderscoreArray () |
Get a MagicWordArray of double-underscore entities. | |
static | getSubstIDs () |
Get an array of parser substitution modifier IDs. | |
static | getVariableIDs () |
Get an array of parser variable IDs. | |
Public Attributes | |
bool | $mCaseSensitive |
string | $mId |
#- | |
string[] | $mSynonyms |
Private Attributes | |
Language | $contLang |
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.
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 57 of file MagicWord.php.
#-
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 108 of file MagicWord.php.
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 501 of file MagicWord.php.
References $value.
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 227 of file MagicWord.php.
References and().
|
static |
Factory: creates an object representing an ID.
string | $id | The internal name of the magic word |
Definition at line 127 of file MagicWord.php.
References wfDeprecated().
Referenced by WikiEditorHooks\getMagicWords().
MagicWord::getBaseRegex | ( | ) |
regex without the slashes and what not
Definition at line 290 of file MagicWord.php.
References $mBaseRegex, and initRegex().
|
static |
Allow external reads of TTL array.
string | $id |
Definition at line 160 of file MagicWord.php.
References wfDeprecated().
|
static |
Get a MagicWordArray of double-underscore entities.
Definition at line 171 of file MagicWord.php.
References wfDeprecated().
MagicWord::getId | ( | ) |
MagicWord::getRegex | ( | ) |
Gets a regex representing matching the word.
Definition at line 238 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 252 of file MagicWord.php.
References initRegex().
MagicWord::getRegexStart | ( | ) |
Gets a regex matching the word, if it is at the string start.
Definition at line 265 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 278 of file MagicWord.php.
References $mRegexStartToEnd, and initRegex().
Referenced by matchStartToEnd().
|
static |
Get an array of parser substitution modifier IDs.
Definition at line 148 of file MagicWord.php.
References wfDeprecated().
MagicWord::getSynonym | ( | $i | ) |
Accesses the synonym list directly.
int | $i |
Definition at line 473 of file MagicWord.php.
References and().
MagicWord::getSynonyms | ( | ) |
|
static |
Get an array of parser variable IDs.
Definition at line 138 of file MagicWord.php.
References wfDeprecated().
MagicWord::getVariableRegex | ( | ) |
Matches the word, where $1 is a wildcard.
Definition at line 447 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 459 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 490 of file MagicWord.php.
References $mModified.
MagicWord::initRegex | ( | ) |
Preliminary initialisation.
Definition at line 195 of file MagicWord.php.
References $mSynonyms, and and().
Referenced by getBaseRegex(), getRegex(), getRegexCase(), getRegexStart(), getRegexStartToEnd(), getVariableRegex(), and getVariableStartToEndRegex().
MagicWord::isCaseSensitive | ( | ) |
MagicWord::load | ( | $id | ) |
Initialises this object with an ID.
string | $id |
MWException |
Definition at line 182 of file MagicWord.php.
MagicWord::match | ( | $text | ) |
Returns true if the text contains the word.
string | $text |
Definition at line 304 of file MagicWord.php.
References and(), and getRegex().
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 370 of file MagicWord.php.
References $mFound, and(), and getRegex().
MagicWord::matchStart | ( | $text | ) |
Returns true if the text starts with the word.
string | $text |
Definition at line 315 of file MagicWord.php.
References and(), and getRegexStart().
MagicWord::matchStartAndRemove | ( | & | $text | ) |
string | &$text |
Definition at line 385 of file MagicWord.php.
References $mFound, and(), and getRegexStart().
MagicWord::matchStartToEnd | ( | $text | ) |
Returns true if the text matched the word.
string | $text |
Definition at line 327 of file MagicWord.php.
References and(), and 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 341 of file MagicWord.php.
References $matches, and(), 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 415 of file MagicWord.php.
References $res, and(), 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 436 of file MagicWord.php.
References $res, and(), and getVariableRegex().
|
private |
Definition at line 94 of file MagicWord.php.
Referenced by __construct().
|
private |
Definition at line 79 of file MagicWord.php.
Referenced by getBaseRegex().
bool MagicWord::$mCaseSensitive |
Definition at line 67 of file MagicWord.php.
Referenced by isCaseSensitive().
|
private |
Definition at line 91 of file MagicWord.php.
Referenced by matchAndRemove(), and matchStartAndRemove().
string MagicWord::$mId |
|
private |
Definition at line 88 of file MagicWord.php.
Referenced by getWasModified().
|
private |
Definition at line 70 of file MagicWord.php.
Referenced by getRegex().
|
private |
Definition at line 73 of file MagicWord.php.
Referenced by getRegexStart().
|
private |
Definition at line 76 of file MagicWord.php.
Referenced by getRegexStartToEnd().
string [] MagicWord::$mSynonyms |
Definition at line 64 of file MagicWord.php.
Referenced by getSynonyms(), and initRegex().
|
private |
Definition at line 82 of file MagicWord.php.
Referenced by getVariableRegex().
|
private |
Definition at line 85 of file MagicWord.php.
Referenced by getVariableStartToEndRegex().