Go to the documentation of this file.
110 $this->mSynonyms = (array)$syn;
111 $this->mCaseSensitive = $cs;
112 $this->contLang =
$contLang ?: MediaWikiServices::getInstance()->getContentLanguage();
123 public static function get( $id ) {
125 return MediaWikiServices::getInstance()->getMagicWordFactory()->get( $id );
136 return MediaWikiServices::getInstance()->getMagicWordFactory()->getVariableIDs();
146 return MediaWikiServices::getInstance()->getMagicWordFactory()->getSubstIDs();
158 return MediaWikiServices::getInstance()->getMagicWordFactory()->getCacheTTL( $id );
169 return MediaWikiServices::getInstance()->getMagicWordFactory()->getDoubleUnderscoreArray();
180 $this->contLang->getMagic( $this );
181 if ( !$this->mSynonyms ) {
182 $this->mSynonyms = [
'brionmademeputthishere' ];
183 throw new MWException(
"Error: invalid magic word '$id'" );
195 usort( $synonyms, [ $this,
'compareStringLength' ] );
198 foreach ( $synonyms as $synonym ) {
200 $escSyn[] = preg_quote( $synonym,
'/' );
202 $this->mBaseRegex = implode(
'|', $escSyn );
204 $case = $this->mCaseSensitive ?
'' :
'iu';
205 $this->mRegex =
"/{$this->mBaseRegex}/{$case}";
206 $this->mRegexStart =
"/^(?:{$this->mBaseRegex})/{$case}";
207 $this->mRegexStartToEnd =
"/^(?:{$this->mBaseRegex})$/{$case}";
208 $this->mVariableRegex = str_replace(
"\\$1",
"(.*?)", $this->mRegex );
209 $this->mVariableStartToEndRegex = str_replace(
"\\$1",
"(.*?)",
210 "/^(?:{$this->mBaseRegex})$/{$case}" );
235 if ( $this->mRegex ==
'' ) {
249 if ( $this->mRegex ===
'' ) {
253 return $this->mCaseSensitive ?
'' :
'iu';
262 if ( $this->mRegex ==
'' ) {
275 if ( $this->mRegexStartToEnd ==
'' ) {
287 if ( $this->mRegex ==
'' ) {
301 return (
bool)preg_match( $this->
getRegex(), $text );
340 if ( $matchcount == 0 ) {
343 # multiple matched parts (variable match); some will be empty because of
344 # synonyms. The variable will be the second non-empty one so remove any
345 # blank elements and re-sort the indices.
367 $this->mFound =
false;
368 $text = preg_replace_callback(
370 [ $this,
'pregRemoveAndRecord' ],
382 $this->mFound =
false;
383 $text = preg_replace_callback(
385 [ $this,
'pregRemoveAndRecord' ],
398 $this->mFound =
true;
411 public function replace( $replacement, $subject, $limit = -1 ) {
418 $this->mModified =
$res !== $subject;
434 $this->mModified =
$res !== $text;
444 if ( $this->mVariableRegex ==
'' ) {
456 if ( $this->mVariableStartToEndRegex ==
'' ) {
470 return $this->mSynonyms[$i];
498 foreach ( $this->mSynonyms as $syn ) {
499 $array[$this->contLang->lc( $syn )] = $value;
substituteCallback( $text, $callback)
Variable handling: {{SUBST:xxx}} style words Calls back a function to determine what to replace xxx w...
matchVariableStartToEnd( $text)
Returns NULL if there's no match, the value of $1 otherwise The return code is the matched string,...
load( $id)
Initialises this object with an ID.
getRegexStartToEnd()
Gets a regex matching the word from start to end of a string.
static escapeRegexReplacement( $string)
Escape a string to make it suitable for inclusion in a preg_replace() replacement parameter.
getRegex()
Gets a regex representing matching the word.
__construct( $id=null, $syn=[], $cs=false, Language $contLang=null)
#-
initRegex()
Preliminary initialisation.
replace( $replacement, $subject, $limit=-1)
Replaces the word with something else.
matchStartToEnd( $text)
Returns true if the text matched the word.
static getVariableIDs()
Get an array of parser variable IDs.
static getCacheTTL( $id)
Allow external reads of TTL array.
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Throws a warning that $function is deprecated.
getWasModified()
Returns true if the last call to replace() or substituteCallback() returned a modified text,...
string $mVariableStartToEndRegex
pregRemoveAndRecord()
Used in matchAndRemove()
This class encapsulates "magic words" such as "#redirect", NOTOC, etc.
getRegexStart()
Gets a regex matching the word, if it is at the string start.
getBaseRegex()
regex without the slashes and what not
matchStartAndRemove(&$text)
getVariableRegex()
Matches the word, where $1 is a wildcard.
addToArray(&$array, $value)
Adds all the synonyms of this MagicWord to an array, to allow quick lookup in a list of magic words.
static getSubstIDs()
Get an array of parser substitution modifier IDs.
matchStart( $text)
Returns true if the text starts with the word.
static getDoubleUnderscoreArray()
Get a MagicWordArray of double-underscore entities.
getRegexCase()
Gets the regexp case modifier to use, i.e.
getVariableStartToEndRegex()
Matches the entire string, where $1 is a wildcard.
getSynonym( $i)
Accesses the synonym list directly.
compareStringLength( $s1, $s2)
A comparison function that returns -1, 0 or 1 depending on whether the first string is longer,...
matchAndRemove(&$text)
Returns true if the text matches the word, and alters the input string, removing all instances of the...
match( $text)
Returns true if the text contains the word.
Internationalisation code.