MediaWiki
1.28.0
|
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. More... | |
__construct ($conf=[]) | |
__destruct () | |
Reduce memory usage to reduce the impact of circular references. More... | |
addTrackingCategory ($msg) | |
areSubpagesAllowed () | |
Return true if subpage links should be expanded on this page. More... | |
argSubstitution ($piece, $frame) | |
Triple brace replacement – used for template arguments. More... | |
armorLinks ($text) | |
Insert a NOPARSE hacky thing into any inline links in a chunk that's going to go through further parsing steps before inline URL expansion. More... | |
attributeStripCallback (&$text, $frame=false) | |
Callback from the Sanitizer for expanding items found in HTML attribute values, so they can be safely tested and escaped. More... | |
braceSubstitution ($piece, $frame) | |
Return the text of a template, after recursively replacing any variables or templates within the template. More... | |
callParserFunction ($frame, $function, array $args=[]) | |
Call a parser function and return an array with text and flags. More... | |
cleanSig ($text, $parsing=false) | |
Clean up signature text. More... | |
clearState () | |
Clear Parser state. More... | |
clearTagHooks () | |
Remove all tag hooks. More... | |
disableCache () | |
Set a flag in the output object indicating that the content is dynamic and shouldn't be cached. More... | |
doAllQuotes ($text) | |
Replace single quotes with HTML markup. More... | |
doBlockLevels ($text, $linestart) | |
Make lists from lines starting with ':', '*', '#', etc. More... | |
doDoubleUnderscore ($text) | |
Strip double-underscore items like NOGALLERY and NOTOC Fills $this->mDoubleUnderscores, returns the modified text. More... | |
doHeadings ($text) | |
Parse headers and return html. More... | |
doMagicLinks ($text) | |
Replace special strings like "ISBN xxx" and "RFC xxx" with magic external links. More... | |
doQuotes ($text) | |
Helper function for doAllQuotes() More... | |
doTableStuff ($text) | |
parse the wiki syntax used to render tables More... | |
enableOOUI () | |
Set's up the PHP implementation of OOUI for use in this request and instructs OutputPage to enable OOUI for itself. More... | |
extensionSubstitution ($params, $frame) | |
Return the text to be used for a given extension tag. More... | |
fetchCurrentRevisionOfTitle ($title) | |
Fetch the current revision of a given title. More... | |
fetchFile ($title, $options=[]) | |
Fetch a file and its title and register a reference to it. More... | |
fetchFileAndTitle ($title, $options=[]) | |
Fetch a file and its title and register a reference to it. More... | |
fetchScaryTemplateMaybeFromCache ($url) | |
fetchTemplate ($title) | |
Fetch the unparsed text of a template and register a reference to it. More... | |
fetchTemplateAndTitle ($title) | |
Fetch the unparsed text of a template and register a reference to it. More... | |
firstCallInit () | |
Do various kinds of initialisation on the first call of the parser. More... | |
formatHeadings ($text, $origText, $isMain=true) | |
This function accomplishes several tasks: 1) Auto-number headings if that option is enabled 2) Add an [edit] link to sections for users who have enabled the option and can edit the page 3) Add a Table of contents on the top for users who have enabled the option 4) Auto-anchor headings. More... | |
getConverterLanguage () | |
Get the language object for language conversion. More... | |
getCustomDefaultSort () | |
Accessor for $mDefaultSort Unlike getDefaultSort(), will return false if none is set. More... | |
getDefaultSort () | |
Accessor for $mDefaultSort Will use the empty string if none is set. More... | |
getExternalLinkAttribs ($url) | |
Get an associative array of additional HTML attributes appropriate for a particular external link. More... | |
getFreshParser () | |
Return this parser if it is not doing anything, otherwise get a fresh parser. More... | |
getFunctionHooks () | |
Get all registered function hook identifiers. More... | |
getFunctionLang () | |
Get a language object for use in parser functions such as {{FORMATNUM:}}. More... | |
getImageParams ($handler) | |
getLinkRenderer () | |
Get a LinkRenderer instance to make links with. More... | |
getOptions () | |
Get the ParserOptions object. More... | |
getOutput () | |
Get the ParserOutput object. More... | |
getPreloadText ($text, Title $title, ParserOptions $options, $params=[]) | |
Process the wikitext for the "?preload=" feature. More... | |
getPreprocessor () | |
Get a preprocessor object. More... | |
getRevisionId () | |
Get the ID of the revision we are parsing. More... | |
getRevisionObject () | |
Get the revision object for $this->mRevisionId. More... | |
getRevisionSize () | |
Get the size of the revision. More... | |
getRevisionTimestamp () | |
Get the timestamp associated with the current revision, adjusted for the default server-local timestamp. More... | |
getRevisionUser () | |
Get the name of the user that edited the last revision. More... | |
getSection ($text, $sectionId, $defaultText= '') | |
This function returns the text of a section, specified by a number ($section). More... | |
getStripList () | |
Get a list of strippable XML-like elements. More... | |
getTags () | |
Accessor. More... | |
getTargetLanguage () | |
Get the target language for the content being parsed. More... | |
getTemplateDom ($title) | |
Get the semi-parsed DOM representation of a template with a given title, and its redirect destination title. More... | |
getTitle () | |
Accessor for the Title object. More... | |
getUser () | |
Get a User object either from $this->mUser, if set, or from the ParserOptions object otherwise. More... | |
getUserSig (&$user, $nickname=false, $fancySig=null) | |
Fetch the user's signature text, if any, and normalize to validated, ready-to-insert wikitext. More... | |
getVariableValue ($index, $frame=false) | |
Return value of a magic variable (like PAGENAME) More... | |
guessLegacySectionNameFromWikiText ($text) | |
Same as guessSectionNameFromWikiText(), but produces legacy anchors instead. More... | |
guessSectionNameFromWikiText ($text) | |
Try to guess the section anchor name based on a wikitext fragment presumably extracted from a heading, for example "Header" from "== Header ==". More... | |
incrementExpensiveFunctionCount () | |
Increment the expensive function count. More... | |
incrementIncludeSize ($type, $size) | |
Increment an include size counter. More... | |
initialiseVariables () | |
initialise the magic variables (like CURRENTMONTHNAME) and substitution modifiers More... | |
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() More... | |
internalParse ($text, $isMain=true, $frame=false) | |
Helper function for parse() that transforms wiki markup into half-parsed HTML. More... | |
interwikiTransclude ($title, $action) | |
Transclude an interwiki link. More... | |
isValidHalfParsedText ($data) | |
Returns true if the given array, presumed to be generated by serializeHalfParsedText(), is compatible with the current version of the parser. More... | |
killMarkers ($text) | |
Remove any strip markers found in the given text. More... | |
limitationWarn ($limitationType, $current= '', $max= '') | |
Warn the user when a parser limitation is reached Will warn at most once the user per limitation type. More... | |
magicLinkCallback ($m) | |
makeFreeExternalLink ($url, $numPostProto) | |
Make a free external link, given a user-supplied URL. More... | |
makeImage ($title, $options, $holders=false) | |
Parse image options text and use it to make an image. More... | |
markerSkipCallback ($s, $callback) | |
Call a callback function on all regions of the given text that are not inside strip markers, and replace those regions with the return value of the callback. More... | |
maybeDoSubpageLink ($target, &$text) | |
Handle link to subpage if necessary. More... | |
nextLinkID () | |
Options ($x=null) | |
Accessor/mutator for the ParserOptions object. More... | |
OutputType ($x=null) | |
Accessor/mutator for the output type. More... | |
parse ($text, Title $title, ParserOptions $options, $linestart=true, $clearState=true, $revid=null) | |
Convert wikitext to HTML Do not call this function recursively. More... | |
parseWidthParam ($value) | |
Parsed a width param of imagelink like 300px or 200x300px. More... | |
preprocess ($text, Title $title=null, ParserOptions $options, $revid=null, $frame=false) | |
Expand templates and variables in the text, producing valid, static wikitext. More... | |
preprocessToDom ($text, $flags=0) | |
Preprocess some wikitext and return the document tree. More... | |
preSaveTransform ($text, Title $title, User $user, ParserOptions $options, $clearState=true) | |
Transform wiki markup when saving a page by doing "\\r\\n" -> "\\n" conversion, substituting signatures, {{subst:}} templates, etc. More... | |
recursivePreprocess ($text, $frame=false) | |
Recursive parser entry point that can be called from an extension tag hook. More... | |
recursiveTagParse ($text, $frame=false) | |
Half-parse wikitext to half-parsed HTML. More... | |
recursiveTagParseFully ($text, $frame=false) | |
Fully parse wikitext to fully parsed HTML. More... | |
renderImageGallery ($text, $params) | |
Renders an image gallery from a text with one line per image. More... | |
replaceExternalLinks ($text) | |
Replace external links (REL) More... | |
replaceInternalLinks ($s) | |
Process [[ ]] wikilinks. More... | |
replaceInternalLinks2 (&$s) | |
Process [[ ]] wikilinks (RIL) More... | |
replaceLinkHolders (&$text, $options=0) | |
Replace "<!--LINK-->" link placeholders with actual links, in the buffer Placeholders created in Linker::link() More... | |
replaceLinkHoldersText ($text) | |
Replace "<!--LINK-->" link placeholders with plain text of links (not HTML-formatted). More... | |
replaceSection ($oldText, $sectionId, $newText) | |
This function returns $oldtext after the content of the section specified by $section has been replaced with $text. More... | |
replaceTransparentTags ($text) | |
Replace transparent tags in $text with the values given by the callbacks. More... | |
replaceVariables ($text, $frame=false, $argsOnly=false) | |
Replace magic variables, templates, and template arguments with the appropriate text. More... | |
serializeHalfParsedText ($text) | |
Save the parser state required to convert the given half-parsed text to HTML. More... | |
setDefaultSort ($sort) | |
Mutator for $mDefaultSort. More... | |
setFunctionHook ($id, $callback, $flags=0) | |
Create a function, e.g. More... | |
setFunctionTagHook ($tag, $callback, $flags) | |
Create a tag function, e.g. More... | |
setHook ($tag, $callback) | |
Create an HTML-style tag, e.g. More... | |
setLinkID ($id) | |
setOutputType ($ot) | |
Set the output type. More... | |
setTitle ($t) | |
Set the context title. More... | |
setTransparentTagHook ($tag, $callback) | |
As setHook(), but letting the contents be parsed. More... | |
setUser ($user) | |
Set the current user. More... | |
startExternalParse (Title $title=null, ParserOptions $options, $outputType, $clearState=true) | |
Set up some variables which are usually set up in parse() so that an external function can call some class members with confidence. More... | |
stripSectionName ($text) | |
Strips a text string of wikitext for use in a section anchor. More... | |
testPreprocess ($text, Title $title, ParserOptions $options) | |
testPst ($text, Title $title, ParserOptions $options) | |
testSrvus ($text, Title $title, ParserOptions $options, $outputType=self::OT_HTML) | |
strip/replaceVariables/unstrip for preprocessor regression testing More... | |
Title ($x=null) | |
Accessor/mutator for the Title object. More... | |
transformMsg ($text, $options, $title=null) | |
Wrapper for preprocess() More... | |
uniqPrefix () | |
Accessor for mUniqPrefix. More... | |
unserializeHalfParsedText ($data) | |
Load the parser state given in the $data array, which is assumed to have been generated by serializeHalfParsedText(). More... | |
validateSig ($text) | |
Check that the user's signature contains no bad XML. More... | |
Static Public Member Functions | |
static | cleanSigInSig ($text) |
Strip 3, 4 or 5 tildes out of signatures. More... | |
static | createAssocArgs ($args) |
Clean up argument array - refactored in 1.9 so parserfunctions can use it, too. More... | |
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. More... | |
static | getExternalLinkRel ($url=false, $title=null) |
Get the rel attribute for a particular external link. More... | |
static | getRandomString () |
Get a random string. More... | |
static | normalizeLinkUrl ($url) |
Replace unusual escape codes in a URL with their equivalent characters. More... | |
static | replaceUnusualEscapes ($url) |
Replace unusual escape codes in a URL with their equivalent characters. More... | |
static | splitWhitespace ($s) |
Return a three-element array: leading whitespace, string contents, trailing whitespace. More... | |
static | statelessFetchRevision (Title $title, $parser=false) |
Wrapper around Revision::newFromTitle to allow passing additional parameters without passing them on to it. More... | |
static | statelessFetchTemplate ($title, $parser=false) |
Static function to get a template Can be overridden via ParserOptions::setTemplateCallback(). More... | |
static | stripOuterParagraph ($html) |
Strip outer. More... | |
Protected Member Functions | |
fetchFileNoRegister ($title, $options=[]) | |
Helper function for fetchFileAndTitle. More... | |
lock () | |
Lock the current instance of the parser. More... | |
makeKnownLinkHolder ($nt, $text= '', $trail= '', $prefix= '') | |
Render a forced-blue link inline; protect against double expansion of URLs if we're in a mode that prepends full URL prefixes to internal links. More... | |
stripAltText ($caption, $holders) | |
Protected Attributes | |
LinkRenderer | $mLinkRenderer |
SectionProfiler | $mProfiler |
Private Member Functions | |
extractSections ($text, $sectionId, $mode, $newText= '') | |
Break wikitext input into sections, and either pull or replace some particular section's text. More... | |
internalParseHalfParsed ($text, $isMain=true, $linestart=true) | |
Helper function for parse() that transforms half-parsed HTML into fully parsed HTML. More... | |
maybeMakeExternalImage ($url) | |
make an image if it's allowed, either through the global option, through the exception, or through the on-wiki whitelist More... | |
pstPass2 ($text, $user) | |
Pre-save transform helper function. More... | |
startParse (Title $title=null, ParserOptions $options, $outputType, $clearState=true) | |
Static Private Member Functions | |
static | normalizeUrlComponent ($component, $unsafe) |
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 70 of file Parser.php.
Parser::__construct | ( | $conf = [] | ) |
array | $conf |
Definition at line 262 of file Parser.php.
References wfDebug(), and wfUrlProtocols().
Parser::__destruct | ( | ) |
Reduce memory usage to reduce the impact of circular references.
Definition at line 288 of file Parser.php.
Parser::__clone | ( | ) |
Allow extensions to clean up when the parser is cloned.
Definition at line 300 of file Parser.php.
References as, and Hooks\run().
Parser::addTrackingCategory | ( | $msg | ) |
string | $msg | Message key |
Definition at line 3994 of file Parser.php.
Referenced by magicLinkCallback().
Parser::areSubpagesAllowed | ( | ) |
Return true if subpage links should be expanded on this page.
Definition at line 2433 of file Parser.php.
References MWNamespace\hasSubpages().
Referenced by replaceInternalLinks2().
Parser::argSubstitution | ( | $piece, | |
$frame | |||
) |
Triple brace replacement – used for template arguments.
array | $piece | |
PPFrame | $frame |
Definition at line 3752 of file Parser.php.
References $ret.
Parser::armorLinks | ( | $text | ) |
Insert a NOPARSE hacky thing into any inline links in a chunk that's going to go through further parsing steps before inline URL expansion.
Not needed quite as much as it used to be since free links are a bit more sensible these days. But bracketed links are still an issue.
string | $text | More-or-less HTML |
Definition at line 2424 of file Parser.php.
Referenced by replaceInternalLinks2().
Parser::attributeStripCallback | ( | & | $text, |
$frame = false |
|||
) |
Callback from the Sanitizer for expanding items found in HTML attribute values, so they can be safely tested and escaped.
string | $text | |
bool | PPFrame | $frame |
Definition at line 5381 of file Parser.php.
Parser::braceSubstitution | ( | $piece, | |
$frame | |||
) |
Return the text of a template, after recursively replacing any variables or templates within the template.
array | $piece | The parts of the template $piece['title']: the title, i.e. the part before the | $piece['parts']: the parameter array $piece['lineStart']: whether the brace was at the start of a line |
PPFrame | $frame | The current frame, contains template arguments |
Exception |
Definition at line 2999 of file Parser.php.
References $args, $context, $limit, $name, $ret, $title, $value, SpecialPageFactory\capturePath(), false, MagicWord\get(), MagicWord\getCacheTTL(), SpecialPageFactory\getPage(), in, MWNamespace\isNonincludable(), list, User\newFromName(), Title\newFromText(), not, NS_TEMPLATE, or, plain, PPFrame\RECOVER_ORIG, PPFrame\STRIP_COMMENTS, wfDebug(), wfEscapeWikiText(), and wfMessage().
Parser::callParserFunction | ( | $frame, | |
$function, | |||
array | $args = [] |
||
) |
Call a parser function and return an array with text and flags.
The returned array will always contain a boolean 'found', indicating whether the parser function was found or not. It may also contain the following: text: string|object, resulting wikitext or PP DOM object isHTML: bool, $text is HTML, armour it against wikitext transformation isChildObj: bool, $text is a DOM node needing expansion in a child frame isLocalObj: bool, $text is a DOM node needing expansion in the current frame nowiki: bool, wiki markup in $text should be escaped
PPFrame | $frame | The current frame, contains template arguments |
string | $function | Function name |
array | $args | Arguments to the function |
MWException |
Definition at line 3328 of file Parser.php.
References $args, $flags, $wgContLang, as, false, global, list, and SFH_OBJECT_ARGS.
Parser::cleanSig | ( | $text, | |
$parsing = false |
|||
) |
Clean up signature text.
1) Strip 3, 4 or 5 tildes out of signatures
string | $text | |
bool | $parsing | Whether we're cleaning (preferences save) or parsing |
Definition at line 4596 of file Parser.php.
References $wgTitle, MagicWord\get(), global, and OT_PREPROCESS.
|
static |
Strip 3, 4 or 5 tildes out of signatures.
string | $text |
Definition at line 4633 of file Parser.php.
Referenced by Preferences\cleanSignature(), and ExtraParserTest\testCleanSigInSig().
Parser::clearState | ( | ) |
Clear Parser state.
Definition at line 341 of file Parser.php.
References firstCallInit(), and Hooks\run().
Parser::clearTagHooks | ( | ) |
Remove all tag hooks.
Definition at line 4767 of file Parser.php.
|
static |
Parser::disableCache | ( | ) |
Set a flag in the output object indicating that the content is dynamic and shouldn't be cached.
Definition at line 5364 of file Parser.php.
References wfDebug().
Parser::doAllQuotes | ( | $text | ) |
Replace single quotes with HTML markup.
string | $text |
Definition at line 1609 of file Parser.php.
References $line, $lines, as, doQuotes(), and StringUtils\explode().
Referenced by internalParse().
Parser::doBlockLevels | ( | $text, | |
$linestart | |||
) |
Make lists from lines starting with ':', '*', '#', etc.
(DBL)
string | $text | |
bool | $linestart | Whether or not this is at the start of a line. |
Definition at line 2458 of file Parser.php.
References BlockLevelPass\doBlockLevels().
Referenced by internalParseHalfParsed().
Parser::doDoubleUnderscore | ( | $text | ) |
Strip double-underscore items like NOGALLERY and NOTOC Fills $this->mDoubleUnderscores, returns the modified text.
string | $text |
Definition at line 3939 of file Parser.php.
References as, MagicWord\get(), MagicWord\getDoubleUnderscoreArray(), and NS_CATEGORY.
Referenced by internalParse().
Parser::doHeadings | ( | $text | ) |
Parse headers and return html.
string | $text |
Definition at line 1593 of file Parser.php.
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 1414 of file Parser.php.
References of, or, and wfUrlProtocolsWithoutProtRel().
Referenced by internalParse().
Parser::doQuotes | ( | $text | ) |
Helper function for doAllQuotes()
string | $text |
Definition at line 1626 of file Parser.php.
References $buffer, $output, and as.
Referenced by doAllQuotes().
Parser::doTableStuff | ( | $text | ) |
parse the wiki syntax used to render tables
string | $text |
Definition at line 1040 of file Parser.php.
References $line, $lines, $matches, $out, as, StringUtils\explode(), Sanitizer\fixTagAttributes(), history, line, of, Makefile\open, or, StringUtils\replaceMarkup(), table, and the.
Referenced by internalParse().
Parser::enableOOUI | ( | ) |
Set's up the PHP implementation of OOUI for use in this request and instructs OutputPage to enable OOUI for itself.
Definition at line 6070 of file Parser.php.
References OutputPage\setupOOUI().
Parser::extensionSubstitution | ( | $params, | |
$frame | |||
) |
Return the text to be used for a given extension tag.
This is the ghost of strip().
array | $params | Associative array of parameters: name PPNode for the tag name attr PPNode for unparsed text where tag attributes are thought to be attributes Optional associative array of parsed attributes inner Contents of extension element noClose Original text did not have a close tag |
PPFrame | $frame |
MWException |
Definition at line 3805 of file Parser.php.
References $content, $flags, $name, $output, $params, as, Sanitizer\decodeTagAttributes(), and list.
|
private |
Break wikitext input into sections, and either pull or replace some particular section's text.
External callers should use the getSection and replaceSection methods.
string | $text | Page wikitext |
string | number | $sectionId | A section identifier string of the form: "<flag1> - <flag2> - ... - <section number>" |
Currently the only recognised flag is "T", which means the target section number was derived during a template inclusion parse, in other words this is a template section edit link. If no flags are given, it was an ordinary section edit link. This flag is required to avoid a section numbering mismatch when a section is enclosed by "<includeonly>" (bug 6563).
The section number 0 pulls the text before the first heading; other numbers will pull the given section along with its lower-level subsections. If the section is not found, $mode=get will return $newtext, and $mode=replace will return $text.
Section 0 is always considered to exist, even if it only contains the empty string. If $text is the empty string and section 0 is replaced, $newText is returned.
string | $mode | One of "get" or "replace" |
string | $newText | Replacement text for section data. |
Definition at line 5461 of file Parser.php.
References $flags, $wgTitle, as, global, not, OT_PLAIN, PPFrame\RECOVER_ORIG, and used.
|
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 943 of file Parser.php.
References $content, $matches, Sanitizer\decodeTagAttributes(), and wfDeprecated().
Parser::fetchCurrentRevisionOfTitle | ( | $title | ) |
Fetch the current revision of a given title.
Note that the revision (and even the title) may not exist in the database, so everything contributing to the output of the parser should use this method where possible, rather than getting the revisions themselves. This method also caches its results, so using it benefits performance.
Title | $title |
Definition at line 3467 of file Parser.php.
References $title.
Parser::fetchFile | ( | $title, | |
$options = [] |
|||
) |
Fetch a file and its title and register a reference to it.
If 'broken' is a key in $options then the file will appear as a broken thumbnail.
Title | $title | |
array | $options | Array of options to RepoGroup::findFile |
Definition at line 3638 of file Parser.php.
Parser::fetchFileAndTitle | ( | $title, | |
$options = [] |
|||
) |
Fetch a file and its title and register a reference to it.
If 'broken' is a key in $options then the file will appear as a broken thumbnail.
Title | $title | |
array | $options | Array of options to RepoGroup::findFile |
Definition at line 3649 of file Parser.php.
|
protected |
Helper function for fetchFileAndTitle.
Also useful if you need to fetch a file but not use it yet, for example to get the file's handler.
Title | $title | |
array | $options | Array of options to RepoGroup::findFile |
Definition at line 3674 of file Parser.php.
References $options, $title, RepoGroup\singleton(), and wfFindFile().
Parser::fetchScaryTemplateMaybeFromCache | ( | $url | ) |
string | $url |
Definition at line 3712 of file Parser.php.
References $dbr, $req, $status, DB_MASTER, DB_REPLICA, MWHttpRequest\factory(), global, wfGetDB(), and wfMessage().
Parser::fetchTemplate | ( | $title | ) |
Fetch the unparsed text of a template and register a reference to it.
Title | $title |
Definition at line 3535 of file Parser.php.
References $title.
Parser::fetchTemplateAndTitle | ( | $title | ) |
Parser::firstCallInit | ( | ) |
Do various kinds of initialisation on the first call of the parser.
Definition at line 323 of file Parser.php.
References initialiseVariables(), CoreTagHooks\register(), CoreParserFunctions\register(), and Hooks\run().
Referenced by clearState().
Parser::formatHeadings | ( | $text, | |
$origText, | |||
$isMain = true |
|||
) |
This function accomplishes several tasks: 1) Auto-number headings if that option is enabled 2) Add an [edit] link to sections for users who have enabled the option and can edit the page 3) Add a Table of contents on the top for users who have enabled the option 4) Auto-anchor headings.
It loops through all headlines, collects the necessary data, then splits up the string and re-inserts the newly formatted headlines.
string | $text | |
string | $origText | Original, untouched wikitext |
bool | $isMain |
Definition at line 4014 of file Parser.php.
References $matches, $wgExperimentalHtmlIds, as, Html\element(), Sanitizer\escapeId(), false, global, list, Linker\makeHeadline(), Sanitizer\normalizeSectionNameWhitespace(), OT_WIKI, PPFrame\RECOVER_ORIG, Hooks\run(), Linker\tocIndent(), Linker\tocLine(), Linker\tocLineEnd(), Linker\tocList(), and Linker\tocUnindent().
Referenced by internalParse().
Parser::getConverterLanguage | ( | ) |
Get the language object for language conversion.
Definition at line 874 of file Parser.php.
References getTargetLanguage().
Referenced by internalParseHalfParsed(), makeFreeExternalLink(), parse(), replaceExternalLinks(), and replaceInternalLinks2().
Parser::getCustomDefaultSort | ( | ) |
Accessor for $mDefaultSort Unlike getDefaultSort(), will return false if none is set.
Definition at line 5743 of file Parser.php.
Parser::getDefaultSort | ( | ) |
Accessor for $mDefaultSort Will use the empty string if none is set.
This value is treated as a prefix, so the empty string is equivalent to sorting by page name.
Definition at line 5729 of file Parser.php.
Referenced by replaceInternalLinks2().
Parser::getExternalLinkAttribs | ( | $url | ) |
Get an associative array of additional HTML attributes appropriate for a particular external link.
This currently may include rel => nofollow (depending on configuration, namespace, and the URL's domain) and/or a target attribute (depending on configuration).
string | $url | URL to extract the domain from for rel => nofollow if appropriate |
Definition at line 1914 of file Parser.php.
References $attribs.
Referenced by makeFreeExternalLink(), and replaceExternalLinks().
|
static |
Get the rel attribute for a particular external link.
string | bool | $url | Optional URL, to extract the domain from for rel => nofollow if appropriate |
Title | $title | Optional Title, for wgNoFollowNsExceptions lookups |
Definition at line 1893 of file Parser.php.
References $title, global, and wfMatchesDomainList().
Referenced by Linker\makeExternalLink().
Parser::getFreshParser | ( | ) |
Return this parser if it is not doing anything, otherwise get a fresh parser.
You can use this method by doing $myParser = $wgParser->getFreshParser(), or more simply $wgParser->getFreshParser()->parse( ... ); if you're unsure if $wgParser is safe to use.
Definition at line 6055 of file Parser.php.
References global.
Parser::getFunctionHooks | ( | ) |
Get all registered function hook identifiers.
Definition at line 4854 of file Parser.php.
Parser::getFunctionLang | ( | ) |
Get a language object for use in parser functions such as {{FORMATNUM:}}.
Definition at line 843 of file Parser.php.
References getTargetLanguage().
Parser::getImageParams | ( | $handler | ) |
Parser::getLinkRenderer | ( | ) |
Get a LinkRenderer instance to make links with.
Definition at line 910 of file Parser.php.
References $mLinkRenderer, and getOptions().
Referenced by magicLinkCallback().
Parser::getOptions | ( | ) |
Get the ParserOptions object.
Definition at line 811 of file Parser.php.
References $mOptions.
Referenced by getLinkRenderer().
Parser::getOutput | ( | ) |
Get the ParserOutput object.
Definition at line 802 of file Parser.php.
References $mOutput.
Referenced by CoreTagHooks\indicator().
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 687 of file Parser.php.
References $flags, $params, getPreprocessor(), lock(), PPFrame\NO_ARGS, PPFrame\NO_TEMPLATES, OT_PLAIN, preprocessToDom(), and startParse().
Parser::getPreprocessor | ( | ) |
Get a preprocessor object.
Definition at line 896 of file Parser.php.
References $mPreprocessor.
Referenced by getPreloadText().
|
static |
Get a random string.
Definition at line 708 of file Parser.php.
References wfDeprecated(), and wfRandomString().
Parser::getRevisionId | ( | ) |
Get the ID of the revision we are parsing.
Definition at line 5611 of file Parser.php.
Parser::getRevisionObject | ( | ) |
Get the revision object for $this->mRevisionId.
Definition at line 5621 of file Parser.php.
References $rev, and Revision\newFromId().
Parser::getRevisionSize | ( | ) |
Get the size of the revision.
Definition at line 5693 of file Parser.php.
Parser::getRevisionTimestamp | ( | ) |
Get the timestamp associated with the current revision, adjusted for the default server-local timestamp.
Definition at line 5650 of file Parser.php.
References $timestamp, $wgContLang, global, and wfTimestampNow().
Parser::getRevisionUser | ( | ) |
Get the name of the user that edited the last revision.
Definition at line 5673 of file Parser.php.
Parser::getSection | ( | $text, | |
$sectionId, | |||
$defaultText = '' |
|||
) |
This function returns the text of a section, specified by a number ($section).
A section is text under a heading like == Heading == or \<h1\>Heading\</h1\>, or the first section before any such heading (section 0).
If a section contains subsections, these are also returned.
string | $text | Text to look in |
string | number | $sectionId | Section identifier as a number or string (e.g. 0, 1 or 'T-1'). |
string | $defaultText | Default to return if section is not found |
Definition at line 5586 of file Parser.php.
Parser::getStripList | ( | ) |
Get a list of strippable XML-like elements.
Definition at line 1013 of file Parser.php.
References $mStripList.
Parser::getTags | ( | ) |
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 856 of file Parser.php.
Referenced by getConverterLanguage(), getFunctionLang(), Linker\makeImageLink(), replaceExternalLinks(), and replaceInternalLinks2().
Parser::getTemplateDom | ( | $title | ) |
Get the semi-parsed DOM representation of a template with a given title, and its redirect destination title.
Cached.
Title | $title |
Definition at line 3424 of file Parser.php.
References $title, list, and Title\makeTitle().
Parser::getTitle | ( | ) |
Accessor for the Title object.
Definition at line 757 of file Parser.php.
References $mTitle.
Parser::getUser | ( | ) |
Get a User object either from $this->mUser, if set, or from the ParserOptions object otherwise.
Definition at line 884 of file Parser.php.
References $mUser.
Parser::getUserSig | ( | & | $user, |
$nickname = false , |
|||
$fancySig = null |
|||
) |
Fetch the user's signature text, if any, and normalize to validated, ready-to-insert wikitext.
If you have pre-fetched the nickname or the fancySig option, you can specify them here to save a database query. Do not reuse this parser instance after calling getUserSig(), as it may have changed if it's the $wgParser.
User | $user | |
string | bool | $nickname | Nickname to use or false to use user's default nickname |
bool | null | $fancySig | whether the nicknname is the complete signature or null to use default value |
Definition at line 4533 of file Parser.php.
References $user, $username, global, wfDebug(), wfEscapeWikiText(), and wfMessage().
Parser::getVariableValue | ( | $index, | |
$frame = false |
|||
) |
Return value of a magic variable (like PAGENAME)
int | $index | |
bool | PPFrame | $frame |
MWException |
Definition at line 2473 of file Parser.php.
References $ret, $value, $wgArticlePath, $wgContLang, $wgLanguageCode, $wgScriptPath, $wgServer, $wgServerName, $wgSitename, $wgStylePath, SiteStats\activeUsers(), SiteStats\articles(), CoreParserFunctions\cascadingsources(), SiteStats\edits(), format, MWTimestamp\getInstance(), MWTimestamp\getLocalInstance(), SpecialVersion\getVersion(), global, SiteStats\images(), SiteStats\numberingroup(), SiteStats\pages(), Hooks\run(), TS_MW, TS_UNIX, SiteStats\users(), wfDebug(), wfEscapeWikiText(), wfTimestamp(), and wfUrlencode().
Parser::guessLegacySectionNameFromWikiText | ( | $text | ) |
Same as guessSectionNameFromWikiText(), but produces legacy anchors instead.
For use in redirects, since IE6 interprets Redirect: headers as something other than UTF-8 (apparently?), resulting in breakage.
string | $text | The section name |
Definition at line 5771 of file Parser.php.
References Sanitizer\escapeId(), and Sanitizer\normalizeSectionNameWhitespace().
Parser::guessSectionNameFromWikiText | ( | $text | ) |
Try to guess the section anchor name based on a wikitext fragment presumably extracted from a heading, for example "Header" from "== Header ==".
string | $text |
Definition at line 5756 of file Parser.php.
References Sanitizer\escapeId(), and Sanitizer\normalizeSectionNameWhitespace().
Parser::incrementExpensiveFunctionCount | ( | ) |
Increment the expensive function count.
Definition at line 3926 of file Parser.php.
Parser::incrementIncludeSize | ( | $type, | |
$size | |||
) |
Increment an include size counter.
string | $type | The type of expansion |
int | $size | The size of the text |
Definition at line 3912 of file Parser.php.
References $type.
Parser::initialiseVariables | ( | ) |
initialise the magic variables (like CURRENTMONTHNAME) and substitution modifiers
Definition at line 2825 of file Parser.php.
References MagicWord\getSubstIDs(), and MagicWord\getVariableIDs().
Referenced by firstCallInit().
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 1026 of file Parser.php.
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 1243 of file Parser.php.
References doAllQuotes(), doDoubleUnderscore(), doHeadings(), doMagicLinks(), doTableStuff(), formatHeadings(), preprocessToDom(), PTD_FOR_INCLUSION, Sanitizer\removeHTMLtags(), replaceExternalLinks(), replaceInternalLinks(), replaceVariables(), and Hooks\run().
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 1313 of file Parser.php.
References doBlockLevels(), getConverterLanguage(), MWTidy\isEnabled(), Sanitizer\normalizeCharReferences(), of, replaceLinkHolders(), replaceTransparentTags(), Hooks\run(), and MWTidy\tidy().
Referenced by parse(), and recursiveTagParseFully().
Parser::interwikiTransclude | ( | $title, | |
$action | |||
) |
Transclude an interwiki link.
Title | $title | |
string | $action |
Definition at line 3693 of file Parser.php.
References $title, global, and wfMessage().
Parser::isValidHalfParsedText | ( | $data | ) |
Returns true if the given array, presumed to be generated by serializeHalfParsedText(), is compatible with the current version of the parser.
array | $data |
Definition at line 5969 of file Parser.php.
Parser::killMarkers | ( | $text | ) |
Remove any strip markers found in the given text.
string | $text | Input string |
Definition at line 5899 of file Parser.php.
Parser::limitationWarn | ( | $limitationType, | |
$current = '' , |
|||
$max = '' |
|||
) |
Warn the user when a parser limitation is reached Will warn at most once the user per limitation type.
The results are shown during preview and run through the Parser (See EditPage.php)
string | $limitationType | Should be one of: 'expensive-parserfunction' (corresponding messages: 'expensive-parserfunction-warning', 'expensive-parserfunction-category') 'post-expand-template-argument' (corresponding messages: 'post-expand-template-argument-warning', 'post-expand-template-argument-category') 'post-expand-template-inclusion' (corresponding messages: 'post-expand-template-inclusion-warning', 'post-expand-template-inclusion-category') 'node-count-exceeded' (corresponding messages: 'node-count-exceeded-warning', 'node-count-exceeded-category') 'expansion-depth-exceeded' (corresponding messages: 'expansion-depth-exceeded-warning', 'expansion-depth-exceeded-category') |
string | int | null | $current | Current value |
string | int | null | $max | Maximum allowed, when an explicit limit has been exceeded, provide the values (optional) |
Definition at line 2977 of file Parser.php.
References wfMessage().
Referenced by parse().
|
protected |
Lock the current instance of the parser.
This is meant to stop someone from calling the parser recursively and messing up all the strip state.
MWException | If parser is in a parse |
Definition at line 6010 of file Parser.php.
Referenced by getPreloadText(), parse(), and preprocess().
Parser::magicLinkCallback | ( | $m | ) |
MWException |
array | $m |
Definition at line 1444 of file Parser.php.
References addTrackingCategory(), getLinkRenderer(), SpecialPage\getTitleFor(), Linker\makeExternalLink(), makeFreeExternalLink(), and wfMessage().
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 1516 of file Parser.php.
References Sanitizer\cleanUrl(), getConverterLanguage(), getExternalLinkAttribs(), Linker\makeExternalLink(), and maybeMakeExternalImage().
Referenced by magicLinkCallback().
Parser::makeImage | ( | $title, | |
$options, | |||
$holders = false |
|||
) |
Parse image options text and use it to make an image.
Title | $title | |
string | $options | |
LinkHolderArray | bool | $holders |
Definition at line 5125 of file Parser.php.
References $handler, $options, $params, $ret, $time, $title, $type, $value, as, StringUtils\explode(), key, list, Linker\makeImageLink(), Title\newFromText(), and Hooks\run().
Referenced by replaceInternalLinks2().
|
protected |
Render a forced-blue link inline; protect against double expansion of URLs if we're in a mode that prepends full URL prefixes to internal links.
Since this little disaster has to split off the trail text to avoid breaking URLs in the following text without breaking trails on the wiki links, it's been made into a horrible function.
Title | $nt | |
string | $text | |
string | $trail | |
string | $prefix |
Definition at line 2400 of file Parser.php.
References $link, list, and Linker\splitTrail().
Parser::markerSkipCallback | ( | $s, | |
$callback | |||
) |
Call a callback function on all regions of the given text that are not inside strip markers, and replace those regions with the return value of the callback.
For example, with input:
aaa<MARKER>bbb
This will call the callback function twice, with 'aaa' and 'bbb'. Those two strings will be replaced with the value returned by the callback in each case.
string | $s | |
callable | $callback |
Definition at line 5869 of file Parser.php.
Parser::maybeDoSubpageLink | ( | $target, | |
& | $text | ||
) |
Handle link to subpage if necessary.
string | $target | The source of the link |
string | &$text | The link text, modified as necessary |
Definition at line 2446 of file Parser.php.
References Linker\normalizeSubpageLink().
Referenced by replaceInternalLinks2().
|
private |
make an image if it's allowed, either through the global option, through the exception, or through the on-wiki whitelist
string | $url |
Definition at line 2015 of file Parser.php.
References as, Linker\makeExternalImage(), text, and wfMessage().
Referenced by makeFreeExternalLink(), and replaceExternalLinks().
Parser::nextLinkID | ( | ) |
Definition at line 828 of file Parser.php.
|
static |
Replace unusual escape codes in a URL with their equivalent characters.
This generally follows the syntax defined in RFC 3986, with special consideration for HTTP query strings.
string | $url |
Definition at line 1956 of file Parser.php.
References $ret.
Referenced by LinkSearchPage\execute(), ApiQueryExtLinksUsage\run(), and ParserMethodsTest\testNormalizeLinkUrl().
|
staticprivate |
Definition at line 1992 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 821 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 793 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 399 of file Parser.php.
References $mOutput, $mRevisionId, $mRevisionObject, $mRevisionSize, $mRevisionTimestamp, $mRevisionUser, $value, as, false, getConverterLanguage(), ParserOptions\getDisableTitleConversion(), global, internalParse(), internalParseHalfParsed(), limitationWarn(), lock(), OT_HTML, Hooks\run(), startParse(), wfDebugLog(), wfHostname(), and wfMessage().
Parser::parseWidthParam | ( | $value | ) |
Parsed a width param of imagelink like 300px or 200x300px.
string | $value |
Definition at line 5981 of file Parser.php.
References $value.
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 644 of file Parser.php.
References $title, lock(), OT_PREPROCESS, replaceVariables(), Hooks\run(), and startParse().
Parser::preprocessToDom | ( | $text, | |
$flags = 0 |
|||
) |
Preprocess some wikitext and return the document tree.
This is the ghost of replace_variables().
string | $text | The text to parse |
int | $flags | Bitwise combination of:
|
The generated DOM tree must depend only on the input text and the flags. The DOM tree must be the same in OT_HTML and OT_WIKI mode, to avoid a regression of bug 4899.
Any flag added to the $flags parameter here, or any other parameter liable to cause a change in the DOM tree for a given text, must be passed through the section identifier in the section edit link and thus back to extractSections().
The output of this function is currently only cached in process memory, but a persistent cache may be implemented at a later date which takes further advantage of these strict dependency requirements.
Definition at line 2855 of file Parser.php.
References $flags.
Referenced by getPreloadText(), and internalParse().
Parser::preSaveTransform | ( | $text, | |
Title | $title, | ||
User | $user, | ||
ParserOptions | $options, | ||
$clearState = true |
|||
) |
Transform wiki markup when saving a page by doing "\\r\\n" -> "\\n" conversion, substituting signatures, {{subst:}} templates, etc.
string | $text | The text to transform |
Title | $title | The Title object for the current article |
User | $user | The User object describing the current user |
ParserOptions | $options | Parsing options |
bool | $clearState | Whether to clear the parser state first |
Definition at line 4425 of file Parser.php.
References ParserOptions\getPreSaveTransform(), TextContent\normalizeLineEndings(), and OT_WIKI.
|
private |
Pre-save transform helper function.
string | $text | |
User | $user |
Definition at line 4457 of file Parser.php.
References $t, $timestamp, $user, $wgContLang, MWTimestamp\getLocalInstance(), global, Title\legalChars(), and use.
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 668 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 603 of file Parser.php.
References internalParse(), and Hooks\run().
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 627 of file Parser.php.
References internalParseHalfParsed(), and recursiveTagParse().
Referenced by CoreTagHooks\indicator().
Parser::renderImageGallery | ( | $text, | |
$params | |||
) |
Renders an image gallery from a text with one line per image.
text labels may be given by using |-style alternative text. E.g. Image:one.jpg|The number "1" Image:tree.jpg|A tree given as text will return the HTML of a gallery with two images, labeled 'The number "1"' and 'A tree'.
string | $text | |
array | $params |
Definition at line 4919 of file Parser.php.
References $e, $handler, $html, $line, $lines, $link, $matches, $options, $params, $title, as, StringUtils\explode(), ImageGalleryBase\factory(), list, Title\newFromText(), NS_FILE, Hooks\run(), Sanitizer\validateTagAttributes(), and wfDebug().
Parser::replaceExternalLinks | ( | $text | ) |
Replace external links (REL)
Note: this is all very hackish and the order of execution matters a lot. Make sure to run tests/parser/parserTests.php if you change this code.
string | $text |
MWException |
Definition at line 1814 of file Parser.php.
References $s, Sanitizer\cleanUrl(), getConverterLanguage(), getExternalLinkAttribs(), getTargetLanguage(), list, Linker\makeExternalLink(), maybeMakeExternalImage(), and Linker\splitTrail().
Referenced by internalParse(), and replaceInternalLinks2().
Parser::replaceInternalLinks | ( | $s | ) |
Process [[ ]] wikilinks.
string | $s |
Definition at line 2074 of file Parser.php.
References $s, and replaceInternalLinks2().
Referenced by internalParse().
Parser::replaceInternalLinks2 | ( | & | $s | ) |
Process [[ ]] wikilinks (RIL)
string | $s |
MWException |
Definition at line 2087 of file Parser.php.
References $line, $link, $s, $wgContLang, $wgExtraInterlanguageLinkPrefixes, areSubpagesAllowed(), armorLinks(), broken, Sanitizer\decodeCharReferences(), directly, StringUtils\explode(), form, getConverterLanguage(), getDefaultSort(), getTargetLanguage(), global, is(), later, Title\legalChars(), link, makeImage(), maybeDoSubpageLink(), Title\newFromText(), normal(), NS_CATEGORY, NS_FILE, on, or, output(), page, replaceExternalLinks(), so, text, that, and the.
Referenced by replaceInternalLinks().
linkcache txt The LinkCache class maintains a list of article titles and the information about whether or not the article exists in the database This is used to mark up links when displaying a page If the same link appears more than once on any page then it only has to be looked up once In most cases link lookups are done in batches with the LinkBatch class or the equivalent in Parser::replaceLinkHolders | ( | & | $text, |
$options = 0 |
|||
) |
Replace "<!--LINK-->" link placeholders with actual links, in the buffer Placeholders created in Linker::link()
string | $text | |
int | $options |
Definition at line 4891 of file Parser.php.
Referenced by internalParseHalfParsed().
Parser::replaceLinkHoldersText | ( | $text | ) |
Replace "<!--LINK-->" link placeholders with plain text of links (not HTML-formatted).
string | $text |
Definition at line 4902 of file Parser.php.
Parser::replaceSection | ( | $oldText, | |
$sectionId, | |||
$newText | |||
) |
This function returns $oldtext after the content of the section specified by $section has been replaced with $text.
If the target section does not exist, $oldtext is returned unchanged.
string | $oldText | Former text of the article |
string | number | $sectionId | Section identifier as a number or string (e.g. 0, 1 or 'T-1'). |
string | $newText | Replacing text |
Definition at line 5602 of file Parser.php.
Parser::replaceTransparentTags | ( | $text | ) |
Replace transparent tags in $text with the values given by the callbacks.
Transparent tag hooks are like regular XML-style tag hooks, except they operate late in the transformation sequence, on HTML instead of wikitext.
string | $text |
Definition at line 5410 of file Parser.php.
References $content, $matches, $output, $params, $tag, as, and list.
Referenced by internalParseHalfParsed().
|
static |
Replace unusual escape codes in a URL with their equivalent characters.
string | $url |
Definition at line 1942 of file Parser.php.
References wfDeprecated().
Replace magic variables, templates, and template arguments with the appropriate text.
Templates are substituted recursively, taking care to avoid infinite loops.
Note that the substitution depends on value of $mOutputType: self::OT_WIKI: only {{subst:}} templates self::OT_PREPROCESS: templates but not extension tags self::OT_HTML: all templates and extension tags
string | $text | The text to transform |
bool | PPFrame | $frame | Object describing the arguments passed to the template. Arguments may also be provided as an associative array, as was the usual case before MW1.12. Providing arguments this way may be useful for extensions wishing to perform variable replacement explicitly. |
bool | $argsOnly | Only do argument (triple-brace) expansion, not double-brace expansion. |
Definition at line 2900 of file Parser.php.
References $flags, PPFrame\NO_TEMPLATES, and wfDebug().
Referenced by internalParse(), preprocess(), and recursivePreprocess().
Parser::serializeHalfParsedText | ( | $text | ) |
Save the parser state required to convert the given half-parsed text to HTML.
"Half-parsed" in this context means the output of recursiveTagParse() or internalParse(). This output has strip markers from replaceVariables (extensionSubstitution() etc.), and link placeholders from replaceLinkHolders().
Returns an array which can be serialized and stored persistently. This array can later be loaded into another parser instance with unserializeHalfParsedText(). The text can then be safely incorporated into the return value of a parser hook.
string | $text |
Definition at line 5919 of file Parser.php.
Parser::setDefaultSort | ( | $sort | ) |
Mutator for $mDefaultSort.
string | $sort | New value |
Definition at line 5714 of file Parser.php.
References $sort.
Parser::setFunctionHook | ( | $id, | |
$callback, | |||
$flags = 0 |
|||
) |
Create a function, e.g.
{{sum:1|2|3}} The callback function should have the form: function myParserFunction( &$parser, $arg1, $arg2, $arg3 ) { ... }
Or with Parser::SFH_OBJECT_ARGS: function myParserFunction( $parser, $frame, $args ) { ... }
The callback may either return the text result of the function, or an array with the text in element 0, and a number of flags in the other elements. The names of the flags are specified in the keys. Valid flags are: found The text returned is valid, stop processing the template. This is on by default. nowiki Wiki markup in the return value should be escaped isHTML The returned text is HTML, armour it against wikitext transformation
string | $id | The magic word ID |
callable | $callback | The callback function (and object) to use |
int | $flags | A combination of the following flags: Parser::SFH_NO_HASH No leading hash, i.e. {{plural:...}} instead of {{if:...}} |
Parser::SFH_OBJECT_ARGS Pass the template arguments as PPNode objects instead of text. This allows for conditional expansion of the parse tree, allowing you to eliminate dead branches and thus speed up parsing. It is also possible to analyse the parse tree of the arguments, and to control the way they are expanded.
The $frame parameter is a PPFrame. This can be used to produce expanded text from the arguments, for instance: $text = isset( $args[0] ) ? $frame->expand( $args[0] ) : '';
For technical reasons, $args[0] is pre-expanded and will be a string. This may change in future versions. Please call $frame->expand() on it anyway so that your code keeps working if/when this is changed.
If you want whitespace to be trimmed from $args, you need to do it yourself, post- expansion.
Please read the documentation in includes/parser/Preprocessor.php for more information about the methods available in PPFrame and PPNode.
MWException |
Definition at line 4816 of file Parser.php.
References $flags, $wgContLang, as, MagicWord\get(), global, and SFH_NO_HASH.
Parser::setFunctionTagHook | ( | $tag, | |
$callback, | |||
$flags | |||
) |
Create a tag function, e.g.
"<test>some stuff</test>". Unlike tag hooks, tag functions are parsed at preprocessor level. Unlike parser functions, their content is not preprocessed.
string | $tag | |
callable | $callback | |
int | $flags |
MWException |
Definition at line 4868 of file Parser.php.
Parser::setHook | ( | $tag, | |
$callback | |||
) |
Create an HTML-style tag, e.g.
"<yourtag>special text</yourtag>" The callback should have the following form: function myParserHook( $text, $params, $parser, $frame ) { ... }
Transform and return $text. Use $parser for any required context, e.g. use $parser->getTitle() and $parser->getOptions() not $wgTitle or $wgOut->mParserOptions
Hooks may return extended information by returning an array, of which the first numbered element (index 0) must be the return string, and all other entries are extracted into local variables within an internal function in the Parser class.
This interface (introduced r61913) appears to be undocumented, but 'markerType' is used by some core tag hooks to override which strip array their results are placed in. Use great caution if attempting this interface, as it is not documented and injudicious use could smash private variables.
string | $tag | The tag to use, e.g. 'hook' for "<hook>" |
callable | $callback | The callback function (and object) to use for the tag |
MWException |
Definition at line 4722 of file Parser.php.
References $tag.
Parser::setLinkID | ( | $id | ) |
int | $id |
Definition at line 835 of file Parser.php.
Parser::setOutputType | ( | $ot | ) |
Set the output type.
int | $ot | New value |
Definition at line 776 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 739 of file Parser.php.
References $t, and Title\newFromText().
Parser::setTransparentTagHook | ( | $tag, | |
$callback | |||
) |
As setHook(), but letting the contents be parsed.
Transparent tag hooks are like regular XML-style tag hooks, except they operate late in the transformation sequence, on HTML instead of wikitext.
This is probably obsoleted by things dealing with parser frames? The only extension currently using it is geoserver.
string | $tag | The tag to use, e.g. 'hook' for "<hook>" |
callable | $callback | The callback function (and object) to use for the tag |
MWException |
Definition at line 4753 of file Parser.php.
References $tag.
Parser::setUser | ( | $user | ) |
Set the current user.
Should only be used when doing pre-save transform.
Definition at line 719 of file Parser.php.
References $user.
|
static |
Return a three-element array: leading whitespace, string contents, trailing whitespace.
string | $s |
Definition at line 2867 of file Parser.php.
References $s.
Parser::startExternalParse | ( | Title | $title = null , |
ParserOptions | $options, | ||
$outputType, | |||
$clearState = true |
|||
) |
Set up some variables which are usually set up in parse() so that an external function can call some class members with confidence.
Title | null | $title | |
ParserOptions | $options | |
int | $outputType | |
bool | $clearState |
Definition at line 4647 of file Parser.php.
References $title.
|
private |
Title | null | $title | |
ParserOptions | $options | |
int | $outputType | |
bool | $clearState |
Definition at line 4659 of file Parser.php.
References $options, and $title.
Referenced by getPreloadText(), parse(), and preprocess().
Wrapper around Revision::newFromTitle to allow passing additional parameters without passing them on to it.
Definition at line 3490 of file Parser.php.
References $rev, $revId, DB_REPLICA, Title\getArticleID(), Title\getLatestRevID(), Revision\newKnownCurrent(), and wfGetDB().
|
static |
Static function to get a template Can be overridden via ParserOptions::setTemplateCallback().
Definition at line 3548 of file Parser.php.
References $content, $parser, $rev, $title, $wgContLang, global, Revision\newFromId(), Revision\newFromTitle(), NS_MEDIAWIKI, Hooks\run(), LinkCache\singleton(), and wfMessage().
|
protected |
string | $caption | |
LinkHolderArray | bool | $holders |
Definition at line 5340 of file Parser.php.
References Sanitizer\stripAllTags().
|
static |
Strip outer.
tag from the HTML source of a single paragraph.
Returns original HTML if the
tag has any attributes, if there's no wrapping
tag, or if there is more than one
tag in the input HTML.
string | $html |
Definition at line 6034 of file Parser.php.
References $html.
Referenced by ApiParamInfo\formatHelpMessages(), ApiAuthManagerHelper\formatMessage(), CoreTagHooks\indicator(), OutputPage\parseInline(), ParserMethodsTest\testStripOuterParagraph(), and Message\toString().
Parser::stripSectionName | ( | $text | ) |
Strips a text string of wikitext for use in a section anchor.
Accepts a text string and then removes all wikitext from the string and leaves only the resultant text (i.e. the result of [[User:WikiSysop|Sysop]] would be "Sysop" and the result of [[User:WikiSysop]] would be "User:WikiSysop") - this is intended to create valid section anchors by mimicing the output of the parser when headings are parsed.
string | $text | Text string to be stripped of wikitext for use in a Section anchor |
Definition at line 5792 of file Parser.php.
References StringUtils\delimiterReplace().
Parser::testPreprocess | ( | $text, | |
Title | $title, | ||
ParserOptions | $options | ||
) |
string | $text | |
Title | $title | |
ParserOptions | $options |
Definition at line 5849 of file Parser.php.
References OT_PREPROCESS.
Parser::testPst | ( | $text, | |
Title | $title, | ||
ParserOptions | $options | ||
) |
string | $text | |
Title | $title | |
ParserOptions | $options |
Definition at line 5839 of file Parser.php.
References $options, and ParserOptions\getUser().
Parser::testSrvus | ( | $text, | |
Title | $title, | ||
ParserOptions | $options, | ||
$outputType = self::OT_HTML |
|||
) |
strip/replaceVariables/unstrip for preprocessor regression testing
string | $text | |
Title | $title | |
ParserOptions | $options | |
int | $outputType |
Definition at line 5821 of file Parser.php.
References Sanitizer\removeHTMLtags().
Parser::Title | ( | $x = null | ) |
Accessor/mutator for the Title object.
Definition at line 767 of file Parser.php.
References wfSetVar().
Parser::transformMsg | ( | $text, | |
$options, | |||
$title = null |
|||
) |
Wrapper for preprocess()
string | $text | The text to preprocess |
ParserOptions | $options | Options |
Title | null | $title | Title object or null to use $wgTitle |
Definition at line 4678 of file Parser.php.
Parser::uniqPrefix | ( | ) |
Accessor for mUniqPrefix.
Definition at line 729 of file Parser.php.
References wfDeprecated().
Parser::unserializeHalfParsedText | ( | $data | ) |
Load the parser state given in the $data array, which is assumed to have been generated by serializeHalfParsedText().
The text contents is extracted from the array, and its markers are transformed into markers appropriate for the current Parser instance. This transformed text is returned, and can be safely included in the return value of a parser hook.
If the $data array has been stored persistently, the caller should first check whether it is still valid, by calling isValidHalfParsedText().
array | $data | Serialized data |
MWException |
Definition at line 5944 of file Parser.php.
Parser::validateSig | ( | $text | ) |
Check that the user's signature contains no bad XML.
string | $text |
Definition at line 4582 of file Parser.php.
References Xml\isWellFormedXmlFragment().
MapCacheLRU null Parser::$currentRevisionCache |
A cache of the current revisions of titles. Keys are $title->getPrefixedDbKey()
Definition at line 243 of file Parser.php.
Parser::$mAutonumber |
Definition at line 177 of file Parser.php.
Parser::$mConf |
Definition at line 166 of file Parser.php.
Parser::$mDefaultSort |
Definition at line 192 of file Parser.php.
Parser::$mDefaultStripList = [] |
Definition at line 147 of file Parser.php.
Parser::$mDoubleUnderscores |
Definition at line 193 of file Parser.php.
Parser::$mExpensiveFunctionCount |
Definition at line 194 of file Parser.php.
Parser::$mExtLinkBracketedRegex |
Definition at line 166 of file Parser.php.
Parser::$mFirstCall = true |
Definition at line 152 of file Parser.php.
Parser::$mForceTocPosition |
Definition at line 195 of file Parser.php.
Parser::$mFunctionHooks = [] |
Definition at line 143 of file Parser.php.
Parser::$mFunctionSynonyms = [ 0 => [] |
Definition at line 144 of file Parser.php.
Parser::$mFunctionTagHooks = [] |
Definition at line 145 of file Parser.php.
Parser::$mGeneratedPPNodeCount |
Definition at line 191 of file Parser.php.
Parser::$mHeadings |
Definition at line 193 of file Parser.php.
Parser::$mHighestExpansionDepth |
Definition at line 191 of file Parser.php.
Parser::$mImageParams = [] |
Definition at line 149 of file Parser.php.
Parser::$mImageParamsMagicArray = [] |
Definition at line 150 of file Parser.php.
Parser::$mIncludeCount |
Definition at line 184 of file Parser.php.
Parser::$mIncludeSizes |
Definition at line 191 of file Parser.php.
bool Parser::$mInParse = false |
Recursive call protection.
This variable should be treated as if it were private.
Definition at line 249 of file Parser.php.
Parser::$mInputSize = false |
Definition at line 222 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 235 of file Parser.php.
LinkHolderArray Parser::$mLinkHolders |
Definition at line 188 of file Parser.php.
Parser::$mLinkID |
Definition at line 190 of file Parser.php.
|
protected |
Definition at line 257 of file Parser.php.
Referenced by getLinkRenderer().
Parser::$mMarkerIndex = 0 |
Definition at line 151 of file Parser.php.
ParserOptions Parser::$mOptions |
Definition at line 208 of file Parser.php.
Referenced by getOptions().
ParserOutput Parser::$mOutput |
Definition at line 176 of file Parser.php.
Referenced by getOutput(), and parse().
Parser::$mOutputType |
Definition at line 214 of file Parser.php.
Parser::$mPPNodeCount |
Definition at line 191 of file Parser.php.
Preprocessor Parser::$mPreprocessor |
Definition at line 170 of file Parser.php.
Referenced by getPreprocessor().
|
protected |
Definition at line 252 of file Parser.php.
Parser::$mRevIdForTs |
Definition at line 221 of file Parser.php.
Parser::$mRevisionId |
Definition at line 217 of file Parser.php.
Referenced by parse().
Parser::$mRevisionObject |
Definition at line 216 of file Parser.php.
Referenced by parse().
Parser::$mRevisionSize |
Definition at line 220 of file Parser.php.
Referenced by parse().
Parser::$mRevisionTimestamp |
Definition at line 218 of file Parser.php.
Referenced by parse().
Parser::$mRevisionUser |
Definition at line 219 of file Parser.php.
Referenced by parse().
Parser::$mShowToc |
Definition at line 195 of file Parser.php.
Parser::$mStripList = [] |
Definition at line 146 of file Parser.php.
Referenced by getStripList().
StripState Parser::$mStripState |
Definition at line 182 of file Parser.php.
MagicWordArray Parser::$mSubstWords |
Definition at line 164 of file Parser.php.
Parser::$mTagHooks = [] |
Definition at line 141 of file Parser.php.
Title Parser::$mTitle |
Definition at line 213 of file Parser.php.
Referenced by getTitle().
Parser::$mTplDomCache |
Definition at line 193 of file Parser.php.
Parser::$mTplRedirCache |
Definition at line 193 of file Parser.php.
Parser::$mTransparentTagHooks = [] |
Definition at line 142 of file Parser.php.
string Parser::$mUniqPrefix = Parser::MARKER_PREFIX |
Deprecated accessor for the strip marker prefix.
Definition at line 228 of file Parser.php.
Parser::$mUrlProtocols |
Definition at line 166 of file Parser.php.
User Parser::$mUser |
Definition at line 200 of file Parser.php.
Referenced by getUser().
Parser::$mVarCache = [] |
Definition at line 148 of file Parser.php.
MagicWordArray Parser::$mVariables |
Definition at line 159 of file Parser.php.
Parser::$ot |
Definition at line 215 of file Parser.php.
Referenced by setOutputType().
const Parser::EXT_IMAGE_REGEX |
Definition at line 98 of file Parser.php.
const Parser::EXT_LINK_ADDR = '(?:[0-9.]+|\\[(?i:[0-9a-f:.]+)\\]|[^][<>"\\x00-\\x20\\x7F\p{Zs}])' |
Definition at line 95 of file Parser.php.
const Parser::EXT_LINK_URL_CLASS = '[^][<>"\\x00-\\x20\\x7F\p{Zs}]' |
Definition at line 92 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 82 of file Parser.php.
const Parser::MARKER_PREFIX = "\x7f'\"`UNIQ-" |
Definition at line 134 of file Parser.php.
Referenced by StripState\__construct(), LanguageConverter\autoConvert(), BlockLevelPass\execute(), PPFrame_Hash\expand(), PPFrame_DOM\expand(), StripState\getSubState(), StripState\mergeCallback(), and MediaWiki\Tidy\RaggettWrapper\replaceCallback().
const Parser::OT_HTML = 1 |
Definition at line 110 of file Parser.php.
Referenced by ParserMethodsTest\testCallParserFunction().
const Parser::OT_MSG = 3 |
Definition at line 113 of file Parser.php.
const Parser::OT_PLAIN = 4 |
Definition at line 114 of file Parser.php.
const Parser::OT_PREPROCESS = 3 |
Definition at line 112 of file Parser.php.
Referenced by ApiExpandTemplates\execute(), ApiParse\execute(), and SpecialExpandTemplates\execute().
const Parser::OT_WIKI = 2 |
Definition at line 111 of file Parser.php.
const Parser::PTD_FOR_INCLUSION = 1 |
Definition at line 106 of file Parser.php.
Referenced by internalParse(), Preprocessor_Hash\preprocessToObj(), and Preprocessor_DOM\preprocessToXml().
const Parser::SFH_NO_HASH = 1 |
Definition at line 85 of file Parser.php.
Referenced by CoreParserFunctions\register().
const Parser::SFH_OBJECT_ARGS = 2 |
Definition at line 86 of file Parser.php.
Referenced by CoreParserFunctions\register(), and TagHookTest\testBadFunctionTagHooks().
const Parser::SPACE_NOT_NL = '(?:\t| |&\#0*160;|&\#[Xx]0*[Aa]0;|\p{Zs})' |
Definition at line 103 of file Parser.php.
const Parser::TOC_END = '</mw:toc>' |
Definition at line 138 of file Parser.php.
Referenced by ParserOutput\getText().
const Parser::TOC_START = '<mw:toc>' |
Definition at line 137 of file Parser.php.
Referenced by ParserOutput\getText().
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 76 of file Parser.php.
Referenced by CacheTime\expired().