BlueSpice MediaWiki master
 All Classes Namespaces Files Functions Variables Groups Pages
ParserOptions Class Reference

Set options of the Parser. More...

Public Member Functions

 getTimestamp ()
 
 setTimestamp ($x)
 
 getEditSection ()
 
 setEditSection ($x)
 
 setRedirectTarget ($title)
 
 getRedirectTarget ()
 
 addExtraKey ($key)
 
 getUser ()
 
 __construct ($user=null, $lang=null)
 
 matches (ParserOptions $other)
 
 registerWatcher ($callback)
 
 optionUsed ($optionName)
 
 optionsHash ($forOptions, $title=null)
 
 isSafeToCache ()
 
 setupFakeRevision ($title, $content, $user)
 

Static Public Member Functions

static newFromAnon ()
 
static newFromUser ($user)
 
static newFromUserAndLang (User $user, Language $lang)
 
static newFromContext (IContextSource $context)
 
static newCanonical (User $user=null, $lang=null)
 
static legacyOptions ()
 
static allCacheVaryingOptions ()
 

Option accessors

 getOption ($name)
 
 setOption ($name, $value)
 
 getInterwikiMagic ()
 
 setInterwikiMagic ($x)
 
 getAllowExternalImages ()
 
 setAllowExternalImages ($x)
 
 getAllowExternalImagesFrom ()
 
 setAllowExternalImagesFrom ($x)
 
 getEnableImageWhitelist ()
 
 setEnableImageWhitelist ($x)
 
 getNumberHeadings ()
 
 setNumberHeadings ($x)
 
 getAllowSpecialInclusion ()
 
 setAllowSpecialInclusion ($x)
 
 getTidy ()
 
 setTidy ($x)
 
 getInterfaceMessage ()
 
 setInterfaceMessage ($x)
 
 getTargetLanguage ()
 
 setTargetLanguage ($x)
 
 getMaxIncludeSize ()
 
 setMaxIncludeSize ($x)
 
 getMaxPPNodeCount ()
 
 setMaxPPNodeCount ($x)
 
 getMaxGeneratedPPNodeCount ()
 
 setMaxGeneratedPPNodeCount ($x)
 
 getMaxPPExpandDepth ()
 
 getMaxTemplateDepth ()
 
 setMaxTemplateDepth ($x)
 
 getExpensiveParserFunctionLimit ()
 
 setExpensiveParserFunctionLimit ($x)
 
 getRemoveComments ()
 
 setRemoveComments ($x)
 
 getEnableLimitReport ()
 
 enableLimitReport ($x=true)
 
 getCleanSignatures ()
 
 setCleanSignatures ($x)
 
 getExternalLinkTarget ()
 
 setExternalLinkTarget ($x)
 
 getDisableContentConversion ()
 
 disableContentConversion ($x=true)
 
 getDisableTitleConversion ()
 
 disableTitleConversion ($x=true)
 
 getThumbSize ()
 
 setThumbSize ($x)
 
 getStubThreshold ()
 
 setStubThreshold ($x)
 
 getIsPreview ()
 
 setIsPreview ($x)
 
 getIsSectionPreview ()
 
 setIsSectionPreview ($x)
 
 getIsPrintable ()
 
 setIsPrintable ($x)
 
 getPreSaveTransform ()
 
 setPreSaveTransform ($x)
 
 getDateFormat ()
 
 setDateFormat ($x)
 
 getUserLangObj ()
 
 getUserLang ()
 
 setUserLang ($x)
 
 getMagicISBNLinks ()
 
 getMagicPMIDLinks ()
 
 getMagicRFCLinks ()
 
 getAllowUnsafeRawHtml ()
 
 setAllowUnsafeRawHtml ($x)
 
 getWrapOutputClass ()
 
 setWrapOutputClass ($className)
 
 getCurrentRevisionCallback ()
 
 setCurrentRevisionCallback ($x)
 
 getTemplateCallback ()
 
 setTemplateCallback ($x)
 
 getSpeculativeRevIdCallback ()
 
 setSpeculativeRevIdCallback ($x)
 
 setOptionLegacy ($name, $value)
 

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.

Constructor & Destructor Documentation

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

Member Function Documentation

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
static ParserOptions::allCacheVaryingOptions ( )
static

Return all option keys that vary the options hash

Since
1.30
Returns
string[]
ParserOptions::disableContentConversion (   $x = true)

Whether content conversion should be disabled

Parameters
bool | null$xNew value (null is no change)
Returns
bool Old value
ParserOptions::disableTitleConversion (   $x = true)

Whether title conversion should be disabled

Parameters
bool | null$xNew value (null is no change)
Returns
bool Old value
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
ParserOptions::getAllowExternalImages ( )

Allow all external images inline?

Returns
bool
ParserOptions::getAllowExternalImagesFrom ( )

External images to allow

When self::getAllowExternalImages() is false

Returns
string|string[] URLs to allow
ParserOptions::getAllowSpecialInclusion ( )

Allow inclusion of special pages?

Returns
bool
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
ParserOptions::getCleanSignatures ( )

Clean up signature texts?

See Also
Parser::cleanSig
Returns
bool
ParserOptions::getCurrentRevisionCallback ( )

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

Since
1.24
Returns
callable
ParserOptions::getDateFormat ( )

Date format index

Returns
string
ParserOptions::getDisableContentConversion ( )

Whether content conversion should be disabled

Returns
bool
ParserOptions::getDisableTitleConversion ( )

Whether title conversion should be disabled

Returns
bool
ParserOptions::getEditSection ( )

Create "edit section" links?

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

Use the on-wiki external image whitelist?

Returns
bool
ParserOptions::getEnableLimitReport ( )

Enable limit report in an HTML comment on output

Returns
bool
ParserOptions::getExpensiveParserFunctionLimit ( )

Maximum number of calls per parse to expensive parser functions

Since
1.20
Returns
int
ParserOptions::getExternalLinkTarget ( )

Target attribute for external links

Returns
string
ParserOptions::getInterfaceMessage ( )

Parsing an interface message?

Returns
bool
ParserOptions::getInterwikiMagic ( )

Whether to extract interlanguage links

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

Returns
bool
ParserOptions::getIsPreview ( )

Parsing the page for a "preview" operation?

Returns
bool
ParserOptions::getIsPrintable ( )

Parsing the printable version of the page?

Returns
bool
ParserOptions::getIsSectionPreview ( )

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

Returns
bool
ParserOptions::getMagicISBNLinks ( )

Are magic ISBN links enabled?

Since
1.28
Returns
bool
ParserOptions::getMagicPMIDLinks ( )

Are magic PMID links enabled?

Since
1.28
Returns
bool
ParserOptions::getMagicRFCLinks ( )

Are magic RFC links enabled?

Since
1.28
Returns
bool
ParserOptions::getMaxGeneratedPPNodeCount ( )

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

Returns
int
ParserOptions::getMaxIncludeSize ( )

Maximum size of template expansions, in bytes

Returns
int
ParserOptions::getMaxPPExpandDepth ( )

Maximum recursion depth in PPFrame::expand()

Returns
int
ParserOptions::getMaxPPNodeCount ( )

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

Returns
int
ParserOptions::getMaxTemplateDepth ( )

Maximum recursion depth for templates within templates

Returns
int
ParserOptions::getNumberHeadings ( )

Automatically number headings?

Returns
bool
ParserOptions::getOption (   $name)

Fetch an option, generically

Since
1.30
Parameters
string$nameOption name
Returns
mixed
ParserOptions::getPreSaveTransform ( )

Transform wiki markup when saving the page?

Returns
bool
ParserOptions::getRedirectTarget ( )

Get the previously-set redirect target.

Since
1.24
Returns
Title|null
ParserOptions::getRemoveComments ( )

Remove HTML comments

Warning
Only applies to preprocess operations
Returns
bool
ParserOptions::getSpeculativeRevIdCallback ( )

Callback to generate a guess for {{REVISIONID}}

Since
1.28
Returns
callable|null
ParserOptions::getStubThreshold ( )

Thumb size preferred by the user.

Returns
int
ParserOptions::getTargetLanguage ( )

Target language for the parse

Returns
Language|null
ParserOptions::getTemplateCallback ( )

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

Returns
callable
ParserOptions::getThumbSize ( )

Thumb size preferred by the user.

Returns
int
ParserOptions::getTidy ( )

Use tidy to cleanup output HTML?

Returns
bool
ParserOptions::getTimestamp ( )

Timestamp used for {{CURRENTDAY}} etc.

Returns
string
ParserOptions::getUser ( )

Current user

Returns
User
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
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
ParserOptions::getWrapOutputClass ( )

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

Since
1.30
Returns
string|bool
ParserOptions::isSafeToCache ( )

Test whether these options are safe to cache

Since
1.30
Returns
bool
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[]
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
static ParserOptions::newCanonical ( User  $user = null,
  $lang = 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
Parameters
User | null$user
Language | StubObject | null$lang
Returns
ParserOptions
static ParserOptions::newFromAnon ( )
static

Get a ParserOptions object for an anonymous user

Warning
For interaction with the parser cache, use WikiPage::makeParserOptions(), ContentHandler::makeParserOptions(), or ParserOptions::newCanonical() instead.
Since
1.27
Returns
ParserOptions
static ParserOptions::newFromContext ( IContextSource  $context)
static

Get a ParserOptions object from a IContextSource object

Warning
For interaction with the parser cache, use WikiPage::makeParserOptions(), ContentHandler::makeParserOptions(), or ParserOptions::newCanonical() instead.
Parameters
IContextSource$context
Returns
ParserOptions
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(), ContentHandler::makeParserOptions(), or ParserOptions::newCanonical() instead.
Parameters
User$user
Returns
ParserOptions
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(), ContentHandler::makeParserOptions(), or ParserOptions::newCanonical() instead.
Parameters
User$user
Language$lang
Returns
ParserOptions
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$titleUsed to get the content language of the page (since r97636)
Returns
string Page rendering hash
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
ParserOptions::registerWatcher (   $callback)

Registers a callback for tracking which ParserOptions which are used. This is a private API with the parser.

Parameters
callable$callback
ParserOptions::setAllowExternalImages (   $x)

Allow all external images inline?

Parameters
bool | null$xNew value (null is no change)
Returns
bool Old value
ParserOptions::setAllowExternalImagesFrom (   $x)

External images to allow

When self::getAllowExternalImages() is false

Parameters
string|string[]|null$x New value (null is no change)
Returns
string|string[] Old value
ParserOptions::setAllowSpecialInclusion (   $x)

Allow inclusion of special pages?

Parameters
bool | null$xNew value (null is no change)
Returns
bool Old value
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
ParserOptions::setCleanSignatures (   $x)

Clean up signature texts?

See Also
Parser::cleanSig
Parameters
bool | null$xNew value (null is no change)
Returns
bool Old value
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
ParserOptions::setDateFormat (   $x)

Date format index

Parameters
string | null$xNew value (null is no change)
Returns
string Old value
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
ParserOptions::setEnableImageWhitelist (   $x)

Use the on-wiki external image whitelist?

Parameters
bool | null$xNew value (null is no change)
Returns
bool Old value
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
ParserOptions::setExternalLinkTarget (   $x)

Target attribute for external links

Parameters
string | null$xNew value (null is no change)
Returns
string Old value
ParserOptions::setInterfaceMessage (   $x)

Parsing an interface message?

Parameters
bool | null$xNew value (null is no change)
Returns
bool Old value
ParserOptions::setInterwikiMagic (   $x)

Specify whether to extract interlanguage links

Parameters
bool | null$xNew value (null is no change)
Returns
bool Old value
ParserOptions::setIsPreview (   $x)

Parsing the page for a "preview" operation?

Parameters
bool | null$xNew value (null is no change)
Returns
bool Old value
ParserOptions::setIsPrintable (   $x)

Parsing the printable version of the page?

Parameters
bool | null$xNew value (null is no change)
Returns
bool Old value
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
ParserOptions::setMaxGeneratedPPNodeCount (   $x)

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

Parameters
int | null$xNew value (null is no change)
Returns
int
ParserOptions::setMaxIncludeSize (   $x)

Maximum size of template expansions, in bytes

Parameters
int | null$xNew value (null is no change)
Returns
int Old value
ParserOptions::setMaxPPNodeCount (   $x)

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

Parameters
int | null$xNew value (null is no change)
Returns
int Old value
ParserOptions::setMaxTemplateDepth (   $x)

Maximum recursion depth for templates within templates

Parameters
int | null$xNew value (null is no change)
Returns
int Old value
ParserOptions::setNumberHeadings (   $x)

Automatically number headings?

Parameters
bool | null$xNew value (null is no change)
Returns
bool Old value
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
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
ParserOptions::setPreSaveTransform (   $x)

Transform wiki markup when saving the page?

Parameters
bool | null$xNew value (null is no change)
Returns
bool Old value
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
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
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
ParserOptions::setStubThreshold (   $x)

Thumb size preferred by the user.

Parameters
int | null$xNew value (null is no change)
Returns
int Old value
ParserOptions::setTargetLanguage (   $x)

Target language for the parse

Parameters
Language | null$xNew value
Returns
Language|null Old value
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
ParserOptions::setThumbSize (   $x)

Thumb size preferred by the user.

Parameters
int | null$xNew value (null is no change)
Returns
int Old value
ParserOptions::setTidy (   $x)

Use tidy to cleanup output HTML?

Parameters
bool | null$xNew value (null is no change)
Returns
bool Old value
ParserOptions::setTimestamp (   $x)

Timestamp used for {{CURRENTDAY}} etc.

Parameters
string | null$xNew value (null is no change)
Returns
string Old value
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
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
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

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