BlueSpice MediaWiki master
 All Classes Namespaces Files Functions Variables Groups Pages
Parser Class Reference
Inheritance diagram for Parser:
Collaboration diagram for Parser:

Public Member Functions

 __construct ($conf=[])
 
 __destruct ()
 
 __clone ()
 
 firstCallInit ()
 
 clearState ()
 
 parse ($text, Title $title, ParserOptions $options, $linestart=true, $clearState=true, $revid=null)
 
 recursiveTagParse ($text, $frame=false)
 
 recursiveTagParseFully ($text, $frame=false)
 
 preprocess ($text, Title $title=null, ParserOptions $options, $revid=null, $frame=false)
 
 recursivePreprocess ($text, $frame=false)
 
 getPreloadText ($text, Title $title, ParserOptions $options, $params=[])
 
 setUser ($user)
 
 setTitle ($t)
 
 getTitle ()
 
 Title ($x=null)
 
 setOutputType ($ot)
 
 OutputType ($x=null)
 
 getOutput ()
 
 getOptions ()
 
 Options ($x=null)
 
 nextLinkID ()
 
 setLinkID ($id)
 
 getFunctionLang ()
 
 getTargetLanguage ()
 
 getConverterLanguage ()
 
 getUser ()
 
 getPreprocessor ()
 
 getLinkRenderer ()
 
 getStripList ()
 
 insertStripItem ($text)
 
 doTableStuff ($text)
 
 internalParse ($text, $isMain=true, $frame=false)
 
 doMagicLinks ($text)
 
 magicLinkCallback ($m)
 
 makeFreeExternalLink ($url, $numPostProto)
 
 doHeadings ($text)
 
 doAllQuotes ($text)
 
 doQuotes ($text)
 
 replaceExternalLinks ($text)
 
 getExternalLinkAttribs ($url)
 
 replaceInternalLinks ($s)
 
 replaceInternalLinks2 (&$s)
 
 armorLinks ($text)
 
 areSubpagesAllowed ()
 
 maybeDoSubpageLink ($target, &$text)
 
 doBlockLevels ($text, $linestart)
 
 getVariableValue ($index, $frame=false)
 
 initialiseVariables ()
 
 preprocessToDom ($text, $flags=0)
 
 replaceVariables ($text, $frame=false, $argsOnly=false)
 
 limitationWarn ($limitationType, $current= '', $max= '')
 
 braceSubstitution ($piece, $frame)
 
 callParserFunction ($frame, $function, array $args=[])
 
 getTemplateDom ($title)
 
 fetchCurrentRevisionOfTitle ($title)
 
 fetchTemplateAndTitle ($title)
 
 fetchTemplate ($title)
 
 fetchFile ($title, $options=[])
 
 fetchFileAndTitle ($title, $options=[])
 
 interwikiTransclude ($title, $action)
 
 fetchScaryTemplateMaybeFromCache ($url)
 
 argSubstitution ($piece, $frame)
 
 extensionSubstitution ($params, $frame)
 
 incrementIncludeSize ($type, $size)
 
 incrementExpensiveFunctionCount ()
 
 doDoubleUnderscore ($text)
 
 addTrackingCategory ($msg)
 
 formatHeadings ($text, $origText, $isMain=true)
 
 preSaveTransform ($text, Title $title, User $user, ParserOptions $options, $clearState=true)
 
 getUserSig (&$user, $nickname=false, $fancySig=null)
 
 validateSig ($text)
 
 cleanSig ($text, $parsing=false)
 
 startExternalParse (Title $title=null, ParserOptions $options, $outputType, $clearState=true)
 
 transformMsg ($text, $options, $title=null)
 
 setHook ($tag, callable $callback)
 
 setTransparentTagHook ($tag, callable $callback)
 
 clearTagHooks ()
 
 setFunctionHook ($id, callable $callback, $flags=0)
 
 getFunctionHooks ()
 
 setFunctionTagHook ($tag, callable $callback, $flags)
 
 replaceLinkHolders (&$text, $options=0)
 
 replaceLinkHoldersText ($text)
 
 renderImageGallery ($text, $params)
 
 getImageParams ($handler)
 
 makeImage ($title, $options, $holders=false)
 
 disableCache ()
 
 attributeStripCallback (&$text, $frame=false)
 
 getTags ()
 
 replaceTransparentTags ($text)
 
 getSection ($text, $sectionId, $defaultText= '')
 
 replaceSection ($oldText, $sectionId, $newText)
 
 getRevisionId ()
 
 getRevisionObject ()
 
 getRevisionTimestamp ()
 
 getRevisionUser ()
 
 getRevisionSize ()
 
 setDefaultSort ($sort)
 
 getDefaultSort ()
 
 getCustomDefaultSort ()
 
 guessSectionNameFromWikiText ($text)
 
 guessLegacySectionNameFromWikiText ($text)
 
 stripSectionName ($text)
 
 testSrvus ($text, Title $title, ParserOptions $options, $outputType=self::OT_HTML)
 
 testPst ($text, Title $title, ParserOptions $options)
 
 testPreprocess ($text, Title $title, ParserOptions $options)
 
 markerSkipCallback ($s, $callback)
 
 killMarkers ($text)
 
 serializeHalfParsedText ($text)
 
 unserializeHalfParsedText ($data)
 
 isValidHalfParsedText ($data)
 
 getFreshParser ()
 
 enableOOUI ()
 

Static Public Member Functions

static extractTagsAndParams ($elements, $text, &$matches)
 
static getExternalLinkRel ($url=false, $title=null)
 
static normalizeLinkUrl ($url)
 
static splitWhitespace ($s)
 
static createAssocArgs ($args)
 
static statelessFetchRevision (Title $title, $parser=false)
 
static statelessFetchTemplate ($title, $parser=false)
 
static cleanSigInSig ($text)
 
static guessSectionNameFromStrippedText ($text)
 
static parseWidthParam ($value, $parseHeight=true)
 
static stripOuterParagraph ($html)
 

Public Attributes

const VERSION = '1.6.4'
 
const HALF_PARSED_VERSION = 2
 
const SFH_NO_HASH = 1
 
const SFH_OBJECT_ARGS = 2
 
const EXT_LINK_URL_CLASS = '[^][<>"\\x00-\\x20\\x7F\p{Zs}\x{FFFD}]'
 
const EXT_LINK_ADDR = '(?:[0-9.]+|\\[(?i:[0-9a-f:.]+)\\]|[^][<>"\\x00-\\x20\\x7F\p{Zs}\x{FFFD}])'
 
const EXT_IMAGE_REGEX
 
const SPACE_NOT_NL = '(?:\t|&nbsp;|&\#0*160;|&\#[Xx]0*[Aa]0;|\p{Zs})'
 
const PTD_FOR_INCLUSION = 1
 
const OT_HTML = 1
 
const OT_WIKI = 2
 
const OT_PREPROCESS = 3
 
const OT_MSG = 3
 
const OT_PLAIN = 4
 
const MARKER_SUFFIX = "-QINU`\"'\x7f"
 
const MARKER_PREFIX = "\x7f'\"`UNIQ-"
 
const TOC_START = '<mw:toc>'
 
const TOC_END = '</mw:toc>'
 
 $mTagHooks = []
 
 $mTransparentTagHooks = []
 
 $mFunctionHooks = []
 
 $mFunctionSynonyms = [ 0 => []
 
 $mFunctionTagHooks = []
 
 $mStripList = []
 
 $mDefaultStripList = []
 
 $mVarCache = []
 
 $mImageParams = []
 
 $mImageParamsMagicArray = []
 
 $mMarkerIndex = 0
 
 $mFirstCall = true
 
 $mVariables
 
 $mSubstWords
 
 $mConf
 
 $mExtLinkBracketedRegex
 
 $mUrlProtocols
 
 $mPreprocessor
 
 $mOutput
 
 $mAutonumber
 
 $mStripState
 
 $mIncludeCount
 
 $mLinkHolders
 
 $mLinkID
 
 $mIncludeSizes
 
 $mPPNodeCount
 
 $mGeneratedPPNodeCount
 
 $mHighestExpansionDepth
 
 $mDefaultSort
 
 $mTplRedirCache
 
 $mTplDomCache
 
 $mHeadings
 
 $mDoubleUnderscores
 
 $mExpensiveFunctionCount
 
 $mShowToc
 
 $mForceTocPosition
 
 $mUser
 
 $mOptions
 
 $mTitle
 
 $mOutputType
 
 $ot
 
 $mRevisionObject
 
 $mRevisionId
 
 $mRevisionTimestamp
 
 $mRevisionUser
 
 $mRevisionSize
 
 $mRevIdForTs
 
 $mInputSize = false
 
 $mUniqPrefix = self::MARKER_PREFIX
 
 $mLangLinkLanguages
 
 $currentRevisionCache
 
 $mInParse = false
 

Protected Member Functions

 makeLimitReport ()
 
 makeKnownLinkHolder ($nt, $text= '', $trail= '', $prefix= '')
 
 fetchFileNoRegister ($title, $options=[])
 
 stripAltText ($caption, $holders)
 
 lock ()
 

Protected Attributes

 $mProfiler
 
 $mLinkRenderer
 

Detailed Description

PHP Parser - Processes wiki markup (which uses a more user-friendly syntax, such as "[[link]]" for making links), and provides a one-way transformation of that wiki markup it into (X)HTML output / markup (which in turn the browser understands, and can display).

There are seven main entry points into the Parser class:

Globals used: object: $wgContLang

Warning
$wgUser or $wgTitle or $wgRequest or $wgLang. Keep them away!
Settings:
$wgNamespacesWithSubpages
Settings only within ParserOptions:
$wgAllowExternalImages $wgAllowSpecialInclusion $wgInterwikiMagic $wgMaxArticleSize

Constructor & Destructor Documentation

Parser::__construct (   $conf = [])
Parameters
array$conf
Parser::__destruct ( )

Reduce memory usage to reduce the impact of circular references

Member Function Documentation

Parser::__clone ( )

Allow extensions to clean up when the parser is cloned

Parser::addTrackingCategory (   $msg)
See Also
ParserOutput::addTrackingCategory()
Parameters
string$msgMessage key
Returns
bool Whether the addition was successful
Parser::areSubpagesAllowed ( )

Return true if subpage links should be expanded on this page.

Returns
bool
Parser::argSubstitution (   $piece,
  $frame 
)

Triple brace replacement – used for template arguments

Parameters
array$piece
PPFrame$frame
Returns
array
Parser::armorLinks (   $text)

Insert a NOPARSE hacky thing into any inline links in a chunk that's going to go through further parsing steps before inline URL expansion.

Not needed quite as much as it used to be since free links are a bit more sensible these days. But bracketed links are still an issue.

Parameters
string$textMore-or-less HTML
Returns
string Less-or-more HTML with NOPARSE bits
Parser::attributeStripCallback ( $text,
  $frame = false 
)

Callback from the Sanitizer for expanding items found in HTML attribute values, so they can be safely tested and escaped.

Parameters
string&$text
bool | PPFrame$frame
Returns
string
Parser::braceSubstitution (   $piece,
  $frame 
)

Return the text of a template, after recursively replacing any variables or templates within the template.

Parameters
array$pieceThe parts of the template $piece['title']: the title, i.e. the part before the | $piece['parts']: the parameter array $piece['lineStart']: whether the brace was at the start of a line
PPFrame$frameThe current frame, contains template arguments
Exceptions
Exception
Returns
string The text of the template
Parser::callParserFunction (   $frame,
  $function,
array  $args = [] 
)

Call a parser function and return an array with text and flags.

The returned array will always contain a boolean 'found', indicating whether the parser function was found or not. It may also contain the following: text: string|object, resulting wikitext or PP DOM object isHTML: bool, $text is HTML, armour it against wikitext transformation isChildObj: bool, $text is a DOM node needing expansion in a child frame isLocalObj: bool, $text is a DOM node needing expansion in the current frame nowiki: bool, wiki markup in $text should be escaped

Since
1.21
Parameters
PPFrame$frameThe current frame, contains template arguments
string$functionFunction name
array$argsArguments to the function
Exceptions
MWException
Returns
array
Parser::cleanSig (   $text,
  $parsing = false 
)

Clean up signature text

1) Strip 3, 4 or 5 tildes out of signatures

See Also
cleanSigInSig 2) Substitute all transclusions
Parameters
string$text
bool$parsingWhether we're cleaning (preferences save) or parsing
Returns
string Signature text
static Parser::cleanSigInSig (   $text)
static

Strip 3, 4 or 5 tildes out of signatures.

Parameters
string$text
Returns
string Signature text with /~{3,5}/ removed
Parser::clearState ( )

Clear Parser state

Parser::clearTagHooks ( )

Remove all tag hooks

static Parser::createAssocArgs (   $args)
static

Clean up argument array - refactored in 1.9 so parserfunctions can use it, too.

Parameters
array$args
Returns
array
Parser::disableCache ( )

Set a flag in the output object indicating that the content is dynamic and shouldn't be cached.

Deprecated:
since 1.28; use getOutput()->updateCacheExpiry()
Parser::doAllQuotes (   $text)

Replace single quotes with HTML markup

Parameters
string$text
Returns
string The altered text
Parser::doBlockLevels (   $text,
  $linestart 
)

Make lists from lines starting with ':', '*', '#', etc. (DBL)

Parameters
string$text
bool$linestartWhether or not this is at the start of a line.
Returns
string The lists rendered as HTML
Parser::doDoubleUnderscore (   $text)

Strip double-underscore items like NOGALLERY and NOTOC Fills $this->mDoubleUnderscores, returns the modified text

Parameters
string$text
Returns
string
Parser::doHeadings (   $text)

Parse headers and return html

Parameters
string$text
Returns
string
Parser::doMagicLinks (   $text)

Replace special strings like "ISBN xxx" and "RFC xxx" with magic external links.

DML

Parameters
string$text
Returns
string
Parser::doQuotes (   $text)

Helper function for doAllQuotes()

Parameters
string$text
Returns
string
Parser::doTableStuff (   $text)

parse the wiki syntax used to render tables

Parameters
string$text
Returns
string
Parser::enableOOUI ( )

Set's up the PHP implementation of OOUI for use in this request and instructs OutputPage to enable OOUI for itself.

Since
1.26
Parser::extensionSubstitution (   $params,
  $frame 
)

Return the text to be used for a given extension tag. This is the ghost of strip().

Parameters
array$paramsAssociative array of parameters: name PPNode for the tag name attr PPNode for unparsed text where tag attributes are thought to be attributes Optional associative array of parsed attributes inner Contents of extension element noClose Original text did not have a close tag
PPFrame$frame
Exceptions
MWException
Returns
string
static Parser::extractTagsAndParams (   $elements,
  $text,
$matches 
)
static

Replaces all occurrences of HTML-style comments and the given tags in the text with a random marker and returns the next text. The output parameter $matches will be an associative array filled with data in the form:

'UNIQ-xxxxx' => [
'element',
'tag content',
[ 'param' => 'x' ],
'<element param="x">tag content</element>' ]
Parameters
array$elementsList of element names. Comments are always extracted.
string$textSource text string.
array&$matchesOut parameter, Array: extracted tags
Returns
string Stripped text
Parser::fetchCurrentRevisionOfTitle (   $title)

Fetch the current revision of a given title. Note that the revision (and even the title) may not exist in the database, so everything contributing to the output of the parser should use this method where possible, rather than getting the revisions themselves. This method also caches its results, so using it benefits performance.

Since
1.24
Parameters
Title$title
Returns
Revision
Parser::fetchFile (   $title,
  $options = [] 
)

Fetch a file and its title and register a reference to it. If 'broken' is a key in $options then the file will appear as a broken thumbnail.

Parameters
Title$title
array$optionsArray of options to RepoGroup::findFile
Returns
File|bool
Parser::fetchFileAndTitle (   $title,
  $options = [] 
)

Fetch a file and its title and register a reference to it. If 'broken' is a key in $options then the file will appear as a broken thumbnail.

Parameters
Title$title
array$optionsArray of options to RepoGroup::findFile
Returns
array ( File or false, Title of file )
Parser::fetchFileNoRegister (   $title,
  $options = [] 
)
protected

Helper function for fetchFileAndTitle.

Also useful if you need to fetch a file but not use it yet, for example to get the file's handler.

Parameters
Title$title
array$optionsArray of options to RepoGroup::findFile
Returns
File|bool
Parser::fetchScaryTemplateMaybeFromCache (   $url)
Parameters
string$url
Returns
mixed|string
Parser::fetchTemplate (   $title)

Fetch the unparsed text of a template and register a reference to it.

Parameters
Title$title
Returns
string|bool
Parser::fetchTemplateAndTitle (   $title)

Fetch the unparsed text of a template and register a reference to it.

Parameters
Title$title
Returns
array ( string or false, Title )
Parser::firstCallInit ( )

Do various kinds of initialisation on the first call of the parser

Parser::formatHeadings (   $text,
  $origText,
  $isMain = true 
)

This function accomplishes several tasks: 1) Auto-number headings if that option is enabled 2) Add an [edit] link to sections for users who have enabled the option and can edit the page 3) Add a Table of contents on the top for users who have enabled the option 4) Auto-anchor headings

It loops through all headlines, collects the necessary data, then splits up the string and re-inserts the newly formatted headlines.

Parameters
string$text
string$origTextOriginal, untouched wikitext
bool$isMain
Returns
mixed|string

Send a hook, one per section. The idea here is to be able to make section-level DIVs, but to do so in a lower-impact, more correct way than r50769

$this : caller $section : the section number &$sectionContent : ref to the content of the section $maybeShowEditLinks : boolean describing whether this section has an edit link

Parser::getConverterLanguage ( )

Get the language object for language conversion

Returns
Language|null
Parser::getCustomDefaultSort ( )

Accessor for $mDefaultSort Unlike getDefaultSort(), will return false if none is set

Returns
string|bool
Parser::getDefaultSort ( )

Accessor for $mDefaultSort Will use the empty string if none is set.

This value is treated as a prefix, so the empty string is equivalent to sorting by page name.

Returns
string
Parser::getExternalLinkAttribs (   $url)

Get an associative array of additional HTML attributes appropriate for a particular external link. This currently may include rel => nofollow (depending on configuration, namespace, and the URL's domain) and/or a target attribute (depending on configuration).

Parameters
string$urlURL to extract the domain from for rel => nofollow if appropriate
Returns
array Associative array of HTML attributes
static Parser::getExternalLinkRel (   $url = false,
  $title = null 
)
static

Get the rel attribute for a particular external link.

Since
1.21
Parameters
string | bool$urlOptional URL, to extract the domain from for rel => nofollow if appropriate
Title$titleOptional Title, for wgNoFollowNsExceptions lookups
Returns
string|null Rel attribute for $url
Parser::getFreshParser ( )

Return this parser if it is not doing anything, otherwise get a fresh parser. You can use this method by doing $myParser = $wgParser->getFreshParser(), or more simply $wgParser->getFreshParser()->parse( ... ); if you're unsure if $wgParser is safe to use.

Since
1.24
Returns
Parser A parser object that is not parsing anything
Parser::getFunctionHooks ( )

Get all registered function hook identifiers

Returns
array
Parser::getFunctionLang ( )

Get a language object for use in parser functions such as {{FORMATNUM:}}

Returns
Language
Parser::getImageParams (   $handler)
Parameters
MediaHandler$handler
Returns
array
Parser::getLinkRenderer ( )

Get a LinkRenderer instance to make links with

Since
1.28
Returns
LinkRenderer
Parser::getOptions ( )

Get the ParserOptions object

Returns
ParserOptions
Parser::getOutput ( )

Get the ParserOutput object

Returns
ParserOutput
Parser::getPreloadText (   $text,
Title  $title,
ParserOptions  $options,
  $params = [] 
)

Process the wikitext for the "?preload=" feature. (T7210)

"<noinclude>", "<includeonly>" etc. are parsed as for template transclusion, comments, templates, arguments, tags hooks and parser functions are untouched.

Parameters
string$text
Title$title
ParserOptions$options
array$params
Returns
string
Parser::getPreprocessor ( )

Get a preprocessor object

Returns
Preprocessor
Parser::getRevisionId ( )

Get the ID of the revision we are parsing

Returns
int|null
Parser::getRevisionObject ( )

Get the revision object for $this->mRevisionId

Returns
Revision|null Either a Revision object or null
Since
1.23 (public since 1.23)
Parser::getRevisionSize ( )

Get the size of the revision

Returns
int|null Revision size
Parser::getRevisionTimestamp ( )

Get the timestamp associated with the current revision, adjusted for the default server-local timestamp

Returns
string
Parser::getRevisionUser ( )

Get the name of the user that edited the last revision

Returns
string User name
Parser::getSection (   $text,
  $sectionId,
  $defaultText = '' 
)

This function returns the text of a section, specified by a number ($section). A section is text under a heading like == Heading == or <h1>Heading</h1>, or the first section before any such heading (section 0).

If a section contains subsections, these are also returned.

Parameters
string$textText to look in
string | int$sectionIdSection identifier as a number or string (e.g. 0, 1 or 'T-1').
string$defaultTextDefault to return if section is not found
Returns
string Text of the requested section
Parser::getStripList ( )

Get a list of strippable XML-like elements

Returns
array
Parser::getTags ( )

Accessor

Returns
array
Parser::getTargetLanguage ( )

Get the target language for the content being parsed. This is usually the language that the content is in.

Since
1.19
Exceptions
MWException
Returns
Language
Parser::getTemplateDom (   $title)

Get the semi-parsed DOM representation of a template with a given title, and its redirect destination title. Cached.

Parameters
Title$title
Returns
array
Parser::getTitle ( )

Accessor for the Title object

Returns
Title
Parser::getUser ( )

Get a User object either from $this->mUser, if set, or from the ParserOptions object otherwise

Returns
User
Parser::getUserSig ( $user,
  $nickname = false,
  $fancySig = null 
)

Fetch the user's signature text, if any, and normalize to validated, ready-to-insert wikitext. If you have pre-fetched the nickname or the fancySig option, you can specify them here to save a database query. Do not reuse this parser instance after calling getUserSig(), as it may have changed if it's the $wgParser.

Parameters
User&$user
string | bool$nicknameNickname to use or false to use user's default nickname
bool | null$fancySigwhether the nicknname is the complete signature or null to use default value
Returns
string
Parser::getVariableValue (   $index,
  $frame = false 
)

Return value of a magic variable (like PAGENAME)

Parameters
string$indexMagic variable identifier as mapped in MagicWord::$mVariableIDs
bool | PPFrame$frame
Exceptions
MWException
Returns
string

Some of these require message or data lookups and can be expensive to check many times.

Parser::guessLegacySectionNameFromWikiText (   $text)

Same as guessSectionNameFromWikiText(), but produces legacy anchors instead, if possible. For use in redirects, since various versions of Microsoft browsers interpret Location: headers as something other than UTF-8, resulting in breakage.

Parameters
string$textThe section name
Returns
string Anchor (starting with '#')
static Parser::guessSectionNameFromStrippedText (   $text)
static

Like guessSectionNameFromWikiText(), but takes already-stripped text as input.

Parameters
string$textSection name (plain text)
Returns
string Anchor (starting with '#')
Parser::guessSectionNameFromWikiText (   $text)

Try to guess the section anchor name based on a wikitext fragment presumably extracted from a heading, for example "Header" from "== Header ==".

Parameters
string$text
Returns
string Anchor (starting with '#')
Parser::incrementExpensiveFunctionCount ( )

Increment the expensive function count

Returns
bool False if the limit has been exceeded
Parser::incrementIncludeSize (   $type,
  $size 
)

Increment an include size counter

Parameters
string$typeThe type of expansion
int$sizeThe size of the text
Returns
bool False if this inclusion would take it over the maximum, true otherwise
Parser::initialiseVariables ( )

initialise the magic variables (like CURRENTMONTHNAME) and substitution modifiers

Parser::insertStripItem (   $text)

Add an item to the strip state Returns the unique tag which must be inserted into the stripped text The tag will be replaced with the original text in unstrip()

Parameters
string$text
Returns
string
Parser::internalParse (   $text,
  $isMain = true,
  $frame = false 
)

Helper function for parse() that transforms wiki markup into half-parsed HTML. Only called for $mOutputType == self::OT_HTML.

Parameters
string$textThe text to parse
bool$isMainWhether this is being called from the main parse() function
PPFrame | bool$frameA pre-processor frame
Returns
string
Parser::interwikiTransclude (   $title,
  $action 
)

Transclude an interwiki link.

Parameters
Title$title
string$action
Returns
string
Parser::isValidHalfParsedText (   $data)

Returns true if the given array, presumed to be generated by serializeHalfParsedText(), is compatible with the current version of the parser.

Deprecated:
since 1.31
Parameters
array$data
Returns
bool
Parser::killMarkers (   $text)

Remove any strip markers found in the given text.

Parameters
string$text
Returns
string
Parser::limitationWarn (   $limitationType,
  $current = '',
  $max = '' 
)

Warn the user when a parser limitation is reached Will warn at most once the user per limitation type

The results are shown during preview and run through the Parser (See EditPage.php)

Parameters
string$limitationTypeShould be one of: 'expensive-parserfunction' (corresponding messages: 'expensive-parserfunction-warning', 'expensive-parserfunction-category') 'post-expand-template-argument' (corresponding messages: 'post-expand-template-argument-warning', 'post-expand-template-argument-category') 'post-expand-template-inclusion' (corresponding messages: 'post-expand-template-inclusion-warning', 'post-expand-template-inclusion-category') 'node-count-exceeded' (corresponding messages: 'node-count-exceeded-warning', 'node-count-exceeded-category') 'expansion-depth-exceeded' (corresponding messages: 'expansion-depth-exceeded-warning', 'expansion-depth-exceeded-category')
string | int | null$currentCurrent value
string | int | null$maxMaximum allowed, when an explicit limit has been exceeded, provide the values (optional)
Parser::lock ( )
protected

Lock the current instance of the parser.

This is meant to stop someone from calling the parser recursively and messing up all the strip state.

Exceptions
MWExceptionIf parser is in a parse
Returns
ScopedCallback The lock will be released once the return value goes out of scope.
Parser::magicLinkCallback (   $m)
Exceptions
MWException
Parameters
array$m
Returns
string HTML
Parser::makeFreeExternalLink (   $url,
  $numPostProto 
)

Make a free external link, given a user-supplied URL

Parameters
string$url
int$numPostProtoThe number of characters after the protocol.
Returns
string HTML
Parser::makeImage (   $title,
  $options,
  $holders = false 
)

Parse image options text and use it to make an image

Parameters
Title$title
string$options
LinkHolderArray | bool$holders
Returns
string HTML
Parser::makeKnownLinkHolder (   $nt,
  $text = '',
  $trail = '',
  $prefix = '' 
)
protected

Render a forced-blue link inline; protect against double expansion of URLs if we're in a mode that prepends full URL prefixes to internal links. Since this little disaster has to split off the trail text to avoid breaking URLs in the following text without breaking trails on the wiki links, it's been made into a horrible function.

Parameters
Title$nt
string$text
string$trail
string$prefix
Returns
string HTML-wikitext mix oh yuck
Parser::makeLimitReport ( )
protected

Set the limit report data in the current ParserOutput, and return the limit report HTML comment.

Returns
string
Parser::markerSkipCallback (   $s,
  $callback 
)

Call a callback function on all regions of the given text that are not inside strip markers, and replace those regions with the return value of the callback. For example, with input:

aaa<MARKER>bbb

This will call the callback function twice, with 'aaa' and 'bbb'. Those two strings will be replaced with the value returned by the callback in each case.

Parameters
string$s
callable$callback
Returns
string
Parser::maybeDoSubpageLink (   $target,
$text 
)

Handle link to subpage if necessary

Parameters
string$targetThe source of the link
string&$textThe link text, modified as necessary
Returns
string The full name of the link
Parser::nextLinkID ( )
Returns
int
static Parser::normalizeLinkUrl (   $url)
static

Replace unusual escape codes in a URL with their equivalent characters

This generally follows the syntax defined in RFC 3986, with special consideration for HTTP query strings.

Parameters
string$url
Returns
string
Parser::Options (   $x = null)

Accessor/mutator for the ParserOptions object

Parameters
ParserOptions$xNew value or null to just get the current one
Returns
ParserOptions Current ParserOptions object
Parser::OutputType (   $x = null)

Accessor/mutator for the output type

Parameters
int | null$xNew value or null to just get the current one
Returns
int
Parser::parse (   $text,
Title  $title,
ParserOptions  $options,
  $linestart = true,
  $clearState = true,
  $revid = null 
)

Convert wikitext to HTML Do not call this function recursively.

Parameters
string$textText we want to parse
Title$title
ParserOptions$options
bool$linestart
bool$clearState
int$revidNumber to pass in {{REVISIONID}}
Returns
ParserOutput A ParserOutput

A converted title will be provided in the output object if title and content conversion are enabled, the article text does not contain a conversion-suppressing double-underscore tag, and no {{DISPLAYTITLE:...}} is present. DISPLAYTITLE takes precedence over automatic link conversion.

static Parser::parseWidthParam (   $value,
  $parseHeight = true 
)
static

Parsed a width param of imagelink like 300px or 200x300px

Parameters
string$value
bool$parseHeight
Returns
array
Since
1.20
Parser::preprocess (   $text,
Title  $title = null,
ParserOptions  $options,
  $revid = null,
  $frame = false 
)

Expand templates and variables in the text, producing valid, static wikitext. Also removes comments. Do not call this function recursively.

Parameters
string$text
Title$title
ParserOptions$options
int | null$revid
bool | PPFrame$frame
Returns
mixed|string
Parser::preprocessToDom (   $text,
  $flags = 0 
)

Preprocess some wikitext and return the document tree. This is the ghost of replace_variables().

Parameters
string$textThe text to parse
int$flagsBitwise combination of:
  • self::PTD_FOR_INCLUSION: Handle "<noinclude>" and "<includeonly>" as if the text is being included. Default is to assume a direct page view.

The generated DOM tree must depend only on the input text and the flags. The DOM tree must be the same in OT_HTML and OT_WIKI mode, to avoid a regression of T6899.

Any flag added to the $flags parameter here, or any other parameter liable to cause a change in the DOM tree for a given text, must be passed through the section identifier in the section edit link and thus back to extractSections().

The output of this function is currently only cached in process memory, but a persistent cache may be implemented at a later date which takes further advantage of these strict dependency requirements.

Returns
PPNode
Parser::preSaveTransform (   $text,
Title  $title,
User  $user,
ParserOptions  $options,
  $clearState = true 
)

Transform wiki markup when saving a page by doing "\r\n" -> "\n" conversion, substituting signatures, {{subst:}} templates, etc.

Parameters
string$textThe text to transform
Title$titleThe Title object for the current article
User$userThe User object describing the current user
ParserOptions$optionsParsing options
bool$clearStateWhether to clear the parser state first
Returns
string The altered wiki markup
Parser::recursivePreprocess (   $text,
  $frame = false 
)

Recursive parser entry point that can be called from an extension tag hook.

Parameters
string$textText to be expanded
bool | PPFrame$frameThe frame to use for expanding any template variables
Returns
string
Since
1.19
Parser::recursiveTagParse (   $text,
  $frame = false 
)

Half-parse wikitext to half-parsed HTML. This recursive parser entry point can be called from an extension tag hook.

The output of this function IS NOT SAFE PARSED HTML; it is "half-parsed" instead, which means that lists and links have not been fully parsed yet, and strip markers are still present.

Use recursiveTagParseFully() to fully parse wikitext to output-safe HTML.

Use this function if you're a parser tag hook and you want to parse wikitext before or after applying additional transformations, and you intend to return the result as hook output, which will cause it to go through the rest of parsing process automatically.

If $frame is not provided, then template variables (e.g., {{{1}}}) within $text are not expanded

Parameters
string$textText extension wants to have parsed
bool | PPFrame$frameThe frame to use for expanding any template variables
Returns
string UNSAFE half-parsed HTML
Parser::recursiveTagParseFully (   $text,
  $frame = false 
)

Fully parse wikitext to fully parsed HTML. This recursive parser entry point can be called from an extension tag hook.

The output of this function is fully-parsed HTML that is safe for output. If you're a parser tag hook, you might want to use recursiveTagParse() instead.

If $frame is not provided, then template variables (e.g., {{{1}}}) within $text are not expanded

Since
1.25
Parameters
string$textText extension wants to have parsed
bool | PPFrame$frameThe frame to use for expanding any template variables
Returns
string Fully parsed HTML
Parser::renderImageGallery (   $text,
  $params 
)

Renders an image gallery from a text with one line per image. text labels may be given by using |-style alternative text. E.g. Image:one.jpg|The number "1" Image:tree.jpg|A tree given as text will return the HTML of a gallery with two images, labeled 'The number "1"' and 'A tree'.

Parameters
string$text
array$params
Returns
string HTML
Parser::replaceExternalLinks (   $text)

Replace external links (REL)

Note: this is all very hackish and the order of execution matters a lot. Make sure to run tests/parser/parserTests.php if you change this code.

Parameters
string$text
Exceptions
MWException
Returns
string
Parser::replaceInternalLinks (   $s)

Process [[ ]] wikilinks

Parameters
string$s
Returns
string Processed text
Parser::replaceInternalLinks2 ( $s)

Process [[ ]] wikilinks (RIL)

Parameters
string&$s
Exceptions
MWException
Returns
LinkHolderArray

Strip the whitespace interwiki links produce, see T10897

Strip the whitespace Category links produce, see T2087

Parser::replaceLinkHolders ( $text,
  $options = 0 
)

Replace "<!--LINK-->" link placeholders with actual links, in the buffer Placeholders created in Linker::link()

Parameters
string&$text
int$options
Parser::replaceLinkHoldersText (   $text)

Replace "<!--LINK-->" link placeholders with plain text of links (not HTML-formatted).

Parameters
string$text
Returns
string
Parser::replaceSection (   $oldText,
  $sectionId,
  $newText 
)

This function returns $oldtext after the content of the section specified by $section has been replaced with $text. If the target section does not exist, $oldtext is returned unchanged.

Parameters
string$oldTextFormer text of the article
string | int$sectionIdSection identifier as a number or string (e.g. 0, 1 or 'T-1').
string$newTextReplacing text
Returns
string Modified text
Parser::replaceTransparentTags (   $text)

Replace transparent tags in $text with the values given by the callbacks.

Transparent tag hooks are like regular XML-style tag hooks, except they operate late in the transformation sequence, on HTML instead of wikitext.

Parameters
string$text
Returns
string
Parser::replaceVariables (   $text,
  $frame = false,
  $argsOnly = false 
)

Replace magic variables, templates, and template arguments with the appropriate text. Templates are substituted recursively, taking care to avoid infinite loops.

Note that the substitution depends on value of $mOutputType: self::OT_WIKI: only {{subst:}} templates self::OT_PREPROCESS: templates but not extension tags self::OT_HTML: all templates and extension tags

Parameters
string$textThe text to transform
bool | PPFrame$frameObject describing the arguments passed to the template. Arguments may also be provided as an associative array, as was the usual case before MW1.12. Providing arguments this way may be useful for extensions wishing to perform variable replacement explicitly.
bool$argsOnlyOnly do argument (triple-brace) expansion, not double-brace expansion.
Returns
string
Parser::serializeHalfParsedText (   $text)

Save the parser state required to convert the given half-parsed text to HTML. "Half-parsed" in this context means the output of recursiveTagParse() or internalParse(). This output has strip markers from replaceVariables (extensionSubstitution() etc.), and link placeholders from replaceLinkHolders().

Returns an array which can be serialized and stored persistently. This array can later be loaded into another parser instance with unserializeHalfParsedText(). The text can then be safely incorporated into the return value of a parser hook.

Deprecated:
since 1.31
Parameters
string$text
Returns
array
Parser::setDefaultSort (   $sort)

Mutator for $mDefaultSort

Parameters
string$sortNew value
Parser::setFunctionHook (   $id,
callable  $callback,
  $flags = 0 
)

Create a function, e.g. {{sum:1|2|3}} The callback function should have the form: function myParserFunction( &$parser, $arg1, $arg2, $arg3 ) { ... }

Or with Parser::SFH_OBJECT_ARGS: function myParserFunction( $parser, $frame, $args ) { ... }

The callback may either return the text result of the function, or an array with the text in element 0, and a number of flags in the other elements. The names of the flags are specified in the keys. Valid flags are: found The text returned is valid, stop processing the template. This is on by default. nowiki Wiki markup in the return value should be escaped isHTML The returned text is HTML, armour it against wikitext transformation

Parameters
string$idThe magic word ID
callable$callbackThe callback function (and object) to use
int$flagsA combination of the following flags: Parser::SFH_NO_HASH No leading hash, i.e. {{plural:...}} instead of {{if:...}}

Parser::SFH_OBJECT_ARGS Pass the template arguments as PPNode objects instead of text. This allows for conditional expansion of the parse tree, allowing you to eliminate dead branches and thus speed up parsing. It is also possible to analyse the parse tree of the arguments, and to control the way they are expanded.

The $frame parameter is a PPFrame. This can be used to produce expanded text from the arguments, for instance: $text = isset( $args[0] ) ? $frame->expand( $args[0] ) : '';

For technical reasons, $args[0] is pre-expanded and will be a string. This may change in future versions. Please call $frame->expand() on it anyway so that your code keeps working if/when this is changed.

If you want whitespace to be trimmed from $args, you need to do it yourself, post- expansion.

Please read the documentation in includes/parser/Preprocessor.php for more information about the methods available in PPFrame and PPNode.

Exceptions
MWException
Returns
string|callable The old callback function for this name, if any
Parser::setFunctionTagHook (   $tag,
callable  $callback,
  $flags 
)

Create a tag function, e.g. "<test>some stuff</test>". Unlike tag hooks, tag functions are parsed at preprocessor level. Unlike parser functions, their content is not preprocessed.

Parameters
string$tag
callable$callback
int$flags
Exceptions
MWException
Returns
null
Parser::setHook (   $tag,
callable  $callback 
)

Create an HTML-style tag, e.g. "<yourtag>special text</yourtag>" The callback should have the following form: function myParserHook( $text, $params, $parser, $frame ) { ... }

Transform and return $text. Use $parser for any required context, e.g. use $parser->getTitle() and $parser->getOptions() not $wgTitle or $wgOut->mParserOptions

Hooks may return extended information by returning an array, of which the first numbered element (index 0) must be the return string, and all other entries are extracted into local variables within an internal function in the Parser class.

This interface (introduced r61913) appears to be undocumented, but 'markerType' is used by some core tag hooks to override which strip array their results are placed in. Use great caution if attempting this interface, as it is not documented and injudicious use could smash private variables.

Parameters
string$tagThe tag to use, e.g. 'hook' for "<hook>"
callable$callbackThe callback function (and object) to use for the tag
Exceptions
MWException
Returns
callable|null The old value of the mTagHooks array associated with the hook
Parser::setLinkID (   $id)
Parameters
int$id
Parser::setOutputType (   $ot)

Set the output type

Parameters
int$otNew value
Parser::setTitle (   $t)

Set the context title

Parameters
Title$t
Parser::setTransparentTagHook (   $tag,
callable  $callback 
)

As setHook(), but letting the contents be parsed.

Transparent tag hooks are like regular XML-style tag hooks, except they operate late in the transformation sequence, on HTML instead of wikitext.

This is probably obsoleted by things dealing with parser frames? The only extension currently using it is geoserver.

Since
1.10
Todo:
better document or deprecate this
Parameters
string$tagThe tag to use, e.g. 'hook' for "<hook>"
callable$callbackThe callback function (and object) to use for the tag
Exceptions
MWException
Returns
callable|null The old value of the mTagHooks array associated with the hook
Parser::setUser (   $user)

Set the current user. Should only be used when doing pre-save transform.

Parameters
User | null$userUser object or null (to reset)
static Parser::splitWhitespace (   $s)
static

Return a three-element array: leading whitespace, string contents, trailing whitespace

Parameters
string$s
Returns
array
Parser::startExternalParse ( Title  $title = null,
ParserOptions  $options,
  $outputType,
  $clearState = true 
)

Set up some variables which are usually set up in parse() so that an external function can call some class members with confidence

Parameters
Title | null$title
ParserOptions$options
int$outputType
bool$clearState
static Parser::statelessFetchRevision ( Title  $title,
  $parser = false 
)
static

Wrapper around Revision::newFromTitle to allow passing additional parameters without passing them on to it.

Since
1.24
Parameters
Title$title
Parser | bool$parser
Returns
Revision|bool False if missing
static Parser::statelessFetchTemplate (   $title,
  $parser = false 
)
static

Static function to get a template Can be overridden via ParserOptions::setTemplateCallback().

Parameters
Title$title
bool | Parser$parser
Returns
array
Parser::stripAltText (   $caption,
  $holders 
)
protected
Parameters
string$caption
LinkHolderArray | bool$holders
Returns
mixed|string
static Parser::stripOuterParagraph (   $html)
static

Strip outer

tag from the HTML source of a single paragraph.

Returns original HTML if the

tag has any attributes, if there's no wrapping

tag, or if there is more than one

tag in the input HTML.

Parameters
string$html
Returns
string
Since
1.24
Parser::stripSectionName (   $text)

Strips a text string of wikitext for use in a section anchor

Accepts a text string and then removes all wikitext from the string and leaves only the resultant text (i.e. the result of [[User:WikiSysop|Sysop]] would be "Sysop" and the result of [[User:WikiSysop]] would be "User:WikiSysop") - this is intended to create valid section anchors by mimicing the output of the parser when headings are parsed.

Parameters
string$textText string to be stripped of wikitext for use in a Section anchor
Returns
string Filtered text string
Parser::testPreprocess (   $text,
Title  $title,
ParserOptions  $options 
)
Parameters
string$text
Title$title
ParserOptions$options
Returns
string
Parser::testPst (   $text,
Title  $title,
ParserOptions  $options 
)
Parameters
string$text
Title$title
ParserOptions$options
Returns
string
Parser::testSrvus (   $text,
Title  $title,
ParserOptions  $options,
  $outputType = self::OT_HTML 
)

strip/replaceVariables/unstrip for preprocessor regression testing

Parameters
string$text
Title$title
ParserOptions$options
int$outputType
Returns
string
Parser::Title (   $x = null)

Accessor/mutator for the Title object

Parameters
Title$xTitle object or null to just get the current one
Returns
Title
Parser::transformMsg (   $text,
  $options,
  $title = null 
)

Wrapper for preprocess()

Parameters
string$textThe text to preprocess
ParserOptions$options
Title | null$titleTitle object or null to use $wgTitle
Returns
string
Parser::unserializeHalfParsedText (   $data)

Load the parser state given in the $data array, which is assumed to have been generated by serializeHalfParsedText(). The text contents is extracted from the array, and its markers are transformed into markers appropriate for the current Parser instance. This transformed text is returned, and can be safely included in the return value of a parser hook.

If the $data array has been stored persistently, the caller should first check whether it is still valid, by calling isValidHalfParsedText().

Deprecated:
since 1.31
Parameters
array$dataSerialized data
Exceptions
MWException
Returns
string
Parser::validateSig (   $text)

Check that the user's signature contains no bad XML

Parameters
string$text
Returns
string|bool An expanded string, or false if invalid.

Member Data Documentation

const Parser::EXT_IMAGE_REGEX
Initial value:
= '/^(http:\/\/|https:\/\/)((?:\\[(?i:[0-9a-f:.]+)\\])?[^][<>"\\x00-\\x20\\x7F\p{Zs}\x{FFFD}]+)
\\/([A-Za-z0-9_.,~%\\-+&;#*?!=()@\\x80-\\xFF]+)\\.((?i)gif|png|jpg|jpeg)$/Sxu'
const Parser::HALF_PARSED_VERSION = 2

Update this version number when the output of serialiseHalfParsedText() changes in an incompatible way

const Parser::VERSION = '1.6.4'

Update this version number when the ParserOutput format changes in an incompatible way, so the parser cache can automatically discard old data.


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