MediaWiki  master
ParserOptions Class Reference

Set options of the Parser. More...

Collaboration diagram for ParserOptions:

Public Member Functions

 __construct (UserIdentity $user, $lang=null)
 
 addExtraKey ( $key)
 Extra key that should be present in the parser cache key. More...
 
 disableContentConversion ( $x=true)
 Whether content conversion should be disabled. More...
 
 disableTitleConversion ( $x=true)
 Whether title conversion should be disabled. More...
 
 enableLimitReport ( $x=true)
 
 getAllowExternalImages ()
 Allow all external images inline? More...
 
 getAllowExternalImagesFrom ()
 External images to allow. More...
 
 getAllowSpecialInclusion ()
 Allow inclusion of special pages? More...
 
 getAllowUnsafeRawHtml ()
 If the wiki is configured to allow raw html ($wgRawHtml = true) is it allowed in the specific case of parsing this page. More...
 
 getCleanSignatures ()
 Clean up signature texts? More...
 
 getCurrentRevisionRecordCallback ()
 Callback for current revision fetching; first argument to call_user_func(). More...
 
 getDateFormat ()
 Date format index. More...
 
 getDisableContentConversion ()
 Whether content conversion should be disabled. More...
 
 getDisableTitleConversion ()
 Whether title conversion should be disabled. More...
 
 getEnableImageWhitelist ()
 Use the on-wiki external image whitelist? More...
 
 getEnableLimitReport ()
 
 getExpensiveParserFunctionLimit ()
 Maximum number of calls per parse to expensive parser functions. More...
 
 getExternalLinkTarget ()
 Target attribute for external links. More...
 
 getInterfaceMessage ()
 Parsing an interface message? More...
 
 getInterwikiMagic ()
 Whether to extract interlanguage links. More...
 
 getIsPreview ()
 Parsing the page for a "preview" operation? More...
 
 getIsPrintable ()
 Parsing the printable version of the page? More...
 
 getIsSectionPreview ()
 Parsing the page for a "preview" operation on a single section? More...
 
 getMagicISBNLinks ()
 Are magic ISBN links enabled? More...
 
 getMagicPMIDLinks ()
 Are magic PMID links enabled? More...
 
 getMagicRFCLinks ()
 Are magic RFC links enabled? More...
 
 getMaxIncludeSize ()
 Maximum size of template expansions, in bytes. More...
 
 getMaxPPExpandDepth ()
 Maximum recursion depth in PPFrame::expand() More...
 
 getMaxPPNodeCount ()
 Maximum number of nodes touched by PPFrame::expand() More...
 
 getMaxTemplateDepth ()
 Maximum recursion depth for templates within templates. More...
 
 getOption ( $name)
 Fetch an option and track that is was accessed. More...
 
 getPreSaveTransform ()
 Transform wiki markup when saving the page? More...
 
 getRedirectTarget ()
 Get the previously-set redirect target. More...
 
 getRemoveComments ()
 Remove HTML comments. More...
 
 getSpeculativePageId ()
 A guess for {{PAGEID}}, calculated using the callback provided via setSpeculativeRevPageCallback(). More...
 
 getSpeculativeRevId ()
 A guess for {{REVISIONID}}, calculated using the callback provided via setSpeculativeRevIdCallback(). More...
 
 getStubThreshold ()
 Thumb size preferred by the user. More...
 
 getTargetLanguage ()
 Target language for the parse. More...
 
 getTemplateCallback ()
 Callback for template fetching; first argument to call_user_func(). More...
 
 getThumbSize ()
 Thumb size preferred by the user. More...
 
 getTimestamp ()
 Timestamp used for {{CURRENTDAY}} etc. More...
 
 getUserIdentity ()
 Get the identity of the user for whom the parse is made. More...
 
 getUserLang ()
 Same as getUserLangObj() but returns a string instead. More...
 
 getUserLangObj ()
 Get the user language used by the parser for this page and split the parser cache. More...
 
 getWrapOutputClass ()
 Class to use to wrap output from Parser::parse() More...
 
 isSafeToCache (array $usedOptions=null)
 Test whether these options are safe to cache. More...
 
 matches (ParserOptions $other)
 Check if these options match that of another options set. More...
 
 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. More...
 
 registerWatcher ( $callback)
 Registers a callback for tracking which ParserOptions which are used. More...
 
 setAllowExternalImages ( $x)
 Allow all external images inline? More...
 
 setAllowExternalImagesFrom ( $x)
 External images to allow. More...
 
 setAllowSpecialInclusion ( $x)
 Allow inclusion of special pages? More...
 
 setAllowUnsafeRawHtml ( $x)
 If the wiki is configured to allow raw html ($wgRawHtml = true) is it allowed in the specific case of parsing this page. More...
 
 setCleanSignatures ( $x)
 Clean up signature texts? More...
 
 setCurrentRevisionRecordCallback ( $x)
 Callback for current revision fetching; first argument to call_user_func(). More...
 
 setDateFormat ( $x)
 Date format index. More...
 
 setEnableImageWhitelist ( $x)
 Use the on-wiki external image whitelist? More...
 
 setExpensiveParserFunctionLimit ( $x)
 Maximum number of calls per parse to expensive parser functions. More...
 
 setExternalLinkTarget ( $x)
 Target attribute for external links. More...
 
 setInterfaceMessage ( $x)
 Parsing an interface message? More...
 
 setInterwikiMagic ( $x)
 Specify whether to extract interlanguage links. More...
 
 setIsPreview ( $x)
 Parsing the page for a "preview" operation? More...
 
 setIsPrintable ( $x)
 Parsing the printable version of the page? More...
 
 setIsSectionPreview ( $x)
 Parsing the page for a "preview" operation on a single section? More...
 
 setMaxIncludeSize ( $x)
 Maximum size of template expansions, in bytes. More...
 
 setMaxPPNodeCount ( $x)
 Maximum number of nodes touched by PPFrame::expand() More...
 
 setMaxTemplateDepth ( $x)
 Maximum recursion depth for templates within templates. More...
 
 setOption ( $name, $value)
 Set an option, generically. More...
 
 setPreSaveTransform ( $x)
 Transform wiki markup when saving the page? More...
 
 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. More...
 
 setRemoveComments ( $x)
 Remove HTML comments. More...
 
 setSpeculativePageIdCallback ( $x)
 Callback to generate a guess for {{PAGEID}}. More...
 
 setSpeculativeRevIdCallback ( $x)
 Callback to generate a guess for {{REVISIONID}}. More...
 
 setStubThreshold ( $x)
 Thumb size preferred by the user. More...
 
 setTargetLanguage ( $x)
 Target language for the parse. More...
 
 setTemplateCallback ( $x)
 Callback for template fetching; first argument to call_user_func(). More...
 
 setThumbSize ( $x)
 Thumb size preferred by the user. More...
 
 setTimestamp ( $x)
 Timestamp used for {{CURRENTDAY}} etc. More...
 
 setupFakeRevision ( $title, $content, $user)
 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. More...
 
 setUserLang ( $x)
 Set the user language used by the parser for this page and split the parser cache. More...
 
 setWrapOutputClass ( $className)
 CSS class to use to wrap output from Parser::parse() More...
 

Static Public Member Functions

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

Protected Member Functions

 setOptionLegacy ( $name, $value)
 Legacy implementation. More...
 

Private Member Functions

 initialiseFromUser (UserIdentity $user, Language $lang)
 Get user options. More...
 
 lazyLoadOption ( $name)
 
 nullifyLazyOption (array $options)
 Resets lazy loaded options to null in the provided $options array. More...
 
 optionToString ( $value)
 Convert an option to a string value. More...
 
 optionUsed ( $optionName)
 Record that an option was internally accessed. More...
 

Static Private Member Functions

static getCacheVaryingOptionsHash ()
 Get cache varying options, with the name of the option in the key, and a boolean in the value which indicates whether the cache is indeed varied. More...
 
static getDefaults ()
 Get default option values. More...
 
static initDateFormat (ParserOptions $popt)
 Lazy initializer for dateFormat. More...
 
static initSpeculativePageId (ParserOptions $popt)
 Callback registered with ParserOptions::$lazyOptions, triggered by getSpeculativePageId(). More...
 
static initSpeculativeRevId (ParserOptions $popt)
 Callback registered with ParserOptions::$lazyOptions, triggered by getSpeculativeRevId(). More...
 

Private Attributes

 $mExtraKey = ''
 Appended to the options hash. More...
 
string null $mTimestamp
 Timestamp used for {{CURRENTDAY}} etc. More...
 
UserIdentity $mUser
 Stored user object. More...
 
callable null $onAccessCallback = null
 Function to be called when an option is accessed. More...
 
array $options
 Current values for all options that are relevant for caching. More...
 
Title null $redirectTarget = null
 If the page being parsed is a redirect, this should hold the redirect target. More...
 

Static Private Attributes

static array null $cacheVaryingOptionsHash = null
 Specify options that are included in the cache key. More...
 
static array $callbacks
 Specify pseudo-options that are actually callbacks. More...
 
static array null $defaults = null
 Default values for all options that are relevant for caching. More...
 
static array $initialCacheVaryingOptionsHash
 Initial inCacheKey options (before hook) More...
 
static callable[] $initialLazyOptions
 Initial lazy-loaded options (before hook) More...
 
static callable[] null $lazyOptions = null
 Lazy-loaded options. More...
 

Detailed Description

Set options of the Parser.

How to add an option in core:

  1. Add it to one of the arrays in ParserOptions::setDefaults()
  2. If necessary, add an entry to ParserOptions::$inCacheKey
  3. Add a getter and setter in the section for that.

How to add an option in an extension:

  1. Use the 'ParserOptionsRegister' hook to register it.
  2. Where necessary, use $popt->getOption() and $popt->setOption() to access it.

Definition at line 45 of file ParserOptions.php.

Constructor & Destructor Documentation

◆ __construct()

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

Definition at line 1018 of file ParserOptions.php.

References $lang, $wgLang, initialiseFromUser(), and StubObject\unstub().

Member Function Documentation

◆ addExtraKey()

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 1001 of file ParserOptions.php.

◆ allCacheVaryingOptions()

static ParserOptions::allCacheVaryingOptions ( )
static

Return all option keys that vary the options hash.

Since
1.30
Returns
string[]

Definition at line 1313 of file ParserOptions.php.

Referenced by ParserCache\makeParserOutputKey(), Parser\RevisionOutputCache\makeParserOutputKey(), and optionsHash().

◆ clearStaticCache()

static ParserOptions::clearStaticCache ( )
static

Reset static caches.

Access: internal
For testing

Definition at line 1108 of file ParserOptions.php.

◆ disableContentConversion()

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 550 of file ParserOptions.php.

References setOptionLegacy().

◆ disableTitleConversion()

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 567 of file ParserOptions.php.

References setOptionLegacy().

◆ enableLimitReport()

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 497 of file ParserOptions.php.

◆ getAllowExternalImages()

ParserOptions::getAllowExternalImages ( )

Allow all external images inline?

Returns
bool

Definition at line 268 of file ParserOptions.php.

References getOption().

◆ getAllowExternalImagesFrom()

ParserOptions::getAllowExternalImagesFrom ( )

External images to allow.

When self::getAllowExternalImages() is false

Returns
string|string[] URLs to allow

Definition at line 291 of file ParserOptions.php.

References getOption().

◆ getAllowSpecialInclusion()

ParserOptions::getAllowSpecialInclusion ( )

Allow inclusion of special pages?

Returns
bool

Definition at line 334 of file ParserOptions.php.

References getOption().

◆ getAllowUnsafeRawHtml()

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 795 of file ParserOptions.php.

References getOption().

◆ getCacheVaryingOptionsHash()

static ParserOptions::getCacheVaryingOptionsHash ( )
staticprivate

Get cache varying options, with the name of the option in the key, and a boolean in the value which indicates whether the cache is indeed varied.

See also
self::allCacheVaryingOptions()
Returns
array

Definition at line 202 of file ParserOptions.php.

References $cacheVaryingOptionsHash, and getDefaults().

Referenced by isSafeToCache().

◆ getCleanSignatures()

ParserOptions::getCleanSignatures ( )

Clean up signature texts?

See also
Parser::cleanSig
Returns
bool

Definition at line 506 of file ParserOptions.php.

References getOption().

◆ getCurrentRevisionRecordCallback()

ParserOptions::getCurrentRevisionRecordCallback ( )

Callback for current revision fetching; first argument to call_user_func().

Access: internal
Since
1.35
Returns
callable

Definition at line 843 of file ParserOptions.php.

References getOption().

◆ getDateFormat()

ParserOptions::getDateFormat ( )

Date format index.

Returns
string

Definition at line 681 of file ParserOptions.php.

References getOption().

◆ getDefaults()

static ParserOptions::getDefaults ( )
staticprivate

Get default option values.

Warning
If you change the default for an existing option, all existing parser cache entries will be invalid. To avoid bugs, you'll need to handle that somehow (e.g. with the RejectParserCacheValue hook) because MediaWiki won't do it for you.
Returns
array

Definition at line 1125 of file ParserOptions.php.

References $initialCacheVaryingOptionsHash, $initialLazyOptions, $userOptionsLookup, $wgAllowExternalImages, $wgAllowExternalImagesFrom, $wgAllowSpecialInclusion, $wgCleanSignatures, $wgEnableImageWhitelist, $wgEnableMagicLinks, $wgExpensiveParserFunctionLimit, $wgExternalLinkTarget, $wgInterwikiMagic, $wgMaxArticleSize, $wgMaxPPExpandDepth, $wgMaxPPNodeCount, $wgMaxTemplateDepth, and Hooks\runner().

Referenced by getCacheVaryingOptionsHash(), getLazyOptions(), isSafeToCache(), and optionsHash().

◆ getDisableContentConversion()

ParserOptions::getDisableContentConversion ( )

Whether content conversion should be disabled.

Returns
bool

Definition at line 541 of file ParserOptions.php.

References getOption().

◆ getDisableTitleConversion()

ParserOptions::getDisableTitleConversion ( )

Whether title conversion should be disabled.

Returns
bool

Definition at line 558 of file ParserOptions.php.

References getOption().

Referenced by Parser\parse().

◆ getEnableImageWhitelist()

ParserOptions::getEnableImageWhitelist ( )

Use the on-wiki external image whitelist?

Returns
bool

Definition at line 314 of file ParserOptions.php.

References getOption().

◆ getEnableLimitReport()

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 485 of file ParserOptions.php.

◆ getExpensiveParserFunctionLimit()

ParserOptions::getExpensiveParserFunctionLimit ( )

Maximum number of calls per parse to expensive parser functions.

Since
1.20
Returns
int

Definition at line 445 of file ParserOptions.php.

References getOption().

◆ getExternalLinkTarget()

ParserOptions::getExternalLinkTarget ( )

Target attribute for external links.

Returns
string

Definition at line 524 of file ParserOptions.php.

References getOption().

◆ getInterfaceMessage()

ParserOptions::getInterfaceMessage ( )

Parsing an interface message?

Returns
bool

Definition at line 351 of file ParserOptions.php.

References getOption().

◆ getInterwikiMagic()

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 251 of file ParserOptions.php.

References getOption().

◆ getIsPreview()

ParserOptions::getIsPreview ( )

Parsing the page for a "preview" operation?

Returns
bool

Definition at line 613 of file ParserOptions.php.

References getOption().

◆ getIsPrintable()

ParserOptions::getIsPrintable ( )

Parsing the printable version of the page?

Returns
bool

Definition at line 647 of file ParserOptions.php.

References getOption().

◆ getIsSectionPreview()

ParserOptions::getIsSectionPreview ( )

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

Returns
bool

Definition at line 630 of file ParserOptions.php.

References getOption().

◆ getLazyOptions()

static 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 185 of file ParserOptions.php.

References $lazyOptions, and getDefaults().

Referenced by lazyLoadOption().

◆ getMagicISBNLinks()

ParserOptions::getMagicISBNLinks ( )

Are magic ISBN links enabled?

Since
1.28
Returns
bool

Definition at line 759 of file ParserOptions.php.

References getOption().

◆ getMagicPMIDLinks()

ParserOptions::getMagicPMIDLinks ( )

Are magic PMID links enabled?

Since
1.28
Returns
bool

Definition at line 768 of file ParserOptions.php.

References getOption().

◆ getMagicRFCLinks()

ParserOptions::getMagicRFCLinks ( )

Are magic RFC links enabled?

Since
1.28
Returns
bool

Definition at line 777 of file ParserOptions.php.

References getOption().

◆ getMaxIncludeSize()

ParserOptions::getMaxIncludeSize ( )

Maximum size of template expansions, in bytes.

Returns
int

Definition at line 385 of file ParserOptions.php.

References getOption().

◆ getMaxPPExpandDepth()

ParserOptions::getMaxPPExpandDepth ( )

Maximum recursion depth in PPFrame::expand()

Returns
int

Definition at line 419 of file ParserOptions.php.

References getOption().

◆ getMaxPPNodeCount()

ParserOptions::getMaxPPNodeCount ( )

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

Returns
int

Definition at line 402 of file ParserOptions.php.

References getOption().

◆ getMaxTemplateDepth()

ParserOptions::getMaxTemplateDepth ( )

Maximum recursion depth for templates within templates.

Returns
int

Definition at line 427 of file ParserOptions.php.

References getOption().

◆ getOption()

◆ getPreSaveTransform()

ParserOptions::getPreSaveTransform ( )

Transform wiki markup when saving the page?

Returns
bool

Definition at line 664 of file ParserOptions.php.

References getOption().

Referenced by Parser\preSaveTransform().

◆ getRedirectTarget()

ParserOptions::getRedirectTarget ( )

Get the previously-set redirect target.

Since
1.24
Returns
Title|null

Definition at line 991 of file ParserOptions.php.

References $redirectTarget.

◆ getRemoveComments()

ParserOptions::getRemoveComments ( )

Remove HTML comments.

Warning
Only applies to preprocess operations
Returns
bool

Definition at line 464 of file ParserOptions.php.

References getOption().

◆ getSpeculativePageId()

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 899 of file ParserOptions.php.

References getOption().

◆ getSpeculativeRevId()

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 885 of file ParserOptions.php.

References getOption().

◆ getStubThreshold()

ParserOptions::getStubThreshold ( )

Thumb size preferred by the user.

Deprecated:
since 1.37. Stub threshold feature has been removed. See T284917.
Returns
int

Definition at line 593 of file ParserOptions.php.

References wfDeprecated().

◆ getTargetLanguage()

ParserOptions::getTargetLanguage ( )

Target language for the parse.

Returns
Language|null

Definition at line 368 of file ParserOptions.php.

References getOption().

◆ getTemplateCallback()

ParserOptions::getTemplateCallback ( )

Callback for template fetching; first argument to call_user_func().

Returns
callable

Definition at line 862 of file ParserOptions.php.

References getOption().

◆ getThumbSize()

ParserOptions::getThumbSize ( )

Thumb size preferred by the user.

Returns
int

Definition at line 575 of file ParserOptions.php.

References getOption().

◆ getTimestamp()

ParserOptions::getTimestamp ( )

Timestamp used for {{CURRENTDAY}} etc.

Returns
string TS_MW timestamp

Definition at line 957 of file ParserOptions.php.

References $mTimestamp, and wfTimestampNow().

◆ getUserIdentity()

ParserOptions::getUserIdentity ( )

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

Since
1.36
Returns
UserIdentity

Definition at line 1010 of file ParserOptions.php.

References $mUser.

Referenced by Parser\fuzzTestPst(), initDateFormat(), and optionsHash().

◆ getUserLang()

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::getFunctionLang() or Parser::getTargetLanguage() instead!
See also
getUserLangObj()
Returns
string Language code
Since
1.17

Definition at line 737 of file ParserOptions.php.

References getUserLangObj().

◆ getUserLangObj()

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::getFunctionLang() or 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 721 of file ParserOptions.php.

References getOption().

Referenced by getUserLang().

◆ getWrapOutputClass()

ParserOptions::getWrapOutputClass ( )

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

Since
1.30
Returns
string|bool

Definition at line 816 of file ParserOptions.php.

References getOption().

◆ initDateFormat()

static ParserOptions::initDateFormat ( ParserOptions  $popt)
staticprivate

Lazy initializer for dateFormat.

Parameters
ParserOptions$popt
Returns
string

Definition at line 690 of file ParserOptions.php.

References getUserIdentity().

◆ initialiseFromUser()

ParserOptions::initialiseFromUser ( UserIdentity  $user,
Language  $lang 
)
private

Get user options.

Parameters
UserIdentity$user
Language$lang

Definition at line 1200 of file ParserOptions.php.

References $lang, and nullifyLazyOption().

Referenced by __construct().

◆ initSpeculativePageId()

static ParserOptions::initSpeculativePageId ( ParserOptions  $popt)
staticprivate

Callback registered with ParserOptions::$lazyOptions, triggered by getSpeculativePageId().

Parameters
ParserOptions$popt
Returns
int|false

Definition at line 923 of file ParserOptions.php.

References getOption().

◆ initSpeculativeRevId()

static ParserOptions::initSpeculativeRevId ( ParserOptions  $popt)
staticprivate

Callback registered with ParserOptions::$lazyOptions, triggered by getSpeculativeRevId().

Parameters
ParserOptions$popt
Returns
int|false

Definition at line 909 of file ParserOptions.php.

References getOption().

◆ isSafeToCache()

ParserOptions::isSafeToCache ( array  $usedOptions = null)

Test whether these options are safe to cache.

Parameters
string[] | null$usedOptionsthe list of options actually used in the parse. Defaults to all options.
Returns
bool
Since
1.30

Definition at line 1415 of file ParserOptions.php.

References $defaults, getCacheVaryingOptionsHash(), getDefaults(), and optionToString().

Referenced by Parser\RevisionOutputCache\save().

◆ lazyLoadOption()

ParserOptions::lazyLoadOption (   $name)
private
Parameters
string$nameLazy load option without tracking usage

Definition at line 158 of file ParserOptions.php.

References $lazyOptions, and getLazyOptions().

Referenced by getOption(), matches(), matchesForCacheKey(), and optionsHash().

◆ matches()

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 1222 of file ParserOptions.php.

References $options, lazyLoadOption(), and optionToString().

◆ matchesForCacheKey()

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 1267 of file ParserOptions.php.

References lazyLoadOption(), and optionToString().

◆ newCanonical()

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

Creates a "canonical" ParserOptions object.

For historical reasons, certain options have default values that are different from the canonical values used for caching.

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 1089 of file ParserOptions.php.

References newFromAnon(), and newFromContext().

Referenced by MediaWiki\Content\Renderer\ContentParseParams\__construct(), ApiParse\execute(), MediaWiki\Rest\Handler\ParsoidHTMLHelper\getHtml(), WikiPage\getParserOutput(), AbstractContent\getParserOutput(), MediaWiki\Revision\RevisionRenderer\getRenderedRevision(), WikiPage\makeParserOptions(), and CLIParser\parse().

◆ newFromAnon()

static ParserOptions::newFromAnon ( )
static

Get a ParserOptions object for an anonymous user.

Since
1.27
Returns
ParserOptions

Definition at line 1032 of file ParserOptions.php.

Referenced by FormatInstallDoc\execute(), MessageCache\getParserOptions(), newCanonical(), and OutputPage\parserOptions().

◆ newFromContext()

◆ newFromUser()

static ParserOptions::newFromUser (   $user)
static

◆ newFromUserAndLang()

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

Get a ParserOptions object from a given user and language.

Parameters
UserIdentity$user
Language$lang
Returns
ParserOptions

Definition at line 1055 of file ParserOptions.php.

References $lang.

Referenced by EditPage\getContentObject(), LocalFile\getDescriptionText(), EditPage\isUndoClean(), MediaWiki\Storage\DerivedPageDataUpdater\prepareContent(), and EditPage\showDiff().

◆ nullifyLazyOption()

ParserOptions::nullifyLazyOption ( array  $options)
private

Resets lazy loaded options to null in the provided $options array.

Parameters
array$options
Returns
array

Definition at line 170 of file ParserOptions.php.

References $options.

Referenced by initialiseFromUser().

◆ optionsHash()

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 1350 of file ParserOptions.php.

References $defaults, $lang, $mExtraKey, $options, $title, $wgRenderHashAppend, allCacheVaryingOptions(), getDefaults(), getUserIdentity(), lazyLoadOption(), optionToString(), and Hooks\runner().

Referenced by ParserCache\makeParserOutputKey(), Parser\RevisionOutputCache\makeParserOutputKey(), and Parser\ParserObserver\notifyParse().

◆ optionToString()

ParserOptions::optionToString (   $value)
private

Convert an option to a string value.

Parameters
mixed$value
Returns
string

Definition at line 1322 of file ParserOptions.php.

Referenced by isSafeToCache(), matches(), matchesForCacheKey(), and optionsHash().

◆ optionUsed()

ParserOptions::optionUsed (   $optionName)
private

Record that an option was internally accessed.

This calls the watcher set by ParserOptions::registerWatcher(). Typically, the watcher callback is ParserOutput::registerOption(). The information registered this way is consumed by ParserCache::save().

Parameters
string$optionNameName of the option

Definition at line 1302 of file ParserOptions.php.

Referenced by getOption().

◆ registerWatcher()

ParserOptions::registerWatcher (   $callback)

Registers a callback for tracking which ParserOptions which are used.

Since
1.16
Parameters
callable | null$callback

Definition at line 1289 of file ParserOptions.php.

◆ setAllowExternalImages()

ParserOptions::setAllowExternalImages (   $x)

Allow all external images inline?

Parameters
bool | null$xNew value (null is no change)
Returns
bool Old value
Deprecated:
since 1.35; per-parser configuration of image handling via parser options is deprecated. Use site configuration.

Definition at line 279 of file ParserOptions.php.

References setOptionLegacy(), and wfDeprecated().

◆ setAllowExternalImagesFrom()

ParserOptions::setAllowExternalImagesFrom (   $x)

External images to allow.

When self::getAllowExternalImages() is false

Parameters
string | string[] | null$xNew value (null is no change)
Returns
string|string[] Old value
Deprecated:
since 1.35; per-parser configuration of image handling via parser options is deprecated. Use site configuration.

Definition at line 305 of file ParserOptions.php.

References setOptionLegacy(), and wfDeprecated().

◆ setAllowSpecialInclusion()

ParserOptions::setAllowSpecialInclusion (   $x)

Allow inclusion of special pages?

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

Definition at line 343 of file ParserOptions.php.

References setOptionLegacy().

◆ setAllowUnsafeRawHtml()

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 807 of file ParserOptions.php.

References setOptionLegacy().

◆ setCleanSignatures()

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 516 of file ParserOptions.php.

References setOptionLegacy().

◆ setCurrentRevisionRecordCallback()

ParserOptions::setCurrentRevisionRecordCallback (   $x)

Callback for current revision fetching; first argument to call_user_func().

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

Definition at line 854 of file ParserOptions.php.

References setOption().

Referenced by setupFakeRevision().

◆ setDateFormat()

ParserOptions::setDateFormat (   $x)

Date format index.

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

Definition at line 700 of file ParserOptions.php.

References setOptionLegacy().

◆ setEnableImageWhitelist()

ParserOptions::setEnableImageWhitelist (   $x)

Use the on-wiki external image whitelist?

Parameters
bool | null$xNew value (null is no change)
Returns
bool Old value
Deprecated:
since 1.35; per-parser configuration of image handling via parser options is deprecated. Use site configuration.

Definition at line 325 of file ParserOptions.php.

References setOptionLegacy(), and wfDeprecated().

◆ setExpensiveParserFunctionLimit()

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 455 of file ParserOptions.php.

References setOptionLegacy().

◆ setExternalLinkTarget()

ParserOptions::setExternalLinkTarget (   $x)

Target attribute for external links.

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

Definition at line 533 of file ParserOptions.php.

References setOptionLegacy().

◆ setInterfaceMessage()

ParserOptions::setInterfaceMessage (   $x)

Parsing an interface message?

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

Definition at line 360 of file ParserOptions.php.

References setOptionLegacy().

◆ setInterwikiMagic()

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 260 of file ParserOptions.php.

References setOptionLegacy().

◆ setIsPreview()

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 622 of file ParserOptions.php.

References setOptionLegacy().

Referenced by ApiParse\tweakParserOptions().

◆ setIsPrintable()

ParserOptions::setIsPrintable (   $x)

Parsing the printable version of the page?

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

Definition at line 656 of file ParserOptions.php.

References setOptionLegacy().

◆ setIsSectionPreview()

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 639 of file ParserOptions.php.

References setOptionLegacy().

Referenced by ApiParse\tweakParserOptions().

◆ setMaxIncludeSize()

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 394 of file ParserOptions.php.

References setOptionLegacy().

◆ setMaxPPNodeCount()

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 411 of file ParserOptions.php.

References setOptionLegacy().

◆ setMaxTemplateDepth()

ParserOptions::setMaxTemplateDepth (   $x)

Maximum recursion depth for templates within templates.

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

Definition at line 436 of file ParserOptions.php.

References setOptionLegacy().

◆ setOption()

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 219 of file ParserOptions.php.

Referenced by setCurrentRevisionRecordCallback(), setSpeculativePageIdCallback(), setSpeculativeRevIdCallback(), setTargetLanguage(), and setWrapOutputClass().

◆ setOptionLegacy()

ParserOptions::setOptionLegacy (   $name,
  $value 
)
protected

◆ setPreSaveTransform()

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 673 of file ParserOptions.php.

References setOptionLegacy().

◆ setRedirectTarget()

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 981 of file ParserOptions.php.

References $title.

◆ setRemoveComments()

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 474 of file ParserOptions.php.

References setOptionLegacy().

◆ setSpeculativePageIdCallback()

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 948 of file ParserOptions.php.

References setOption().

◆ setSpeculativeRevIdCallback()

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 937 of file ParserOptions.php.

References setOption().

◆ setStubThreshold()

ParserOptions::setStubThreshold (   $x)

Thumb size preferred by the user.

Deprecated:
since 1.37. Stub threshold feature has been removed. See T284917.
Parameters
int | null$xNew value (null is no change)
Returns
int Old value

Definition at line 604 of file ParserOptions.php.

References wfDeprecated().

◆ setTargetLanguage()

ParserOptions::setTargetLanguage (   $x)

Target language for the parse.

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

Definition at line 377 of file ParserOptions.php.

References setOption().

◆ setTemplateCallback()

ParserOptions::setTemplateCallback (   $x)

Callback for template fetching; first argument to call_user_func().

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

Definition at line 871 of file ParserOptions.php.

References setOptionLegacy().

◆ setThumbSize()

ParserOptions::setThumbSize (   $x)

Thumb size preferred by the user.

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

Definition at line 584 of file ParserOptions.php.

References setOptionLegacy().

◆ setTimestamp()

ParserOptions::setTimestamp (   $x)

Timestamp used for {{CURRENTDAY}} etc.

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

Definition at line 969 of file ParserOptions.php.

References wfSetVar().

◆ setupFakeRevision()

ParserOptions::setupFakeRevision (   $title,
  $content,
  $user 
)

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.

Since
1.25
Parameters
Title$title
Content$content
UserIdentity$userThe user that the fake revision is attributed to
Returns
ScopedCallback to unset the hook

Definition at line 1441 of file ParserOptions.php.

References $content, $title, $wgHooks, and setCurrentRevisionRecordCallback().

◆ setUserLang()

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 746 of file ParserOptions.php.

References setOptionLegacy().

◆ setWrapOutputClass()

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|bool Current value

Definition at line 827 of file ParserOptions.php.

References setOption(), and wfDeprecated().

Referenced by ApiParse\tweakParserOptions().

Member Data Documentation

◆ $cacheVaryingOptionsHash

array null ParserOptions::$cacheVaryingOptionsHash = null
staticprivate

Specify options that are included in the cache key.

Definition at line 74 of file ParserOptions.php.

Referenced by getCacheVaryingOptionsHash().

◆ $callbacks

array ParserOptions::$callbacks
staticprivate
Initial value:
= [
'currentRevisionRecordCallback' => true,
'templateCallback' => true,
'speculativeRevIdCallback' => true,
'speculativePageIdCallback' => true,
]

Specify pseudo-options that are actually callbacks.

These must be ignored when checking for cacheability.

Definition at line 92 of file ParserOptions.php.

◆ $defaults

array null ParserOptions::$defaults = null
staticprivate

Default values for all options that are relevant for caching.

See also
self::getDefaults()

Definition at line 52 of file ParserOptions.php.

Referenced by isSafeToCache(), and optionsHash().

◆ $initialCacheVaryingOptionsHash

array ParserOptions::$initialCacheVaryingOptionsHash
staticprivate
Initial value:
= [
'dateformat' => true,
'thumbsize' => true,
'printable' => true,
'userlang' => true,
]

Initial inCacheKey options (before hook)

Definition at line 80 of file ParserOptions.php.

Referenced by getDefaults().

◆ $initialLazyOptions

callable [] ParserOptions::$initialLazyOptions
staticprivate
Initial value:
= [
'dateformat' => [ __CLASS__, 'initDateFormat' ],
'speculativeRevId' => [ __CLASS__, 'initSpeculativeRevId' ],
'speculativePageId' => [ __CLASS__, 'initSpeculativePageId' ],
]

Initial lazy-loaded options (before hook)

Definition at line 64 of file ParserOptions.php.

Referenced by getDefaults().

◆ $lazyOptions

callable [] null ParserOptions::$lazyOptions = null
staticprivate

Lazy-loaded options.

Definition at line 58 of file ParserOptions.php.

Referenced by getLazyOptions(), and lazyLoadOption().

◆ $mExtraKey

ParserOptions::$mExtraKey = ''
private

Appended to the options hash.

Definition at line 137 of file ParserOptions.php.

Referenced by optionsHash().

◆ $mTimestamp

string null ParserOptions::$mTimestamp
private

Timestamp used for {{CURRENTDAY}} etc.

Note
Caching based on parse time is handled externally

Definition at line 110 of file ParserOptions.php.

Referenced by getTimestamp().

◆ $mUser

UserIdentity ParserOptions::$mUser
private

Stored user object.

Todo:
Track this for caching somehow without fragmenting the cache

Definition at line 117 of file ParserOptions.php.

Referenced by getUserIdentity().

◆ $onAccessCallback

callable null ParserOptions::$onAccessCallback = null
private

Function to be called when an option is accessed.

Note
Used for collecting used options, does not affect caching

Definition at line 124 of file ParserOptions.php.

◆ $options

array ParserOptions::$options
private

Current values for all options that are relevant for caching.

Definition at line 103 of file ParserOptions.php.

Referenced by matches(), nullifyLazyOption(), and optionsHash().

◆ $redirectTarget

Title null ParserOptions::$redirectTarget = null
private

If the page being parsed is a redirect, this should hold the redirect target.

Todo:
Track this for caching somehow

Definition at line 132 of file ParserOptions.php.

Referenced by getRedirectTarget().


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