|
MediaWiki master
|
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...
Inherits MediaWiki\Language\MessageLocalizer.

Public Member Functions | |
| __clone () | |
| Allow extensions to clean up when the parser is cloned. | |
| __construct (private ServiceOptions $svcOptions, private ParserCoreTagHooks $parserCoreTagHooks, private MagicWordFactory $magicWordFactory, private Language $contLang, private UrlUtils $urlUtils, private SpecialPageFactory $specialPageFactory, private LinkRendererFactory $linkRendererFactory, private NamespaceInfo $nsInfo, private LoggerInterface $logger, private BadFileLookup $badFileLookup, private RepoGroup $repoGroup, private LanguageFactory $languageFactory, private LanguageConverterFactory $languageConverterFactory, private LanguageNameUtils $languageNameUtils, private HookContainer $hookContainer, private TidyDriverBase $tidy, private WANObjectCache $wanCache, private UserOptionsLookup $userOptionsLookup, private UserFactory $userFactory, private TitleFormatter $titleFormatter, private HttpRequestFactory $httpRequestFactory, private TrackingCategories $trackingCategories, private SignatureValidatorFactory $signatureValidatorFactory, private UserNameUtils $userNameUtils, private LinkAlwaysKnownLookup $linkAlwaysKnownLookup,) | |
| Constructing parsers directly is not allowed! | |
| __destruct () | |
| Reduce memory usage to reduce the impact of circular references. | |
| addTrackingCategory ( $msg) | |
| argSubstitution (array $piece, PPFrame $frame) | |
| Triple brace replacement – used for template arguments. | |
| braceSubstitution (array $piece, PPFrame $frame) | |
| Return the text of a template, after recursively replacing any variables or templates within the template. | |
| callParserFunction (PPFrame $frame, $function, array $args=[], bool $inSolState=false) | |
| Call a parser function and return an array with text and flags. | |
| cleanSig ( $text, $parsing=false) | |
| Clean up signature text. | |
| clearState () | |
| Clear Parser state. | |
| clearTagHooks () | |
| Remove all tag hooks. | |
| doQuotes ( $text) | |
| Helper function for handleAllQuotes(). | |
| extensionSubstitution (array $params, PPFrame $frame) | |
| Return the text to be used for a given extension tag. | |
| fetchCurrentRevisionRecordOfTitle (LinkTarget $link) | |
| Fetch the current revision of a given title as a RevisionRecord. | |
| fetchFileAndTitle (LinkTarget $link, array $options=[]) | |
| Fetch a file and its title and register a reference to it. | |
| fetchTemplateAndTitle (LinkTarget $link) | |
| Fetch the unparsed text of a template and register a reference to it. | |
| firstCallInit () | |
| Used to do various kinds of initialisation on the first call of the parser. | |
| getBadFileLookup () | |
| Get the BadFileLookup instance that this Parser is using. | |
| getContentLanguage () | |
| Get the content language that this Parser is using. | |
| getExternalLinkAttribs ( $url) | |
| Get an associative array of additional HTML attributes appropriate for a particular external link. | |
| getFlatSectionInfo ( $text) | |
| Get an array of preprocessor section information. | |
| getFunctionHooks () | |
| Get all registered function hook identifiers. | |
| getFunctionSynonyms () | |
| getLinkRenderer () | |
| Get a LinkRenderer instance to make links with. | |
| getMagicWordFactory () | |
| Get the MagicWordFactory that this Parser is using. | |
| getMiserMode () | |
| getNamespaceInfo () | |
| getOptions () | |
| getOutput () | |
| getOutputType () | |
| Accessor for the output type. | |
| getPage () | |
| Returns the page used as context for parsing, e.g. | |
| getParseTime () | |
| Return the parse time. | |
| getPreloadText ( $text, PageReference $page, ParserOptions $options, $params=[]) | |
| Process the wikitext for the "?preload=" feature. | |
| getPreprocessor () | |
| Get a preprocessor object. | |
| getRevisionId () | |
| Get the ID of the revision we are parsing. | |
| getRevisionRecordObject () | |
| Get the revision record object for $this->mRevisionId. | |
| getRevisionSize () | |
| Get the size of the revision. | |
| getRevisionTimestamp () | |
| Get the timestamp associated with the current revision, adjusted for the default server-local timestamp. | |
| getRevisionUser () | |
| Get the name of the user that edited the last revision. | |
| getSection ( $text, $sectionId, $defaultText='') | |
| This function returns the text of a section, specified by a number ($section). | |
| getStripList () | |
| Get a list of strippable XML-like elements. | |
| getStripState () | |
| getTags () | |
| Accessor. | |
| getTargetLanguage () | |
| Get the target language for the content being parsed. | |
| getTargetLanguageConverter () | |
| Shorthand for getting a Language Converter for Target language. | |
| getTemplateDom (LinkTarget $title, bool $inSolState=false) | |
| Get the semi-parsed DOM representation of a template with a given title, and its redirect destination title. | |
| getTitle () | |
| getUrlProtocols () | |
| getUserIdentity () | |
| Get a user either from the user set on Parser if it's set, or from the ParserOptions object otherwise. | |
| getUserSig (UserIdentity $user, $nickname=false, $fancySig=null) | |
| Fetch the user's signature text, if any, and normalize to validated, ready-to-insert wikitext. | |
| guessLegacySectionNameFromWikiText ( $text) | |
| Same as guessSectionNameFromWikiText(), but produces legacy anchors instead, if possible. | |
| guessSectionNameFromWikiText ( $text) | |
| Try to guess the section anchor name based on a wikitext fragment presumably extracted from a heading, for example "Header" from "== Header ==". | |
| incrementExpensiveFunctionCount () | |
| 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. | |
| interwikiTransclude (LinkTarget $link, $action) | |
| Transclude an interwiki link. | |
| isCurrentRevisionOfTitleCached (LinkTarget $link) | |
| isLocked () | |
| Will entry points such as parse() throw an exception due to the parser already being active? | |
| killMarkers ( $text) | |
| Remove any strip markers found in the given text. | |
| limitationWarn ( $limitationType, $current='', $max='') | |
| Warn the user when a parser limitation is reached Will warn at most once the user per limitation type. | |
| makeImage (LinkTarget $link, $options, $holders=false) | |
| Parse image options text and use it to make an image. | |
| makeImageHtml (LinkTarget $link, string $options) | |
| Parse image options text and use it to make an image. | |
| makeLimitReport (ParserOptions $parserOptions, ParserOutput $parserOutput) | |
| Set the limit report data in the current ParserOutput. | |
| markerSkipCallback ( $s, callable $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. | |
| modifyImageHtml (File $file, array $params, string &$html) | |
| Give hooks a chance to modify image thumbnail HTML. | |
| msg ( $key,... $params) | |
| Helper function to correctly set the target language and title of a message based on the parser context. | |
| nextLinkID () | |
| parse ( $text, PageReference $page, ParserOptions $options, $linestart=true, $clearState=true, $revid=null) | |
| Convert wikitext to HTML Do not call this function recursively. | |
| parseExtensionTagAsTopLevelDoc (string $text, PPFrame|false $frame=false) | |
| Needed by Parsoid/PHP to ensure all the hooks for extensions are run in the right order. | |
| parseWidthParam ( $value, $parseHeight=true, bool $localized=false) | |
| Parsed a width param of imagelink like 300px or 200x300px. | |
| preprocess ( $text, ?PageReference $page, ParserOptions $options, $revid=null, $frame=false) | |
| Expand templates and variables in the text, producing valid, static wikitext. | |
| preprocessToDom ( $text, $flags=0) | |
| Get the document object model for the given wikitext. | |
| preSaveTransform ( $text, PageReference $page, UserIdentity $user, ParserOptions $options, $clearState=true) | |
| Transform wiki markup when saving a page by doing "\\r\\n" -> "\\n" conversion, substituting signatures, {{subst:}} templates, etc. | |
| 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. | |
| renderImageGallery ( $text, array $params) | |
| Renders an image gallery from a text with one line per image. | |
| replaceSection ( $oldText, $sectionId, $newText) | |
| This function returns $oldtext after the content of the section specified by $section has been replaced with $text. | |
| replaceVariables ( $text, $frame=false, $argsOnly=false, array $options=[]) | |
| Replace magic variables, templates, and template arguments with the appropriate text. | |
| resetOutput () | |
| Reset the ParserOutput. | |
| setFunctionHook ( $id, callable $callback, $flags=0) | |
| Create a function, e.g. | |
| setHook ( $tag, callable $callback) | |
| Create an HTML-style tag, e.g. | |
| setLinkID ( $id) | |
| setOptions (ParserOptions $options) | |
| Mutator for the ParserOptions object. | |
| setOutputType ( $ot) | |
| Mutator for the output type. | |
| setPage (?PageReference $t=null) | |
| Set the page used as context for parsing, e.g. | |
| setTitle (?Title $t=null) | |
| Set the context title. | |
| setUseParsoidFragments (bool $val) | |
| setUser (?UserIdentity $user) | |
| Set the current user. | |
| splitDisplayTitle (HtmlArmor $displayTitle, ?ILanguageConverter $languageConverter=null) | |
| Split a user-supplied display title for the page being parsed into namespace, separator, and main title portions. | |
| startExternalParse (?PageReference $page, ParserOptions $options, $outputType, $clearState=true, $revId=null) | |
| Set up some variables which are usually set up in parse() so that an external function can call some class members with confidence. | |
| stripSectionName ( $text) | |
| Strips a text string of wikitext for use in a section anchor. | |
| tagNeedsNowikiStrippedInTagPF (string $lowerTagName) | |
| transformMsg ( $text, ParserOptions $options, ?PageReference $page=null) | |
| Wrapper for preprocess(). | |
| useParsoidFragments () | |
| validateSig ( $text) | |
| Check that the user's signature contains no bad XML. | |
Static Public Member Functions | |
| static | cleanSigInSig ( $text) |
| Strip 3, 4 or 5 tildes out of signatures. | |
| static | defaultFetchRevisionRecord (RevisionLookup $revisionLookup, LinkTarget $link, $parser) |
| Default implementation of fetchCurrentRevisionRecordOfTitle(). | |
| static | defaultFetchTemplate (RevisionLookup $revLookup, HookRunner $hookRunner, LinkCache $linkCache, ShadowPageLoader $shadowPageLoader, $link, $parser) |
| Static function to get a template Can be overridden via ParserOptions::setTemplateCallback(), in which case the service arguments are not passed. | |
| static | extractBody (string $text) |
| Strip everything but the <body> from the provided string. | |
| static | extractTagsAndParams (array $elements, $text, &$matches) |
| Replaces all occurrences of HTML-style comments and the given tags in the text with a random marker and returns the next text. | |
| static | formatPageTitle ( $nsText, $nsSeparator, $mainText, ?Language $titleLang=null) |
| Add HTML tags marking the parts of a page title, to be displayed in the first heading of the page. | |
| static | getExternalLinkRel ( $url=false, $title=null) |
| Get the rel attribute for a particular external link. | |
| static | guessSectionNameFromStrippedText ( $text) |
| Like guessSectionNameFromWikiText(), but takes already-stripped text as input. | |
| static | localizeTOC (?TOCData $tocData, Language $lang, ?ILanguageConverter $converter, ?string $preferredVariant=null) |
| Localize the TOC into the given target language; this includes invoking the language converter on the headings. | |
| static | normalizeLinkUrl ( $url) |
| Replace unusual escape codes in a URL with their equivalent characters. | |
| static | replaceTableOfContentsMarker ( $text, $toc) |
| Replace table of contents marker in parsed HTML. | |
| static | splitPageTitle (HtmlArmor $pageTitle, LinkTarget|PageReference $page, ILanguageConverter $languageConverter) |
| Split a page title into namespace, separator, and main title portions, so that they can be styled individually (see ::formatPageTitle()). | |
| static | statelessFetchRevisionRecord (LinkTarget $link, $parser=null) |
| static | statelessFetchTemplate ( $page, $parser=false) |
| static | stripOuterParagraph ( $html) |
| Strip outer. | |
Public Attributes | |
| $mExpensiveFunctionCount | |
| Number of expensive parser function calls. | |
| $mExtArrays | |
| $mExtHashTables | |
| $mExtLoopsCounter | |
| $mExtVariables | |
| array | $mHeadings |
| int | $mHighestExpansionDepth |
| $mMarkerIndex = 0 | |
| int | $mPPNodeCount |
| const | CONSTRUCTOR_OPTIONS |
| const | EXT_LINK_URL_CLASS = '[^][<>"\\x00-\\x20\\x7F\p{Zs}\x{FFFD}]' |
| Everything except bracket, space, or control characters. | |
| const | MARKER_PREFIX = "\x7f'\"`UNIQ-" |
| const | OT_HTML = 1 |
| Output type: like Parser::parse(). | |
| const | OT_PLAIN = 4 |
| Output type: like Parser::extractSections() - portions of the original are returned unchanged. | |
| const | OT_PREPROCESS = 3 |
| Output type: like Parser::preprocess(). | |
| const | OT_WIKI = 2 |
| Output type: like Parser::preSaveTransform(). | |
| const | SFH_NO_HASH = 1 |
| const | SFH_OBJECT_ARGS = 2 |
Protected Member Functions | |
| fetchFileNoRegister (LinkTarget $link, array $options=[]) | |
| Helper function for fetchFileAndTitle. | |
| getHookContainer () | |
| Get a HookContainer capable of returning metadata about hooks or running extension hooks. | |
| getHookRunner () | |
| Get a HookRunner for calling core hooks. | |
| lock () | |
| Lock the current instance of the parser. | |
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:
Definition at line 139 of file Parser.php.
| MediaWiki\Parser\Parser::__construct | ( | private ServiceOptions | $svcOptions, |
| private ParserCoreTagHooks | $parserCoreTagHooks, | ||
| private MagicWordFactory | $magicWordFactory, | ||
| private Language | $contLang, | ||
| private UrlUtils | $urlUtils, | ||
| private SpecialPageFactory | $specialPageFactory, | ||
| private LinkRendererFactory | $linkRendererFactory, | ||
| private NamespaceInfo | $nsInfo, | ||
| private LoggerInterface | $logger, | ||
| private BadFileLookup | $badFileLookup, | ||
| private RepoGroup | $repoGroup, | ||
| private LanguageFactory | $languageFactory, | ||
| private LanguageConverterFactory | $languageConverterFactory, | ||
| private LanguageNameUtils | $languageNameUtils, | ||
| private HookContainer | $hookContainer, | ||
| private TidyDriverBase | $tidy, | ||
| private WANObjectCache | $wanCache, | ||
| private UserOptionsLookup | $userOptionsLookup, | ||
| private UserFactory | $userFactory, | ||
| private TitleFormatter | $titleFormatter, | ||
| private HttpRequestFactory | $httpRequestFactory, | ||
| private TrackingCategories | $trackingCategories, | ||
| private SignatureValidatorFactory | $signatureValidatorFactory, | ||
| private UserNameUtils | $userNameUtils, | ||
| private LinkAlwaysKnownLookup | $linkAlwaysKnownLookup ) |
Constructing parsers directly is not allowed!
Use a ParserFactory.
Definition at line 394 of file Parser.php.
References MediaWiki\Parser\ParserFactory\$inParserFactory, MediaWiki\Config\ServiceOptions\assertRequiredOptions(), MediaWiki\Config\ServiceOptions\get(), MediaWiki\Language\LanguageConverterFactory\isConversionDisabled(), MediaWiki\Deferred\LinksUpdate\GenericPageLinksTable\makeTitle(), NS_SPECIAL, MediaWiki\MainConfigNames\PreprocessorCacheThreshold, and MediaWiki\Parser\ParserCoreTagHooks\register().
| MediaWiki\Parser\Parser::__destruct | ( | ) |
Reduce memory usage to reduce the impact of circular references.
Definition at line 467 of file Parser.php.
| MediaWiki\Parser\Parser::__clone | ( | ) |
Allow extensions to clean up when the parser is cloned.
Definition at line 482 of file Parser.php.
| MediaWiki\Parser\Parser::addTrackingCategory | ( | $msg | ) |
| string | $msg | Message key |
Definition at line 4202 of file Parser.php.
Referenced by MediaWiki\Parser\CoreParserFunctions\displaytitle(), limitationWarn(), and parseWidthParam().
| MediaWiki\Parser\Parser::argSubstitution | ( | array | $piece, |
| PPFrame | $frame ) |
Triple brace replacement – used for template arguments.
| array | $piece | |
| PPFrame | $frame |
Definition at line 3942 of file Parser.php.
References MediaWiki\Parser\PPFrame\expand(), MediaWiki\Parser\PPFrame\getArgument(), MediaWiki\Parser\PPFrame\isTemplate(), limitationWarn(), and MediaWiki\Parser\PPFrame\virtualBracketedImplode().
| MediaWiki\Parser\Parser::braceSubstitution | ( | array | $piece, |
| PPFrame | $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 2944 of file Parser.php.
| MediaWiki\Parser\Parser::callParserFunction | ( | PPFrame | $frame, |
| $function, | |||
| array | $args = [], | ||
| bool | $inSolState = false ) |
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 most wikitext transformation isRawHTML: bool, $text is raw HTML, armour it against all 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 |
| bool | $inSolState | Is the template processing starting in Start-Of-Line (SOL) position? Prepreprocessing (on behalf of Parsoid) uses this flag to set lineStart property on processor DOM tree nodes. Since the preprocessor tree doesn't rely on expanded templates, this flag is a best guess since {{expands-to-empty-string}} can blind it to SOL context. This flag is always false for legacy parser template expansions. |
Definition at line 3359 of file Parser.php.
References MediaWiki\Parser\PPFrame\expand(), preprocessToDom(), and MediaWiki\Parser\Preprocessor\START_IN_SOL_STATE.
| MediaWiki\Parser\Parser::cleanSig | ( | $text, | |
| $parsing = false ) |
Clean up signature text.
1) Strip 3, 4 or 5 tildes out of signatures, see cleanSigInSig 2) Substitute all transclusions
| string | $text | |
| bool | $parsing | Whether we're cleaning (preferences save) or parsing |
Definition at line 4882 of file Parser.php.
References if, lock(), and MediaWiki\Parser\ParserOptions\newFromUser().
|
static |
Strip 3, 4 or 5 tildes out of signatures.
| string | $text |
Definition at line 4924 of file Parser.php.
Referenced by getUserSig().
| MediaWiki\Parser\Parser::clearState | ( | ) |
Clear Parser state.
Definition at line 510 of file Parser.php.
References getHookContainer(), and resetOutput().
| MediaWiki\Parser\Parser::clearTagHooks | ( | ) |
|
static |
Default implementation of fetchCurrentRevisionRecordOfTitle().
| RevisionLookup | $revisionLookup | |
| LinkTarget | $link | |
| Parser | null | $parser |
Definition at line 3555 of file Parser.php.
References MediaWiki\Revision\RevisionLookup\getKnownLatestRevision().
|
static |
Static function to get a template Can be overridden via ParserOptions::setTemplateCallback(), in which case the service arguments are not passed.
| RevisionLookup | $revLookup | |
| HookRunner | $hookRunner | |
| LinkCache | $linkCache | |
| ShadowPageLoader | $shadowPageLoader | |
| LinkTarget | $link | |
| Parser | false | $parser |
Definition at line 3651 of file Parser.php.
References MediaWiki\Page\LinkCache\addBadLinkObj(), MediaWiki\ShadowPage\ShadowPageLoader\get(), and MediaWiki\Revision\RevisionLookup\getRevisionByTitle().
| MediaWiki\Parser\Parser::doQuotes | ( | $text | ) |
Helper function for handleAllQuotes().
| string | $text |
Definition at line 1925 of file Parser.php.
Referenced by MediaWiki\Parser\CoreParserFunctions\displaytitle(), and stripSectionName().
| MediaWiki\Parser\Parser::extensionSubstitution | ( | array | $params, |
| PPFrame | $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 |
Definition at line 3999 of file Parser.php.
Referenced by MediaWiki\Parser\CoreParserFunctions\tagObj().
|
static |
Strip everything but the <body> from the provided string.
| string | $text |
Definition at line 6697 of file Parser.php.
|
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:
| string[] | $elements | List of element names. Comments are always extracted. |
| string | $text | Source text string. |
| array[] | &$matches | Out parameter, Array: extracted tags |
Definition at line 1185 of file Parser.php.
| MediaWiki\Parser\Parser::fetchCurrentRevisionRecordOfTitle | ( | LinkTarget | $link | ) |
Fetch the current revision of a given title as a RevisionRecord.
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.
This can return null if the callback returns false
| LinkTarget | $link |
Definition at line 3510 of file Parser.php.
| MediaWiki\Parser\Parser::fetchFileAndTitle | ( | LinkTarget | $link, |
| array | $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.
| LinkTarget | $link | |
| array | $options | Array of options to RepoGroup::findFile |
Definition at line 3820 of file Parser.php.
References fetchFileNoRegister().
|
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.
| LinkTarget | $link | |
| array | $options | Array of options to RepoGroup::findFile |
Definition at line 3847 of file Parser.php.
Referenced by fetchFileAndTitle().
| MediaWiki\Parser\Parser::fetchTemplateAndTitle | ( | LinkTarget | $link | ) |
Fetch the unparsed text of a template and register a reference to it.
| LinkTarget | $link |
Definition at line 3595 of file Parser.php.
References getOutput(), and getTitle().
Referenced by getTemplateDom().
| MediaWiki\Parser\Parser::firstCallInit | ( | ) |
Used to do various kinds of initialisation on the first call of the parser.
Definition at line 498 of file Parser.php.
|
static |
Add HTML tags marking the parts of a page title, to be displayed in the first heading of the page.
| string | HtmlArmor | $nsText | |
| string | HtmlArmor | $nsSeparator | |
| string | HtmlArmor | $mainText | |
| ?Language | $titleLang | If present, the title will be wrapped with a setting appropriate lang and dir attributes. |
Definition at line 6621 of file Parser.php.
| MediaWiki\Parser\Parser::getBadFileLookup | ( | ) |
Get the BadFileLookup instance that this Parser is using.
Definition at line 1162 of file Parser.php.
Referenced by MediaWiki\Linker\Linker\makeImageLink().
| MediaWiki\Parser\Parser::getContentLanguage | ( | ) |
Get the content language that this Parser is using.
Definition at line 1152 of file Parser.php.
Referenced by MediaWiki\Parser\CoreParserFunctions\lc(), MediaWiki\Parser\CoreParserFunctions\lcfirst(), MediaWiki\Parser\CoreParserFunctions\ns(), MediaWiki\Parser\CoreParserFunctions\pagesincategory(), MediaWiki\Parser\CoreParserFunctions\uc(), and MediaWiki\Parser\CoreParserFunctions\ucfirst().
| MediaWiki\Parser\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).
Definition at line 2213 of file Parser.php.
References $url, getLinkRenderer(), and getTitle().
|
static |
Get the rel attribute for a particular external link.
Definition at line 2196 of file Parser.php.
References $url, MediaWiki\MediaWikiServices\getInstance(), and wfDeprecated().
| MediaWiki\Parser\Parser::getFlatSectionInfo | ( | $text | ) |
Get an array of preprocessor section information.
Preprocessor sections are those identified by wikitext-style syntax, not HTML-style syntax. Templates are not expanded, so these sections do not include sections created by templates or parser functions. This is the same definition of a section as used by section editing, but not the same as TOC generation.
These sections are typically smaller than those acted on by getSection() and replaceSection() since they are not nested. Section nesting could be reconstructed from the heading levels.
The return value is an array of associative array info structures. Each associative array contains the following keys, describing a section:
Definition at line 6044 of file Parser.php.
References MediaWiki\Parser\PPFrame\expand(), getPreprocessor(), lock(), MediaWiki\Parser\ParserOptions\newFromUser(), preprocessToDom(), and MediaWiki\Parser\PPFrame\RECOVER_ORIG.
| MediaWiki\Parser\Parser::getFunctionHooks | ( | ) |
Get all registered function hook identifiers.
Definition at line 5159 of file Parser.php.
| MediaWiki\Parser\Parser::getFunctionSynonyms | ( | ) |
Definition at line 5828 of file Parser.php.
|
protected |
Get a HookContainer capable of returning metadata about hooks or running extension hooks.
Definition at line 1582 of file Parser.php.
Referenced by clearState().
|
protected |
Get a HookRunner for calling core hooks.
Definition at line 1610 of file Parser.php.
| MediaWiki\Parser\Parser::getLinkRenderer | ( | ) |
Get a LinkRenderer instance to make links with.
Definition at line 1130 of file Parser.php.
Referenced by getExternalLinkAttribs(), and MediaWiki\Parser\CoreParserFunctions\isbn().
| MediaWiki\Parser\Parser::getMagicWordFactory | ( | ) |
Get the MagicWordFactory that this Parser is using.
Definition at line 1142 of file Parser.php.
Referenced by MediaWiki\Parser\CoreParserFunctions\categorysort(), MediaWiki\Parser\CoreParserFunctions\contentmodel(), MediaWiki\Parser\CoreParserFunctions\defaultsort(), MediaWiki\Parser\CoreParserFunctions\displaytitle(), MediaWiki\Parser\CoreParserFunctions\formatnum(), MediaWiki\Parser\CoreParserFunctions\pagesincategory(), and MediaWiki\Parser\CoreParserFunctions\urlencode().
| MediaWiki\Parser\Parser::getMiserMode | ( | ) |
Definition at line 1598 of file Parser.php.
References return.
Referenced by MediaWiki\Parser\CoreParserFunctions\revisionid().
| MediaWiki\Parser\Parser::getNamespaceInfo | ( | ) |
Definition at line 1590 of file Parser.php.
References return.
Referenced by MediaWiki\Parser\CoreParserFunctions\revisionid().
| MediaWiki\Parser\Parser::getOptions | ( | ) |
Definition at line 1054 of file Parser.php.
Referenced by MediaWiki\Parser\CoreParserFunctions\formatDate(), MediaWiki\Parser\CoreParserFunctions\gender(), getUserIdentity(), MediaWiki\Parser\ParserCoreTagHooks\html(), MediaWiki\Parser\CoreParserFunctions\intFunction(), and MediaWiki\Parser\CoreParserFunctions\revisionid().
| MediaWiki\Parser\Parser::getOutput | ( | ) |
Definition at line 1046 of file Parser.php.
References return.
Referenced by MediaWiki\Parser\CoreParserFunctions\categorysort(), MediaWiki\Parser\CoreParserFunctions\defaultsort(), MediaWiki\Parser\CoreParserFunctions\displaytitle(), MediaWiki\Parser\CoreMagicVariables\expand(), fetchTemplateAndTitle(), MediaWiki\Parser\CoreParserFunctions\interlanguagelink(), MediaWiki\Parser\CoreParserFunctions\interwikilink(), MediaWiki\Parser\CoreParserFunctions\isbn(), MediaWiki\Parser\CoreParserFunctions\pageid(), MediaWiki\Parser\CoreParserFunctions\revisionid(), and MediaWiki\Parser\CoreParserFunctions\revisionuser().
| MediaWiki\Parser\Parser::getOutputType | ( | ) |
Accessor for the output type.
Definition at line 1022 of file Parser.php.
References return.
| MediaWiki\Parser\Parser::getPage | ( | ) |
Returns the page used as context for parsing, e.g.
when resolving relative subpage links.
Definition at line 1005 of file Parser.php.
References if, and wfDeprecated().
Referenced by getUserSig(), and splitDisplayTitle().
| MediaWiki\Parser\Parser::getParseTime | ( | ) |
Return the parse time.
This is the timestamp recorded in ParserOptions, except that it can also be modified by the ParserGetVariableValueTs hook.
Definition at line 567 of file Parser.php.
| MediaWiki\Parser\Parser::getPreloadText | ( | $text, | |
| PageReference | $page, | ||
| ParserOptions | $options, | ||
| $params = [] ) |
Process the wikitext for the "?preload=" feature.
(T7210)
"<noinclude>", "<includeonly>" etc. are parsed as for template transclusion, comments, templates, arguments, tags hooks and parser functions are untouched.
| string | $text | |
| PageReference | $page | |
| ParserOptions | $options | |
| array | $params |
Definition at line 930 of file Parser.php.
References MediaWiki\Parser\Preprocessor\DOM_FOR_INCLUSION, getPreprocessor(), lock(), MediaWiki\Parser\PPFrame\NO_ARGS, MediaWiki\Parser\PPFrame\NO_TEMPLATES, and preprocessToDom().
| MediaWiki\Parser\Parser::getPreprocessor | ( | ) |
Get a preprocessor object.
Definition at line 1120 of file Parser.php.
Referenced by getFlatSectionInfo(), getPreloadText(), preprocessToDom(), and replaceVariables().
| MediaWiki\Parser\Parser::getRevisionId | ( | ) |
Get the ID of the revision we are parsing.
The return value will be either:
Definition at line 6098 of file Parser.php.
Referenced by MediaWiki\Parser\CoreParserFunctions\revisionid().
| MediaWiki\Parser\Parser::getRevisionRecordObject | ( | ) |
Get the revision record object for $this->mRevisionId.
Definition at line 6108 of file Parser.php.
References MediaWiki\MediaWikiServices\getInstance(), and getTitle().
Referenced by getRevisionSize(), getRevisionUser(), and MediaWiki\Parser\CoreParserFunctions\revisionid().
| MediaWiki\Parser\Parser::getRevisionSize | ( | ) |
Get the size of the revision.
Definition at line 6217 of file Parser.php.
References getRevisionRecordObject().
Referenced by makeLimitReport().
| MediaWiki\Parser\Parser::getRevisionTimestamp | ( | ) |
Get the timestamp associated with the current revision, adjusted for the default server-local timestamp.
Definition at line 6165 of file Parser.php.
References if.
| MediaWiki\Parser\Parser::getRevisionUser | ( | ) |
Get the name of the user that edited the last revision.
Definition at line 6193 of file Parser.php.
References getRevisionRecordObject(), getUserIdentity(), and if.
Referenced by MediaWiki\Parser\CoreParserFunctions\revisionuser().
| MediaWiki\Parser\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 | int | $sectionId | Section identifier as a number or string (e.g. 0, 1 or 'T-1'). |
| string | false | $defaultText | Default to return if section is not found |
Definition at line 5994 of file Parser.php.
References return.
| MediaWiki\Parser\Parser::getStripList | ( | ) |
Get a list of strippable XML-like elements.
Definition at line 1248 of file Parser.php.
Referenced by MediaWiki\Parser\CoreParserFunctions\tagObj().
| MediaWiki\Parser\Parser::getStripState | ( | ) |
Definition at line 1256 of file Parser.php.
Referenced by MediaWiki\Parser\CoreParserFunctions\tagObj().
| MediaWiki\Parser\Parser::getTags | ( | ) |
| MediaWiki\Parser\Parser::getTargetLanguage | ( | ) |
Get the target language for the content being parsed.
This is usually the language that the content is in.
Definition at line 1091 of file Parser.php.
References getTitle().
Referenced by MediaWiki\Parser\CoreParserFunctions\bcp47(), MediaWiki\Parser\CoreParserFunctions\bidi(), MediaWiki\Parser\CoreParserFunctions\contentmodel(), MediaWiki\Parser\CoreParserFunctions\dir(), MediaWiki\Parser\CoreParserFunctions\formatDate(), MediaWiki\Parser\CoreParserFunctions\formatnum(), MediaWiki\Parser\CoreParserFunctions\gender(), getTargetLanguageConverter(), MediaWiki\Parser\CoreParserFunctions\grammar(), MediaWiki\Parser\CoreParserFunctions\language(), MediaWiki\Parser\CoreParserFunctions\numberingroup(), MediaWiki\Parser\CoreParserFunctions\numberofactiveusers(), MediaWiki\Parser\CoreParserFunctions\numberofadmins(), MediaWiki\Parser\CoreParserFunctions\numberofarticles(), MediaWiki\Parser\CoreParserFunctions\numberofedits(), MediaWiki\Parser\CoreParserFunctions\numberoffiles(), MediaWiki\Parser\CoreParserFunctions\numberofpages(), MediaWiki\Parser\CoreParserFunctions\numberofusers(), MediaWiki\Parser\CoreParserFunctions\pagesincategory(), MediaWiki\Parser\CoreParserFunctions\pagesinnamespace(), MediaWiki\Parser\CoreParserFunctions\pagesize(), and MediaWiki\Parser\CoreParserFunctions\plural().
| MediaWiki\Parser\Parser::getTargetLanguageConverter | ( | ) |
Shorthand for getting a Language Converter for Target language.
Definition at line 1560 of file Parser.php.
References getTargetLanguage(), and return.
Referenced by MediaWiki\Parser\CoreParserFunctions\categorysort(), MediaWiki\Parser\CoreParserFunctions\defaultsort(), MediaWiki\Parser\CoreParserFunctions\displaytitle(), and parse().
| MediaWiki\Parser\Parser::getTemplateDom | ( | LinkTarget | $title, |
| bool | $inSolState = false ) |
Get the semi-parsed DOM representation of a template with a given title, and its redirect destination title.
Cached.
The second element of the returned array may be a Title object, or may be the passed $title parameter, so if you need a Title, pass it a Title rather than a TitleValue.
| LinkTarget | $title | |
| bool | $inSolState | Is the template processing starting in Start-Of-Line (SOL) position? Prepreprocessing (on behalf of Parsoid) uses this flag to set lineStart property on processor DOM tree nodes. Since the preprocessor tree doesn't rely on expanded templates, this flag is a best guess since {{expands-to-empty-string}} can blind it to SOL context. This flag is always false for legacy parser template expansions. |
Definition at line 3454 of file Parser.php.
References MediaWiki\Parser\Preprocessor\DOM_FOR_INCLUSION, fetchTemplateAndTitle(), MediaWiki\Deferred\LinksUpdate\GenericPageLinksTable\makeTitle(), preprocessToDom(), and MediaWiki\Parser\Preprocessor\START_IN_SOL_STATE.
| MediaWiki\Parser\Parser::getTitle | ( | ) |
Definition at line 972 of file Parser.php.
References return.
Referenced by MediaWiki\Parser\CoreParserFunctions\cascadingsources(), MediaWiki\Parser\CoreParserFunctions\displaytitle(), fetchTemplateAndTitle(), getExternalLinkAttribs(), getRevisionRecordObject(), getTargetLanguage(), MediaWiki\Linker\Linker\makeImageLink(), MediaWiki\Parser\CoreParserFunctions\pageid(), MediaWiki\Parser\CoreParserFunctions\protectionexpiry(), MediaWiki\Parser\CoreParserFunctions\protectionlevel(), MediaWiki\Parser\CoreParserFunctions\revisionid(), and MediaWiki\Parser\CoreParserFunctions\revisionuser().
| MediaWiki\Parser\Parser::getUrlProtocols | ( | ) |
| MediaWiki\Parser\Parser::getUserIdentity | ( | ) |
Get a user either from the user set on Parser if it's set, or from the ParserOptions object otherwise.
Definition at line 1110 of file Parser.php.
References getOptions(), getUserIdentity(), and return.
Referenced by getRevisionUser(), and getUserIdentity().
| MediaWiki\Parser\Parser::getUserSig | ( | UserIdentity | $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.
| UserIdentity | $user | |
| string | false | $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 4779 of file Parser.php.
References cleanSigInSig(), getPage(), wfEscapeWikiText(), and wfMessage().
| MediaWiki\Parser\Parser::guessLegacySectionNameFromWikiText | ( | $text | ) |
Same as guessSectionNameFromWikiText(), but produces legacy anchors instead, if possible.
For use in redirects, since various versions of Microsoft browsers interpret Location: headers as something other than UTF-8, resulting in breakage.
| string | $text | The section name |
Definition at line 6279 of file Parser.php.
References stripSectionName(), and wfDeprecated().
|
static |
Like guessSectionNameFromWikiText(), but takes already-stripped text as input.
| string | $text | Section name (plain text) |
Definition at line 6293 of file Parser.php.
| MediaWiki\Parser\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 6261 of file Parser.php.
References stripSectionName().
Referenced by MediaWiki\Parser\CoreParserFunctions\anchorencode().
| MediaWiki\Parser\Parser::incrementExpensiveFunctionCount | ( | ) |
Definition at line 4117 of file Parser.php.
Referenced by MediaWiki\Parser\CoreParserFunctions\cascadingsources(), MediaWiki\Parser\CoreParserFunctions\contentmodel(), MediaWiki\Parser\CoreParserFunctions\pageid(), MediaWiki\Parser\CoreParserFunctions\pagesincategory(), MediaWiki\Parser\CoreParserFunctions\protectionexpiry(), and MediaWiki\Parser\CoreParserFunctions\protectionlevel().
| MediaWiki\Parser\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 1269 of file Parser.php.
References MARKER_PREFIX.
| MediaWiki\Parser\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.
Definition at line 1492 of file Parser.php.
Referenced by parse(), and recursiveTagParse().
| MediaWiki\Parser\Parser::interwikiTransclude | ( | LinkTarget | $link, |
| $action ) |
Transclude an interwiki link.
| LinkTarget | $link | |
| string | $action | Usually one of (raw, render) |
Definition at line 3870 of file Parser.php.
References if, and wfMessage().
| MediaWiki\Parser\Parser::isCurrentRevisionOfTitleCached | ( | LinkTarget | $link | ) |
| LinkTarget | $link |
Definition at line 3537 of file Parser.php.
| MediaWiki\Parser\Parser::isLocked | ( | ) |
Will entry points such as parse() throw an exception due to the parser already being active?
Definition at line 6491 of file Parser.php.
| MediaWiki\Parser\Parser::killMarkers | ( | $text | ) |
Remove any strip markers found in the given text.
| string | $text |
Definition at line 6399 of file Parser.php.
References killMarkers(), and return.
Referenced by MediaWiki\Parser\CoreParserFunctions\anchorencode(), MediaWiki\Parser\CoreParserFunctions\displaytitle(), MediaWiki\Parser\CoreParserFunctions\grammar(), killMarkers(), MediaWiki\Parser\CoreParserFunctions\pad(), MediaWiki\Parser\CoreParserFunctions\tagObj(), and MediaWiki\Parser\CoreParserFunctions\urlencode().
| MediaWiki\Parser\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 2919 of file Parser.php.
References addTrackingCategory(), and MediaWiki\Message\Message\numParam().
Referenced by argSubstitution(), and parse().
|
static |
Localize the TOC into the given target language; this includes invoking the language converter on the headings.
| ?TOCData | $tocData | The Table of Contents |
| Language | $lang | The target language |
| ?ILanguageConverter | $converter | The target language converter, or null if language conversion is to be suppressed. |
| ?string | $preferredVariant | The target variant for language conversion. |
Definition at line 4615 of file Parser.php.
References MediaWiki\Language\ILanguageConverter\convertTo(), MediaWiki\Language\Language\formatNum(), and MediaWiki\Language\ILanguageConverter\getPreferredVariant().
|
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.
Definition at line 6453 of file Parser.php.
References if.
Referenced by cleanSig(), getFlatSectionInfo(), getPreloadText(), parse(), preprocess(), and preSaveTransform().
| MediaWiki\Parser\Parser::makeImage | ( | LinkTarget | $link, |
| $options, | |||
| $holders = false ) |
Parse image options text and use it to make an image.
| LinkTarget | $link | |
| string | $options | |
| LinkHolderArray | false | $holders | If $holders is false, link holders are replaced in the alt text but may still be present elsewhere in the returned HTML. Use ::makeImageHtml if you want to ensure no link holders remain in the returned HTML. |
Definition at line 5449 of file Parser.php.
References wfDeprecated().
| MediaWiki\Parser\Parser::makeImageHtml | ( | LinkTarget | $link, |
| string | $options ) |
Parse image options text and use it to make an image.
| LinkTarget | $link | |
| string | $options |
Definition at line 5429 of file Parser.php.
References return.
| MediaWiki\Parser\Parser::makeLimitReport | ( | ParserOptions | $parserOptions, |
| ParserOutput | $parserOutput ) |
Set the limit report data in the current ParserOutput.
Definition at line 706 of file Parser.php.
References MediaWiki\MainConfigNames\EnableParserLimitReporting, MediaWiki\Parser\ParserOutput\getCacheExpiry(), MediaWiki\Parser\CacheTime\getCacheExpirySource(), MediaWiki\Parser\CacheTime\getCacheTime(), MediaWiki\Parser\ParserOptions\getExpensiveParserFunctionLimit(), MediaWiki\Parser\ParserOptions\getMaxIncludeSize(), MediaWiki\Parser\ParserOptions\getMaxPPExpandDepth(), MediaWiki\Parser\ParserOptions\getMaxPPNodeCount(), getRevisionSize(), MediaWiki\Parser\ParserOutput\getTimeProfile(), MediaWiki\Parser\ParserOutput\hasReducedExpiry(), MediaWiki\Parser\ParserOptions\isMessage(), MediaWiki\MainConfigNames\MaxArticleSize, MediaWiki\Parser\ParserOutput\setLimitReportData(), MediaWiki\MainConfigNames\ShowHostnames, and wfHostname().
Referenced by parse().
| MediaWiki\Parser\Parser::markerSkipCallback | ( | $s, | |
| callable | $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 6368 of file Parser.php.
Referenced by MediaWiki\Parser\CoreParserFunctions\formatnum(), MediaWiki\Parser\CoreParserFunctions\lc(), and MediaWiki\Parser\CoreParserFunctions\uc().
| MediaWiki\Parser\Parser::modifyImageHtml | ( | File | $file, |
| array | $params, | ||
| string & | $html ) |
Give hooks a chance to modify image thumbnail HTML.
| File | $file | |
| array | $params | |
| string | &$html |
Definition at line 5757 of file Parser.php.
| MediaWiki\Parser\Parser::msg | ( | $key, | |
| ... ) |
Helper function to correctly set the target language and title of a message based on the parser context.
Most uses of system messages inside extensions or parser functions should use this method (instead of directly using wfMessage) to ensure that the cache is not polluted.
This is the method for getting translated interface messages.
| string | string[] | MessageSpecifier | $key | Message key, or array of keys, or a MessageSpecifier. |
| MessageParam|MessageSpecifier|string|int|float|list<MessageParam|MessageSpecifier|string|int|float> | ...$params See Message\params() |
Implements MediaWiki\Language\MessageLocalizer.
Definition at line 4219 of file Parser.php.
Referenced by MediaWiki\Parser\CoreParserFunctions\categorysort(), MediaWiki\Parser\CoreParserFunctions\defaultsort(), MediaWiki\Parser\CoreParserFunctions\displaytitle(), MediaWiki\Parser\ParserCoreTagHooks\html(), and MediaWiki\Parser\ParserCoreTagHooks\indicator().
| MediaWiki\Parser\Parser::nextLinkID | ( | ) |
|
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.
Definition at line 2239 of file Parser.php.
References $url.
| MediaWiki\Parser\Parser::parse | ( | $text, | |
| PageReference | $page, | ||
| 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 |
| -taint | $text | escapes_htmlnoent |
| PageReference | $page | |
| ParserOptions | $options | |
| bool | $linestart | |
| bool | $clearState | |
| int | RevisionRecord | null | $revid | ID of the revision being rendered. This is used to render REVISION* magic words. 0 means that any current revision will be used. Null means that {{REVISIONID}}/{{REVISIONUSER}} will be empty and {{REVISIONTIMESTAMP}} will use the current timestamp. |
Definition at line 598 of file Parser.php.
References MediaWiki\Parser\ParserOptions\getDisableTitleConversion(), MediaWiki\Parser\ParserOptions\getExpensiveParserFunctionLimit(), getTargetLanguageConverter(), internalParse(), limitationWarn(), lock(), makeLimitReport(), MediaWiki\Parser\Sanitizer\removeSomeTags(), and splitDisplayTitle().
| MediaWiki\Parser\Parser::parseExtensionTagAsTopLevelDoc | ( | string | $text, |
| PPFrame|false | $frame = false ) |
Needed by Parsoid/PHP to ensure all the hooks for extensions are run in the right order.
The primary differences between this and recursiveTagParseFully are: (a) absence of $frame (b) passing true to internalParseHalfParse so all hooks are run (c) running 'ParserAfterParse' hook at the same point in the parsing pipeline when parse() does it. This kinda mimics Parsoid/JS behavior where exttags are processed by the M/w API.
This is a temporary convenience method and will go away as we proceed further with Parsoid <-> Parser.php integration.
Definition at line 864 of file Parser.php.
References recursiveTagParse().
| MediaWiki\Parser\Parser::parseWidthParam | ( | $value, | |
| $parseHeight = true, | |||
| bool | $localized = false ) |
Parsed a width param of imagelink like 300px or 200x300px.
| string | $value | |
| bool | $parseHeight | |
| bool | $localized | Defaults to false; set to true if the $value has already been matched against img_width to localize the px suffix. |
Definition at line 6416 of file Parser.php.
References addTrackingCategory().
Referenced by MediaWiki\Parser\CoreParserFunctions\filepath(), MediaWiki\Gallery\ImageGalleryBase\setHeights(), and MediaWiki\Gallery\ImageGalleryBase\setWidths().
| MediaWiki\Parser\Parser::preprocess | ( | $text, | |
| ?PageReference | $page, | ||
| 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 | |
| ?PageReference | $page | |
| ParserOptions | $options | |
| int | null | $revid | |
| PPFrame | false | $frame |
Definition at line 883 of file Parser.php.
References lock(), and replaceVariables().
| MediaWiki\Parser\Parser::preprocessToDom | ( | $text, | |
| $flags = 0 ) |
Get the document object model for the given wikitext.
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 T6899.
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().
| string | $text | Wikitext |
| int | $flags | Bit field of Preprocessor::DOM_* constants |
Definition at line 2823 of file Parser.php.
References getPreprocessor().
Referenced by callParserFunction(), getFlatSectionInfo(), getPreloadText(), and getTemplateDom().
| MediaWiki\Parser\Parser::preSaveTransform | ( | $text, | |
| PageReference | $page, | ||
| UserIdentity | $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 |
| PageReference | $page | the current article |
| UserIdentity | $user | the current user |
| ParserOptions | $options | Parsing options |
| bool | $clearState | Whether to clear the parser state first |
Definition at line 4658 of file Parser.php.
| MediaWiki\Parser\Parser::recursivePreprocess | ( | $text, | |
| $frame = false ) |
Recursive parser entry point that can be called from an extension tag hook.
| string | $text | Text to be expanded |
| PPFrame | false | $frame | The frame to use for expanding any template variables |
Definition at line 910 of file Parser.php.
References replaceVariables().
| MediaWiki\Parser\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 |
| -taint | $text | escapes_htmlnoent |
| PPFrame | false | $frame | The frame to use for expanding any template variables |
Definition at line 814 of file Parser.php.
References internalParse().
Referenced by MediaWiki\Parser\ParserCoreTagHooks\langconvert(), parseExtensionTagAsTopLevelDoc(), MediaWiki\Parser\ParserCoreTagHooks\pre(), and recursiveTagParseFully().
| MediaWiki\Parser\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 |
| -taint | $text | escapes_htmlnoent |
| PPFrame | false | $frame | The frame to use for expanding any template variables |
Definition at line 838 of file Parser.php.
References recursiveTagParse().
Referenced by MediaWiki\Parser\CoreParserFunctions\interwikilink().
| MediaWiki\Parser\Parser::renderImageGallery | ( | $text, | |
| array | $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 5198 of file Parser.php.
| MediaWiki\Parser\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 | int | $sectionId | Section identifier as a number or string (e.g. 0, 1 or 'T-1'). |
| string | false | $newText | Replacing text |
Definition at line 6011 of file Parser.php.
References return.
|
static |
Replace table of contents marker in parsed HTML.
Used to remove or replace the marker. This method should be used instead of direct access to Parser::TOC_PLACEHOLDER, since in the future the placeholder might have additional attributes attached which should be ignored when the replacement is made.
| string | $text | Parsed HTML |
| string | $toc | HTML table of contents string, or else an empty string to remove the marker. |
Definition at line 4945 of file Parser.php.
References if.
| MediaWiki\Parser\Parser::replaceVariables | ( | $text, | |
| $frame = false, | |||
| $argsOnly = false, | |||
| array | $options = [] ) |
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 |
| false | PPFrame | array | $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. |
| array | $options | Various options used by Parsoid:
|
Definition at line 2853 of file Parser.php.
References getPreprocessor(), and if.
Referenced by preprocess(), and recursivePreprocess().
| MediaWiki\Parser\Parser::resetOutput | ( | ) |
Reset the ParserOutput.
Definition at line 555 of file Parser.php.
Referenced by clearState().
| MediaWiki\Parser\Parser::setFunctionHook | ( | $id, | |
| callable | $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 most wikitext transformation, but perform language conversion and some other postprocessing isRawHTML The returned text is raw HTML, include it verbatim in the output.
| 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.
Definition at line 5125 of file Parser.php.
Referenced by MediaWiki\Parser\CoreParserFunctions\register().
| MediaWiki\Parser\Parser::setHook | ( | $tag, | |
| callable | $callback ) |
Create an HTML-style tag, e.g.
"<yourtag>special text</yourtag>" The callback should have the following form: function myParserHook( $text, array $params, Parser $parser, PPFrame $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. The following other keys are used:
| string | $tag | The tag to use, e.g. 'hook' for "<hook>" |
| callable | $callback | The callback to use for the tag |
Definition at line 5054 of file Parser.php.
| MediaWiki\Parser\Parser::setLinkID | ( | $id | ) |
| MediaWiki\Parser\Parser::setOptions | ( | ParserOptions | $options | ) |
Mutator for the ParserOptions object.
| ParserOptions | $options | The new parser options |
Definition at line 1063 of file Parser.php.
| MediaWiki\Parser\Parser::setOutputType | ( | $ot | ) |
Mutator for the output type.
| int | $ot | One of the Parser::OT_… constants |
Definition at line 1031 of file Parser.php.
| MediaWiki\Parser\Parser::setPage | ( | ?PageReference | $t = null | ) |
Set the page used as context for parsing, e.g.
when resolving relative subpage links.
| ?PageReference | $t |
Definition at line 982 of file Parser.php.
References MediaWiki\Deferred\LinksUpdate\GenericPageLinksTable\makeTitle(), and NS_SPECIAL.
Referenced by setTitle().
| MediaWiki\Parser\Parser::setTitle | ( | ?Title | $t = null | ) |
Set the context title.
| Title | null | $t |
Definition at line 963 of file Parser.php.
References setPage().
| MediaWiki\Parser\Parser::setUseParsoidFragments | ( | bool | $val | ) |
| MediaWiki\Parser\Parser::setUser | ( | ?UserIdentity | $user | ) |
Set the current user.
Should only be used when doing pre-save transform.
| UserIdentity | null | $user | user identity or null (to reset) |
Definition at line 952 of file Parser.php.
| MediaWiki\Parser\Parser::splitDisplayTitle | ( | HtmlArmor | $displayTitle, |
| ?ILanguageConverter | $languageConverter = null ) |
Split a user-supplied display title for the page being parsed into namespace, separator, and main title portions.
| HtmlArmor | $displayTitle | The user-supplied display title |
| ?ILanguageConverter | $languageConverter | Optional language converter for (possibly gender-aware) namespace matching |
Definition at line 6527 of file Parser.php.
References getPage(), return, and splitPageTitle().
Referenced by MediaWiki\Parser\CoreParserFunctions\displaytitle(), and parse().
|
static |
Split a page title into namespace, separator, and main title portions, so that they can be styled individually (see ::formatPageTitle()).
Avoid using this if possible: the split is not guaranteed to succeed. This is used in legacy situations where unsplit title text, possible with span wrappers and other styling, is provided from the user as in the {{displaytitle}} parser function and -{T|...}-.
If the text can't confidently be split – for example because it doesn't begin with $page's localized namespace prefix – the whole text is returned as the main title with an empty namespace, which ::formatPageTitle() then renders without a mw-page-title-namespace span. That maintains the pre-T314399 behavior, but may have minor styling issues with skins.
| HtmlArmor | $pageTitle | The page title ("safe HTML") |
| LinkTarget | PageReference | $page | Page corresponding to $pageTitle |
| ILanguageConverter | $languageConverter | Language converter for (possibly gender-aware) namespace matching |
Definition at line 6564 of file Parser.php.
Referenced by splitDisplayTitle().
| MediaWiki\Parser\Parser::startExternalParse | ( | ?PageReference | $page, |
| ParserOptions | $options, | ||
| $outputType, | |||
| $clearState = true, | |||
| $revId = null ) |
Set up some variables which are usually set up in parse() so that an external function can call some class members with confidence.
| ?PageReference | $page | |
| ParserOptions | $options | |
| int | $outputType | One of the Parser::OT_… constants |
| bool | $clearState | |
| int | null | $revId |
Definition at line 4985 of file Parser.php.
|
static |
| LinkTarget | $link | |
| Parser | null | $parser |
Definition at line 3580 of file Parser.php.
References MediaWiki\MediaWikiServices\getInstance(), and wfDeprecated().
|
static |
| LinkTarget | $page | |
| Parser | false | $parser |
Definition at line 3800 of file Parser.php.
References MediaWiki\MediaWikiServices\getInstance().
|
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 6505 of file Parser.php.
Referenced by MediaWiki\Parser\CoreParserFunctions\interwikilink().
| MediaWiki\Parser\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 mimicking 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 6330 of file Parser.php.
References doQuotes().
Referenced by guessLegacySectionNameFromWikiText(), and guessSectionNameFromWikiText().
| MediaWiki\Parser\Parser::tagNeedsNowikiStrippedInTagPF | ( | string | $lowerTagName | ) |
Definition at line 3979 of file Parser.php.
Referenced by MediaWiki\Parser\CoreParserFunctions\tagObj().
| MediaWiki\Parser\Parser::transformMsg | ( | $text, | |
| ParserOptions | $options, | ||
| ?PageReference | $page = null ) |
Wrapper for preprocess().
| string | $text | The text to preprocess |
| ParserOptions | $options | |
| ?PageReference | $page | The context page |
Definition at line 5020 of file Parser.php.
| MediaWiki\Parser\Parser::useParsoidFragments | ( | ) |
Definition at line 2888 of file Parser.php.
References return, and useParsoidFragments().
Referenced by setUseParsoidFragments(), and useParsoidFragments().
| MediaWiki\Parser\Parser::validateSig | ( | $text | ) |
Check that the user's signature contains no bad XML.
| string | $text |
Definition at line 4857 of file Parser.php.
| MediaWiki\Parser\Parser::$mExpensiveFunctionCount |
Number of expensive parser function calls.
Definition at line 281 of file Parser.php.
| MediaWiki\Parser\Parser::$mExtArrays |
Definition at line 302 of file Parser.php.
| MediaWiki\Parser\Parser::$mExtHashTables |
Definition at line 304 of file Parser.php.
| MediaWiki\Parser\Parser::$mExtLoopsCounter |
Definition at line 306 of file Parser.php.
| MediaWiki\Parser\Parser::$mExtVariables |
Definition at line 300 of file Parser.php.
| array MediaWiki\Parser\Parser::$mHeadings |
Definition at line 274 of file Parser.php.
| int MediaWiki\Parser\Parser::$mHighestExpansionDepth |
Definition at line 271 of file Parser.php.
| MediaWiki\Parser\Parser::$mMarkerIndex = 0 |
Definition at line 241 of file Parser.php.
| int MediaWiki\Parser\Parser::$mPPNodeCount |
Definition at line 266 of file Parser.php.
| const MediaWiki\Parser\Parser::CONSTRUCTOR_OPTIONS |
Definition at line 362 of file Parser.php.
Referenced by MediaWiki\Parser\ParserFactory\__construct().
| const MediaWiki\Parser\Parser::EXT_LINK_URL_CLASS = '[^][<>"\\x00-\\x20\\x7F\p{Zs}\x{FFFD}]' |
Everything except bracket, space, or control characters.
\p{Zs} is unicode 'separator, space' category. It covers the space 0x20 as well as U+3000 is IDEOGRAPHIC SPACE for T21052. \x{FFFD} is the Unicode replacement character, which the HTML5 spec uses to replace invalid HTML characters.
Definition at line 154 of file Parser.php.
| const MediaWiki\Parser\Parser::MARKER_PREFIX = "\x7f'\"`UNIQ-" |
Definition at line 206 of file Parser.php.
Referenced by MediaWiki\Parser\StripState\__construct(), MediaWiki\Parser\PPFrame_Hash\expand(), and insertStripItem().
| const MediaWiki\Parser\Parser::OT_HTML = 1 |
Output type: like Parser::parse().
Definition at line 177 of file Parser.php.
Referenced by MediaWiki\Parser\PPFrame_Hash\expand(), MediaWiki\Parser\Parsoid\Config\DataAccess\makeLimitReport(), and MediaWiki\Parser\Parsoid\Config\DataAccess\parseWikitextWithTitle().
| const MediaWiki\Parser\Parser::OT_PLAIN = 4 |
Output type: like Parser::extractSections() - portions of the original are returned unchanged.
Definition at line 186 of file Parser.php.
| const MediaWiki\Parser\Parser::OT_PREPROCESS = 3 |
Output type: like Parser::preprocess().
Definition at line 181 of file Parser.php.
Referenced by MediaWiki\Parser\PPFrame_Hash\expand(), and MediaWiki\Parser\Parsoid\Config\DataAccess\preprocessWikitext().
| const MediaWiki\Parser\Parser::OT_WIKI = 2 |
Output type: like Parser::preSaveTransform().
Definition at line 179 of file Parser.php.
Referenced by MediaWiki\Parser\PPFrame_Hash\expand().
| const MediaWiki\Parser\Parser::SFH_NO_HASH = 1 |
Definition at line 143 of file Parser.php.
Referenced by MediaWiki\Parser\CoreParserFunctions\register().
| const MediaWiki\Parser\Parser::SFH_OBJECT_ARGS = 2 |
Definition at line 144 of file Parser.php.
Referenced by MediaWiki\Parser\CoreParserFunctions\register().