Manual:Parser.php

From MediaWiki.org
Jump to: navigation, search


MediaWiki File: Parser.php
Location: /includes/parser/
Source code:

HEAD1.18alpha
1.17.01.16.5

Classes: Parser

Contents

[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 the XML style tags 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, parser functions, templates, and template parameters; it calls:
    • function preprocessToDom: calls function preprocessToObj in Preprocessor DOM.php.
    • function expand, also in Preprocessor DOM.php. This function calls:
      • function braceSubstitution: 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.
          • For evaluating variables depending on time the PHP functions time and date are called.
        • If $part1 contains a colon and the part before the colon is a parser function name, the function concerned in CoreParserFunctions.php is called, or an extension parser function given by call_user_func_array.
        • In the remaining cases a template is expanded.
          • 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.
      • function argSubstitution: performs triple-brace expansion (it 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

[edit] See also

[edit] External link

Language: English  • 日本語
Personal tools
Namespaces
Variants
Actions
Site
Support
Download
Development
Communication
Print/export
Toolbox