|
MediaWiki master
|
This class encapsulates "magic words" such as "#redirect", NOTOC, etc. More...
Public Member Functions | |
| __construct ( $id=null, $syn=[], $cs=false, ?Language $contentLanguage=null) | |
| getBaseRegex () | |
| Get the middle of {. | |
| getId () | |
| getRegex () | |
| Create a regex to match the magic word in wikitext. | |
| getRegexCase () | |
| Get the regexp case modifier ("iu" or empty string). | |
| getRegexStart () | |
| Create a regex to match the word at the start of a line in wikitext. | |
| getRegexStartToEnd () | |
| Create a regex to match the word as the only thing on a line of wikitext. | |
| getSynonym ( $i) | |
| Get one of the synonyms. | |
| getSynonyms () | |
| Get full list of synonyms. | |
| isCaseSensitive () | |
| load ( $id) | |
| Load synonym data from {. | |
| match ( $text) | |
| Check if given wikitext contains the magic word. | |
| matchAndRemove (&$text) | |
| Remove any matches of this magic word from a given text. | |
| matchStartAndRemove (&$text) | |
| matchStartToEnd ( $text) | |
| Check if given wikitext contains the word as the only thing on a line. | |
| replace ( $replacement, $subject, $limit=-1) | |
| Replace any matches of this word with something else. | |
Public Attributes | |
| bool | $mCaseSensitive |
| string null | $mId |
| Potentially null for a short time before {. | |
| array string[] | $mSynonyms |
This class encapsulates "magic words" such as "#redirect", NOTOC, etc.
See docs/magicword.md.
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[].
For magic words which name Parser double underscore names, add a GetDoubleUnderscoreIDs hook. Use string keys.
For magic words which name Parser magic variables, add a GetMagicVariableIDs hook. Use string keys.
Definition at line 51 of file MagicWord.php.
| MediaWiki\Parser\MagicWord::__construct | ( | $id = null, | |
| $syn = [], | |||
| $cs = false, | |||
| ?Language | $contentLanguage = null ) |
| string | null | $id | Preload internal name of the magic word |
| string[] | string | $syn | Preload synonyms for the magic word |
| bool | $cs | If magic word is case sensitive |
| Language | null | $contentLanguage |
Definition at line 73 of file MagicWord.php.
References MediaWiki\MediaWikiServices\getInstance().
| MediaWiki\Parser\MagicWord::getBaseRegex | ( | ) |
Get the middle of {.
Definition at line 145 of file MagicWord.php.
| MediaWiki\Parser\MagicWord::getId | ( | ) |
Definition at line 270 of file MagicWord.php.
References wfDeprecated().
| MediaWiki\Parser\MagicWord::getRegex | ( | ) |
Create a regex to match the magic word in wikitext.
Definition at line 101 of file MagicWord.php.
| MediaWiki\Parser\MagicWord::getRegexCase | ( | ) |
Get the regexp case modifier ("iu" or empty string).
This is for building custom regexes that include {
Definition at line 114 of file MagicWord.php.
| MediaWiki\Parser\MagicWord::getRegexStart | ( | ) |
Create a regex to match the word at the start of a line in wikitext.
Definition at line 124 of file MagicWord.php.
| MediaWiki\Parser\MagicWord::getRegexStartToEnd | ( | ) |
Create a regex to match the word as the only thing on a line of wikitext.
Definition at line 134 of file MagicWord.php.
| MediaWiki\Parser\MagicWord::getSynonym | ( | $i | ) |
Get one of the synonyms.
This exists primarily for calling getSynonym( 0 ), which is how you can obtain the preferred name of a magic word according to the current wiki's content language. For example, when demonstrating or semi-automatically creating content that uses a given magic word.
This works because {
Messages*.php file lists the preferred/canonical form as the first value.Calling this with a number other than 0 is unsupported and may fail.
| int | $i |
Definition at line 244 of file MagicWord.php.
| MediaWiki\Parser\MagicWord::getSynonyms | ( | ) |
| MediaWiki\Parser\MagicWord::isCaseSensitive | ( | ) |
| MediaWiki\Parser\MagicWord::load | ( | $id | ) |
Load synonym data from {.
| string | $id |
Definition at line 87 of file MagicWord.php.
| MediaWiki\Parser\MagicWord::match | ( | $text | ) |
Check if given wikitext contains the magic word.
| string | $text |
Definition at line 166 of file MagicWord.php.
Referenced by MediaWiki\Content\WikitextContent\matchMagicWord().
| MediaWiki\Parser\MagicWord::matchAndRemove | ( | & | $text | ) |
Remove any matches of this magic word from a given text.
Returns true if the text contains one or more matches, and alters the input string to remove all instances of the magic word.
| string | &$text |
Definition at line 191 of file MagicWord.php.
| MediaWiki\Parser\MagicWord::matchStartAndRemove | ( | & | $text | ) |
| MediaWiki\Parser\MagicWord::matchStartToEnd | ( | $text | ) |
Check if given wikitext contains the word as the only thing on a line.
| string | $text |
Definition at line 177 of file MagicWord.php.
| MediaWiki\Parser\MagicWord::replace | ( | $replacement, | |
| $subject, | |||
| $limit = -1 ) |
Replace any matches of this word with something else.
| string | $replacement | |
| string | $subject | |
| int | $limit |
Definition at line 214 of file MagicWord.php.
| bool MediaWiki\Parser\MagicWord::$mCaseSensitive |
Definition at line 60 of file MagicWord.php.
| string null MediaWiki\Parser\MagicWord::$mId |
Potentially null for a short time before {.
Definition at line 54 of file MagicWord.php.
| array string [] MediaWiki\Parser\MagicWord::$mSynonyms |
Definition at line 57 of file MagicWord.php.