MediaWiki REL1_27
|
PHP Parser - Processes wiki markup (which uses a more user-friendly syntax, such as "[[link]]" for making links), and provides a one-way transformation of that wiki markup it into (X)HTML output / markup (which in turn the browser understands, and can display). More...
Public Member Functions | |
__clone () | |
Allow extensions to clean up when the parser is cloned. | |
__construct ( $conf=[]) | |
__destruct () | |
Reduce memory usage to reduce the impact of circular references. | |
clearState () | |
Clear Parser state. | |
doAllQuotes ( $text) | |
Replace single quotes with HTML markup. | |
doHeadings ( $text) | |
Parse headers and return html. | |
doMagicLinks ( $text) | |
Replace special strings like "ISBN xxx" and "RFC xxx" with magic external links. | |
doQuotes ( $text) | |
Helper function for doAllQuotes() | |
doTableStuff ( $text) | |
parse the wiki syntax used to render tables | |
firstCallInit () | |
Do various kinds of initialisation on the first call of the parser. | |
getConverterLanguage () | |
Get the language object for language conversion. | |
getFunctionLang () | |
Get a language object for use in parser functions such as {{FORMATNUM:}}. | |
getOptions () | |
Get the ParserOptions object. | |
getOutput () | |
Get the ParserOutput object. | |
getPreloadText ( $text, Title $title, ParserOptions $options, $params=[]) | |
Process the wikitext for the "?preload=" feature. | |
getPreprocessor () | |
Get a preprocessor object. | |
getStripList () | |
Get a list of strippable XML-like elements. | |
getTargetLanguage () | |
Get the target language for the content being parsed. | |
getTitle () | |
Accessor for the Title object. | |
getUser () | |
Get a User object either from $this->mUser, if set, or from the ParserOptions object otherwise. | |
insertStripItem ( $text) | |
Add an item to the strip state Returns the unique tag which must be inserted into the stripped text The tag will be replaced with the original text in unstrip() | |
internalParse ( $text, $isMain=true, $frame=false) | |
Helper function for parse() that transforms wiki markup into half-parsed HTML. | |
makeFreeExternalLink ( $url, $numPostProto) | |
Make a free external link, given a user-supplied URL. | |
nextLinkID () | |
Options ( $x=null) | |
Accessor/mutator for the ParserOptions object. | |
OutputType ( $x=null) | |
Accessor/mutator for the output type. | |
parse ( $text, Title $title, ParserOptions $options, $linestart=true, $clearState=true, $revid=null) | |
Convert wikitext to HTML Do not call this function recursively. | |
preprocess ( $text, Title $title=null, ParserOptions $options, $revid=null, $frame=false) | |
Expand templates and variables in the text, producing valid, static wikitext. | |
recursivePreprocess ( $text, $frame=false) | |
Recursive parser entry point that can be called from an extension tag hook. | |
recursiveTagParse ( $text, $frame=false) | |
Half-parse wikitext to half-parsed HTML. | |
recursiveTagParseFully ( $text, $frame=false) | |
Fully parse wikitext to fully parsed HTML. | |
setLinkID ( $id) | |
setOutputType ( $ot) | |
Set the output type. | |
setTitle ( $t) | |
Set the context title. | |
setUser ( $user) | |
Set the current user. | |
Title ( $x=null) | |
Accessor/mutator for the Title object. | |
uniqPrefix () | |
Accessor for mUniqPrefix. | |
Static Public Member Functions | |
static | extractTagsAndParams ( $elements, $text, &$matches, $uniq_prefix=null) |
Replaces all occurrences of HTML-style comments and the given tags in the text with a random marker and returns the next text. | |
static | getRandomString () |
Get a random string. | |
Protected Attributes | |
SectionProfiler | $mProfiler |
Private Member Functions | |
internalParseHalfParsed ( $text, $isMain=true, $linestart=true) | |
Helper function for parse() that transforms half-parsed HTML into fully parsed HTML. | |
PHP Parser - Processes wiki markup (which uses a more user-friendly syntax, such as "[[link]]" for making links), and provides a one-way transformation of that wiki markup it into (X)HTML output / markup (which in turn the browser understands, and can display).
There are seven main entry points into the Parser class:
Globals used: object: $wgContLang
Definition at line 67 of file Parser.php.
Parser::__construct | ( | $conf = [] | ) |
array | $conf |
Definition at line 264 of file Parser.php.
References wfDebug(), and wfUrlProtocols().
Parser::__destruct | ( | ) |
Reduce memory usage to reduce the impact of circular references.
Definition at line 290 of file Parser.php.
Parser::__clone | ( | ) |
Allow extensions to clean up when the parser is cloned.
Definition at line 302 of file Parser.php.
References as.
Parser::clearState | ( | ) |
Clear Parser state.
Definition at line 345 of file Parser.php.
References $parser, and firstCallInit().
Parser::doAllQuotes | ( | $text | ) |
Replace single quotes with HTML markup.
string | $text |
Definition at line 1587 of file Parser.php.
References $line, $lines, as, doQuotes(), and StringUtils\explode().
Referenced by internalParse().
Parser::doHeadings | ( | $text | ) |
Parse headers and return html.
string | $text |
Definition at line 1571 of file Parser.php.
References $i.
Referenced by internalParse().
Parser::doMagicLinks | ( | $text | ) |
Replace special strings like "ISBN xxx" and "RFC xxx" with magic external links.
DML
string | $text |
Definition at line 1410 of file Parser.php.
References of, or, and wfUrlProtocolsWithoutProtRel().
Referenced by internalParse().
Parser::doQuotes | ( | $text | ) |
Helper function for doAllQuotes()
string | $text |
Definition at line 1604 of file Parser.php.
References $i.
Referenced by CoreParserFunctions\displaytitle(), and doAllQuotes().
Parser::doTableStuff | ( | $text | ) |
parse the wiki syntax used to render tables
string | $text |
Definition at line 1033 of file Parser.php.
References $line, $lines, $matches, $out, as, attributes, StringUtils\explode(), Sanitizer\fixTagAttributes(), history, line, of, or, StringUtils\replaceMarkup(), table, and the.
Referenced by internalParse().
|
static |
Replaces all occurrences of HTML-style comments and the given tags in the text with a random marker and returns the next text.
The output parameter $matches will be an associative array filled with data in the form:
array | $elements | List of element names. Comments are always extracted. |
string | $text | Source text string. |
array | $matches | Out parameter, Array: extracted tags |
string | null | $uniq_prefix |
Definition at line 936 of file Parser.php.
References $content, $matches, Sanitizer\decodeTagAttributes(), and wfDeprecated().
Parser::firstCallInit | ( | ) |
Do various kinds of initialisation on the first call of the parser.
Definition at line 325 of file Parser.php.
References $parser, initialiseVariables(), CoreParserFunctions\register(), and CoreTagHooks\register().
Referenced by clearState().
Parser::getConverterLanguage | ( | ) |
Get the language object for language conversion.
Definition at line 885 of file Parser.php.
References getTargetLanguage().
Referenced by internalParseHalfParsed(), makeFreeExternalLink(), and parse().
Parser::getFunctionLang | ( | ) |
Get a language object for use in parser functions such as {{FORMATNUM:}}.
Definition at line 854 of file Parser.php.
References getTargetLanguage().
Parser::getOptions | ( | ) |
Parser::getOutput | ( | ) |
Parser::getPreloadText | ( | $text, | |
Title | $title, | ||
ParserOptions | $options, | ||
$params = [] |
|||
) |
Process the wikitext for the "?preload=" feature.
(bug 5210)
"<noinclude>", "<includeonly>" etc. are parsed as for template transclusion, comments, templates, arguments, tags hooks and parser functions are untouched.
string | $text | |
Title | $title | |
ParserOptions | $options | |
array | $params |
Definition at line 698 of file Parser.php.
References $flags, $options, $params, getPreprocessor(), lock(), PPFrame\NO_ARGS, PPFrame\NO_TEMPLATES, preprocessToDom(), and startParse().
Parser::getPreprocessor | ( | ) |
Get a preprocessor object.
Definition at line 907 of file Parser.php.
Referenced by getPreloadText().
|
static |
Get a random string.
Definition at line 719 of file Parser.php.
References wfDeprecated(), and wfRandomString().
Parser::getStripList | ( | ) |
Get a list of strippable XML-like elements.
Definition at line 1006 of file Parser.php.
Parser::getTargetLanguage | ( | ) |
Get the target language for the content being parsed.
This is usually the language that the content is in.
MWException |
Definition at line 867 of file Parser.php.
Referenced by getConverterLanguage(), and getFunctionLang().
Parser::getTitle | ( | ) |
Parser::getUser | ( | ) |
Get a User object either from $this->mUser, if set, or from the ParserOptions object otherwise.
Definition at line 895 of file Parser.php.
Parser::insertStripItem | ( | $text | ) |
Add an item to the strip state Returns the unique tag which must be inserted into the stripped text The tag will be replaced with the original text in unstrip()
string | $text |
Definition at line 1019 of file Parser.php.
Parser::internalParse | ( | $text, | |
$isMain = true , |
|||
$frame = false |
|||
) |
Helper function for parse() that transforms wiki markup into half-parsed HTML.
Only called for $mOutputType == self::OT_HTML.
string | $text | The text to parse |
bool | $isMain | Whether this is being called from the main parse() function |
PPFrame | bool | $frame | A pre-processor frame |
Definition at line 1236 of file Parser.php.
References $parser, doAllQuotes(), doDoubleUnderscore(), doHeadings(), doMagicLinks(), doTableStuff(), formatHeadings(), preprocessToDom(), PTD_FOR_INCLUSION, Sanitizer\removeHTMLtags(), replaceExternalLinks(), replaceInternalLinks(), and replaceVariables().
Referenced by parse(), and recursiveTagParse().
Helper function for parse() that transforms half-parsed HTML into fully parsed HTML.
string | $text | |
bool | $isMain | |
bool | $linestart |
Definition at line 1307 of file Parser.php.
References $parser, doBlockLevels(), getConverterLanguage(), MWTidy\getModuleStyles(), MWTidy\isEnabled(), Sanitizer\normalizeCharReferences(), of, replaceLinkHolders(), replaceTransparentTags(), and MWTidy\tidy().
Referenced by parse(), and recursiveTagParseFully().
Parser::makeFreeExternalLink | ( | $url, | |
$numPostProto | |||
) |
Make a free external link, given a user-supplied URL.
string | $url | |
int | $numPostProto | The number of characters after the protocol. |
Definition at line 1496 of file Parser.php.
References Sanitizer\cleanUrl(), getConverterLanguage(), getExternalLinkAttribs(), Linker\makeExternalLink(), and maybeMakeExternalImage().
Parser::nextLinkID | ( | ) |
Definition at line 839 of file Parser.php.
Parser::Options | ( | $x = null | ) |
Accessor/mutator for the ParserOptions object.
ParserOptions | $x | New value or null to just get the current one |
Definition at line 832 of file Parser.php.
References wfSetVar().
Parser::OutputType | ( | $x = null | ) |
Accessor/mutator for the output type.
int | null | $x | New value or null to just get the current one |
Definition at line 804 of file Parser.php.
References wfSetVar().
Parser::parse | ( | $text, | |
Title | $title, | ||
ParserOptions | $options, | ||
$linestart = true , |
|||
$clearState = true , |
|||
$revid = null |
|||
) |
Convert wikitext to HTML Do not call this function recursively.
string | $text | Text we want to parse |
Title | $title | |
ParserOptions | $options | |
bool | $linestart | |
bool | $clearState | |
int | $revid | Number to pass in {{REVISIONID}} |
Definition at line 409 of file Parser.php.
References $options, $parser, $title, $value, $wgShowHostnames, as, getConverterLanguage(), global, internalParse(), internalParseHalfParsed(), limitationWarn(), lock(), startParse(), wfDebugLog(), wfHostname(), and wfMessage().
Parser::preprocess | ( | $text, | |
Title | $title = null , |
||
ParserOptions | $options, | ||
$revid = null , |
|||
$frame = false |
|||
) |
Expand templates and variables in the text, producing valid, static wikitext.
Also removes comments. Do not call this function recursively.
string | $text | |
Title | $title | |
ParserOptions | $options | |
int | null | $revid | |
bool | PPFrame | $frame |
Definition at line 653 of file Parser.php.
References $options, $parser, $title, lock(), replaceVariables(), and startParse().
Parser::recursivePreprocess | ( | $text, | |
$frame = false |
|||
) |
Recursive parser entry point that can be called from an extension tag hook.
string | $text | Text to be expanded |
bool | PPFrame | $frame | The frame to use for expanding any template variables |
Definition at line 679 of file Parser.php.
References replaceVariables().
Parser::recursiveTagParse | ( | $text, | |
$frame = false |
|||
) |
Half-parse wikitext to half-parsed HTML.
This recursive parser entry point can be called from an extension tag hook.
The output of this function IS NOT SAFE PARSED HTML; it is "half-parsed" instead, which means that lists and links have not been fully parsed yet, and strip markers are still present.
Use recursiveTagParseFully() to fully parse wikitext to output-safe HTML.
Use this function if you're a parser tag hook and you want to parse wikitext before or after applying additional transformations, and you intend to return the result as hook output, which will cause it to go through the rest of parsing process automatically.
If $frame is not provided, then template variables (e.g., {{{1}}}) within $text are not expanded
string | $text | Text extension wants to have parsed |
bool | PPFrame | $frame | The frame to use for expanding any template variables |
Definition at line 610 of file Parser.php.
References $parser, and internalParse().
Referenced by recursiveTagParseFully().
Parser::recursiveTagParseFully | ( | $text, | |
$frame = false |
|||
) |
Fully parse wikitext to fully parsed HTML.
This recursive parser entry point can be called from an extension tag hook.
The output of this function is fully-parsed HTML that is safe for output. If you're a parser tag hook, you might want to use recursiveTagParse() instead.
If $frame is not provided, then template variables (e.g., {{{1}}}) within $text are not expanded
string | $text | Text extension wants to have parsed |
bool | PPFrame | $frame | The frame to use for expanding any template variables |
Definition at line 636 of file Parser.php.
References internalParseHalfParsed(), and recursiveTagParse().
Parser::setLinkID | ( | $id | ) |
int | $id |
Definition at line 846 of file Parser.php.
Parser::setOutputType | ( | $ot | ) |
Set the output type.
int | $ot | New value |
Definition at line 787 of file Parser.php.
References $ot, OT_HTML, OT_PLAIN, OT_PREPROCESS, and OT_WIKI.
Parser::setTitle | ( | $t | ) |
Set the context title.
Title | $t |
Definition at line 750 of file Parser.php.
References $t, and Title\newFromText().
Parser::setUser | ( | $user | ) |
Set the current user.
Should only be used when doing pre-save transform.
Definition at line 730 of file Parser.php.
References $user.
Parser::Title | ( | $x = null | ) |
Accessor/mutator for the Title object.
Definition at line 778 of file Parser.php.
References wfSetVar().
Parser::uniqPrefix | ( | ) |
Accessor for mUniqPrefix.
Definition at line 740 of file Parser.php.
References wfDeprecated().
MapCacheLRU null Parser::$currentRevisionCache |
A cache of the current revisions of titles. Keys are $title->getPrefixedDbKey()
Definition at line 250 of file Parser.php.
Parser::$mArgStack |
Definition at line 191 of file Parser.php.
Parser::$mAutonumber |
Definition at line 184 of file Parser.php.
Parser::$mConf |
Definition at line 173 of file Parser.php.
Parser::$mDefaultSort |
Definition at line 199 of file Parser.php.
Parser::$mDefaultStripList = [] |
Definition at line 154 of file Parser.php.
Parser::$mDoubleUnderscores |
Definition at line 200 of file Parser.php.
Parser::$mDTopen |
Definition at line 184 of file Parser.php.
Parser::$mExpensiveFunctionCount |
Definition at line 201 of file Parser.php.
Parser::$mExtLinkBracketedRegex |
Definition at line 173 of file Parser.php.
Parser::$mFirstCall = true |
Definition at line 159 of file Parser.php.
Parser::$mForceTocPosition |
Definition at line 202 of file Parser.php.
Parser::$mFunctionHooks = [] |
Definition at line 150 of file Parser.php.
Parser::$mFunctionSynonyms = [ 0 => [], 1 => [] ] |
Definition at line 151 of file Parser.php.
Parser::$mFunctionTagHooks = [] |
Definition at line 152 of file Parser.php.
Parser::$mGeneratedPPNodeCount |
Definition at line 198 of file Parser.php.
Parser::$mHeadings |
Definition at line 200 of file Parser.php.
Parser::$mHighestExpansionDepth |
Definition at line 198 of file Parser.php.
Parser::$mImageParams = [] |
Definition at line 156 of file Parser.php.
Parser::$mImageParamsMagicArray = [] |
Definition at line 157 of file Parser.php.
Parser::$mIncludeCount |
Definition at line 191 of file Parser.php.
Parser::$mIncludeSizes |
Definition at line 198 of file Parser.php.
bool Parser::$mInParse = false |
Recursive call protection.
This variable should be treated as if it were private.
Definition at line 256 of file Parser.php.
Parser::$mInPre |
Definition at line 191 of file Parser.php.
Parser::$mInputSize = false |
Definition at line 229 of file Parser.php.
array Parser::$mLangLinkLanguages |
Array with the language name of each language link (i.e.
the interwiki prefix) in the key, value arbitrary. Used to avoid sending duplicate language links to the ParserOutput.
Definition at line 242 of file Parser.php.
Parser::$mLastSection |
Definition at line 191 of file Parser.php.
LinkHolderArray Parser::$mLinkHolders |
Definition at line 195 of file Parser.php.
Parser::$mLinkID |
Definition at line 197 of file Parser.php.
Parser::$mMarkerIndex = 0 |
Definition at line 158 of file Parser.php.
ParserOptions Parser::$mOptions |
Definition at line 215 of file Parser.php.
ParserOutput Parser::$mOutput |
Definition at line 183 of file Parser.php.
Parser::$mOutputType |
Definition at line 221 of file Parser.php.
Parser::$mPPNodeCount |
Definition at line 198 of file Parser.php.
Preprocessor Parser::$mPreprocessor |
Definition at line 177 of file Parser.php.
|
protected |
Definition at line 259 of file Parser.php.
Parser::$mRevIdForTs |
Definition at line 228 of file Parser.php.
Parser::$mRevisionId |
Definition at line 224 of file Parser.php.
Parser::$mRevisionObject |
Definition at line 223 of file Parser.php.
Parser::$mRevisionSize |
Definition at line 227 of file Parser.php.
Parser::$mRevisionTimestamp |
Definition at line 225 of file Parser.php.
Parser::$mRevisionUser |
Definition at line 226 of file Parser.php.
Parser::$mShowToc |
Definition at line 202 of file Parser.php.
Parser::$mStripList = [] |
Definition at line 153 of file Parser.php.
StripState Parser::$mStripState |
Definition at line 189 of file Parser.php.
MagicWordArray Parser::$mSubstWords |
Definition at line 171 of file Parser.php.
Parser::$mTagHooks = [] |
Definition at line 148 of file Parser.php.
Title Parser::$mTitle |
Definition at line 220 of file Parser.php.
Parser::$mTplDomCache |
Definition at line 200 of file Parser.php.
Parser::$mTplRedirCache |
Definition at line 200 of file Parser.php.
Parser::$mTransparentTagHooks = [] |
Definition at line 149 of file Parser.php.
string Parser::$mUniqPrefix = Parser::MARKER_PREFIX |
Deprecated accessor for the strip marker prefix.
Definition at line 235 of file Parser.php.
Parser::$mUrlProtocols |
Definition at line 173 of file Parser.php.
User Parser::$mUser |
Definition at line 207 of file Parser.php.
Parser::$mVarCache = [] |
Definition at line 155 of file Parser.php.
MagicWordArray Parser::$mVariables |
Definition at line 166 of file Parser.php.
Parser::$ot |
Definition at line 222 of file Parser.php.
Referenced by setOutputType().
const Parser::COLON_STATE_CLOSETAG = 3 |
Definition at line 106 of file Parser.php.
const Parser::COLON_STATE_COMMENT = 5 |
Definition at line 108 of file Parser.php.
const Parser::COLON_STATE_COMMENTDASH = 6 |
Definition at line 109 of file Parser.php.
const Parser::COLON_STATE_COMMENTDASHDASH = 7 |
Definition at line 110 of file Parser.php.
const Parser::COLON_STATE_TAG = 1 |
Definition at line 104 of file Parser.php.
const Parser::COLON_STATE_TAGSLASH = 4 |
Definition at line 107 of file Parser.php.
const Parser::COLON_STATE_TAGSTART = 2 |
Definition at line 105 of file Parser.php.
const Parser::COLON_STATE_TEXT = 0 |
Definition at line 103 of file Parser.php.
Parser::else |
Definition at line 1482 of file Parser.php.
const Parser::EXT_IMAGE_REGEX |
Definition at line 95 of file Parser.php.
const Parser::EXT_LINK_ADDR = '(?:[0-9.]+|\\[(?i:[0-9a-f:.]+)\\]|[^][<>"\\x00-\\x20\\x7F\p{Zs}])' |
Definition at line 92 of file Parser.php.
const Parser::EXT_LINK_URL_CLASS = '[^][<>"\\x00-\\x20\\x7F\p{Zs}]' |
Definition at line 89 of file Parser.php.
const Parser::HALF_PARSED_VERSION = 2 |
Update this version number when the output of serialiseHalfParsedText() changes in an incompatible way.
Definition at line 79 of file Parser.php.
const Parser::MARKER_PREFIX = "\x7f'\"`UNIQ-" |
Definition at line 141 of file Parser.php.
Referenced by MediaWiki\Tidy\RaggettWrapper\replaceCallback().
const Parser::OT_HTML = 1 |
Definition at line 117 of file Parser.php.
const Parser::OT_MSG = 3 |
Definition at line 120 of file Parser.php.
const Parser::OT_PLAIN = 4 |
Definition at line 121 of file Parser.php.
const Parser::OT_PREPROCESS = 3 |
Definition at line 119 of file Parser.php.
const Parser::OT_WIKI = 2 |
Definition at line 118 of file Parser.php.
const Parser::PTD_FOR_INCLUSION = 1 |
Definition at line 113 of file Parser.php.
Referenced by internalParse().
const Parser::SFH_NO_HASH = 1 |
Definition at line 82 of file Parser.php.
const Parser::SFH_OBJECT_ARGS = 2 |
Definition at line 83 of file Parser.php.
const Parser::SPACE_NOT_NL = '(?:\t| |&\#0*160;|&\#[Xx]0*[Aa]0;|\p{Zs})' |
Definition at line 100 of file Parser.php.
const Parser::TOC_END = '</mw:toc>' |
Definition at line 145 of file Parser.php.
const Parser::TOC_START = '<mw:toc>' |
Definition at line 144 of file Parser.php.
const Parser::VERSION = '1.6.4' |
Update this version number when the ParserOutput format changes in an incompatible way, so the parser cache can automatically discard old data.
Definition at line 73 of file Parser.php.