MediaWiki REL1_32
ParserOptions Class Reference

Set options of the Parser. More...

Collaboration diagram for ParserOptions:

Public Member Functions

 __construct ( $user=null, $lang=null)
 
 addExtraKey ( $key)
 Extra key that should be present in the parser cache key.
 
 getEditSection ()
 Create "edit section" links?
 
 getRedirectTarget ()
 Get the previously-set redirect target.
 
 getTimestamp ()
 Timestamp used for {{CURRENTDAY}} etc.
 
 getUser ()
 Current user.
 
 isSafeToCache ()
 Test whether these options are safe to cache.
 
 matches (ParserOptions $other)
 Check if these options match that of another options set.
 
 optionsHash ( $forOptions, $title=null)
 Generate a hash string with the values set on these ParserOptions for the keys given in the array.
 
 optionUsed ( $optionName)
 Called when an option is accessed.
 
 registerWatcher ( $callback)
 Registers a callback for tracking which ParserOptions which are used.
 
 setEditSection ( $x)
 Create "edit section" links?
 
 setRedirectTarget ( $title)
 Set the redirect target.
 
 setTimestamp ( $x)
 Timestamp used for {{CURRENTDAY}} etc.
 
 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.
 

Static Public Member Functions

static allCacheVaryingOptions ()
 Return all option keys that vary the options hash.
 
static legacyOptions ()
 Returns the full array of options that would have been used by in 1.16.
 
static newCanonical ( $context=null, $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 (User $user, Language $lang)
 Get a ParserOptions object from a given user and language.
 

Public Attributes

const HAS_NEWCANONICAL_FROM_CONTEXT = 1
 Flag indicating that newCanonical() accepts an IContextSource or the string 'canonical', for back-compat checks from extensions.
 

Private Member Functions

 initialiseFromUser ( $user, $lang)
 Get user options.
 
 optionToString ( $value)
 Convert an option to a string value.
 

Static Private Member Functions

static getCanonicalOverrides ()
 Get "canonical" non-default option values.
 
static getDefaults ()
 Get default option values.
 

Private Attributes

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

Static Private Attributes

static array null $defaults = null
 Default values for all options that are relevant for caching.
 
static array $inCacheKey
 Specify options that are included in the cache key.
 
static callback[] $lazyOptions
 Lazy-loaded options.
 

Option accessors

 getOption ( $name)
 Fetch an option, generically.
 
 setOption ( $name, $value)
 Set an option, generically.
 
 getInterwikiMagic ()
 Whether to extract interlanguage links.
 
 setInterwikiMagic ( $x)
 Specify whether to extract interlanguage links.
 
 getAllowExternalImages ()
 Allow all external images inline?
 
 setAllowExternalImages ( $x)
 Allow all external images inline?
 
 getAllowExternalImagesFrom ()
 External images to allow.
 
 setAllowExternalImagesFrom ( $x)
 External images to allow.
 
 getEnableImageWhitelist ()
 Use the on-wiki external image whitelist?
 
 setEnableImageWhitelist ( $x)
 Use the on-wiki external image whitelist?
 
 getNumberHeadings ()
 Automatically number headings?
 
 setNumberHeadings ( $x)
 Automatically number headings?
 
 getAllowSpecialInclusion ()
 Allow inclusion of special pages?
 
 setAllowSpecialInclusion ( $x)
 Allow inclusion of special pages?
 
 getTidy ()
 Use tidy to cleanup output HTML?
 
 setTidy ( $x)
 Use tidy to cleanup output HTML?
 
 getInterfaceMessage ()
 Parsing an interface message?
 
 setInterfaceMessage ( $x)
 Parsing an interface message?
 
 getTargetLanguage ()
 Target language for the parse.
 
 setTargetLanguage ( $x)
 Target language for the parse.
 
 getMaxIncludeSize ()
 Maximum size of template expansions, in bytes.
 
 setMaxIncludeSize ( $x)
 Maximum size of template expansions, in bytes.
 
 getMaxPPNodeCount ()
 Maximum number of nodes touched by PPFrame::expand()
 
 setMaxPPNodeCount ( $x)
 Maximum number of nodes touched by PPFrame::expand()
 
 getMaxGeneratedPPNodeCount ()
 Maximum number of nodes generated by Preprocessor::preprocessToObj()
 
 setMaxGeneratedPPNodeCount ( $x)
 Maximum number of nodes generated by Preprocessor::preprocessToObj()
 
 getMaxPPExpandDepth ()
 Maximum recursion depth in PPFrame::expand()
 
 getMaxTemplateDepth ()
 Maximum recursion depth for templates within templates.
 
 setMaxTemplateDepth ( $x)
 Maximum recursion depth for templates within templates.
 
 getExpensiveParserFunctionLimit ()
 Maximum number of calls per parse to expensive parser functions.
 
 setExpensiveParserFunctionLimit ( $x)
 Maximum number of calls per parse to expensive parser functions.
 
 getRemoveComments ()
 Remove HTML comments.
 
 setRemoveComments ( $x)
 Remove HTML comments.
 
 getEnableLimitReport ()
 Enable limit report in an HTML comment on output.
 
 enableLimitReport ( $x=true)
 Enable limit report in an HTML comment on output.
 
 getCleanSignatures ()
 Clean up signature texts?
 
 setCleanSignatures ( $x)
 Clean up signature texts?
 
 getExternalLinkTarget ()
 Target attribute for external links.
 
 setExternalLinkTarget ( $x)
 Target attribute for external links.
 
 getDisableContentConversion ()
 Whether content conversion should be disabled.
 
 disableContentConversion ( $x=true)
 Whether content conversion should be disabled.
 
 getDisableTitleConversion ()
 Whether title conversion should be disabled.
 
 disableTitleConversion ( $x=true)
 Whether title conversion should be disabled.
 
 getThumbSize ()
 Thumb size preferred by the user.
 
 setThumbSize ( $x)
 Thumb size preferred by the user.
 
 getStubThreshold ()
 Thumb size preferred by the user.
 
 setStubThreshold ( $x)
 Thumb size preferred by the user.
 
 getIsPreview ()
 Parsing the page for a "preview" operation?
 
 setIsPreview ( $x)
 Parsing the page for a "preview" operation?
 
 getIsSectionPreview ()
 Parsing the page for a "preview" operation on a single section?
 
 setIsSectionPreview ( $x)
 Parsing the page for a "preview" operation on a single section?
 
 getIsPrintable ()
 Parsing the printable version of the page?
 
 setIsPrintable ( $x)
 Parsing the printable version of the page?
 
 getPreSaveTransform ()
 Transform wiki markup when saving the page?
 
 setPreSaveTransform ( $x)
 Transform wiki markup when saving the page?
 
 getDateFormat ()
 Date format index.
 
 setDateFormat ( $x)
 Date format index.
 
 getUserLangObj ()
 Get the user language used by the parser for this page and split the parser cache.
 
 getUserLang ()
 Same as getUserLangObj() but returns a string instead.
 
 setUserLang ( $x)
 Set the user language used by the parser for this page and split the parser cache.
 
 getMagicISBNLinks ()
 Are magic ISBN links enabled?
 
 getMagicPMIDLinks ()
 Are magic PMID links enabled?
 
 getMagicRFCLinks ()
 Are magic RFC links enabled?
 
 getAllowUnsafeRawHtml ()
 If the wiki is configured to allow raw html ($wgRawHtml = true) is it allowed in the specific case of parsing this page.
 
 setAllowUnsafeRawHtml ( $x)
 If the wiki is configured to allow raw html ($wgRawHtml = true) is it allowed in the specific case of parsing this page.
 
 getWrapOutputClass ()
 Class to use to wrap output from Parser::parse()
 
 setWrapOutputClass ( $className)
 CSS class to use to wrap output from Parser::parse()
 
 getCurrentRevisionCallback ()
 Callback for current revision fetching; first argument to call_user_func().
 
 setCurrentRevisionCallback ( $x)
 Callback for current revision fetching; first argument to call_user_func().
 
 getTemplateCallback ()
 Callback for template fetching; first argument to call_user_func().
 
 setTemplateCallback ( $x)
 Callback for template fetching; first argument to call_user_func().
 
 getSpeculativeRevId ()
 A guess for {{REVISIONID}}, calculated using the callback provided via setSpeculativeRevIdCallback().
 
 getSpeculativeRevIdCallback ()
 Callback to generate a guess for {{REVISIONID}}.
 
 setSpeculativeRevIdCallback ( $x)
 Callback to generate a guess for {{REVISIONID}}.
 
 setOptionLegacy ( $name, $value)
 Legacy implementation.
 
static initDateFormat ( $popt)
 Lazy initializer for dateFormat.
 
static initSpeculativeRevId (ParserOptions $popt)
 Callback registered with ParserOptions::$lazyOptions, triggered by getSpeculativeRevId().
 

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

Constructor & Destructor Documentation

◆ __construct()

ParserOptions::__construct ( $user = null,
$lang = null )
Warning
For interaction with the parser cache, use WikiPage::makeParserOptions() or ParserOptions::newCanonical() instead.
Parameters
User | null$user
Language | null$lang

Definition at line 975 of file ParserOptions.php.

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

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 957 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 1286 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 520 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 537 of file ParserOptions.php.

References setOptionLegacy().

◆ enableLimitReport()

ParserOptions::enableLimitReport ( $x = true)

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

References setOptionLegacy().

Referenced by ParserMethodsTest\testRevisionAccess().

◆ getAllowExternalImages()

ParserOptions::getAllowExternalImages ( )

Allow all external images inline?

Returns
bool

Definition at line 202 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 222 of file ParserOptions.php.

References getOption().

◆ getAllowSpecialInclusion()

ParserOptions::getAllowSpecialInclusion ( )

Allow inclusion of special pages?

Returns
bool

Definition at line 276 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 757 of file ParserOptions.php.

References getOption().

◆ getCanonicalOverrides()

static ParserOptions::getCanonicalOverrides ( )
staticprivate

Get "canonical" non-default option values.

See also
self::newCanonical
Warning
If you change the override 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 1163 of file ParserOptions.php.

References $wgEnableParserLimitReporting.

◆ getCleanSignatures()

ParserOptions::getCleanSignatures ( )

Clean up signature texts?

See also
Parser::cleanSig
Returns
bool

Definition at line 476 of file ParserOptions.php.

References getOption().

◆ getCurrentRevisionCallback()

ParserOptions::getCurrentRevisionCallback ( )

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

Since
1.24
Returns
callable

Definition at line 804 of file ParserOptions.php.

References getOption().

◆ getDateFormat()

ParserOptions::getDateFormat ( )

Date format index.

Returns
string

Definition at line 647 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 (unless it's being overridden by self::getCanonicalOverrides()), 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 1089 of file ParserOptions.php.

References $wgAllowExternalImages, $wgAllowExternalImagesFrom, $wgAllowSpecialInclusion, $wgCleanSignatures, $wgDisableLangConversion, $wgDisableTitleConversion, $wgEnableImageWhitelist, $wgEnableMagicLinks, $wgExpensiveParserFunctionLimit, $wgExternalLinkTarget, $wgInterwikiMagic, $wgMaxArticleSize, $wgMaxGeneratedPPNodeCount, $wgMaxPPExpandDepth, $wgMaxPPNodeCount, $wgMaxTemplateDepth, and User\getDefaultOption().

◆ getDisableContentConversion()

ParserOptions::getDisableContentConversion ( )

Whether content conversion should be disabled.

Returns
bool

Definition at line 511 of file ParserOptions.php.

References getOption().

◆ getDisableTitleConversion()

ParserOptions::getDisableTitleConversion ( )

Whether title conversion should be disabled.

Returns
bool

Definition at line 528 of file ParserOptions.php.

References getOption().

◆ getEditSection()

ParserOptions::getEditSection ( )

Create "edit section" links?

Deprecated
since 1.31, use ParserOutput::getText() options instead.
Returns
bool

Definition at line 911 of file ParserOptions.php.

References wfDeprecated().

◆ getEnableImageWhitelist()

ParserOptions::getEnableImageWhitelist ( )

Use the on-wiki external image whitelist?

Returns
bool

Definition at line 242 of file ParserOptions.php.

References getOption().

◆ getEnableLimitReport()

ParserOptions::getEnableLimitReport ( )

Enable limit report in an HTML comment on output.

Returns
bool

Definition at line 458 of file ParserOptions.php.

References getOption().

◆ getExpensiveParserFunctionLimit()

ParserOptions::getExpensiveParserFunctionLimit ( )

Maximum number of calls per parse to expensive parser functions.

Since
1.20
Returns
int

Definition at line 421 of file ParserOptions.php.

References getOption().

◆ getExternalLinkTarget()

ParserOptions::getExternalLinkTarget ( )

Target attribute for external links.

Returns
string

Definition at line 494 of file ParserOptions.php.

References getOption().

◆ getInterfaceMessage()

ParserOptions::getInterfaceMessage ( )

Parsing an interface message?

Returns
bool

Definition at line 310 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 185 of file ParserOptions.php.

References getOption().

◆ getIsPreview()

ParserOptions::getIsPreview ( )

Parsing the page for a "preview" operation?

Returns
bool

Definition at line 579 of file ParserOptions.php.

References getOption().

◆ getIsPrintable()

ParserOptions::getIsPrintable ( )

Parsing the printable version of the page?

Returns
bool

Definition at line 613 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 596 of file ParserOptions.php.

References getOption().

◆ getMagicISBNLinks()

ParserOptions::getMagicISBNLinks ( )

Are magic ISBN links enabled?

Since
1.28
Returns
bool

Definition at line 722 of file ParserOptions.php.

References getOption().

◆ getMagicPMIDLinks()

ParserOptions::getMagicPMIDLinks ( )

Are magic PMID links enabled?

Since
1.28
Returns
bool

Definition at line 731 of file ParserOptions.php.

References getOption().

◆ getMagicRFCLinks()

ParserOptions::getMagicRFCLinks ( )

Are magic RFC links enabled?

Since
1.28
Returns
bool

Definition at line 739 of file ParserOptions.php.

References getOption().

◆ getMaxGeneratedPPNodeCount()

ParserOptions::getMaxGeneratedPPNodeCount ( )

Maximum number of nodes generated by Preprocessor::preprocessToObj()

Returns
int

Definition at line 378 of file ParserOptions.php.

References getOption().

◆ getMaxIncludeSize()

ParserOptions::getMaxIncludeSize ( )

Maximum size of template expansions, in bytes.

Returns
int

Definition at line 344 of file ParserOptions.php.

References getOption().

◆ getMaxPPExpandDepth()

ParserOptions::getMaxPPExpandDepth ( )

Maximum recursion depth in PPFrame::expand()

Returns
int

Definition at line 395 of file ParserOptions.php.

References getOption().

◆ getMaxPPNodeCount()

ParserOptions::getMaxPPNodeCount ( )

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

Returns
int

Definition at line 361 of file ParserOptions.php.

References getOption().

◆ getMaxTemplateDepth()

ParserOptions::getMaxTemplateDepth ( )

Maximum recursion depth for templates within templates.

Returns
int

Definition at line 403 of file ParserOptions.php.

References getOption().

◆ getNumberHeadings()

ParserOptions::getNumberHeadings ( )

Automatically number headings?

Returns
bool

Definition at line 259 of file ParserOptions.php.

References getOption().

◆ getOption()

◆ getPreSaveTransform()

ParserOptions::getPreSaveTransform ( )

Transform wiki markup when saving the page?

Returns
bool

Definition at line 630 of file ParserOptions.php.

References getOption().

◆ getRedirectTarget()

ParserOptions::getRedirectTarget ( )

Get the previously-set redirect target.

Since
1.24
Returns
Title|null

Definition at line 947 of file ParserOptions.php.

◆ getRemoveComments()

ParserOptions::getRemoveComments ( )

Remove HTML comments.

Warning
Only applies to preprocess operations
Returns
bool

Definition at line 440 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 845 of file ParserOptions.php.

References getOption().

◆ getSpeculativeRevIdCallback()

ParserOptions::getSpeculativeRevIdCallback ( )

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

Since
1.28
Deprecated
since 1.32, use getSpeculativeRevId() instead!
Returns
callable|null

Definition at line 869 of file ParserOptions.php.

References getOption().

◆ getStubThreshold()

ParserOptions::getStubThreshold ( )

Thumb size preferred by the user.

Returns
int

Definition at line 562 of file ParserOptions.php.

References getOption().

Referenced by WikiPage\getParserOutput(), and WikiPage\shouldCheckParserCache().

◆ getTargetLanguage()

ParserOptions::getTargetLanguage ( )

Target language for the parse.

Returns
Language|null

Definition at line 327 of file ParserOptions.php.

References getOption().

◆ getTemplateCallback()

ParserOptions::getTemplateCallback ( )

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

Returns
callable

Definition at line 822 of file ParserOptions.php.

References getOption().

◆ getThumbSize()

ParserOptions::getThumbSize ( )

Thumb size preferred by the user.

Returns
int

Definition at line 545 of file ParserOptions.php.

References getOption().

◆ getTidy()

ParserOptions::getTidy ( )

Use tidy to cleanup output HTML?

Returns
bool

Definition at line 293 of file ParserOptions.php.

References getOption().

◆ getTimestamp()

ParserOptions::getTimestamp ( )

Timestamp used for {{CURRENTDAY}} etc.

Returns
string

Definition at line 890 of file ParserOptions.php.

References wfTimestampNow().

◆ getUser()

ParserOptions::getUser ( )

Current user.

Returns
User

Definition at line 965 of file ParserOptions.php.

Referenced by 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 700 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 684 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 778 of file ParserOptions.php.

References getOption().

◆ initDateFormat()

static ParserOptions::initDateFormat ( $popt)
staticprivate

Lazy initializer for dateFormat.

Definition at line 654 of file ParserOptions.php.

◆ initialiseFromUser()

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

Get user options.

Parameters
User$user
Language$lang

Definition at line 1178 of file ParserOptions.php.

References $lang, $user, and options().

Referenced by __construct().

◆ initSpeculativeRevId()

static ParserOptions::initSpeculativeRevId ( ParserOptions $popt)
staticprivate

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

Parameters
ParserOptions$popt
Returns
bool|false

Definition at line 855 of file ParserOptions.php.

◆ isSafeToCache()

ParserOptions::isSafeToCache ( )

Test whether these options are safe to cache.

Since
1.30
Returns
bool

Definition at line 1389 of file ParserOptions.php.

References $defaults, $value, options(), and optionToString().

Referenced by WikiPage\getParserOutput().

◆ legacyOptions()

static ParserOptions::legacyOptions ( )
static

Returns the full array of options that would have been used by in 1.16.

Used to get the old parser cache entries when available.

Deprecated
since 1.30. You probably want self::allCacheVaryingOptions() instead.
Returns
string[]

Definition at line 1269 of file ParserOptions.php.

References wfDeprecated().

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

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

◆ newCanonical()

static ParserOptions::newCanonical ( $context = null,
$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
Parameters
IContextSource | string | User | null$context
  • If an IContextSource, the options are initialized based on the source's User and Language.
  • If the string 'canonical', the options are initialized with an anonymous user and the content language.
  • If a User or null, the options are initialized for that User (or $wgUser if null). '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 1061 of file ParserOptions.php.

References $context, and $ret.

◆ newFromAnon()

static ParserOptions::newFromAnon ( )
static

Get a ParserOptions object for an anonymous user.

Warning
For interaction with the parser cache, use WikiPage::makeParserOptions() or ParserOptions::newCanonical() instead.
Since
1.27
Returns
ParserOptions

Definition at line 1001 of file ParserOptions.php.

◆ newFromContext()

static ParserOptions::newFromContext ( IContextSource $context)
static

Get a ParserOptions object from a IContextSource object.

Warning
For interaction with the parser cache, use WikiPage::makeParserOptions() or ParserOptions::newCanonical() instead.
Parameters
IContextSource$context
Returns
ParserOptions

Definition at line 1040 of file ParserOptions.php.

References $context.

◆ newFromUser()

static ParserOptions::newFromUser ( $user)
static

Get a ParserOptions object from a given user.

Language will be taken from $wgLang.

Warning
For interaction with the parser cache, use WikiPage::makeParserOptions() or ParserOptions::newCanonical() instead.
Parameters
User$user
Returns
ParserOptions

Definition at line 1015 of file ParserOptions.php.

◆ newFromUserAndLang()

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

Get a ParserOptions object from a given user and language.

Warning
For interaction with the parser cache, use WikiPage::makeParserOptions() or ParserOptions::newCanonical() instead.
Parameters
User$user
Language$lang
Returns
ParserOptions

Definition at line 1028 of file ParserOptions.php.

References $lang.

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

References $defaults, $options, $wgRenderHashAppend, getUser(), options(), and optionToString().

◆ optionToString()

ParserOptions::optionToString ( $value)
private

Convert an option to a string value.

Parameters
mixed$value
Returns
string

Definition at line 1300 of file ParserOptions.php.

References $value.

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

◆ optionUsed()

ParserOptions::optionUsed ( $optionName)

Called when an option is accessed.

Calls the watcher that was set using registerWatcher(). Typically, the watcher callback is ParserOutput::registerOption(). The information registered that way will be used by ParserCache::save().

Parameters
string$optionNameName of the option

Definition at line 1256 of file ParserOptions.php.

Referenced by getOption().

◆ registerWatcher()

ParserOptions::registerWatcher ( $callback)

Registers a callback for tracking which ParserOptions which are used.

This is a private API with the parser.

Parameters
callable$callback

Definition at line 1244 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

Definition at line 211 of file ParserOptions.php.

References setOptionLegacy().

◆ 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

Definition at line 234 of file ParserOptions.php.

References setOptionLegacy().

◆ 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 285 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 769 of file ParserOptions.php.

References setOptionLegacy().

Referenced by MessageCache\getParserOptions().

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

References setOptionLegacy().

◆ setCurrentRevisionCallback()

ParserOptions::setCurrentRevisionCallback ( $x)

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

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

Definition at line 814 of file ParserOptions.php.

References setOptionLegacy().

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

References setOptionLegacy().

◆ setEditSection()

ParserOptions::setEditSection ( $x)

Create "edit section" links?

Deprecated
since 1.31, use ParserOutput::getText() options instead.
Parameters
bool | null$xNew value (null is no change)
Returns
bool Old value

Definition at line 922 of file ParserOptions.php.

References wfDeprecated().

◆ setEnableImageWhitelist()

ParserOptions::setEnableImageWhitelist ( $x)

Use the on-wiki external image whitelist?

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

Definition at line 251 of file ParserOptions.php.

References setOptionLegacy().

◆ 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 431 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 503 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 319 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 194 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 588 of file ParserOptions.php.

References setOptionLegacy().

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

References setOptionLegacy().

◆ setMaxGeneratedPPNodeCount()

ParserOptions::setMaxGeneratedPPNodeCount ( $x)

Maximum number of nodes generated by Preprocessor::preprocessToObj()

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

Definition at line 387 of file ParserOptions.php.

References setOptionLegacy().

◆ 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 353 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 370 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 412 of file ParserOptions.php.

References setOptionLegacy().

◆ setNumberHeadings()

ParserOptions::setNumberHeadings ( $x)

Automatically number headings?

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

Definition at line 268 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 153 of file ParserOptions.php.

References $name, $value, and options().

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

◆ setOptionLegacy()

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

References setOptionLegacy().

◆ setRedirectTarget()

ParserOptions::setRedirectTarget ( $title)

Set the redirect target.

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

References setOptionLegacy().

◆ setSpeculativeRevIdCallback()

ParserOptions::setSpeculativeRevIdCallback ( $x)

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

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

Definition at line 879 of file ParserOptions.php.

References setOption(), and setOptionLegacy().

◆ setStubThreshold()

ParserOptions::setStubThreshold ( $x)

Thumb size preferred by the user.

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

Definition at line 571 of file ParserOptions.php.

References setOptionLegacy().

◆ setTargetLanguage()

ParserOptions::setTargetLanguage ( $x)

Target language for the parse.

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

Definition at line 336 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 831 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 554 of file ParserOptions.php.

References setOptionLegacy().

◆ setTidy()

ParserOptions::setTidy ( $x)

Use tidy to cleanup output HTML?

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

Definition at line 302 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 902 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
User$userThe user that the fake revision is attributed to
Returns
ScopedCallback to unset the hook

Definition at line 1413 of file ParserOptions.php.

References $content, $parser, $wgHooks, key, and setCurrentRevisionCallback().

◆ 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 709 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 789 of file ParserOptions.php.

References setOption(), and wfDeprecated().

Member Data Documentation

◆ $defaults

array null ParserOptions::$defaults = null
staticprivate

Default values for all options that are relevant for caching.

See also
self::getDefaults()

Definition at line 56 of file ParserOptions.php.

Referenced by isSafeToCache(), and optionsHash().

◆ $inCacheKey

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

Specify options that are included in the cache key.

Definition at line 71 of file ParserOptions.php.

◆ $lazyOptions

callback [] ParserOptions::$lazyOptions
staticprivate
Initial value:
= [
'dateformat' => [ __CLASS__, 'initDateFormat' ],
'speculativeRevId' => [ __CLASS__, 'initSpeculativeRevId' ],
]

Lazy-loaded options.

Definition at line 62 of file ParserOptions.php.

◆ $mExtraKey

ParserOptions::$mExtraKey = ''
private

Appended to the options hash.

Definition at line 118 of file ParserOptions.php.

◆ $mTimestamp

string null ParserOptions::$mTimestamp
private

Timestamp used for {{CURRENTDAY}} etc.

Note
Caching based on parse time is handled externally

Definition at line 91 of file ParserOptions.php.

◆ $mUser

User ParserOptions::$mUser
private

Stored user object.

Todo
Track this for caching somehow without fragmenting the cache insanely

Definition at line 98 of file ParserOptions.php.

◆ $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 105 of file ParserOptions.php.

◆ $options

array ParserOptions::$options
private

Current values for all options that are relevant for caching.

Definition at line 84 of file ParserOptions.php.

◆ $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 113 of file ParserOptions.php.

◆ HAS_NEWCANONICAL_FROM_CONTEXT

const ParserOptions::HAS_NEWCANONICAL_FROM_CONTEXT = 1

Flag indicating that newCanonical() accepts an IContextSource or the string 'canonical', for back-compat checks from extensions.

Since
1.32

Definition at line 49 of file ParserOptions.php.


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