A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.mediawiki.org/wiki/Special:MyLanguage/Manual:Parser.php below:

Manual:Parser.php - MediaWiki

This page is

outdated

.

For more complete information on current code, please refer to

corresponding class/file

. If you have checked or updated this page and found the content to be suitable, please remove this notice. See the

talk page

for a possible discussion on this.

This file contains the class Parser, which contains the method parse, which converts Wikitext to HTML.

Getting the Parser[edit]

In many contexts, such as when creating a parser function or special page, you should have access to a Parser instance.

How to create a new Parser instance[edit]

If you do not have access, you can create a new instance by using ParserFactory and calling its create method.[1] The constructor of the ParserFactory takes several arguments. To create a ParserFactory with default options, use MediaWikiServices::getInstance()->getParserFactory().

One-liner for getting a new Parser instance:

$localParser = MediaWikiServices::getInstance()->getParserFactory()->create();

This new instance is not ready for use yet. The next step is to set ParserOptions.

How to get the main Parser instance[edit]

One-liner for getting the main Parser instance, though unsafe when the caller is not in a top-level context:

$localParser = MediaWikiServices::getInstance()->getParser();
  1. Call helper function Parser::internalParse(), which in turns calls
    1. Parser::replaceVariables, which replaces magic variables, templates, and template arguments with the appropriate text.
      1. It calls Parser::preprocessToDom, which preprocesses some wikitext and returns the document tree.
      2. Next it creates a PPFrame object and calls its expand() method to do the actual template magic.
    2. Sanitizer::removeHTMLtags(), which cleans up HTML, removes dangerous tags and attributes, and removes HTML comments.
    3. Parser::handleTables, which handles and renders the wikitext for tables.
    4. Parser::handleDoubleUnderscore, which removes valid double-underscore items, like __NOTOC__, and records them in array $Parser->mDoubleUnderscores.
    5. Parser::handleHeadings, which parses and renders section headers.
    6. Parser::handleInternalLinks, which processes internal links ([[ ]]) and stores them in $Parser->mLinkHolders (a LinkHolderArray object),
    7. Parser::handleAllQuotes, which replaces single quotes with HTML markup (‎<i>, ‎<b>, etc).
    8. Parser::handleExternalLinks, which replaces and renders external links.
    9. Parser::handleMagicLinks, which replaces special strings like "ISBN xxx" and "RFC xxx" with magic external links.
    10. Parser::handleHeadings, which:
      • auto numbers headings if that options is enabled,
      • adds an [edit] link to sections for users who have enabled the option and can edit the page,
      • adds a Table of contents on the top for users who have enabled the option, and
      • auto-anchors headings.
  2. Next, parse() calls Parser::doBlockLevels, which renders lists from lines starting with ':', '*', '#', etc.
  3. Parser::replaceLinkHolders is called, which calls LinkHolderArray::replace on $Parser->mLinkHolders to replace link placeholders with actual links, in the buffer Placeholders created in Skin::makeLinkObj()
  4. Next, the text is language converted (when applicable) using the convert method of the appropriate Language object.
  5. Parser::replaceTransparentTags used to be called, which replaced transparent tags with values which are provided by the callback functions in $Parser->mTransparentTagHooks. Transparent tag hooks are like regular XML-style tag hooks, except they operate late in the transformation sequence, on HTML instead of wikitext.
  6. Sanitizer::normalizeCharReferences is called, which ensures that any entities and character references are legal for XML and XHTML specifically.
  7. If HTML tidy is enabled, MWTidy::tidy is called to do the tidying.
  8. Finally the rendered HTML result of the parse process is stored in the ParserOutput object $Parser->mOutput, which is returned to the caller of Parser::parse.

The following hooks are made available at various stages in the parsing cycle:

Dynamic properties[edit]

Do not add class properties to the Parser that have not been declared by the Parser. Exceptions aside, dynamic properties are deprecated in PHP 8.2 and they may not sit well with the shift to parallellised envisaged for Parsoid . If you are write an extension and need to store custom data in the Parser, see extension data for one possible way out.

  1. Prior to MediaWiki 1.36, it was still possible to construct a Parser class directly.

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4