Manual:Parser.php

Description
This file contains the class Parser, which contains the method parse, which converts Wikitext to HTML. It performs, among other things, the following actions:

Call helper function Parser::internalParse, which in turns calls Parser::replaceVariables</tt></>, which replaces magic variables, templates, and template arguments with the appropriate text. It calls <tvar|todom>Parser::preprocessToDom</tt></>, which preprocesses some wikitext and returns the document tree. Next it creates a <tvar|dom>PPFrame DOM</tt></> object and calls its <tvar|expand>expand</tt></> method to do the actual template magic. <tvar|sanitizer>Sanitizer::removeHTMLtags</tt></>, which cleans up HTML, removes dangerous tags and attributes, and removes HTML comments. <tvar|stuff>Parser::doTableStuff</tt></>, which handles and renders the wikitext for tables. <tvar|underscore>Parser::doDoubleUnderscore</tt></>, which removes valid switches>Special:MyLanguage/Help:Magic_words#Behavior_switches</>|double-underscore items, like <tvar|notoc> </>, and records them in array <tvar|underscores> </>. <tvar|headings>Parser::doHeadings</tt></>, which parses and renders section headers. <tvar|internal>Parser::replaceInternalLinks</tt></>, which processes internal links (<tvar|brace> </>) and stores them in  (a LinkHolderArray</tt> object), <tvar|allquotes>Parser::doAllQuotes</tt></>, which replaces single quotes with HTML markup ( <i>, <b>, etc). <tvar|extlinks>Parser::replaceExternalLinks</tt></>, which replaces and renders external links. <tvar|magiclinks>Parser::doMagicLinks</tt></>, which replaces special strings like "ISBN xxx" and "RFC xxx" with magic external links. <tvar|format>Parser::formatHeadings</tt></>, which: auto numbers headings if that options is enabled, adds an <tvar|edit> [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. Next, <tvar|parse>parse</tt></> calls <tvar|blocklevels>Parser::doBlockLevels</tt></>, which renders lists from lines starting with ':', '*', '#', etc. <tvar|holders>Parser::replaceLinkHolders</tt></> is called, which calls <tvar|array><tt>LinkHolderArray::replace</tt></> on <tvar|mlink> </> to replace link placeholders with actual links, in the buffer Placeholders created in <tvar|makelink>Skin::makeLinkObj</> Next, the text is language converted (when applicable) using the <tvar|convert><tt>convert</tt></> method of the appropriate <tvar|lang>Language</> object. <tvar|transparent><tt>Parser::replaceTransparentTags</tt></> is called, which replaces transparent tags with values which are provided by the callback functions in <tvar|taghooks><tt>$Parser->mTransparentTagHooks</tt></>. Transparent tag hooks are like regular XML-style tag hooks, except they operate late in the transformation sequence, on HTML instead of wikitext. <tvar|charref><tt>Sanitizer::normalizeCharReferences</tt></> is called, which ensures that any entities and character references are legal for XML and XHTML specifically. If htmltidy>Special:MyLanguage/Manual:$wgUseTidy</>|HTML tidy is enabled, <tvar|tidy><tt>MWTidy::tidy</tt></> is called to do the tidying. Finally the rendered HTML result of the parse process is stored in the <tvar|parseroutput><tt>ParserOutput</tt></> object <tvar|moutput> </>, which is returned to the caller of <tvar|parse><tt>Parser::parse</tt></>.

== hooks>Special:MyLanguage/Manual:Hooks</>|Hooks ==

Accessors
Accessor for <tvar|msort>$mDefaultSort</>. Unlike <tvar|getsort>getDefaultSort</>, it will return false if none is set. Accessor for <tvar|msort>$mDefaultSort</>. Will use the empty string if none is set. Get the ParserOptions object. Get the ParserOutput object. Get a preprocessor object. Get the ID of the revision we are parsing. Get the timestamp associated with the current revision, adjusted for the default server-local timestamp. Get the name of the user that edited the last revision. Accessor. Get the target language for the content being parsed. Accessor for the Title object. Get a User object either from <tvar|mUser>$this->mUser</>, if set, or from the ParserOptions object otherwise.

Set
Create a function, e.g. <tvar|example> </>. The callback function should have the form: <tvar|code> .</> Create a tag function, e.g. <tvar|example> </>. Unlike tag hooks, tag functions are parsed at preprocessor level. Unlike parser functions, their content is not preprocessed. Create an HTML-style tag, e.g. <tvar|example> </>. The callback should have the following form: <tvar|code> </>