Manual:Parser.php
From MediaWiki.org
This page may need updating.
[edit] Description
This file contains among other things class Parser, which contains function parse, which is called from function addPrimaryWikiText in OutputPage.php for parsing the wikitext $text. This function parse calls function strip, which strips and renders nowiki, pre, math, and hiero; e.g., each text between nowiki tags is replaced by a temporary code which at the end is replaced by the original text in an unstrip operation. After that XML-style tags of extensions are processed.
There is a hook before and after this call of strip, see the next section. After that the function calls function internalParse, which converts the string $text from wikitext to HTML.
This function starts with hook ParserBeforeInternalParse and calls, in this order:
- function replaceVariables: recursively expands variables, templates, and template parameters; it calls:
- function replace_callback: parses the wikitext with respect to pairs of double and triple braces.
- function braceSubstitution: expands variables and templates.
- If there are no pipes it calls function variableSubstitution.
- If the text between the braces is the name of a variable it calls function getVariableValue.
- If we have, after the opening braces, the title of a core parser function and then a colon, the function concerned in CoreParserFunctions.php is called.
- function createAssocArgs: converts an array of parameter definitions such "a=3", "5", "a=4", and "8" into an associative array with the parameter names a, 1, and 2 as indexes and parameter values 4, 5, and 8 as array values.
- If there are no pipes it calls function variableSubstitution.
- function argSubstitution: expands template parameters.
- function doTableStuff: converts wikitable syntax to HTML.
- function doHeadings: converts header codes: ==a== becomes <h2>a</h2> etc.
- function reformat in DateFormatter.php: converts dates and times according to preferences
- function doAllQuotes: replaces double and triple quotation marks by <i> and <b>.
- function replaceInternalLinks: converts the internal links to HTML.
- function replaceExternalLinks: converts the external links to HTML.
After that there is tidying, with a hook before and after it.
The file also contains function preprocess, used for Special:ExpandTemplates, which contains a call of function replaceVariables between a strip and unstrip call.
Further the file contains function setFunctionHook, called when setting up a function, and associating the magic_word_id of a parser function with the name of the PHP function defining it (see also parser function extensions). This information is stored in array mFunctionHooks. Also the array mFunctionSynonyms is created, with a case-sensitive boolean as index, and as value an array with the magic words that can be used in the wikitext as indexes, and the magic word id's as values. These arrays are used during the parsing.
[edit] Hooks
| Version | Hook | Description |
|---|---|---|
| 1.5.0 | ParserAfterStrip | |
| 1.5.0 | ParserAfterTidy | Used to add some final processing to the fully-rendered page output |
| 1.6.0 | ParserBeforeInternalParse | |
| 1.5.0 | ParserBeforeStrip | Used to process the raw wiki code before any internal processing is applied |
| 1.5.0 | ParserBeforeTidy | Used to process the nearly-rendered html code for the page (but before any html tidying occurs) |
| 1.6.0 | ParserClearState | |
| 1.6.0 | ParserGetVariableValueSwitch | |
| 1.6.0 | ParserGetVariableValueTs | |
| 1.6.0 | ParserGetVariableValueVarCache | |
| 1.6.0 | ParserTestParser |

