MagicWord Class Reference
[Parser]

This class encapsulates "magic words" such as redirect, __NOTOC__, etc. More...

List of all members.

Public Member Functions

 __construct ($id=0, $syn= '', $cs=false)
 #@-
 load ($id)
 initRegex ()
 Preliminary initialisation.
 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.
 getBaseRegex ()
 regex without the slashes and what not
 match ($text)
 Returns true if the text contains the word.
 matchStart ($text)
 Returns true if the text starts with the word.
 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.
 matchAndRemove (&$text)
 Returns true if the text matches the word, and alters the input string, removing all instances of the word.
 matchStartAndRemove (&$text)
 pregRemoveAndRecord ()
 Used in matchAndRemove().
 replace ($replacement, $subject, $limit=-1)
 Replaces the word with something else.
 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.
 getVariableRegex ()
 Matches the word, where $1 is a wildcard.
 getVariableStartToEndRegex ()
 Matches the entire string, where $1 is a wildcard.
 getSynonym ($i)
 Accesses the synonym list directly.
 getSynonyms ()
 getWasModified ()
 Returns true if the last call to replace() or substituteCallback() returned a modified text, otherwise false.
 addToArray (&$array, $value)
 Adds all the synonyms of this MagicWord to an array, to allow quick lookup in a list of magic words.
 isCaseSensitive ()
 getId ()

Static Public Member Functions

static & get ($id)
 Factory: creates an object representing an ID.
static getVariableIDs ()
 Get an array of parser variable IDs.
static getCacheTTL ($id)
static getDoubleUnderscoreArray ()
 Get a MagicWordArray of double-underscore entities.
 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.

Public Attributes

 $mId
 #@+
 $mSynonyms
 $mCaseSensitive
 $mRegex
 $mRegexStart
 $mBaseRegex
 $mVariableRegex
 $mModified
 $mFound

Static Public Attributes

static $mVariableIDsInitialised = false
static $mVariableIDs
static $mCacheTTLs
static $mDoubleUnderscoreIDs
static $mObjects = array()
static $mDoubleUnderscoreArray = null


Detailed Description

This class encapsulates "magic words" such as redirect, __NOTOC__, etc.

Usage: if (MagicWord::get( 'redirect' )->match( $text ) )

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 the LanguageGetMagic hook. For magic words which are also Parser variables, add a MagicWordwgVariableIDs hook. Use string keys.

Definition at line 28 of file MagicWord.php.


Constructor & Destructor Documentation

MagicWord::__construct ( id = 0,
syn = '',
cs = false 
)

#@-

Definition at line 178 of file MagicWord.php.


Member Function Documentation

MagicWord::addToArray ( &$  array,
value 
)

Adds all the synonyms of this MagicWord to an array, to allow quick lookup in a list of magic words.

Definition at line 467 of file MagicWord.php.

References $wgContLang.

static& MagicWord::get ( id  )  [static]

MagicWord::getBaseRegex (  ) 

regex without the slashes and what not

Definition at line 311 of file MagicWord.php.

References initRegex().

static MagicWord::getCacheTTL ( id  )  [static]

Definition at line 224 of file MagicWord.php.

Referenced by Parser::braceSubstitution().

static MagicWord::getDoubleUnderscoreArray (  )  [static]

Get a MagicWordArray of double-underscore entities.

Definition at line 233 of file MagicWord.php.

Referenced by Parser::doDoubleUnderscore().

MagicWord::getId (  ) 

Definition at line 478 of file MagicWord.php.

MagicWord::getRegex (  ) 

Gets a regex representing matching the word.

Definition at line 279 of file MagicWord.php.

References initRegex().

Referenced by match(), matchAndRemove(), and replace().

MagicWord::getRegexCase (  ) 

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 291 of file MagicWord.php.

References initRegex().

MagicWord::getRegexStart (  ) 

Gets a regex matching the word, if it is at the string start.

Definition at line 301 of file MagicWord.php.

References initRegex().

Referenced by matchStart(), and matchStartAndRemove().

MagicWord::getSynonym ( i  ) 

Accesses the synonym list directly.

Definition at line 427 of file MagicWord.php.

References $i.

MagicWord::getSynonyms (  ) 

Definition at line 431 of file MagicWord.php.

static MagicWord::getVariableIDs (  )  [static]

Get an array of parser variable IDs.

Definition at line 207 of file MagicWord.php.

References $magicWords, and wfRunHooks().

Referenced by Parser::initialiseVariables().

MagicWord::getVariableRegex (  ) 

Matches the word, where $1 is a wildcard.

Definition at line 407 of file MagicWord.php.

References initRegex().

Referenced by substituteCallback().

MagicWord::getVariableStartToEndRegex (  ) 

Matches the entire string, where $1 is a wildcard.

Definition at line 417 of file MagicWord.php.

References initRegex().

Referenced by matchVariableStartToEnd().

MagicWord::getWasModified (  ) 

Returns true if the last call to replace() or substituteCallback() returned a modified text, otherwise false.

Definition at line 439 of file MagicWord.php.

MagicWord::initRegex (  ) 

Preliminary initialisation.

Access:
private

Definition at line 256 of file MagicWord.php.

Referenced by getBaseRegex(), getRegex(), getRegexCase(), getRegexStart(), getVariableRegex(), and getVariableStartToEndRegex().

MagicWord::isCaseSensitive (  ) 

Definition at line 474 of file MagicWord.php.

MagicWord::load ( id  ) 

Definition at line 241 of file MagicWord.php.

References $wgContLang, and wfDebugLog().

MagicWord::match ( text  ) 

Returns true if the text contains the word.

Returns:
bool

Definition at line 322 of file MagicWord.php.

References $text, and getRegex().

MagicWord::matchAndRemove ( &$  text  ) 

Returns true if the text matches the word, and alters the input string, removing all instances of the word.

Definition at line 363 of file MagicWord.php.

References $text, and getRegex().

MagicWord::matchStart ( text  ) 

Returns true if the text starts with the word.

Returns:
bool

Definition at line 330 of file MagicWord.php.

References $text, and getRegexStart().

MagicWord::matchStartAndRemove ( &$  text  ) 

Definition at line 369 of file MagicWord.php.

References $text, and 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.

Definition at line 340 of file MagicWord.php.

References $text, and getVariableStartToEndRegex().

MagicWord::pregRemoveAndRecord (  ) 

Used in matchAndRemove().

Access:
private

Definition at line 379 of file MagicWord.php.

MagicWord::replace ( replacement,
subject,
limit = -1 
)

Replaces the word with something else.

Definition at line 387 of file MagicWord.php.

References $res, StringUtils::escapeRegexReplacement(), and getRegex().

MagicWord::replaceMultiple ( magicarr,
subject,
&$  result 
) [static]

$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.

Definition at line 450 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.

Definition at line 398 of file MagicWord.php.

References $res, $text, and getVariableRegex().


Member Data Documentation

MagicWord::$mBaseRegex

Definition at line 33 of file MagicWord.php.

MagicWord::$mCacheTTLs [static]

Definition at line 118 of file MagicWord.php.

MagicWord::$mCaseSensitive

Definition at line 32 of file MagicWord.php.

MagicWord::$mDoubleUnderscoreArray = null [static]

Definition at line 174 of file MagicWord.php.

MagicWord::$mDoubleUnderscoreIDs [static]

Initial value:

 array(
                'notoc',
                'nogallery',
                'forcetoc',
                'toc',
                'noeditsection',
                'newsectionlink',
                'nonewsectionlink',
                'hiddencat',
                'index',
                'noindex',
                'staticredirect',
        )

Definition at line 158 of file MagicWord.php.

MagicWord::$mFound

Definition at line 34 of file MagicWord.php.

MagicWord::$mId

#@+

Access:
private

Definition at line 32 of file MagicWord.php.

MagicWord::$mModified

Definition at line 34 of file MagicWord.php.

MagicWord::$mObjects = array() [static]

Definition at line 173 of file MagicWord.php.

MagicWord::$mRegex

Definition at line 32 of file MagicWord.php.

MagicWord::$mRegexStart

Definition at line 33 of file MagicWord.php.

MagicWord::$mSynonyms

Definition at line 32 of file MagicWord.php.

MagicWord::$mVariableIDs [static]

Definition at line 37 of file MagicWord.php.

MagicWord::$mVariableIDsInitialised = false [static]

Definition at line 36 of file MagicWord.php.

MagicWord::$mVariableRegex

Definition at line 33 of file MagicWord.php.


The documentation for this class was generated from the following file:

Generated on Sat Sep 5 02:08:42 2009 for MediaWiki by  doxygen 1.5.9