101 'currentmonthnamegen',
102 'currentmonthabbrev',
161 'numberofactiveusers',
179 'currentmonth' => 86400,
180 'currentmonth1' => 86400,
181 'currentmonthname' => 86400,
182 'currentmonthnamegen' => 86400,
183 'currentmonthabbrev' => 86400,
184 'currentday' => 3600,
185 'currentday2' => 3600,
186 'currentdayname' => 3600,
187 'currentyear' => 86400,
188 'currenttime' => 3600,
189 'currenthour' => 3600,
190 'localmonth' => 86400,
191 'localmonth1' => 86400,
192 'localmonthname' => 86400,
193 'localmonthnamegen' => 86400,
194 'localmonthabbrev' => 86400,
197 'localdayname' => 3600,
198 'localyear' => 86400,
201 'numberofarticles' => 3600,
202 'numberoffiles' => 3600,
203 'numberofedits' => 3600,
204 'currentweek' => 3600,
205 'currentdow' => 3600,
208 'numberofusers' => 3600,
209 'numberofactiveusers' => 3600,
210 'numberofpages' => 3600,
211 'currentversion' => 86400,
212 'currenttimestamp' => 3600,
213 'localtimestamp' => 3600,
214 'pagesinnamespace' => 3600,
215 'numberofadmins' => 3600,
216 'numberingroup' => 3600,
247 $this->mSynonyms = (
array)$syn;
248 $this->mCaseSensitive = $cs;
258 public static function &
get( $id ) {
259 if ( !isset( self::$mObjects[$id] ) ) {
262 self::$mObjects[$id] = $mw;
264 return self::$mObjects[$id];
273 if ( !self::$mVariableIDsInitialised ) {
275 Hooks::run(
'MagicWordwgVariableIDs', [ &self::$mVariableIDs ] );
276 self::$mVariableIDsInitialised =
true;
296 if ( array_key_exists( $id, self::$mCacheTTLs ) ) {
297 return self::$mCacheTTLs[$id];
309 if ( is_null( self::$mDoubleUnderscoreArray ) ) {
310 Hooks::run(
'GetDoubleUnderscoreIDs', [ &self::$mDoubleUnderscoreIDs ] );
311 self::$mDoubleUnderscoreArray =
new MagicWordArray( self::$mDoubleUnderscoreIDs );
321 self::$mObjects = [];
334 if ( !$this->mSynonyms ) {
335 $this->mSynonyms = [
'brionmademeputthishere' ];
336 throw new MWException(
"Error: invalid magic word '$id'" );
348 usort( $synonyms, [ $this,
'compareStringLength' ] );
351 foreach ( $synonyms as $synonym ) {
353 $escSyn[] = preg_quote( $synonym,
'/' );
355 $this->mBaseRegex = implode(
'|', $escSyn );
357 $case = $this->mCaseSensitive ?
'' :
'iu';
358 $this->mRegex =
"/{$this->mBaseRegex}/{$case}";
359 $this->mRegexStart =
"/^(?:{$this->mBaseRegex})/{$case}";
360 $this->mRegexStartToEnd =
"/^(?:{$this->mBaseRegex})$/{$case}";
361 $this->mVariableRegex = str_replace(
"\\$1",
"(.*?)", $this->mRegex );
362 $this->mVariableStartToEndRegex = str_replace(
"\\$1",
"(.*?)",
363 "/^(?:{$this->mBaseRegex})$/{$case}" );
381 } elseif ( $l1 > $l2 ) {
394 if ( $this->mRegex ==
'' ) {
408 if ( $this->mRegex ===
'' ) {
412 return $this->mCaseSensitive ?
'' :
'iu';
421 if ( $this->mRegex ==
'' ) {
434 if ( $this->mRegexStartToEnd ==
'' ) {
446 if ( $this->mRegex ==
'' ) {
460 return (
bool)preg_match( $this->
getRegex(), $text );
499 if ( $matchcount == 0 ) {
502 # multiple matched parts (variable match); some will be empty because of
503 # synonyms. The variable will be the second non-empty one so remove any
504 # blank elements and re-sort the indices.
526 $this->mFound =
false;
527 $text = preg_replace_callback(
529 [ $this,
'pregRemoveAndRecord' ],
541 $this->mFound =
false;
542 $text = preg_replace_callback(
544 [ $this,
'pregRemoveAndRecord' ],
557 $this->mFound =
true;
570 public function replace( $replacement, $subject, $limit = -1 ) {
577 $this->mModified =
$res !== $subject;
593 $this->mModified =
$res !== $text;
603 if ( $this->mVariableRegex ==
'' ) {
615 if ( $this->mVariableStartToEndRegex ==
'' ) {
629 return $this->mSynonyms[$i];
658 foreach ( $this->mSynonyms as $syn ) {
Class for handling an array of magic words.
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.
static $mDoubleUnderscoreIDs
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.
static $mVariableIDsInitialised
static clearCache()
Clear the self::$mObjects variable For use in parser tests.
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 $mDoubleUnderscoreArray
static getSubstIDs()
Get an array of parser substitution modifier IDs.
__construct( $id=0, $syn=[], $cs=false)
#-
pregRemoveAndRecord()
Used in matchAndRemove()
matchAndRemove(&$text)
Returns true if the text matches the word, and alters the input string, removing all instances of the...
static escapeRegexReplacement( $string)
Escape a string to make it suitable for inclusion in a preg_replace() replacement parameter.
this class mediates it Skin Encapsulates a look and feel for the wiki All of the functions that render HTML and make choices about how to render it are here and are called from various other places when and is meant to be subclassed with other skins that may override some of its functions The User object contains a reference to a and so rather than having a global skin object we just rely on the global User and get the skin with $wgUser and also has some character encoding functions and other locale stuff The current user interface language is instantiated as and the local content language as $wgContLang
the array() calling protocol came about after MediaWiki 1.4rc1.