MediaWiki master
MediaWiki\Parser\ParserOptions Class Reference

Set options of the Parser. More...

Public Member Functions

 __construct (UserIdentity $user, $lang=null)
 addExtraKey ( $key)
 Extra key that should be present in the parser cache key.
 allCacheVaryingOptionsWithPostproc ()
 Return all option keys that vary the options hash, including postprocessing options if appropriate.
 clearPostproc ()
 disableContentConversion ( $x=true)
 Whether content conversion should be disabled.
 disableTitleConversion ( $x=true)
 Whether title conversion should be disabled.
 enableLimitReport ( $x=true)
 enablePostproc ()
 Indicates that these options should apply post-processing options, and ensures that the cache is split accordingly.
 getAllowExternalImages ()
 Allow all external images inline?
 getAllowExternalImagesFrom ()
 External images to allow.
 getAllowSpecialInclusion ()
 Allow inclusion of special pages?
 getAllowUnsafeRawHtml ()
 If the wiki is configured to allow raw html ($wgRawHtml = true) is it allowed in the specific case of parsing this page.
 getCleanSignatures ()
 Clean up signature texts?
 getCollapsibleSections ()
 Should section contents be wrapped in.
 getCurrentRevisionRecordCallback ()
 Callback to fetch the current revision.
 getDateFormat ()
 Date format index.
 getDisableContentConversion ()
 Whether content conversion should be disabled.
 getDisableTitleConversion ()
 Whether title conversion should be disabled.
 getEnableImageWhitelist ()
 Use the on-wiki external image whitelist?
 getEnableLimitReport ()
 getExpensiveParserFunctionLimit ()
 Maximum number of calls per parse to expensive parser functions.
 getExternalLinkTarget ()
 Target attribute for external links.
 getInterfaceMessage ()
 Parsing an interface message in the user language?
 getInterwikiMagic ()
 Whether to extract interlanguage links.
 getIsPreview ()
 Parsing the page for a "preview" operation?
 getIsPrintable ()
 getIsSectionPreview ()
 Parsing the page for a "preview" operation on a single section?
 getMagicISBNLinks ()
 Are magic ISBN links enabled?
 getMagicPMIDLinks ()
 Are magic PMID links enabled?
 getMagicRFCLinks ()
 Are magic RFC links enabled?
 getMaxIncludeSize ()
 Maximum size of template expansions, in bytes.
 getMaxPPExpandDepth ()
 Maximum recursion depth in PPFrame::expand().
 getMaxPPNodeCount ()
 Maximum number of nodes touched by PPFrame::expand().
 getMaxTemplateDepth ()
 Maximum recursion depth for templates within templates.
 getOption ( $name)
 Fetch an option and track that is was accessed.
 getPostproc ()
 Returns usage of postprocessing (and splits the cache accordingly).
 getPreSaveTransform ()
 Transform wiki markup when saving the page?
 getRedirectTarget ()
 Get the previously-set redirect target.
 getRemoveComments ()
 Remove HTML comments.
 getRenderReason ()
 Returns reason for rendering the content.
 getSpeculativePageId ()
 A guess for {{PAGEID}}, calculated using the callback provided via setSpeculativeRevPageCallback().
 getSpeculativeRevId ()
 A guess for {{REVISIONID}}, calculated using the callback provided via setSpeculativeRevIdCallback().
 getSuppressSectionEditLinks ()
 Should section edit links be suppressed?
 getSuppressTOC ()
 Should the table of contents be suppressed?
 getTargetLanguage ()
 Target language for the parse.
 getTemplateCallback ()
 Callback to fetch a template.
 getThumbSize ()
 Get thumbnail size.
 getTimestamp ()
 Timestamp used for {{CURRENTDAY}} etc.
 getUseParsoid ()
 Parsoid-format HTML output, or legacy wikitext parser HTML?
 getUserIdentity ()
 Get the identity of the user for whom the parse is made.
 getUserLang ()
 Same as getUserLangObj() but returns a string instead.
 getUserLangObj ()
 Get the user language used by the parser for this page and split the parser cache.
 getVariant ()
 Returns the target language variant, or null if no language conversion is to be performed.
 getWrapOutputClass ()
 Class to use to wrap output from Parser::parse().
 isMessage ()
 Parsing a message?
 isSafeToCache (?array $usedOptions=null)
 Test whether the set of provided options are safe to cache.
 matches (ParserOptions $other)
 Check if these options match that of another options set.
 matchesForCacheKey (ParserOptions $other)
 optionsHash ( $forOptions, $title=null)
 Generate a hash string with the values set on these ParserOptions for the keys given in the array.
 registerWatcher ( $callback)
 Registers a callback for tracking which ParserOptions which are used.
 setAllowSpecialInclusion ( $x)
 Allow inclusion of special pages?
 setAllowUnsafeRawHtml ( $x)
 If the wiki is configured to allow raw html ($wgRawHtml = true) is it allowed in the specific case of parsing this page.
 setCleanSignatures ( $x)
 Clean up signature texts?
 setCollapsibleSections ()
 Wrap section contents in a.
 setCurrentRevisionRecordCallback ( $x)
 Callback to fetch the current revision.
 setDateFormat ( $x)
 Date format index.
 setExpensiveParserFunctionLimit ( $x)
 Maximum number of calls per parse to expensive parser functions.
 setExternalLinkTarget ( $x)
 Target attribute for external links.
 setInterfaceMessage ( $x)
 Parsing an interface message in the user language?
 setInterwikiMagic ( $x)
 Specify whether to extract interlanguage links.
 setIsMessage ( $x)
 Set whether we are parsing a message.
 setIsPreview ( $x)
 Parsing the page for a "preview" operation?
 setIsPrintable ( $x)
 setIsSectionPreview ( $x)
 Parsing the page for a "preview" operation on a single section?
 setMaxIncludeSize ( $x)
 Maximum size of template expansions, in bytes.
 setMaxPPNodeCount ( $x)
 Maximum number of nodes touched by PPFrame::expand().
 setMaxTemplateDepth ( $x)
 Maximum recursion depth for templates within templates.
 setOption ( $name, $value)
 Set an option, generically.
 setPreSaveTransform ( $x)
 Transform wiki markup when saving the page?
 setRedirectTarget ( $title)
 Note that setting or changing this does not make the page a redirect or change its target, it merely records the information for reference during the parse.
 setRemoveComments ( $x)
 Remove HTML comments.
 setRenderReason (string $renderReason)
 Sets reason for rendering the content.
 setSpeculativePageIdCallback ( $x)
 Callback to generate a guess for {{PAGEID}}.
 setSpeculativeRevIdCallback ( $x)
 Callback to generate a guess for {{REVISIONID}}.
 setSuppressSectionEditLinks ()
 Suppress section edit links in the output.
 setSuppressTOC ()
 Suppress generation of the table of contents.
 setTargetLanguage ( $x)
 Target language for the parse.
 setTemplateCallback ( $x)
 Set the callback to fetch a template.
 setThumbSize ( $x)
 Thumb size preferred by the user.
 setTimestamp ( $x)
 Timestamp used for {{CURRENTDAY}} etc.
 setupFakeRevision ( $page, $content, $user, $currentRevId=0)
 Sets a hook to force that a page exists, and sets a current revision callback to return a revision with custom content when the current revision of the page is requested.
 setUseParsoid (bool $value=true)
 Request Parsoid-format HTML output.
 setUseParsoidForLinksUpdate ()
 Select the parser configured by $wgUseParsoidLinksUpdate, for a parse whose output updates the links tables and other derived page metadata.
 setUserLang ( $x)
 Set the user language used by the parser for this page and split the parser cache.
 setVariant (?Language $variantLanguage)
 Set the target language variant.
 setWrapOutputClass ( $className)
 CSS class to use to wrap output from Parser::parse().

Static Public Member Functions

static allCacheVaryingOptions (bool $includePostproc=false)
 Return all option keys that vary the options hash.
static clearStaticCache ()
 Reset static caches.
static getLazyOptions ()
 Get lazy-loaded options.
static newCanonical ( $context, $userLang=null)
 Creates a "canonical" ParserOptions object.
static newFromAnon ()
 Get a ParserOptions object for an anonymous user.
static newFromContext (IContextSource $context)
 Get a ParserOptions object from a IContextSource object.
static newFromUser ( $user)
 Get a ParserOptions object from a given user.
static newFromUserAndLang (UserIdentity $user, Language $lang)
 Get a ParserOptions object from a given user and language.

Static Public Attributes

static array list< string > $postprocOptions
 List of "postprocessing options", excluded from most ParserOption operations by default.

Protected Member Functions

 setOptionLegacy ( $name, $value)
 Legacy implementation.

Detailed Description

Set options of the Parser.

How to add an option in core:

  1. Add it to one of the arrays in ParserOptions::getDefaults() (see documentation there)
  2. If necessary: a. add an entry to ParserOptions::$initialCacheVaryingOptionsHash: this splits the cache on that option b. add an entry to ParserOptions::$callbacks: this is used for pseudo-options that shouldn't be considered to compute cacheability c. add an entry to ParserOptions::$initialLazyOptions: this ensures that the option is only loaded on read. The cacheability of these options is also determined by their usage during the parse and their presence in the $initialCacheVaryingOptionsHash or $callbacks arrays. Setting options that are not from (2a) or (2b) will make the parse uncacheable if they are actually used during the parse in the (current default article parse) setup where option usage is recorded to determine cacheability (see ::isSafeToCache() below for details.)
  3. Add a getter and setter in the section for that. These should be typically be wrappers around getOption/setOption in order to ensure that $this->optionUsed() gets invoked.

How to add an option in an extension:

  1. Use the 'ParserOptionsRegister' hook to register it. This callback will provide $defaults (step 1), $cacheVaryingOptionsHash (2a) and $lazyOptions (2c) arrays which serve the same purpose as for options defined in core. It is not possible to add a pseudo-option (2b) from an extension at this time.
  2. Where necessary, use $popt->getOption() and $popt->setOption() to access it.

Definition at line 70 of file ParserOptions.php.

Constructor & Destructor Documentation

◆ __construct()

MediaWiki\Parser\ParserOptions::__construct ( UserIdentity $user,
$lang = null )
Parameters
UserIdentity$user
Language | null$lang

Definition at line 1192 of file ParserOptions.php.

Member Function Documentation

◆ addExtraKey()

MediaWiki\Parser\ParserOptions::addExtraKey ( $key)

Extra key that should be present in the parser cache key.

Warning
Consider registering your additional options with the ParserOptionsRegister hook instead of using this method.
Parameters
string$key

Definition at line 1175 of file ParserOptions.php.

◆ allCacheVaryingOptions()

MediaWiki\Parser\ParserOptions::allCacheVaryingOptions ( bool $includePostproc = false)
static

Return all option keys that vary the options hash.

Since
1.30
Parameters
bool$includePostprocWhen false (the default) removes all options from self::$postprocOptions from the return value
Returns
list<string>

Definition at line 1603 of file ParserOptions.php.

◆ allCacheVaryingOptionsWithPostproc()

MediaWiki\Parser\ParserOptions::allCacheVaryingOptionsWithPostproc ( )

Return all option keys that vary the options hash, including postprocessing options if appropriate.

Since
1.46
Returns
list<string>

Definition at line 1617 of file ParserOptions.php.

◆ clearPostproc()

MediaWiki\Parser\ParserOptions::clearPostproc ( )

Definition at line 1930 of file ParserOptions.php.

◆ clearStaticCache()

MediaWiki\Parser\ParserOptions::clearStaticCache ( )
static

Reset static caches.

Access: internal
For testing

Definition at line 1303 of file ParserOptions.php.

◆ disableContentConversion()

MediaWiki\Parser\ParserOptions::disableContentConversion ( $x = true)

Whether content conversion should be disabled.

Parameters
bool | null$xNew value (null is no change)
Returns
bool Old value

Definition at line 599 of file ParserOptions.php.

References setOptionLegacy().

◆ disableTitleConversion()

MediaWiki\Parser\ParserOptions::disableTitleConversion ( $x = true)

Whether title conversion should be disabled.

Parameters
bool | null$xNew value (null is no change)
Returns
bool Old value

Definition at line 616 of file ParserOptions.php.

References setOptionLegacy().

◆ enableLimitReport()

MediaWiki\Parser\ParserOptions::enableLimitReport ( $x = true)
Deprecated
since 1.38. This does nothing now, to control limit reporting please provide 'includeDebugInfo' option to ParserOutput::getText.

Enable limit report in an HTML comment on output

Parameters
bool | null$xNew value (null is no change)
Returns
bool Old value

Definition at line 544 of file ParserOptions.php.

◆ enablePostproc()

MediaWiki\Parser\ParserOptions::enablePostproc ( )

Indicates that these options should apply post-processing options, and ensures that the cache is split accordingly.

Since
1.46
Stability: unstable
See also
setPostProc for a non-cache-splitting alternative

Definition at line 1912 of file ParserOptions.php.

References getOption(), and setOption().

◆ getAllowExternalImages()

MediaWiki\Parser\ParserOptions::getAllowExternalImages ( )

Allow all external images inline?

Returns
bool

Definition at line 328 of file ParserOptions.php.

References getOption().

◆ getAllowExternalImagesFrom()

MediaWiki\Parser\ParserOptions::getAllowExternalImagesFrom ( )

External images to allow.

When self::getAllowExternalImages() is false

Returns
string|string[] URLs to allow

Definition at line 339 of file ParserOptions.php.

References getOption().

◆ getAllowSpecialInclusion()

MediaWiki\Parser\ParserOptions::getAllowSpecialInclusion ( )

Allow inclusion of special pages?

Returns
bool

Definition at line 355 of file ParserOptions.php.

References getOption().

◆ getAllowUnsafeRawHtml()

MediaWiki\Parser\ParserOptions::getAllowUnsafeRawHtml ( )

If the wiki is configured to allow raw html ($wgRawHtml = true) is it allowed in the specific case of parsing this page.

This is meant to disable unsafe parser tags in cases where a malicious user may control the input to the parser.

Note
This is expected to be true for normal pages even if the wiki has $wgRawHtml disabled in general. The setting only signifies that raw html would be unsafe in the current context provided that raw html is allowed at all.
Since
1.29
Returns
bool

Definition at line 971 of file ParserOptions.php.

References getOption().

◆ getCleanSignatures()

MediaWiki\Parser\ParserOptions::getCleanSignatures ( )

Clean up signature texts?

See also
Parser::cleanSig
Returns
bool

Definition at line 553 of file ParserOptions.php.

References getOption().

◆ getCollapsibleSections()

MediaWiki\Parser\ParserOptions::getCollapsibleSections ( )

Should section contents be wrapped in.

to make them collapsible?
Since
1.42

Definition at line 919 of file ParserOptions.php.

References getOption(), and return.

◆ getCurrentRevisionRecordCallback()

MediaWiki\Parser\ParserOptions::getCurrentRevisionRecordCallback ( )

Callback to fetch the current revision.

Since
1.35
Returns
callable

Definition at line 1018 of file ParserOptions.php.

References getOption().

◆ getDateFormat()

MediaWiki\Parser\ParserOptions::getDateFormat ( )

Date format index.

Returns
string

Definition at line 765 of file ParserOptions.php.

References getOption().

◆ getDisableContentConversion()

MediaWiki\Parser\ParserOptions::getDisableContentConversion ( )

Whether content conversion should be disabled.

Returns
bool

Definition at line 590 of file ParserOptions.php.

References getOption().

◆ getDisableTitleConversion()

MediaWiki\Parser\ParserOptions::getDisableTitleConversion ( )

Whether title conversion should be disabled.

Returns
bool

Definition at line 607 of file ParserOptions.php.

References getOption().

Referenced by MediaWiki\Parser\Parser\parse().

◆ getEnableImageWhitelist()

MediaWiki\Parser\ParserOptions::getEnableImageWhitelist ( )

Use the on-wiki external image whitelist?

Returns
bool

Definition at line 347 of file ParserOptions.php.

References getOption().

◆ getEnableLimitReport()

MediaWiki\Parser\ParserOptions::getEnableLimitReport ( )
Deprecated
since 1.38. This does nothing now, to control limit reporting please provide 'includeDebugInfo' option to ParserOutput::getText.

Enable limit report in an HTML comment on output

Returns
bool

Definition at line 532 of file ParserOptions.php.

◆ getExpensiveParserFunctionLimit()

MediaWiki\Parser\ParserOptions::getExpensiveParserFunctionLimit ( )

Maximum number of calls per parse to expensive parser functions.

Since
1.20
Returns
int

Definition at line 492 of file ParserOptions.php.

References getOption().

Referenced by MediaWiki\Parser\Parser\makeLimitReport(), and MediaWiki\Parser\Parser\parse().

◆ getExternalLinkTarget()

MediaWiki\Parser\ParserOptions::getExternalLinkTarget ( )

Target attribute for external links.

Returns
string|false
Access: internal
Only set by installer (T317647)

Definition at line 572 of file ParserOptions.php.

References getOption().

◆ getInterfaceMessage()

MediaWiki\Parser\ParserOptions::getInterfaceMessage ( )

Parsing an interface message in the user language?

Note: use isMessage() to determine if we are parsing a message in any language.

Returns
bool

Definition at line 375 of file ParserOptions.php.

References getOption().

◆ getInterwikiMagic()

MediaWiki\Parser\ParserOptions::getInterwikiMagic ( )

Whether to extract interlanguage links.

When true, interlanguage links will be returned by ParserOutput::getLanguageLinks() instead of generating link HTML.

Returns
bool

Definition at line 311 of file ParserOptions.php.

References getOption().

◆ getIsPreview()

MediaWiki\Parser\ParserOptions::getIsPreview ( )

Parsing the page for a "preview" operation?

Returns
bool

Definition at line 653 of file ParserOptions.php.

References getOption().

Referenced by MediaWiki\Parser\ParserOutput\setFromParserOptions().

◆ getIsPrintable()

MediaWiki\Parser\ParserOptions::getIsPrintable ( )
Deprecated
since 1.47 No longer needed per T259141
Returns
bool

Definition at line 693 of file ParserOptions.php.

References wfDeprecated().

◆ getIsSectionPreview()

MediaWiki\Parser\ParserOptions::getIsSectionPreview ( )

Parsing the page for a "preview" operation on a single section?

Returns
bool

Definition at line 673 of file ParserOptions.php.

References getOption().

◆ getLazyOptions()

MediaWiki\Parser\ParserOptions::getLazyOptions ( )
static

Get lazy-loaded options.

This array should be initialised by the constructor. The return type hint is used as an assertion to ensure this has happened and to coerce the type for static analysis.

Access: internal
Public for testing only
Returns
array

Definition at line 245 of file ParserOptions.php.

References if.

◆ getMagicISBNLinks()

MediaWiki\Parser\ParserOptions::getMagicISBNLinks ( )

Are magic ISBN links enabled?

Since
1.28
Returns
bool

Definition at line 843 of file ParserOptions.php.

References getOption().

◆ getMagicPMIDLinks()

MediaWiki\Parser\ParserOptions::getMagicPMIDLinks ( )

Are magic PMID links enabled?

Since
1.28
Returns
bool

Definition at line 852 of file ParserOptions.php.

References getOption().

◆ getMagicRFCLinks()

MediaWiki\Parser\ParserOptions::getMagicRFCLinks ( )

Are magic RFC links enabled?

Since
1.28
Returns
bool

Definition at line 861 of file ParserOptions.php.

References getOption().

◆ getMaxIncludeSize()

MediaWiki\Parser\ParserOptions::getMaxIncludeSize ( )

Maximum size of template expansions, in bytes.

Returns
int

Definition at line 430 of file ParserOptions.php.

References getOption().

Referenced by MediaWiki\Parser\Parser\makeLimitReport().

◆ getMaxPPExpandDepth()

MediaWiki\Parser\ParserOptions::getMaxPPExpandDepth ( )

Maximum recursion depth in PPFrame::expand().

Returns
int

Definition at line 464 of file ParserOptions.php.

References getOption().

Referenced by MediaWiki\Parser\Parser\makeLimitReport().

◆ getMaxPPNodeCount()

MediaWiki\Parser\ParserOptions::getMaxPPNodeCount ( )

Maximum number of nodes touched by PPFrame::expand().

Returns
int

Definition at line 447 of file ParserOptions.php.

References getOption().

Referenced by MediaWiki\Parser\Parser\makeLimitReport().

◆ getMaxTemplateDepth()

MediaWiki\Parser\ParserOptions::getMaxTemplateDepth ( )

Maximum recursion depth for templates within templates.

Returns
int
Access: internal
Only used by Parser (T318826)

Definition at line 473 of file ParserOptions.php.

References getOption().

◆ getOption()

◆ getPostproc()

MediaWiki\Parser\ParserOptions::getPostproc ( )

Returns usage of postprocessing (and splits the cache accordingly).

Since
1.46
Stability: unstable
See also
shouldIncludePostproc for a non-cache-splitting alternative

Definition at line 1901 of file ParserOptions.php.

References getOption(), and return.

◆ getPreSaveTransform()

MediaWiki\Parser\ParserOptions::getPreSaveTransform ( )

Transform wiki markup when saving the page?

Returns
bool

Definition at line 709 of file ParserOptions.php.

References getOption().

◆ getRedirectTarget()

MediaWiki\Parser\ParserOptions::getRedirectTarget ( )

Get the previously-set redirect target.

Since
1.24
Returns
Title|null

Definition at line 1165 of file ParserOptions.php.

◆ getRemoveComments()

MediaWiki\Parser\ParserOptions::getRemoveComments ( )

Remove HTML comments.

Warning
Only applies to preprocess operations
Returns
bool

Definition at line 511 of file ParserOptions.php.

References getOption().

◆ getRenderReason()

MediaWiki\Parser\ParserOptions::getRenderReason ( )

Returns reason for rendering the content.

This human-readable, intended for logging and debugging only. Expected values include "edit", "view", "purge", "LinksUpdate", etc.

Definition at line 1883 of file ParserOptions.php.

References return.

Referenced by MediaWiki\Parser\RevisionOutputCache\save().

◆ getSpeculativePageId()

MediaWiki\Parser\ParserOptions::getSpeculativePageId ( )

A guess for {{PAGEID}}, calculated using the callback provided via setSpeculativeRevPageCallback().

For consistency, the value will be calculated upon the first call of this method, and re-used for subsequent calls.

If no callback was defined via setSpeculativePageIdCallback(), this method will return false.

Since
1.34
Returns
int|false

Definition at line 1075 of file ParserOptions.php.

References getOption().

◆ getSpeculativeRevId()

MediaWiki\Parser\ParserOptions::getSpeculativeRevId ( )

A guess for {{REVISIONID}}, calculated using the callback provided via setSpeculativeRevIdCallback().

For consistency, the value will be calculated upon the first call of this method, and re-used for subsequent calls.

If no callback was defined via setSpeculativeRevIdCallback(), this method will return false.

Since
1.32
Returns
int|false

Definition at line 1061 of file ParserOptions.php.

References getOption().

◆ getSuppressSectionEditLinks()

MediaWiki\Parser\ParserOptions::getSuppressSectionEditLinks ( )

Should section edit links be suppressed?

Used when parsing wikitext which will be presented in a non-interactive context: previews, UX text, etc.

Since
1.42
Returns
bool

Definition at line 900 of file ParserOptions.php.

References getOption().

◆ getSuppressTOC()

MediaWiki\Parser\ParserOptions::getSuppressTOC ( )

Should the table of contents be suppressed?

Used when parsing "code" pages (like JavaScript) as wikitext for backlink support and categories, but where we don't want other metadata generated (like the table of contents).

See also
T307691
Since
1.39
Returns
bool

Definition at line 874 of file ParserOptions.php.

References getOption().

◆ getTargetLanguage()

MediaWiki\Parser\ParserOptions::getTargetLanguage ( )

Target language for the parse.

Returns
Language|null

Definition at line 413 of file ParserOptions.php.

References getOption().

◆ getTemplateCallback()

MediaWiki\Parser\ParserOptions::getTemplateCallback ( )

Callback to fetch a template.

See also
Parser::defaultFetchTemplate
Returns
callable(ParsoidLinkTarget,Parser|false):array

Definition at line 1038 of file ParserOptions.php.

References getOption().

◆ getThumbSize()

MediaWiki\Parser\ParserOptions::getThumbSize ( )

Get thumbnail size.

Returns
int
Deprecated
since 1.47; thumbnail resizing is handled client-side (T417514)

Definition at line 627 of file ParserOptions.php.

References MediaWiki\MediaWikiServices\getInstance(), and wfDeprecated().

Referenced by setThumbSize().

◆ getTimestamp()

MediaWiki\Parser\ParserOptions::getTimestamp ( )

Timestamp used for {{CURRENTDAY}} etc.

Returns
string TS::MW timestamp

Definition at line 1133 of file ParserOptions.php.

References wfTimestampNow().

◆ getUseParsoid()

MediaWiki\Parser\ParserOptions::getUseParsoid ( )

Parsoid-format HTML output, or legacy wikitext parser HTML?

See also
T300191
Stability: unstable
Since
1.41
Returns
bool

Definition at line 729 of file ParserOptions.php.

References getOption(), and return.

Referenced by MediaWiki\Content\TextContentHandler\collectMetadata(), isSafeToCache(), and MediaWiki\Parser\ParserOutput\setFromParserOptions().

◆ getUserIdentity()

MediaWiki\Parser\ParserOptions::getUserIdentity ( )

Get the identity of the user for whom the parse is made.

Since
1.36
Returns
UserIdentity

Definition at line 1184 of file ParserOptions.php.

References return.

Referenced by optionsHash().

◆ getUserLang()

MediaWiki\Parser\ParserOptions::getUserLang ( )

Same as getUserLangObj() but returns a string instead.

Warning
Calling this causes the parser cache to be fragmented by user language! To avoid cache fragmentation, output should not depend on the user language. Use Parser::getTargetLanguage() instead!
See also
getUserLangObj()
Returns
string Language code
Since
1.17

Definition at line 821 of file ParserOptions.php.

References getUserLangObj().

◆ getUserLangObj()

MediaWiki\Parser\ParserOptions::getUserLangObj ( )

Get the user language used by the parser for this page and split the parser cache.

Warning
Calling this causes the parser cache to be fragmented by user language! To avoid cache fragmentation, output should not depend on the user language. Use Parser::getTargetLanguage() instead!
Note
This function will trigger a cache fragmentation by recording the 'userlang' option, see optionUsed(). This is done to avoid cache pollution when the page is rendered based on the language of the user.
When saving, this will return the default language instead of the user's. {{int: }} uses this which used to produce inconsistent link tables (T16404).
Returns
Language
Since
1.19

Definition at line 805 of file ParserOptions.php.

References getOption().

Referenced by getUserLang().

◆ getVariant()

MediaWiki\Parser\ParserOptions::getVariant ( )

Returns the target language variant, or null if no language conversion is to be performed.

This is a postprocessing option, and has an effect on Parsoid parses only. null means LanguageConverter should be bypassed.

Since
1.46

Definition at line 953 of file ParserOptions.php.

References getOption(), and return.

◆ getWrapOutputClass()

MediaWiki\Parser\ParserOptions::getWrapOutputClass ( )

Class to use to wrap output from Parser::parse().

Since
1.30
Returns
string|false

Definition at line 992 of file ParserOptions.php.

References getOption().

Referenced by MediaWiki\Parser\ParserOutput\setFromParserOptions().

◆ isMessage()

MediaWiki\Parser\ParserOptions::isMessage ( )

Parsing a message?

Since
1.45
Returns
bool

Definition at line 394 of file ParserOptions.php.

References getOption().

Referenced by MediaWiki\Parser\Parser\makeLimitReport(), and MediaWiki\Parser\ParserOutput\setFromParserOptions().

◆ isSafeToCache()

MediaWiki\Parser\ParserOptions::isSafeToCache ( ?array $usedOptions = null)

Test whether the set of provided options are safe to cache.

A set of options is safe to cache if it's composed of the following:

  • options that are in the set of cache varying options (which split the cache)
  • pseudo-options that are, in fact, callbacks (which are ignored for the cacheability computation)
  • options that are neither, but whose value matches the default value defined for the option
    Parameters
    string[] | null$usedOptionsthe list of options to check; typically the ones that are actually used in the parse. Defaults to all options.
    Returns
    bool
    Since
    1.30

Definition at line 1738 of file ParserOptions.php.

References MediaWiki\MediaWikiServices\getInstance(), getUseParsoid(), MediaWiki\MainConfigNames\ParserOptionsLogUnsafeSampleRate, MediaWiki\MainConfigNames\UsePostprocCacheLegacy, and MediaWiki\MainConfigNames\UsePostprocCacheParsoid.

Referenced by MediaWiki\Parser\RevisionOutputCache\save().

◆ matches()

MediaWiki\Parser\ParserOptions::matches ( ParserOptions $other)

Check if these options match that of another options set.

This ignores report limit settings that only affect HTML comments

Parameters
ParserOptions$other
Returns
bool
Since
1.25

Definition at line 1507 of file ParserOptions.php.

◆ matchesForCacheKey()

MediaWiki\Parser\ParserOptions::matchesForCacheKey ( ParserOptions $other)
Parameters
ParserOptions$other
Returns
bool Whether the cache key relevant options match those of $other
Since
1.33

Definition at line 1552 of file ParserOptions.php.

◆ newCanonical()

MediaWiki\Parser\ParserOptions::newCanonical ( $context,
$userLang = null )
static

Creates a "canonical" ParserOptions object.

For historical reasons, certain options may have default values that are different from the canonical values used for caching; this is done to avoid expiring the entirety of an existing ParserCache's contents in production when a default changes. See the discussion in ::getDefaults() for more details.

Since
1.30
1.32 Added string and IContextSource as options for the first parameter
1.36 UserIdentity is also allowed
Deprecated
since 1.38. Use ::newFromContext, ::newFromAnon or ::newFromUserAndLang instead. Canonical ParserOptions are now exactly the same as non-canonical.
Parameters
IContextSource | string | UserIdentity$context
  • If an IContextSource, the options are initialized based on the source's UserIdentity and Language.
  • If the string 'canonical', the options are initialized with an anonymous user and the content language.
  • If a UserIdentity, the options are initialized for that UserIdentity 'userlang' is taken from the $userLang parameter, defaulting to $wgLang if that is null.
Language | StubObject | null$userLang(see above)
Returns
ParserOptions

Definition at line 1284 of file ParserOptions.php.

◆ newFromAnon()

MediaWiki\Parser\ParserOptions::newFromAnon ( )
static

Get a ParserOptions object for an anonymous user.

Todo
Move to ParserFactory or create a ParserOptionsFactory
Since
1.27
Returns
ParserOptions

Definition at line 1205 of file ParserOptions.php.

References MediaWiki\MediaWikiServices\getInstance().

Referenced by FormatInstallDoc\execute(), PurgeParserCache\execute(), and CLIParser\render().

◆ newFromContext()

MediaWiki\Parser\ParserOptions::newFromContext ( IContextSource $context)
static

Get a ParserOptions object from a IContextSource object.

Since
1.19
Parameters
IContextSource$context
Returns
ParserOptions

Definition at line 1241 of file ParserOptions.php.

References MediaWiki\MediaWikiServices\getInstance(), MediaWiki\Context\IContextSource\getLanguage(), MediaWiki\Context\IContextSource\getRequest(), and MediaWiki\Context\IContextSource\getUser().

Referenced by MediaWiki\Actions\RawAction\getRawText().

◆ newFromUser()

MediaWiki\Parser\ParserOptions::newFromUser ( $user)
static

Get a ParserOptions object from a given user.

Language will be taken from main request context.

Since
1.13
Parameters
UserIdentity$user
Returns
ParserOptions

Definition at line 1218 of file ParserOptions.php.

Referenced by CompareParsers\checkOptions(), MediaWiki\Parser\Parser\cleanSig(), MediaWiki\Parser\Parser\getFlatSectionInfo(), and DumpRenderer\handleRevision().

◆ newFromUserAndLang()

MediaWiki\Parser\ParserOptions::newFromUserAndLang ( UserIdentity $user,
Language $lang )
static

Get a ParserOptions object from a given user and language.

Since
1.19
Parameters
UserIdentity$user
Language$lang
Returns
ParserOptions

Definition at line 1230 of file ParserOptions.php.

◆ optionsHash()

MediaWiki\Parser\ParserOptions::optionsHash ( $forOptions,
$title = null )

Generate a hash string with the values set on these ParserOptions for the keys given in the array.

This will be used as part of the hash key for the parser cache, so users sharing the options with vary for the same page share the same cached data safely.

Since
1.17
Parameters
string[]$forOptions
Title | null$titleUsed to get the content language of the page (since r97636)
Returns
string Page rendering hash

Definition at line 1662 of file ParserOptions.php.

References MediaWiki\MediaWikiServices\getInstance(), getUserIdentity(), and MediaWiki\MainConfigNames\RenderHashAppend.

Referenced by MediaWiki\Parser\ParserObserver\notifyParse().

◆ registerWatcher()

MediaWiki\Parser\ParserOptions::registerWatcher ( $callback)

Registers a callback for tracking which ParserOptions which are used.

Since
1.16
Parameters
callable | null$callbackNew callback
Returns
callable|null The old callback, if any

Definition at line 1575 of file ParserOptions.php.

Referenced by MediaWiki\OutputTransform\OutputTransformPipeline\run().

◆ setAllowSpecialInclusion()

MediaWiki\Parser\ParserOptions::setAllowSpecialInclusion ( $x)

Allow inclusion of special pages?

Parameters
bool | null$xNew value (null is no change)
Returns
bool Old value

Definition at line 364 of file ParserOptions.php.

References setOptionLegacy().

◆ setAllowUnsafeRawHtml()

MediaWiki\Parser\ParserOptions::setAllowUnsafeRawHtml ( $x)

If the wiki is configured to allow raw html ($wgRawHtml = true) is it allowed in the specific case of parsing this page.

See also
self::getAllowUnsafeRawHtml()
Since
1.29
Parameters
bool | null$xValue to set or null to get current value
Returns
bool Current value for allowUnsafeRawHtml

Definition at line 983 of file ParserOptions.php.

References setOptionLegacy().

◆ setCleanSignatures()

MediaWiki\Parser\ParserOptions::setCleanSignatures ( $x)

Clean up signature texts?

See also
Parser::cleanSig
Parameters
bool | null$xNew value (null is no change)
Returns
bool Old value

Definition at line 563 of file ParserOptions.php.

References setOptionLegacy().

◆ setCollapsibleSections()

MediaWiki\Parser\ParserOptions::setCollapsibleSections ( )

Wrap section contents in a.

to allow client-side code to collapse them.
Since
1.42

Definition at line 928 of file ParserOptions.php.

References setOption().

◆ setCurrentRevisionRecordCallback()

MediaWiki\Parser\ParserOptions::setCurrentRevisionRecordCallback ( $x)

Callback to fetch the current revision.

Access: internal
Since
1.35
Parameters
callable | null$xNew value
Returns
callable Old value

Definition at line 1029 of file ParserOptions.php.

References setOption().

Referenced by setupFakeRevision().

◆ setDateFormat()

MediaWiki\Parser\ParserOptions::setDateFormat ( $x)

Date format index.

Parameters
string | null$xNew value (null is no change)
Returns
string Old value

Definition at line 784 of file ParserOptions.php.

References setOptionLegacy().

◆ setExpensiveParserFunctionLimit()

MediaWiki\Parser\ParserOptions::setExpensiveParserFunctionLimit ( $x)

Maximum number of calls per parse to expensive parser functions.

Since
1.20
Parameters
int | null$xNew value (null is no change)
Returns
int Old value

Definition at line 502 of file ParserOptions.php.

References setOptionLegacy().

◆ setExternalLinkTarget()

MediaWiki\Parser\ParserOptions::setExternalLinkTarget ( $x)

Target attribute for external links.

Parameters
string | false | null$xNew value (null is no change)
Returns
string Old value
Access: internal
Only used by installer (T317647)

Definition at line 582 of file ParserOptions.php.

References setOptionLegacy().

◆ setInterfaceMessage()

MediaWiki\Parser\ParserOptions::setInterfaceMessage ( $x)

Parsing an interface message in the user language?

Parameters
bool | null$xNew value (null is no change)
Returns
bool Old value

Definition at line 384 of file ParserOptions.php.

References setOptionLegacy().

◆ setInterwikiMagic()

MediaWiki\Parser\ParserOptions::setInterwikiMagic ( $x)

Specify whether to extract interlanguage links.

Parameters
bool | null$xNew value (null is no change)
Returns
bool Old value

Definition at line 320 of file ParserOptions.php.

References setOptionLegacy().

◆ setIsMessage()

MediaWiki\Parser\ParserOptions::setIsMessage ( $x)

Set whether we are parsing a message.

Since
1.45
Parameters
bool$x
Returns
bool

Definition at line 405 of file ParserOptions.php.

References setOption().

Referenced by MediaWiki\Output\OutputPage\wrapWikiMsg().

◆ setIsPreview()

MediaWiki\Parser\ParserOptions::setIsPreview ( $x)

Parsing the page for a "preview" operation?

Parameters
bool | null$xNew value (null is no change)
Returns
bool Old value

Definition at line 662 of file ParserOptions.php.

References setOption(), and setOptionLegacy().

◆ setIsPrintable()

MediaWiki\Parser\ParserOptions::setIsPrintable ( $x)
Deprecated
since 1.47 No longer needed per T259141

Definition at line 701 of file ParserOptions.php.

References wfDeprecated().

◆ setIsSectionPreview()

MediaWiki\Parser\ParserOptions::setIsSectionPreview ( $x)

Parsing the page for a "preview" operation on a single section?

Parameters
bool | null$xNew value (null is no change)
Returns
bool Old value

Definition at line 682 of file ParserOptions.php.

References setOption(), and setOptionLegacy().

◆ setMaxIncludeSize()

MediaWiki\Parser\ParserOptions::setMaxIncludeSize ( $x)

Maximum size of template expansions, in bytes.

Parameters
int | null$xNew value (null is no change)
Returns
int Old value

Definition at line 439 of file ParserOptions.php.

References setOptionLegacy().

◆ setMaxPPNodeCount()

MediaWiki\Parser\ParserOptions::setMaxPPNodeCount ( $x)

Maximum number of nodes touched by PPFrame::expand().

Parameters
int | null$xNew value (null is no change)
Returns
int Old value

Definition at line 456 of file ParserOptions.php.

References setOptionLegacy().

◆ setMaxTemplateDepth()

MediaWiki\Parser\ParserOptions::setMaxTemplateDepth ( $x)

Maximum recursion depth for templates within templates.

Parameters
int | null$xNew value (null is no change)
Returns
int Old value
Access: internal
Only used by ParserTestRunner (T318826)

Definition at line 483 of file ParserOptions.php.

References setOptionLegacy().

◆ setOption()

MediaWiki\Parser\ParserOptions::setOption ( $name,
$value )

Set an option, generically.

Since
1.30
Parameters
string$nameOption name
mixed$valueNew value. Passing null will set null, unlike many of the existing accessors which ignore null for historical reasons.
Returns
mixed Old value

Definition at line 279 of file ParserOptions.php.

Referenced by enablePostproc(), setCollapsibleSections(), setCurrentRevisionRecordCallback(), setIsMessage(), setIsPreview(), setIsSectionPreview(), setSpeculativePageIdCallback(), setSpeculativeRevIdCallback(), setSuppressSectionEditLinks(), setSuppressTOC(), setTargetLanguage(), setUseParsoid(), setVariant(), and setWrapOutputClass().

◆ setOptionLegacy()

MediaWiki\Parser\ParserOptions::setOptionLegacy ( $name,
$value )
protected

Legacy implementation.

Since
1.30 For implementing legacy setters only. Don't use this in new code.
Deprecated
since 1.30
Parameters
string$nameOption name
mixed$valueNew value. Passing null does not set the value.
Returns
mixed Old value

Definition at line 296 of file ParserOptions.php.

References wfSetVar().

Referenced by disableContentConversion(), disableTitleConversion(), setAllowSpecialInclusion(), setAllowUnsafeRawHtml(), setCleanSignatures(), setDateFormat(), setExpensiveParserFunctionLimit(), setExternalLinkTarget(), setInterfaceMessage(), setInterwikiMagic(), setIsPreview(), setIsSectionPreview(), setMaxIncludeSize(), setMaxPPNodeCount(), setMaxTemplateDepth(), setPreSaveTransform(), setRemoveComments(), setTemplateCallback(), and setUserLang().

◆ setPreSaveTransform()

MediaWiki\Parser\ParserOptions::setPreSaveTransform ( $x)

Transform wiki markup when saving the page?

Parameters
bool | null$xNew value (null is no change)
Returns
bool Old value

Definition at line 718 of file ParserOptions.php.

References setOptionLegacy().

◆ setRedirectTarget()

MediaWiki\Parser\ParserOptions::setRedirectTarget ( $title)

Note that setting or changing this does not make the page a redirect or change its target, it merely records the information for reference during the parse.

Since
1.24
Parameters
Title | null$title

Definition at line 1155 of file ParserOptions.php.

◆ setRemoveComments()

MediaWiki\Parser\ParserOptions::setRemoveComments ( $x)

Remove HTML comments.

Warning
Only applies to preprocess operations
Parameters
bool | null$xNew value (null is no change)
Returns
bool Old value

Definition at line 521 of file ParserOptions.php.

References setOptionLegacy().

◆ setRenderReason()

MediaWiki\Parser\ParserOptions::setRenderReason ( string $renderReason)

Sets reason for rendering the content.

This human-readable, intended for logging and debugging only. Expected values include "edit", "view", "purge", "LinksUpdate", etc.

Definition at line 1891 of file ParserOptions.php.

◆ setSpeculativePageIdCallback()

MediaWiki\Parser\ParserOptions::setSpeculativePageIdCallback ( $x)

Callback to generate a guess for {{PAGEID}}.

Parameters
callable | null$xNew value
Returns
callable|null Old value
Since
1.34

Definition at line 1124 of file ParserOptions.php.

References setOption().

◆ setSpeculativeRevIdCallback()

MediaWiki\Parser\ParserOptions::setSpeculativeRevIdCallback ( $x)

Callback to generate a guess for {{REVISIONID}}.

Parameters
callable | null$xNew value
Returns
callable|null Old value
Since
1.28

Definition at line 1113 of file ParserOptions.php.

References setOption().

◆ setSuppressSectionEditLinks()

MediaWiki\Parser\ParserOptions::setSuppressSectionEditLinks ( )

Suppress section edit links in the output.

Used when parsing wikitext which will be presented in a non-interactive context: previews, UX text, etc.

Since
1.42

Definition at line 910 of file ParserOptions.php.

References setOption().

◆ setSuppressTOC()

MediaWiki\Parser\ParserOptions::setSuppressTOC ( )

Suppress generation of the table of contents.

Used when parsing "code" pages (like JavaScript) as wikitext for backlink support and categories, but where we don't want other metadata generated (like the table of contents).

See also
T307691
Since
1.39
Deprecated
since 1.42; just clear the metadata in the final parser output

Definition at line 888 of file ParserOptions.php.

References setOption(), and wfDeprecated().

◆ setTargetLanguage()

MediaWiki\Parser\ParserOptions::setTargetLanguage ( $x)

Target language for the parse.

Parameters
Language | null$xNew value
Returns
Language|null Old value

Definition at line 422 of file ParserOptions.php.

References setOption().

◆ setTemplateCallback()

MediaWiki\Parser\ParserOptions::setTemplateCallback ( $x)

Set the callback to fetch a template.

Parameters
callable(ParsoidLinkTarget,Parser|false):array|null$x New value (null is no change)
Returns
callable(ParsoidLinkTarget,Parser|false):array Old value

Definition at line 1047 of file ParserOptions.php.

References setOptionLegacy().

◆ setThumbSize()

MediaWiki\Parser\ParserOptions::setThumbSize ( $x)

Thumb size preferred by the user.

This is ignored by the parser.

Parameters
int | null$xNew value (null is no change)
Returns
int Old value
Deprecated
since 1.47; thumbnail resizing is handled client-side (T417514)

Definition at line 644 of file ParserOptions.php.

References getThumbSize(), and wfDeprecated().

◆ setTimestamp()

MediaWiki\Parser\ParserOptions::setTimestamp ( $x)

Timestamp used for {{CURRENTDAY}} etc.

Parameters
string | null$xNew value (null is no change)
Returns
string Old value

Definition at line 1143 of file ParserOptions.php.

References wfSetVar().

◆ setupFakeRevision()

MediaWiki\Parser\ParserOptions::setupFakeRevision ( $page,
$content,
$user,
$currentRevId = 0 )

Sets a hook to force that a page exists, and sets a current revision callback to return a revision with custom content when the current revision of the page is requested.

Parameters
PageIdentity$page
Content$content
UserIdentity$userThe user that the fake revision is attributed to
int$currentRevId
Access: internal
since 1.44, this method is no longer considered safe to call by extensions. It may be removed or changed in a backwards incompatible way in 1.45 or later.
Since
1.25

Definition at line 1817 of file ParserOptions.php.

References setCurrentRevisionRecordCallback().

◆ setUseParsoid()

MediaWiki\Parser\ParserOptions::setUseParsoid ( bool $value = true)

Request Parsoid-format HTML output.

See also
T300191
Stability: unstable
Since
1.41

Definition at line 739 of file ParserOptions.php.

References setOption().

Referenced by setUseParsoidForLinksUpdate().

◆ setUseParsoidForLinksUpdate()

MediaWiki\Parser\ParserOptions::setUseParsoidForLinksUpdate ( )

Select the parser configured by $wgUseParsoidLinksUpdate, for a parse whose output updates the links tables and other derived page metadata.

When that setting is null, the useParsoid option is left unchanged.

See also
MainConfigSchema::UseParsoidLinksUpdate
Access: internal
Temporary, for use while $wgUseParsoidLinksUpdate exists
Since
1.47

Definition at line 752 of file ParserOptions.php.

References setUseParsoid().

◆ setUserLang()

MediaWiki\Parser\ParserOptions::setUserLang ( $x)

Set the user language used by the parser for this page and split the parser cache.

Parameters
string | Language$xNew value
Returns
Language Old value

Definition at line 830 of file ParserOptions.php.

References MediaWiki\MediaWikiServices\getInstance(), and setOptionLegacy().

◆ setVariant()

MediaWiki\Parser\ParserOptions::setVariant ( ?Language $variantLanguage)

Set the target language variant.

This is a postprocessing option, and has an effect on Parsoid parses only. null means LanguageConverter should be bypassed, so -{...}- constructs will not be filled in at all. Setting the variant to the base language will ensure that -{...}- constructs will be processed, even though no text conversion will occur.

Since
1.46

Definition at line 942 of file ParserOptions.php.

References setOption().

◆ setWrapOutputClass()

MediaWiki\Parser\ParserOptions::setWrapOutputClass ( $className)

CSS class to use to wrap output from Parser::parse().

Since
1.30
Parameters
string$classNameClass name to use for wrapping. Passing false to indicate "no wrapping" was deprecated in MediaWiki 1.31.
Returns
string|false Current value

Definition at line 1003 of file ParserOptions.php.

References setOption(), and wfDeprecated().

Member Data Documentation

◆ $postprocOptions

array list<string> MediaWiki\Parser\ParserOptions::$postprocOptions
static
Initial value:
= [
'skin',
'allowTOC',
'injectTOC',
'includeDebugInfo',
'collapsibleSections',
'enableSectionEditLinks',
'wrapperDivClass',
'deduplicateStyles',
'unwrap',
'absoluteURLs',
'variant',
]

List of "postprocessing options", excluded from most ParserOption operations by default.

Access: internal

Definition at line 126 of file ParserOptions.php.


The documentation for this class was generated from the following file: