110 $this->mSynonyms = (
array)$syn;
111 $this->mCaseSensitive =
$cs;
115 $this->contLang = MediaWikiServices::getInstance()->getContentLanguage();
127 public static function get( $id ) {
129 return MediaWikiServices::getInstance()->getMagicWordFactory()->get( $id );
140 return MediaWikiServices::getInstance()->getMagicWordFactory()->getVariableIDs();
150 return MediaWikiServices::getInstance()->getMagicWordFactory()->getSubstIDs();
162 return MediaWikiServices::getInstance()->getMagicWordFactory()->getCacheTTL( $id );
173 return MediaWikiServices::getInstance()->getMagicWordFactory()->getDoubleUnderscoreArray();
184 $this->contLang->getMagic( $this );
185 if ( !$this->mSynonyms ) {
186 $this->mSynonyms = [
'brionmademeputthishere' ];
187 throw new MWException(
"Error: invalid magic word '$id'" );
199 usort( $synonyms, [ $this,
'compareStringLength' ] );
202 foreach ( $synonyms as $synonym ) {
206 $this->mBaseRegex = implode(
'|', $escSyn );
208 $case = $this->mCaseSensitive ?
'' :
'iu';
209 $this->mRegex =
"/{$this->mBaseRegex}/{$case}";
210 $this->mRegexStart =
"/^(?:{$this->mBaseRegex})/{$case}";
211 $this->mRegexStartToEnd =
"/^(?:{$this->mBaseRegex})$/{$case}";
212 $this->mVariableRegex =
str_replace(
"\\$1",
"(.*?)", $this->mRegex );
213 $this->mVariableStartToEndRegex =
str_replace(
"\\$1",
"(.*?)",
214 "/^(?:{$this->mBaseRegex})$/{$case}" );
239 if ( $this->mRegex ==
'' ) {
253 if ( $this->mRegex ===
'' ) {
257 return $this->mCaseSensitive ?
'' :
'iu';
266 if ( $this->mRegex ==
'' ) {
279 if ( $this->mRegexStartToEnd ==
'' ) {
291 if ( $this->mRegex ==
'' ) {
344 if ( $matchcount == 0 ) {
347 # multiple matched parts (variable match); some will be empty because of
348 # synonyms. The variable will be the second non-empty one so remove any
349 # blank elements and re-sort the indices.
371 $this->mFound =
false;
374 [ $this,
'pregRemoveAndRecord' ],
386 $this->mFound =
false;
389 [ $this,
'pregRemoveAndRecord' ],
402 $this->mFound =
true;
415 public function replace( $replacement, $subject, $limit = -1 ) {
418 StringUtils::escapeRegexReplacement( $replacement ),
422 $this->mModified =
$res !== $subject;
438 $this->mModified =
$res !== $text;
448 if ( $this->mVariableRegex ==
'' ) {
460 if ( $this->mVariableStartToEndRegex ==
'' ) {
474 return $this->mSynonyms[
$i];
502 foreach ( $this->mSynonyms as $syn ) {
503 $array[$this->contLang->lc( $syn )] =
$value;
and that you know you can do these things To protect your we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights These restrictions translate to certain responsibilities for you if you distribute copies of the or if you modify it For if you distribute copies of such a whether gratis or for a you must give the recipients all the rights that you have You must make sure that receive or can get the source code And you must show them these terms so they know their rights We protect your rights with two and(2) offer you this license which gives you legal permission to copy
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Throws a warning that $function is deprecated.
Internationalisation code.
This class encapsulates "magic words" such as "#redirect", NOTOC, etc.
getVariableRegex()
Matches the word, where $1 is a wildcard.
compareStringLength( $s1, $s2)
A comparison function that returns -1, 0 or 1 depending on whether the first string is longer,...
initRegex()
Preliminary initialisation.
getWasModified()
Returns true if the last call to replace() or substituteCallback() returned a modified text,...
replace( $replacement, $subject, $limit=-1)
Replaces the word with something else.
getVariableStartToEndRegex()
Matches the entire string, where $1 is a wildcard.
getRegexStartToEnd()
Gets a regex matching the word from start to end of a string.
__construct( $id=null, $syn=[], $cs=false, Language $contLang=null)
#-
substituteCallback( $text, $callback)
Variable handling: {{SUBST:xxx}} style words Calls back a function to determine what to replace xxx w...
getBaseRegex()
regex without the slashes and what not
static getCacheTTL( $id)
Allow external reads of TTL array.
matchStartAndRemove(&$text)
static getVariableIDs()
Get an array of parser variable IDs.
getRegexStart()
Gets a regex matching the word, if it is at the string start.
matchStart( $text)
Returns true if the text starts with the word.
getSynonym( $i)
Accesses the synonym list directly.
getRegex()
Gets a regex representing matching the word.
load( $id)
Initialises this object with an ID.
matchVariableStartToEnd( $text)
Returns NULL if there's no match, the value of $1 otherwise The return code is the matched string,...
getRegexCase()
Gets the regexp case modifier to use, i.e.
addToArray(&$array, $value)
Adds all the synonyms of this MagicWord to an array, to allow quick lookup in a list of magic words.
matchStartToEnd( $text)
Returns true if the text matched the word.
string $mVariableStartToEndRegex
static getDoubleUnderscoreArray()
Get a MagicWordArray of double-underscore entities.
match( $text)
Returns true if the text contains the word.
static getSubstIDs()
Get an array of parser substitution modifier IDs.
pregRemoveAndRecord()
Used in matchAndRemove()
matchAndRemove(&$text)
Returns true if the text matches the word, and alters the input string, removing all instances of the...
The wiki should then use memcached to cache various data To use multiple just add more items to the array To increase the weight of a make its entry a array("192.168.0.1:11211", 2))