MediaWiki
REL1_19
|
This class encapsulates "magic words" such as #redirect, __NOTOC__, etc. More...
Public Member Functions | |
__construct ($id=0, $syn=array(), $cs=false) | |
#@- | |
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. | |
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) | |
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. | |
replaceMultiple ($magicarr, $subject, &$result) | |
$magicarr is an associative array of (magic word ID => replacement) This method uses the php feature to do several replacements at the same time, thereby gaining some efficiency. | |
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 | clearCache () |
Clear the self::$mObjects variable For use in parser tests. | |
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 | |
$mBaseRegex = '' | |
$mCaseSensitive | |
$mFound = false | |
$mId | |
#@+ | |
$mModified = false | |
$mRegex = '' | |
$mRegexStart = '' | |
$mSynonyms | |
$mVariableRegex = '' | |
$mVariableStartToEndRegex = '' | |
Static Public Attributes | |
static | $mCacheTTLs |
static | $mDoubleUnderscoreArray = null |
static | $mDoubleUnderscoreIDs |
static | $mObjects = array() |
static | $mSubstIDs |
static | $mVariableIDs |
static | $mVariableIDsInitialised = false |
This class encapsulates "magic words" such as #redirect, __NOTOC__, etc.
if (MagicWord::get( 'redirect' )->match( $text ) ) { // some code }
Possible future improvements: * Simultaneous searching for a number of magic words * MagicWord::$mObjects in shared memory
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[].
$magicWords = array(); $magicWords['en'] = array( 'magicwordkey' => array( 0, 'case_insensitive_magic_word' ), 'magicwordkey2' => array( 1, 'CASE_sensitive_magic_word2' ), );
For magic words which are also Parser variables, add a MagicWordwgVariableIDs hook. Use string keys.
Definition at line 46 of file MagicWord.php.
MagicWord::__construct | ( | $ | id = 0 , |
$ | syn = array() , |
||
$ | cs = false |
||
) |
#@-
Definition at line 203 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.
$array | |
$value |
Definition at line 599 of file MagicWord.php.
References $wgContLang.
static MagicWord::clearCache | ( | ) | [static] |
Clear the self::$mObjects variable For use in parser tests.
Definition at line 277 of file MagicWord.php.
Referenced by NewParserTest\setupGlobals(), and ParserTest\setupGlobals().
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.
$s1 | string |
$s2 | string |
Definition at line 333 of file MagicWord.php.
static& MagicWord::get | ( | $ | id | ) | [static] |
Factory: creates an object representing an ID.
$id |
Definition at line 216 of file MagicWord.php.
Referenced by Parser\braceSubstitution(), Parser\cleanSig(), Parser\doDoubleUnderscore(), MagicWordArray\getBaseRegex(), MagicWordArray\getHash(), CoreParserFunctions\isRaw(), SpecialMergeHistory\merge(), Title\moveToInternal(), Title\newFromRedirectInternal(), Parser\renderImageGallery(), replaceMultiple(), DoubleRedirectJob\run(), and Parser\setFunctionHook().
regex without the slashes and what not
Definition at line 388 of file MagicWord.php.
References initRegex().
static MagicWord::getCacheTTL | ( | $ | id | ) | [static] |
Allow external reads of TTL array.
$id | int |
Definition at line 253 of file MagicWord.php.
Referenced by Parser\braceSubstitution().
static MagicWord::getDoubleUnderscoreArray | ( | ) | [static] |
Get a MagicWordArray of double-underscore entities.
Definition at line 266 of file MagicWord.php.
References $mDoubleUnderscoreArray.
Referenced by Parser\doDoubleUnderscore().
MagicWord::getId | ( | ) |
Definition at line 616 of file MagicWord.php.
Gets a regex representing matching the word.
Definition at line 350 of file MagicWord.php.
References initRegex().
Referenced by match(), matchAndRemove(), and replace().
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 364 of file MagicWord.php.
References initRegex().
Gets a regex matching the word, if it is at the string start.
Definition at line 376 of file MagicWord.php.
References initRegex().
Referenced by matchStart(), and matchStartAndRemove().
static MagicWord::getSubstIDs | ( | ) | [static] |
Get an array of parser substitution modifier IDs.
Definition at line 243 of file MagicWord.php.
References $mSubstIDs.
Referenced by Parser\initialiseVariables().
MagicWord::getSynonym | ( | $ | i | ) |
Accesses the synonym list directly.
$i | int |
Definition at line 545 of file MagicWord.php.
Definition at line 552 of file MagicWord.php.
static MagicWord::getVariableIDs | ( | ) | [static] |
Get an array of parser variable IDs.
Definition at line 230 of file MagicWord.php.
References $mVariableIDs, and wfRunHooks().
Referenced by Parser\initialiseVariables().
Matches the word, where $1 is a wildcard.
Definition at line 519 of file MagicWord.php.
References initRegex().
Referenced by substituteCallback().
Matches the entire string, where $1 is a wildcard.
Definition at line 531 of file MagicWord.php.
References initRegex().
Referenced by matchVariableStartToEnd().
Returns true if the last call to replace() or substituteCallback() returned a modified text, otherwise false.
Definition at line 562 of file MagicWord.php.
Preliminary initialisation.
Definition at line 303 of file MagicWord.php.
Referenced by getBaseRegex(), getRegex(), getRegexCase(), getRegexStart(), getVariableRegex(), and getVariableStartToEndRegex().
Definition at line 609 of file MagicWord.php.
MagicWord::load | ( | $ | id | ) |
Initialises this object with an ID.
$id |
Definition at line 286 of file MagicWord.php.
References $wgContLang, wfDebugLog(), wfProfileIn(), and wfProfileOut().
MagicWord::match | ( | $ | text | ) |
Returns true if the text contains the word.
$text | string |
Definition at line 402 of file MagicWord.php.
References getRegex().
MagicWord::matchAndRemove | ( | &$ | text | ) |
Returns true if the text matches the word, and alters the input string, removing all instances of the word.
$text | string |
Definition at line 457 of file MagicWord.php.
References getRegex().
MagicWord::matchStart | ( | $ | text | ) |
Returns true if the text starts with the word.
$text | string |
Definition at line 413 of file MagicWord.php.
References getRegexStart().
MagicWord::matchStartAndRemove | ( | &$ | text | ) |
$text |
Definition at line 467 of file MagicWord.php.
References getRegexStart().
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.
$text | string |
Definition at line 427 of file MagicWord.php.
References $matches, and getVariableStartToEndRegex().
MagicWord::replace | ( | $ | replacement, |
$ | subject, | ||
$ | limit = -1 |
||
) |
Replaces the word with something else.
$replacement | |
$subject | |
$limit | int |
Definition at line 492 of file MagicWord.php.
References $limit, $res, StringUtils\escapeRegexReplacement(), and getRegex().
MagicWord::replaceMultiple | ( | $ | magicarr, |
$ | subject, | ||
&$ | result | ||
) |
$magicarr is an associative array of (magic word ID => replacement) This method uses the php feature to do several replacements at the same time, thereby gaining some efficiency.
The result is placed in the out variable $result. The return value is true if something was replaced.
$magicarr | |
$subject | |
$result |
Definition at line 579 of file MagicWord.php.
References $result, and get().
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.
$text | string |
$callback |
Definition at line 508 of file MagicWord.php.
References $res, and getVariableRegex().
MagicWord::$mBaseRegex = '' |
Definition at line 53 of file MagicWord.php.
MagicWord::$mCacheTTLs [static] |
Definition at line 135 of file MagicWord.php.
MagicWord::$mCaseSensitive |
Definition at line 50 of file MagicWord.php.
MagicWord::$mDoubleUnderscoreArray = null [static] |
Definition at line 199 of file MagicWord.php.
Referenced by getDoubleUnderscoreArray().
MagicWord::$mDoubleUnderscoreIDs [static] |
array( 'notoc', 'nogallery', 'forcetoc', 'toc', 'noeditsection', 'newsectionlink', 'nonewsectionlink', 'hiddencat', 'index', 'noindex', 'staticredirect', 'notitleconvert', 'nocontentconvert', )
Definition at line 177 of file MagicWord.php.
MagicWord::$mFound = false |
Definition at line 57 of file MagicWord.php.
MagicWord::$mId |
MagicWord::$mModified = false |
Definition at line 56 of file MagicWord.php.
MagicWord::$mObjects = array() [static] |
Definition at line 198 of file MagicWord.php.
MagicWord::$mRegex = '' |
Definition at line 51 of file MagicWord.php.
MagicWord::$mRegexStart = '' |
Definition at line 52 of file MagicWord.php.
MagicWord::$mSubstIDs [static] |
array( 'subst', 'safesubst', )
Definition at line 193 of file MagicWord.php.
Referenced by getSubstIDs().
MagicWord::$mSynonyms |
Definition at line 50 of file MagicWord.php.
MagicWord::$mVariableIDs [static] |
Definition at line 60 of file MagicWord.php.
Referenced by getVariableIDs().
MagicWord::$mVariableIDsInitialised = false [static] |
Definition at line 59 of file MagicWord.php.
MagicWord::$mVariableRegex = '' |
Definition at line 54 of file MagicWord.php.
MagicWord::$mVariableStartToEndRegex = '' |
Definition at line 55 of file MagicWord.php.