MediaWiki  1.34.4
MediaWiki\Extensions\ParserFunctions\ParserFunctions Class Reference

Parser function handlers. More...

Static Public Member Functions

static expr (Parser $parser, $expr='')
 {{expr: expression }} More...
 
static if (Parser $parser, PPFrame $frame, array $args)
 {{if: test string | value if test string is not empty | value if test string is empty }} More...
 
static ifeq (Parser $parser, PPFrame $frame, array $args)
 {{ifeq: string 1 | string 2 | value if identical | value if different }} More...
 
static iferror (Parser $parser, PPFrame $frame, array $args)
 {{iferror: test string | value if error | value if no error }} More...
 
static ifexist (Parser $parser, PPFrame $frame, array $args)
 {{ifexist: page title | value if exists | value if doesn't exist }} More...
 
static ifexpr (Parser $parser, PPFrame $frame, array $args)
 {{ifexpr: expression | value if true | value if false }} More...
 
static localTime (Parser $parser, PPFrame $frame, array $args)
 {{#timel: ... More...
 
static rel2abs (Parser $parser, $to='', $from='')
 {{rel2abs: path }} or {{rel2abs: path | base path }} More...
 
static runCount (Parser $parser, $inStr='', $inSubStr='')
 {{#count: string | substr }} More...
 
static runExplode (Parser $parser, $inStr='', $inDiv='', $inPos=0, $inLim=null)
 {{#explode:string | delimiter | position | limit}} More...
 
static runLen (Parser $parser, $inStr='')
 {{#len:string}} More...
 
static runPos (Parser $parser, $inStr='', $inNeedle='', $inOffset=0)
 {{#pos: string | needle | offset}} More...
 
static runReplace (Parser $parser, $inStr='', $inReplaceFrom='', $inReplaceTo='', $inLimit=-1)
 {{#replace:string | from | to | limit }} More...
 
static runRPos (Parser $parser, $inStr='', $inNeedle='')
 {{#rpos: string | needle}} More...
 
static runSub (Parser $parser, $inStr='', $inStart=0, $inLength=0)
 {{#sub: string | start | length }} More...
 
static runUrlDecode (Parser $parser, $inStr='')
 {{#urldecode:string}} More...
 
static switch (Parser $parser, PPFrame $frame, array $args)
 {{switch: comparison string | case = result | case = result | ... More...
 
static time (Parser $parser, PPFrame $frame, array $args)
 {{time: format string }} {{time: format string | date/time object }} {{time: format string | date/time object | language code }} More...
 
static titleparts (Parser $parser, $title='', $parts=0, $offset=0)
 Obtain a specified number of slash-separated parts of a title, e.g. More...
 

Public Attributes

const MAX_TIME_CHARS = 6000
 ~10 seconds More...
 

Static Private Member Functions

static checkLength ( $text)
 Verifies parameter is less than max string length. More...
 
static decodeTrimExpand ( $obj, PPFrame $frame, &$trimExpanded=null)
 Take a PPNode (-ish thing), expand it, remove entities, and trim. More...
 
static & getExprParser ()
 
static ifexistInternal (Parser $parser, PPFrame $frame, $titletext='', $then='', $else='')
 
static registerClearHook ()
 Register ParserClearState hook. More...
 
static timeCommon (Parser $parser, PPFrame $frame=null, $format='', $date='', $language='', $local=false)
 Used by time() and localTime() More...
 
static tooLongError ()
 Generates error message. More...
 

Static Private Attributes

static $mExprParser
 
static $mTimeCache = []
 
static $mTimeChars = 0
 

Detailed Description

Member Function Documentation

◆ checkLength()

static MediaWiki\Extensions\ParserFunctions\ParserFunctions::checkLength (   $text)
staticprivate

Verifies parameter is less than max string length.

Parameters
string$text
Returns
bool

Definition at line 617 of file ParserFunctions.php.

◆ decodeTrimExpand()

static MediaWiki\Extensions\ParserFunctions\ParserFunctions::decodeTrimExpand (   $obj,
PPFrame  $frame,
$trimExpanded = null 
)
staticprivate

Take a PPNode (-ish thing), expand it, remove entities, and trim.

For use when doing string comparisions, where user expects entities to be equal for what they stand for (e.g. comparisions with {{PAGENAME}})

Parameters
PPNode | string$objThing to expand
PPFrame$frame
string&$trimExpandedExpanded and trimmed version of PPNode, but with char refs intact
Returns
string The trimmed, expanded and entity reference decoded version of the PPNode

Definition at line 917 of file ParserFunctions.php.

References Sanitizer\decodeCharReferences(), and PPFrame\expand().

Referenced by MediaWiki\Extensions\ParserFunctions\ParserFunctions\ifeq(), and MediaWiki\Extensions\ParserFunctions\ParserFunctions\switch().

◆ expr()

static MediaWiki\Extensions\ParserFunctions\ParserFunctions::expr ( Parser  $parser,
  $expr = '' 
)
static

◆ getExprParser()

static& MediaWiki\Extensions\ParserFunctions\ParserFunctions::getExprParser ( )
staticprivate

◆ if()

static MediaWiki\Extensions\ParserFunctions\ParserFunctions::if ( Parser  $parser,
PPFrame  $frame,
array  $args 
)
static

{{if: test string | value if test string is not empty | value if test string is empty }}

Parser $parser PPFrame $frame array $args string

Definition at line 118 of file ParserFunctions.php.

References $args, and PPFrame\expand().

◆ ifeq()

static MediaWiki\Extensions\ParserFunctions\ParserFunctions::ifeq ( Parser  $parser,
PPFrame  $frame,
array  $args 
)
static

{{ifeq: string 1 | string 2 | value if identical | value if different }}

Parser $parser PPFrame $frame array $args string

Definition at line 137 of file ParserFunctions.php.

References $args, MediaWiki\Extensions\ParserFunctions\ParserFunctions\decodeTrimExpand(), and PPFrame\expand().

◆ iferror()

static MediaWiki\Extensions\ParserFunctions\ParserFunctions::iferror ( Parser  $parser,
PPFrame  $frame,
array  $args 
)
static

{{iferror: test string | value if error | value if no error }}

Error is when the input string contains an HTML object with class="error", as generated by other parser functions such as expr, time and rel2abs.

Parser $parser PPFrame $frame array $args string

Definition at line 163 of file ParserFunctions.php.

References $args, and PPFrame\expand().

◆ ifexist()

static MediaWiki\Extensions\ParserFunctions\ParserFunctions::ifexist ( Parser  $parser,
PPFrame  $frame,
array  $args 
)
static

◆ ifexistInternal()

static MediaWiki\Extensions\ParserFunctions\ParserFunctions::ifexistInternal ( Parser  $parser,
PPFrame  $frame,
  $titletext = '',
  $then = '',
  $else = '' 
)
staticprivate

◆ ifexpr()

static MediaWiki\Extensions\ParserFunctions\ParserFunctions::ifexpr ( Parser  $parser,
PPFrame  $frame,
array  $args 
)
static

◆ localTime()

static MediaWiki\Extensions\ParserFunctions\ParserFunctions::localTime ( Parser  $parser,
PPFrame  $frame,
array  $args 
)
static

{{#timel: ...

}}

Identical to {{time: ... }}, except that it uses the local time of the wiki (as set in $wgLocaltimezone) when no date is given.

Parser $parser PPFrame $frame array $args string

Definition at line 569 of file ParserFunctions.php.

References $args, PPFrame\expand(), and MediaWiki\Extensions\ParserFunctions\ParserFunctions\timeCommon().

◆ registerClearHook()

static MediaWiki\Extensions\ParserFunctions\ParserFunctions::registerClearHook ( )
staticprivate

Register ParserClearState hook.

We defer this until needed to avoid the loading of the code of this file when no parser function is actually called.

Definition at line 38 of file ParserFunctions.php.

References $wgHooks.

Referenced by MediaWiki\Extensions\ParserFunctions\ParserFunctions\timeCommon().

◆ rel2abs()

static MediaWiki\Extensions\ParserFunctions\ParserFunctions::rel2abs ( Parser  $parser,
  $to = '',
  $from = '' 
)
static

{{rel2abs: path }} or {{rel2abs: path | base path }}

Returns the absolute path to a subpage, relative to the current article title. Treats titles as slash-separated paths.

Following subpage link syntax instead of standard path syntax, an initial slash is treated as a relative path, and vice versa.

Parser $parser string $to string $from string

Definition at line 275 of file ParserFunctions.php.

References Parser\getTitle(), and wfMessage().

◆ runCount()

static MediaWiki\Extensions\ParserFunctions\ParserFunctions::runCount ( Parser  $parser,
  $inStr = '',
  $inSubStr = '' 
)
static

{{#count: string | substr }}

Returns number of occurrences of "substr" in "string".

Note: If "substr" is empty, a single space is used.

Parameters
Parser$parser
string$inStr
string$inSubStr
Returns
int|string

Definition at line 759 of file ParserFunctions.php.

References Parser\killMarkers(), and MediaWiki\Extensions\ParserFunctions\ParserFunctions\tooLongError().

◆ runExplode()

static MediaWiki\Extensions\ParserFunctions\ParserFunctions::runExplode ( Parser  $parser,
  $inStr = '',
  $inDiv = '',
  $inPos = 0,
  $inLim = null 
)
static

{{#explode:string | delimiter | position | limit}}

Breaks "string" into chunks separated by "delimiter" and returns the chunk identified by "position".

Note: Negative position can be used to specify tokens from the end. Note: If the divider is an empty string, single space is used instead. Note: Empty string is returned if there are not enough exploded chunks.

Parameters
Parser$parser
string$inStr
string$inDiv
int$inPos
int | null$inLim
Returns
string

Definition at line 857 of file ParserFunctions.php.

References $matches, Parser\killMarkers(), and MediaWiki\Extensions\ParserFunctions\ParserFunctions\tooLongError().

◆ runLen()

static MediaWiki\Extensions\ParserFunctions\ParserFunctions::runLen ( Parser  $parser,
  $inStr = '' 
)
static

{{#len:string}}

Reports number of characters in string.

Parameters
Parser$parser
string$inStr
Returns
int

Definition at line 641 of file ParserFunctions.php.

References Parser\killMarkers().

◆ runPos()

static MediaWiki\Extensions\ParserFunctions\ParserFunctions::runPos ( Parser  $parser,
  $inStr = '',
  $inNeedle = '',
  $inOffset = 0 
)
static

{{#pos: string | needle | offset}}

Finds first occurrence of "needle" in "string" starting at "offset".

Note: If the needle is an empty string, single space is used instead. Note: If the needle is not found, empty string is returned.

Parameters
Parser$parser
string$inStr
int | string$inNeedle
int$inOffset
Returns
int|string

Definition at line 659 of file ParserFunctions.php.

References Parser\killMarkers(), and MediaWiki\Extensions\ParserFunctions\ParserFunctions\tooLongError().

◆ runReplace()

static MediaWiki\Extensions\ParserFunctions\ParserFunctions::runReplace ( Parser  $parser,
  $inStr = '',
  $inReplaceFrom = '',
  $inReplaceTo = '',
  $inLimit = -1 
)
static

{{#replace:string | from | to | limit }}

Replaces each occurrence of "from" in "string" with "to". At most "limit" replacements are performed.

Note: Armored against replacements that would generate huge strings. Note: If "from" is an empty string, single space is used instead.

Parameters
Parser$parser
string$inStr
string$inReplaceFrom
string$inReplaceTo
int$inLimit
Returns
mixed|string

Definition at line 793 of file ParserFunctions.php.

References StringUtils\escapeRegexReplacement(), Parser\killMarkers(), and MediaWiki\Extensions\ParserFunctions\ParserFunctions\tooLongError().

◆ runRPos()

static MediaWiki\Extensions\ParserFunctions\ParserFunctions::runRPos ( Parser  $parser,
  $inStr = '',
  $inNeedle = '' 
)
static

{{#rpos: string | needle}}

Finds last occurrence of "needle" in "string".

Note: If the needle is an empty string, single space is used instead. Note: If the needle is not found, -1 is returned.

Parameters
Parser$parser
string$inStr
int | string$inNeedle
Returns
int|string

Definition at line 692 of file ParserFunctions.php.

References Parser\killMarkers(), and MediaWiki\Extensions\ParserFunctions\ParserFunctions\tooLongError().

◆ runSub()

static MediaWiki\Extensions\ParserFunctions\ParserFunctions::runSub ( Parser  $parser,
  $inStr = '',
  $inStart = 0,
  $inLength = 0 
)
static

{{#sub: string | start | length }}

Returns substring of "string" starting at "start" and having "length" characters.

Note: If length is zero, the rest of the input is returned. Note: A negative value for "start" operates from the end of the "string". Note: A negative value for "length" returns a string reduced in length by that amount.

Parameters
Parser$parser
string$inStr
int$inStart
int$inLength
Returns
string

Definition at line 731 of file ParserFunctions.php.

References Parser\killMarkers(), and MediaWiki\Extensions\ParserFunctions\ParserFunctions\tooLongError().

◆ runUrlDecode()

static MediaWiki\Extensions\ParserFunctions\ParserFunctions::runUrlDecode ( Parser  $parser,
  $inStr = '' 
)
static

{{#urldecode:string}}

Decodes URL-encoded (like%20that) strings.

Parameters
Parser$parser
string$inStr
Returns
string

Definition at line 896 of file ParserFunctions.php.

References Parser\killMarkers(), and MediaWiki\Extensions\ParserFunctions\ParserFunctions\tooLongError().

◆ switch()

static MediaWiki\Extensions\ParserFunctions\ParserFunctions::switch ( Parser  $parser,
PPFrame  $frame,
array  $args 
)
static

{{switch: comparison string | case = result | case = result | ...

| default result }}

Parser $parser PPFrame $frame array $args string

Definition at line 200 of file ParserFunctions.php.

References $args, MediaWiki\Extensions\ParserFunctions\ParserFunctions\decodeTrimExpand(), PPFrame\expand(), and Parser\getMagicWordFactory().

◆ time()

static MediaWiki\Extensions\ParserFunctions\ParserFunctions::time ( Parser  $parser,
PPFrame  $frame,
array  $args 
)
static

{{time: format string }} {{time: format string | date/time object }} {{time: format string | date/time object | language code }}

Parser $parser PPFrame $frame array $args string

Definition at line 548 of file ParserFunctions.php.

References $args, PPFrame\expand(), and MediaWiki\Extensions\ParserFunctions\ParserFunctions\timeCommon().

◆ timeCommon()

static MediaWiki\Extensions\ParserFunctions\ParserFunctions::timeCommon ( Parser  $parser,
PPFrame  $frame = null,
  $format = '',
  $date = '',
  $language = '',
  $local = false 
)
staticprivate

◆ titleparts()

static MediaWiki\Extensions\ParserFunctions\ParserFunctions::titleparts ( Parser  $parser,
  $title = '',
  $parts = 0,
  $offset = 0 
)
static

Obtain a specified number of slash-separated parts of a title, e.g.

{{titleparts:Hello/World|1}} => "Hello"

Parser $parser Parent parser string $title Title to split int $parts Number of parts to keep int $offset Offset starting at 1 string

Definition at line 588 of file ParserFunctions.php.

References $title, and Title\newFromText().

◆ tooLongError()

Member Data Documentation

◆ $mExprParser

MediaWiki\Extensions\ParserFunctions\ParserFunctions::$mExprParser
staticprivate

◆ $mTimeCache

MediaWiki\Extensions\ParserFunctions\ParserFunctions::$mTimeCache = []
staticprivate

Definition at line 27 of file ParserFunctions.php.

◆ $mTimeChars

MediaWiki\Extensions\ParserFunctions\ParserFunctions::$mTimeChars = 0
staticprivate

Definition at line 28 of file ParserFunctions.php.

◆ MAX_TIME_CHARS

const MediaWiki\Extensions\ParserFunctions\ParserFunctions::MAX_TIME_CHARS = 6000

~10 seconds

Definition at line 31 of file ParserFunctions.php.


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