BlueSpice MediaWiki REL1_27
 All Classes Namespaces Files Functions Variables Groups Pages
MagicWord Class Reference

Public Member Functions

 __construct ($id=0, $syn=[], $cs=false)
 
 load ($id)
 
 initRegex ()
 
 compareStringLength ($s1, $s2)
 
 getRegex ()
 
 getRegexCase ()
 
 getRegexStart ()
 
 getRegexStartToEnd ()
 
 getBaseRegex ()
 
 match ($text)
 
 matchStart ($text)
 
 matchStartToEnd ($text)
 
 matchVariableStartToEnd ($text)
 
 matchAndRemove (&$text)
 
 matchStartAndRemove (&$text)
 
 pregRemoveAndRecord ()
 
 replace ($replacement, $subject, $limit=-1)
 
 substituteCallback ($text, $callback)
 
 getVariableRegex ()
 
 getVariableStartToEndRegex ()
 
 getSynonym ($i)
 
 getSynonyms ()
 
 getWasModified ()
 
 replaceMultiple ($magicarr, $subject, &$result)
 
 addToArray (&$array, $value)
 
 isCaseSensitive ()
 
 getId ()
 

Static Public Member Functions

static & get ($id)
 
static getVariableIDs ()
 
static getSubstIDs ()
 
static getCacheTTL ($id)
 
static getDoubleUnderscoreArray ()
 
static clearCache ()
 

Public Attributes

 $mId
 
 $mSynonyms
 
 $mCaseSensitive
 

Static Public Attributes

static $mVariableIDsInitialised = false
 
static $mVariableIDs
 
static $mCacheTTLs
 
static static $mDoubleUnderscoreIDs
 
static $mSubstIDs
 
static $mObjects = []
 
static $mDoubleUnderscoreArray = null
 

Detailed Description

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

Usage:
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[].

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

Constructor & Destructor Documentation

MagicWord::__construct (   $id = 0,
  $syn = [],
  $cs = false 
)

#@-

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

Parameters
array$array
string$value
static MagicWord::clearCache ( )
static

Clear the self::$mObjects variable For use in parser tests

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.

Parameters
string$s1
string$s2
Returns
int
static& MagicWord::get (   $id)
static

Factory: creates an object representing an ID

Parameters
int$id
Returns
MagicWord
MagicWord::getBaseRegex ( )

regex without the slashes and what not

Returns
string
static MagicWord::getCacheTTL (   $id)
static

Allow external reads of TTL array

Parameters
int$id
Returns
int
static MagicWord::getDoubleUnderscoreArray ( )
static

Get a MagicWordArray of double-underscore entities

Returns
MagicWordArray
MagicWord::getId ( )
Returns
int
MagicWord::getRegex ( )

Gets a regex representing matching the word

Returns
string
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

Returns
string
MagicWord::getRegexStart ( )

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

Returns
string
MagicWord::getRegexStartToEnd ( )

Gets a regex matching the word from start to end of a string

Returns
string
Since
1.23
static MagicWord::getSubstIDs ( )
static

Get an array of parser substitution modifier IDs

Returns
array
MagicWord::getSynonym (   $i)

Accesses the synonym list directly

Parameters
int$i
Returns
string
MagicWord::getSynonyms ( )
Returns
array
static MagicWord::getVariableIDs ( )
static

Get an array of parser variable IDs

Returns
array
MagicWord::getVariableRegex ( )

Matches the word, where $1 is a wildcard

Returns
string
MagicWord::getVariableStartToEndRegex ( )

Matches the entire string, where $1 is a wildcard

Returns
string
MagicWord::getWasModified ( )

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

Returns
bool
MagicWord::initRegex ( )

Preliminary initialisation

MagicWord::isCaseSensitive ( )
Returns
bool
MagicWord::load (   $id)

Initialises this object with an ID

Parameters
int$id
Exceptions
MWException
MagicWord::match (   $text)

Returns true if the text contains the word

Parameters
string$text
Returns
bool
MagicWord::matchAndRemove ( $text)

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

Parameters
string$text
Returns
bool
MagicWord::matchStart (   $text)

Returns true if the text starts with the word

Parameters
string$text
Returns
bool
MagicWord::matchStartAndRemove ( $text)
Parameters
string$text
Returns
bool
MagicWord::matchStartToEnd (   $text)

Returns true if the text matched the word

Parameters
string$text
Returns
bool
Since
1.23
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.

Parameters
string$text
Returns
string
MagicWord::pregRemoveAndRecord ( )

Used in matchAndRemove()

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

Replaces the word with something else

Parameters
string$replacement
string$subject
int$limit
Returns
string
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.

Deprecated:
since 1.25, unused
Parameters
array$magicarr
string$subject
string$result
Returns
bool
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

Parameters
string$text
callable$callback
Returns
string

Member Data Documentation

MagicWord::$mCacheTTLs
static
Initial value:
= [
'currentmonth' => 86400
static MagicWord::$mDoubleUnderscoreIDs
static
Initial value:
= [
'notoc',
'nogallery',
'forcetoc',
'toc',
'noeditsection',
'newsectionlink',
'nonewsectionlink',
'hiddencat',
'index',
'noindex',
'staticredirect',
'notitleconvert',
'nocontentconvert',
]
MagicWord::$mSubstIDs
static
Initial value:
= [
'subst',
'safesubst',
]

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