Go to the documentation of this file.
110 $this->mSynonyms = (
array)$syn;
111 $this->mCaseSensitive = $cs;
115 $this->contLang = MediaWikiServices::getInstance()->getContentLanguage();
127 public static function get( $id ) {
128 return MediaWikiServices::getInstance()->getMagicWordFactory()->get( $id );
138 return MediaWikiServices::getInstance()->getMagicWordFactory()->getVariableIDs();
147 return MediaWikiServices::getInstance()->getMagicWordFactory()->getSubstIDs();
158 return MediaWikiServices::getInstance()->getMagicWordFactory()->getCacheTTL( $id );
168 return MediaWikiServices::getInstance()->getMagicWordFactory()->getDoubleUnderscoreArray();
179 $this->contLang->getMagic( $this );
180 if ( !$this->mSynonyms ) {
181 $this->mSynonyms = [
'brionmademeputthishere' ];
182 throw new MWException(
"Error: invalid magic word '$id'" );
194 usort( $synonyms, [ $this,
'compareStringLength' ] );
197 foreach ( $synonyms
as $synonym ) {
199 $escSyn[] = preg_quote( $synonym,
'/' );
201 $this->mBaseRegex = implode(
'|', $escSyn );
203 $case = $this->mCaseSensitive ?
'' :
'iu';
204 $this->mRegex =
"/{$this->mBaseRegex}/{$case}";
205 $this->mRegexStart =
"/^(?:{$this->mBaseRegex})/{$case}";
206 $this->mRegexStartToEnd =
"/^(?:{$this->mBaseRegex})$/{$case}";
207 $this->mVariableRegex = str_replace(
"\\$1",
"(.*?)", $this->mRegex );
208 $this->mVariableStartToEndRegex = str_replace(
"\\$1",
"(.*?)",
209 "/^(?:{$this->mBaseRegex})$/{$case}" );
234 if ( $this->mRegex ==
'' ) {
248 if ( $this->mRegex ===
'' ) {
252 return $this->mCaseSensitive ?
'' :
'iu';
261 if ( $this->mRegex ==
'' ) {
274 if ( $this->mRegexStartToEnd ==
'' ) {
286 if ( $this->mRegex ==
'' ) {
300 return (
bool)preg_match( $this->
getRegex(), $text );
339 if ( $matchcount == 0 ) {
342 # multiple matched parts (variable match); some will be empty because of
343 # synonyms. The variable will be the second non-empty one so remove any
344 # blank elements and re-sort the indices.
366 $this->mFound =
false;
367 $text = preg_replace_callback(
369 [ $this,
'pregRemoveAndRecord' ],
381 $this->mFound =
false;
382 $text = preg_replace_callback(
384 [ $this,
'pregRemoveAndRecord' ],
397 $this->mFound =
true;
410 public function replace( $replacement, $subject, $limit = -1 ) {
417 $this->mModified =
$res !== $subject;
433 $this->mModified =
$res !== $text;
443 if ( $this->mVariableRegex ==
'' ) {
455 if ( $this->mVariableStartToEndRegex ==
'' ) {
469 return $this->mSynonyms[$i];
497 foreach ( $this->mSynonyms
as $syn ) {
498 $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)
#-
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
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.
getWasModified()
Returns true if the last call to replace() or substituteCallback() returned a modified text,...
string $mVariableStartToEndRegex
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
pregRemoveAndRecord()
Used in matchAndRemove()
This class encapsulates "magic words" such as "#redirect", NOTOC, etc.
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))
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.
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
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.
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency MediaWikiServices
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.