Manual:Parser.php

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 the XML style tags nowiki, pre</tt>, math</tt>, and hiero</tt>; e.g., each text between nowiki</tt> 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</tt>, see the next section. After that the function calls function internalParse</tt>, which converts the string $text</tt> from wikitext to HTML.

This function starts with hook ParserBeforeInternalParse</tt> and calls, in this order:


 * function replaceVariables</tt>: recursively expands variables, templates, and template parameters; it calls:
 * function preprocessToDom</tt>: calls function preprocessToObj</tt> in Preprocessor DOM.php</tt>.
 * function expand</tt>, also in Preprocessor DOM.php. This function calls:
 * function braceSubstitution</tt>: performs double-brace expansion: it expands variables, parser functions, and templates. It extracts $part1, the bit before the first |.
 * If $part1 is a variable name it calls function getVariableValue</tt>.
 * For evaluating variables depending on time the PHP functions time</tt> and <tt>date</tt> are called.
 * If $part1 contains a colon and the part before the colon is a parser function name, the function concerned in <tt>CoreParserFunctions.php</tt> is called, or an extension parser function given by call_user_func_array.
 * In the remaining cases a template is expanded.
 * <tt>function createAssocArgs</tt>: 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.
 * <tt>function argSubstitution</tt>: performs triple-brace expansion (it expands template parameters).
 * <tt>function doTableStuff</tt>: converts wikitable syntax to HTML.
 * <tt>function doHeadings</tt>: converts header codes: <tt> ==a== </tt> becomes <tt> a <tt> etc.
 * <tt>function reformat</tt> in <tt>DateFormatter.php</tt>: converts dates and times according to preferences
 * <tt>function doAllQuotes</tt>: replaces double and triple quotation marks by <tt> <i> </tt> and <tt> <b> </tt>.
 * <tt>function replaceInternalLinks</tt>: converts the internal links to HTML.
 * <tt>function replaceExternalLinks</tt>: converts the external links to HTML.

After that there is tidying, with a hook before and after it.

The file also contains <tt>function preprocess</tt>, used for Special:ExpandTemplates, which contains a call of function <tt>replaceVariables</tt> between a <tt>strip</tt> and <tt>unstrip</tt> call.

Further the file contains <tt>function setFunctionHook</tt>, called when setting up a function, and associating the <tt>magic_word_id</tt> of a parser function with the name of the PHP function defining it (see also parser function extensions). This information is stored in <tt>array mFunctionHooks</tt>. Also the <tt>array mFunctionSynonyms</tt> 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.

External link

 * The MediaWiki parser, uncovered