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 replace_callback</tt>: parses the wikitext with respect to pairs of double and triple braces.
 * function braceSubstitution</tt>: expands variables and templates.
 * If there are no pipes it calls function variableSubstitution</tt>.
 * If the text between the braces is the name of a variable it calls function getVariableValue</tt>.
 * For evaluating variables depending on time the PHP functions time</tt> and date</tt> are called.
 * If we have, after the opening braces, the title of a core parser function and then a colon, the function concerned in CoreParserFunctions.php</tt> is called.
 * <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>: 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