MediaWiki  REL1_31
ParserOutput Class Reference
Inheritance diagram for ParserOutput:
Collaboration diagram for ParserOutput:

Public Member Functions

 __construct ( $text='', $languageLinks=[], $categoryLinks=[], $unused=false, $titletext='')
 
 __sleep ()
 
 addCategory ( $c, $sort)
 
 addExternalLink ( $url)
 
 addHeadItem ( $section, $tag=false)
 Add some text to the "<head>". More...
 
 addImage ( $name, $timestamp=null, $sha1=null)
 Register a file dependency for this output. More...
 
 addInterwikiLink ( $title)
 
 addJsConfigVars ( $keys, $value=null)
 Add one or more variables to be set in mw.config in JavaScript. More...
 
 addLanguageLink ( $t)
 
 addLink (Title $title, $id=null)
 Record a local or interwiki inline link for saving in future link tables. More...
 
 addModules ( $modules)
 
 addModuleScripts ( $modules)
 
 addModuleStyles ( $modules)
 
 addOutputHook ( $hook, $data=false)
 
 addOutputPageMetadata (OutputPage $out)
 Copy items from the OutputPage object into this one. More...
 
 addTemplate ( $title, $page_id, $rev_id)
 Register a template dependency for this output. More...
 
 addTrackingCategory ( $msg, $title)
 Add a tracking category, getting the title from a system message, or print a debug message if the title is invalid. More...
 
 addWarning ( $s)
 
 finalizeAdaptiveCacheExpiry ()
 Call this when parsing is done to lower the TTL based on low parse times. More...
 
getCategories ()
 
 getCategoryLinks ()
 
 getDisplayTitle ()
 Get the title to be used for display. More...
 
 getEditSectionTokens ()
 
 getEnableOOUI ()
 
 getExtensionData ( $key)
 Gets extensions data previously attached to this ParserOutput using setExtensionData(). More...
 
getExternalLinks ()
 
getFileSearchOptions ()
 
 getFlag ( $flag)
 
 getHeadItems ()
 
 getHideNewSection ()
 
getImages ()
 
 getIndexPolicy ()
 
 getIndicators ()
 
 getInterwikiLinks ()
 
 getJsConfigVars ()
 
getLanguageLinks ()
 
 getLimitReportData ()
 
 getLimitReportJSData ()
 
getLinks ()
 
 getModules ()
 
 getModuleScripts ()
 
 getModuleStyles ()
 
 getNewSection ()
 
 getNoGallery ()
 
 getOutputHooks ()
 
 getProperties ()
 
 getProperty ( $name)
 
 getRawText ()
 Get the cacheable text with <mw:editsection> markers still in it. More...
 
 getSections ()
 
 getSpeculativeRevIdUsed ()
 
getTemplateIds ()
 
getTemplates ()
 
 getText ( $options=[])
 Get the output HTML. More...
 
 getTimeSinceStart ( $clock)
 Returns the time since resetParseStartTime() was last called. More...
 
 getTimestamp ()
 
 getTitleText ()
 
 getTOCEnabled ()
 
 getTOCHTML ()
 
 getUsedOptions ()
 Returns the options from its ParserOptions which have been taken into account to produce this output or false if not available. More...
 
 getWarnings ()
 
 hasDynamicContent ()
 Check whether the cache TTL was lowered due to dynamic content. More...
 
 hideNewSection ( $value)
 
 preventClickjacking ( $flag=null)
 Get or set the prevent-clickjacking flag. More...
 
 recordOption ( $option)
 Tags a parser option for use in the cache key for this parser output. More...
 
 resetParseStartTime ()
 Resets the parse start timestamps for future calls to getTimeSinceStart() More...
 
 setCategoryLinks ( $cl)
 
 setDisplayTitle ( $text)
 Override the title to be used for display. More...
 
 setEditSectionTokens ( $t)
 
 setEnableOOUI ( $enable=false)
 Enables OOUI, if true, in any OutputPage instance this ParserOutput object is added to. More...
 
 setExtensionData ( $key, $value)
 Attaches arbitrary data to this ParserObject. More...
 
 setFlag ( $flag)
 Fairly generic flag setter thingy. More...
 
 setIndexPolicy ( $policy)
 
 setIndicator ( $id, $content)
 
 setLanguageLinks ( $ll)
 
 setLimitReportData ( $key, $value)
 Sets parser limit report data for a key. More...
 
 setNewSection ( $value)
 
 setProperty ( $name, $value)
 Set a property to be stored in the page_props database table. More...
 
 setSections ( $toc)
 
 setSpeculativeRevIdUsed ( $id)
 
 setText ( $text)
 
 setTimestamp ( $timestamp)
 
 setTitleText ( $t)
 
 setTOCEnabled ( $flag)
 
 setTOCHTML ( $tochtml)
 
 unsetProperty ( $name)
 
 updateRuntimeAdaptiveExpiry ( $ttl)
 Lower the runtime adaptive TTL to at most this value. More...
 
- Public Member Functions inherited from CacheTime
 expired ( $touched)
 Return true if this cached output object predates the global or per-article cache invalidation timestamps, or if it comes from an incompatible older version. More...
 
 getCacheExpiry ()
 Returns the number of seconds after which this object should expire. More...
 
 getCacheRevisionId ()
 
 getCacheTime ()
 
 isCacheable ()
 
 isDifferentRevision ( $id)
 Return true if this cached output object is for a different revision of the page. More...
 
 setCacheRevisionId ( $id)
 
 setCacheTime ( $t)
 setCacheTime() sets the timestamp expressing when the page has been rendered. More...
 
 updateCacheExpiry ( $seconds)
 Sets the number of seconds after which this object should expire. More...
 

Static Public Member Functions

static isLinkInternal ( $internal, $url)
 Checks, if a url is pointing to the own server. More...
 

Public Attributes

 $mCategories
 
 $mEnableOOUI = false
 
 $mExternalLinks = []
 
 $mFileSearchOptions = []
 
 $mHeadItems = []
 
 $mHideNewSection = false
 
 $mImages = []
 
 $mIndicators = []
 
 $mInterwikiLinks = []
 
 $mJsConfigVars = []
 
 $mLanguageLinks
 
 $mLinks = []
 
 $mModules = []
 
 $mModuleScripts = []
 
 $mModuleStyles = []
 
 $mNewSection = false
 
 $mNoGallery = false
 
 $mOutputHooks = []
 
 $mProperties = []
 
 $mSections = []
 
 $mTemplateIds = []
 
 $mTemplates = []
 
 $mText
 
 $mTimestamp
 
 $mTitleText
 
 $mTOCHTML = ''
 
 $mWarnings = []
 
const EDITSECTION_REGEX
 
const FAST_AR_TTL = 60
 
const MIN_AR_TTL = 15
 
const PARSE_FAST_SEC = 0.100
 
const PARSE_SLOW_SEC = 1.0
 
const SLOW_AR_TTL = 3600
 
const SUPPORTS_STATELESS_TRANSFORMS = 1
 Feature flags to indicate to extensions that MediaWiki core supports and uses getText() stateless transforms. More...
 
const SUPPORTS_UNWRAP_TRANSFORM = 1
 
- Public Attributes inherited from CacheTime
 $mCacheExpiry = null
 
 $mCacheRevisionId = null
 
 $mCacheTime = ''
 
array bool $mUsedOptions
 ParserOptions which have been taken into account to produce output or false if not available. More...
 
 $mVersion = Parser::VERSION
 

Static Private Member Functions

static getTimes ( $clock=null)
 

Private Attributes

 $mAccessedOptions = []
 
 $mExtensionData = []
 
 $mFlags = []
 
 $mIndexPolicy = ''
 
 $mLimitReportData = []
 
array $mLimitReportJSData = []
 Parser limit report data for JSON. More...
 
int $mMaxAdaptiveExpiry = INF
 Upper bound of expiry based on parse duration. More...
 
 $mParseStartTime = []
 
 $mPreventClickjacking = false
 
int null $mSpeculativeRevId
 Assumed rev ID for {{REVISIONID}} if no revision is set. More...
 

Detailed Description

Definition at line 25 of file ParserOutput.php.

Constructor & Destructor Documentation

◆ __construct()

ParserOutput::__construct (   $text = '',
  $languageLinks = [],
  $categoryLinks = [],
  $unused = false,
  $titletext = '' 
)

Definition at line 230 of file ParserOutput.php.

Member Function Documentation

◆ __sleep()

ParserOutput::__sleep ( )

Definition at line 1213 of file ParserOutput.php.

◆ addCategory()

ParserOutput::addCategory (   $c,
  $sort 
)

Definition at line 567 of file ParserOutput.php.

References $sort.

Referenced by addTrackingCategory().

◆ addExternalLink()

ParserOutput::addExternalLink (   $url)

◆ addHeadItem()

ParserOutput::addHeadItem (   $section,
  $tag = false 
)

Add some text to the "<head>".

If $tag is set, the section with that tag will only be included once in a given page.

Parameters
string$section
string | bool$tag

Definition at line 741 of file ParserOutput.php.

References $section.

◆ addImage()

ParserOutput::addImage (   $name,
  $timestamp = null,
  $sha1 = null 
)

Register a file dependency for this output.

Parameters
string$nameTitle dbKey
string$timestampMW timestamp of file creation (or false if non-existing)
string$sha1Base 36 SHA-1 of file (or false if non-existing)
Returns
void

Definition at line 692 of file ParserOutput.php.

References $name.

◆ addInterwikiLink()

ParserOutput::addInterwikiLink (   $title)
Parameters
Title$titleTitle object, must be an interwiki link
Exceptions
MWExceptionIf given invalid input

Definition at line 723 of file ParserOutput.php.

References $title.

Referenced by addLink().

◆ addJsConfigVars()

ParserOutput::addJsConfigVars (   $keys,
  $value = null 
)

Add one or more variables to be set in mw.config in JavaScript.

Parameters
string | array$keysKey or array of key/value pairs.
mixed$value[optional] Value of the configuration variable.
Since
1.23

Definition at line 768 of file ParserOutput.php.

References $keys, $value, and as.

Referenced by addOutputPageMetadata().

◆ addLanguageLink()

ParserOutput::addLanguageLink (   $t)

Definition at line 591 of file ParserOutput.php.

References $t.

◆ addLink()

ParserOutput::addLink ( Title  $title,
  $id = null 
)

Record a local or interwiki inline link for saving in future link tables.

Parameters
Title$title
int | null$idOptional known page_id so we can skip the lookup

Definition at line 657 of file ParserOutput.php.

References $title, addInterwikiLink(), NS_FILE, NS_MEDIA, and NS_SPECIAL.

◆ addModules()

ParserOutput::addModules (   $modules)

Definition at line 749 of file ParserOutput.php.

References $modules, and array().

Referenced by addOutputPageMetadata().

◆ addModuleScripts()

ParserOutput::addModuleScripts (   $modules)

Definition at line 753 of file ParserOutput.php.

References $modules, and array().

Referenced by addOutputPageMetadata().

◆ addModuleStyles()

ParserOutput::addModuleStyles (   $modules)

Definition at line 757 of file ParserOutput.php.

References $modules, and array().

Referenced by addOutputPageMetadata().

◆ addOutputHook()

ParserOutput::addOutputHook (   $hook,
  $data = false 
)

Definition at line 599 of file ParserOutput.php.

◆ addOutputPageMetadata()

ParserOutput::addOutputPageMetadata ( OutputPage  $out)

◆ addTemplate()

ParserOutput::addTemplate (   $title,
  $page_id,
  $rev_id 
)

Register a template dependency for this output.

Parameters
Title$title
int$page_id
int$rev_id
Returns
void

Definition at line 706 of file ParserOutput.php.

References $title.

◆ addTrackingCategory()

ParserOutput::addTrackingCategory (   $msg,
  $title 
)

Add a tracking category, getting the title from a system message, or print a debug message if the title is invalid.

Any message used with this function should be registered so it will show up on Special:TrackingCategories. Core messages should be added to SpecialTrackingCategories::$coreTrackingCategories, and extensions should add to "TrackingCategories" in their extension.json.

Todo:
Migrate some code to TrackingCategories
Parameters
string$msgMessage key
Title$titletitle of the page which is being tracked
Returns
bool Whether the addition was successful
Since
1.25

Definition at line 810 of file ParserOutput.php.

References $title, addCategory(), Title\makeTitleSafe(), NS_CATEGORY, wfDebug(), and wfMessage().

◆ addWarning()

ParserOutput::addWarning (   $s)

Definition at line 595 of file ParserOutput.php.

References $s.

◆ finalizeAdaptiveCacheExpiry()

ParserOutput::finalizeAdaptiveCacheExpiry ( )

Call this when parsing is done to lower the TTL based on low parse times.

Since
1.28

Definition at line 1193 of file ParserOutput.php.

References FAST_AR_TTL, getTimeSinceStart(), and CacheTime\updateCacheExpiry().

◆ getCategories()

& ParserOutput::getCategories ( )

Definition at line 396 of file ParserOutput.php.

References $mCategories.

Referenced by LinksUpdate\__construct(), and SpecialExpandTemplates\showHtmlPreview().

◆ getCategoryLinks()

ParserOutput::getCategoryLinks ( )

◆ getDisplayTitle()

ParserOutput::getDisplayTitle ( )

Get the title to be used for display.

As per the contract of setDisplayTitle(), this is safe HTML, ready to be served to the client.

Returns
string HTML

Definition at line 861 of file ParserOutput.php.

References $t, and getTitleText().

◆ getEditSectionTokens()

ParserOutput::getEditSectionTokens ( )
Deprecated:
since 1.31 Use getText() options.

Definition at line 419 of file ParserOutput.php.

References wfDeprecated().

◆ getEnableOOUI()

ParserOutput::getEnableOOUI ( )

Definition at line 515 of file ParserOutput.php.

References $mEnableOOUI.

◆ getExtensionData()

ParserOutput::getExtensionData (   $key)

Gets extensions data previously attached to this ParserOutput using setExtensionData().

Typically, such data would be set while parsing the page, e.g. by a parser function.

Since
1.21
Parameters
string$keyThe key to look up.
Returns
mixed|null The value previously set for the given key using setExtensionData() or null if no value was set for this key.

Definition at line 1056 of file ParserOutput.php.

◆ getExternalLinks()

& ParserOutput::getExternalLinks ( )

◆ getFileSearchOptions()

& ParserOutput::getFileSearchOptions ( )

Definition at line 440 of file ParserOutput.php.

References $mFileSearchOptions.

◆ getFlag()

ParserOutput::getFlag (   $flag)

Definition at line 877 of file ParserOutput.php.

Referenced by ApiStashEdit\buildStashValue().

◆ getHeadItems()

ParserOutput::getHeadItems ( )

Definition at line 452 of file ParserOutput.php.

References $mHeadItems.

◆ getHideNewSection()

ParserOutput::getHideNewSection ( )

Definition at line 609 of file ParserOutput.php.

References $mHideNewSection.

◆ getImages()

& ParserOutput::getImages ( )

Definition at line 436 of file ParserOutput.php.

References $mImages.

Referenced by LinksUpdate\__construct().

◆ getIndexPolicy()

ParserOutput::getIndexPolicy ( )

Definition at line 484 of file ParserOutput.php.

References $mIndexPolicy.

◆ getIndicators()

ParserOutput::getIndicators ( )
Returns
array
Since
1.25

Definition at line 404 of file ParserOutput.php.

References $mIndicators.

◆ getInterwikiLinks()

ParserOutput::getInterwikiLinks ( )

Definition at line 388 of file ParserOutput.php.

References $mInterwikiLinks.

Referenced by LinksUpdate\__construct().

◆ getJsConfigVars()

ParserOutput::getJsConfigVars ( )
Returns
array
Since
1.23

Definition at line 472 of file ParserOutput.php.

References $mJsConfigVars.

◆ getLanguageLinks()

& ParserOutput::getLanguageLinks ( )

Definition at line 384 of file ParserOutput.php.

References $mLanguageLinks.

Referenced by LinksUpdate\__construct().

◆ getLimitReportData()

ParserOutput::getLimitReportData ( )

Definition at line 499 of file ParserOutput.php.

References $mLimitReportData.

◆ getLimitReportJSData()

ParserOutput::getLimitReportJSData ( )

Definition at line 503 of file ParserOutput.php.

References $mLimitReportJSData.

◆ getLinks()

& ParserOutput::getLinks ( )

◆ getModules()

ParserOutput::getModules ( )

Definition at line 456 of file ParserOutput.php.

References $mModules.

◆ getModuleScripts()

ParserOutput::getModuleScripts ( )

Definition at line 460 of file ParserOutput.php.

References $mModuleScripts.

◆ getModuleStyles()

ParserOutput::getModuleStyles ( )

Definition at line 464 of file ParserOutput.php.

References $mModuleStyles.

◆ getNewSection()

ParserOutput::getNewSection ( )

Definition at line 612 of file ParserOutput.php.

References $mNewSection.

◆ getNoGallery()

ParserOutput::getNoGallery ( )

Definition at line 448 of file ParserOutput.php.

References $mNoGallery.

◆ getOutputHooks()

ParserOutput::getOutputHooks ( )

Definition at line 476 of file ParserOutput.php.

References $mOutputHooks, and array().

◆ getProperties()

ParserOutput::getProperties ( )

Definition at line 962 of file ParserOutput.php.

References $mProperties.

Referenced by LinksUpdate\__construct().

◆ getProperty()

ParserOutput::getProperty (   $name)
Parameters
string$nameThe property name to look up.
Returns
mixed|bool The value previously set using setProperty(). False if null or no value was set for the given property name.
Note
You need to use getProperties() to check for boolean and null properties.

Definition at line 954 of file ParserOutput.php.

References $name.

◆ getRawText()

ParserOutput::getRawText ( )

Get the cacheable text with <mw:editsection> markers still in it.

The return value is suitable for writing back via setText() but is not valid for display to the user.

Returns
string
Since
1.27

Definition at line 247 of file ParserOutput.php.

References $mText.

◆ getSections()

ParserOutput::getSections ( )

Definition at line 412 of file ParserOutput.php.

References $mSections.

◆ getSpeculativeRevIdUsed()

ParserOutput::getSpeculativeRevIdUsed ( )
Returns
int|null
Since
1.28

Definition at line 380 of file ParserOutput.php.

References $mSpeculativeRevId.

◆ getTemplateIds()

& ParserOutput::getTemplateIds ( )

Definition at line 432 of file ParserOutput.php.

References $mTemplateIds.

◆ getTemplates()

& ParserOutput::getTemplates ( )

◆ getText()

ParserOutput::getText (   $options = [])

Get the output HTML.

Parameters
array$options(since 1.31) Transformations to apply to the HTML
  • allowTOC: (bool) Show the TOC, assuming there were enough headings to generate one and __NOTOC__ wasn't used. Default is true, but might be statefully overridden.
  • enableSectionEditLinks: (bool) Include section edit links, assuming section edit link tokens are present in the HTML. Default is true, but might be statefully overridden.
  • unwrap: (bool) Remove a wrapping mw-parser-output div. Default is false.
  • deduplicateStyles: (bool) When true, which is the default, <style> tags with the data-mw-deduplicate attribute set are deduplicated by value of the attribute: all but the first will be replaced by <link rel="mw-deduplicated-inline-style" href="mw-data:..."/> tags, where the scheme-specific-part of the href is the (percent-encoded) value of the data-mw-deduplicate attribute.
Returns
string HTML

Definition at line 270 of file ParserOutput.php.

References $mText, $options, $skin, $wgLang, $wgOut, Html\closeElement(), Sanitizer\decodeCharReferences(), Sanitizer\decodeTagAttributes(), Html\element(), global, Title\newFromText(), Html\openElement(), Hooks\runWithoutAbort(), Parser\TOC_END, Parser\TOC_START, use, and wfUrlencode().

◆ getTimes()

static ParserOutput::getTimes (   $clock = null)
staticprivate

Definition at line 1064 of file ParserOutput.php.

References $ret, and wfGetRusage().

Referenced by getTimeSinceStart(), and resetParseStartTime().

◆ getTimeSinceStart()

array $mParseStartTime Timestamps for ParserOutput::getTimeSinceStart (   $clock)

Returns the time since resetParseStartTime() was last called.

Clocks available are:

  • wall: Wall clock time
  • cpu: CPU time (requires getrusage)
Since
1.22
Parameters
string$clock
Returns
float|null

Definition at line 1098 of file ParserOutput.php.

References getTimes().

Referenced by finalizeAdaptiveCacheExpiry().

◆ getTimestamp()

ParserOutput::getTimestamp ( )
Returns
string|null TS_MW timestamp of the revision content

Definition at line 495 of file ParserOutput.php.

References $mTimestamp.

Referenced by ApiStashEdit\buildStashValue().

◆ getTitleText()

ParserOutput::getTitleText ( )

Definition at line 408 of file ParserOutput.php.

References $mTitleText.

Referenced by Article\adjustDisplayTitle(), and getDisplayTitle().

◆ getTOCEnabled()

ParserOutput::getTOCEnabled ( )
Deprecated:
since 1.31 Use getText() options.

Definition at line 510 of file ParserOutput.php.

References wfDeprecated().

◆ getTOCHTML()

ParserOutput::getTOCHTML ( )

Definition at line 488 of file ParserOutput.php.

References $mTOCHTML.

◆ getUsedOptions()

ParserOutput::getUsedOptions ( )

Returns the options from its ParserOptions which have been taken into account to produce this output or false if not available.

Returns
array

Definition at line 974 of file ParserOutput.php.

◆ getWarnings()

ParserOutput::getWarnings ( )

Definition at line 480 of file ParserOutput.php.

◆ hasDynamicContent()

ParserOutput::hasDynamicContent ( )

Check whether the cache TTL was lowered due to dynamic content.

When content is determined by more than hard state (e.g. page edits), such as template/file transclusions based on the current timestamp or extension tags that generate lists based on queries, this return true.

Returns
bool
Since
1.25

Definition at line 1160 of file ParserOutput.php.

References $wgParserCacheExpireTime, CacheTime\getCacheExpiry(), and global.

Referenced by WikiPage\triggerOpportunisticLinksUpdate().

◆ hideNewSection()

ParserOutput::hideNewSection (   $value)

Definition at line 606 of file ParserOutput.php.

References $value.

◆ isLinkInternal()

static ParserOutput::isLinkInternal (   $internal,
  $url 
)
static

Checks, if a url is pointing to the own server.

Parameters
string$internalThe server to check against
string$urlThe url to check
Returns
bool

Definition at line 623 of file ParserOutput.php.

References check, http, https, in, is(), link, links, of, or, query, and server.

Referenced by addExternalLink(), and ParserOutputTest\testIsLinkInternal().

◆ preventClickjacking()

ParserOutput::preventClickjacking (   $flag = null)

Get or set the prevent-clickjacking flag.

Since
1.24
Parameters
bool | null$flagNew flag value, or null to leave it unchanged
Returns
bool Old flag value

Definition at line 1173 of file ParserOutput.php.

References wfSetVar().

◆ recordOption()

ParserOutput::recordOption (   $option)

Tags a parser option for use in the cache key for this parser output.

Registered as a watcher at ParserOptions::registerWatcher() by Parser::clearState(). The information gathered here is available via getUsedOptions(), and is used by ParserCache::save().

See also
ParserCache::getKey
ParserCache::save
ParserOptions::addExtraKey
ParserOptions::optionsHash
Parameters
string$option

Definition at line 993 of file ParserOutput.php.

◆ resetParseStartTime()

ParserOutput::resetParseStartTime ( )

Resets the parse start timestamps for future calls to getTimeSinceStart()

Since
1.22

Definition at line 1083 of file ParserOutput.php.

References getTimes().

◆ setCategoryLinks()

ParserOutput::setCategoryLinks (   $cl)

Definition at line 527 of file ParserOutput.php.

References wfSetVar().

◆ setDisplayTitle()

ParserOutput::setDisplayTitle (   $text)

Override the title to be used for display.

Note
this is assumed to have been validated (check equal normalisation, etc.)
this is expected to be safe HTML, ready to be served to the client.
Parameters
string$textDesired title text

Definition at line 848 of file ParserOutput.php.

References setProperty(), and setTitleText().

◆ setEditSectionTokens()

ParserOutput::setEditSectionTokens (   $t)
Deprecated:
since 1.31 Use getText() options.

Definition at line 542 of file ParserOutput.php.

References wfDeprecated().

◆ setEnableOOUI()

ParserOutput::setEnableOOUI (   $enable = false)

Enables OOUI, if true, in any OutputPage instance this ParserOutput object is added to.

Since
1.26
Parameters
bool$enableIf OOUI should be enabled or not

Definition at line 587 of file ParserOutput.php.

◆ setExtensionData()

ParserOutput::setExtensionData (   $key,
  $value 
)

Attaches arbitrary data to this ParserObject.

This can be used to store some information in the ParserOutput object for later use during page output. The data will be cached along with the ParserOutput object, but unlike data set using setProperty(), it is not recorded in the database.

This method is provided to overcome the unsafe practice of attaching extra information to a ParserObject by directly assigning member variables.

To use setExtensionData() to pass extension information from a hook inside the parser to a hook in the page output, use this in the parser hook:

Example:
$parser->getOutput()->setExtensionData( 'my_ext_foo', '...' );

And then later, in OutputPageParserOutput or similar:

Example:
$output->getExtensionData( 'my_ext_foo' );

In MediaWiki 1.20 and older, you have to use a custom member variable within the ParserOutput object:

Example:
$parser->getOutput()->my_ext_foo = '...';
Since
1.21
Parameters
string$keyThe key for accessing the data. Extensions should take care to avoid conflicts in naming keys. It is suggested to use the extension's name as a prefix.
mixed$valueThe value to set. Setting a value to null is equivalent to removing the value.

Definition at line 1037 of file ParserOutput.php.

References $value.

◆ setFlag()

ParserOutput::setFlag (   $flag)

Fairly generic flag setter thingy.

Parameters
string$flag

Definition at line 873 of file ParserOutput.php.

◆ setIndexPolicy()

ParserOutput::setIndexPolicy (   $policy)

Definition at line 547 of file ParserOutput.php.

References wfSetVar().

◆ setIndicator()

ParserOutput::setIndicator (   $id,
  $content 
)
Parameters
string$id
string$content
Since
1.25

Definition at line 576 of file ParserOutput.php.

◆ setLanguageLinks()

ParserOutput::setLanguageLinks (   $ll)

Definition at line 523 of file ParserOutput.php.

References wfSetVar().

◆ setLimitReportData()

ParserOutput::setLimitReportData (   $key,
  $value 
)

Sets parser limit report data for a key.

The key is used as the prefix for various messages used for formatting:

  • $key: The label for the field in the limit report
  • $key-value-text: Message used to format the value in the "NewPP limit report" HTML comment. If missing, uses $key-format.
  • $key-value-html: Message used to format the value in the preview limit report table. If missing, uses $key-format.
  • $key-value: Message used to format the value. If missing, uses "$1".

Note that all values are interpreted as wikitext, and so should be encoded with htmlspecialchars() as necessary, but should avoid complex HTML for sanity of display in the "NewPP limit report" comment.

Since
1.22
Parameters
string$keyMessage key
mixed$valueAppropriate for Message::params()

Definition at line 1126 of file ParserOutput.php.

References $name, $value, and list.

◆ setNewSection()

ParserOutput::setNewSection (   $value)

Definition at line 603 of file ParserOutput.php.

References $value.

◆ setProperty()

ParserOutput::setProperty (   $name,
  $value 
)

Set a property to be stored in the page_props database table.

page_props is a key value store indexed by the page ID. This allows the parser to set a property on a page which can then be quickly retrieved given the page ID or via a DB join when given the page title.

Since 1.23, page_props are also indexed by numeric value, to allow for efficient "top k" queries of pages wrt a given property.

setProperty() is thus used to propagate properties from the parsed page to request contexts other than a page view of the currently parsed article.

Some applications examples:

  • To implement hidden categories, hiding pages from category listings by storing a property.
  • Overriding the displayed article title.
    See also
    ParserOutput::setDisplayTitle()
  • To implement image tagging, for example displaying an icon on an image thumbnail to indicate that it is listed for deletion on Wikimedia Commons. This is not actually implemented, yet but would be pretty cool.
Note
Do not use setProperty() to set a property which is only used in a context where the ParserOutput object itself is already available, for example a normal page view. There is no need to save such a property in the database since the text is already parsed. You can just hook OutputPageParserOutput and get your data out of the ParserOutput object.

If you are writing an extension where you want to set a property in the parser which is used by an OutputPageParserOutput hook, you have to associate the extension data directly with the ParserOutput object. Since MediaWiki 1.21, you can use setExtensionData() to do this:

Example:
$parser->getOutput()->setExtensionData( 'my_ext_foo', '...' );

And then later, in OutputPageParserOutput or similar:

Example:
$output->getExtensionData( 'my_ext_foo' );

In MediaWiki 1.20 and older, you have to use a custom member variable within the ParserOutput object:

Example:
$parser->getOutput()->my_ext_foo = '...';
Parameters
string$name
mixed$value

Definition at line 942 of file ParserOutput.php.

References $name, and $value.

Referenced by setDisplayTitle().

◆ setSections()

ParserOutput::setSections (   $toc)

Definition at line 535 of file ParserOutput.php.

References wfSetVar().

◆ setSpeculativeRevIdUsed()

ParserOutput::setSpeculativeRevIdUsed (   $id)
Parameters
int$id
Since
1.28

Definition at line 372 of file ParserOutput.php.

◆ setText()

◆ setTimestamp()

ParserOutput::setTimestamp (   $timestamp)

Definition at line 555 of file ParserOutput.php.

References wfSetVar().

◆ setTitleText()

ParserOutput::setTitleText (   $t)

Definition at line 531 of file ParserOutput.php.

References $t, and wfSetVar().

Referenced by setDisplayTitle().

◆ setTOCEnabled()

ParserOutput::setTOCEnabled (   $flag)
Deprecated:
since 1.31 Use getText() options.

Definition at line 562 of file ParserOutput.php.

References wfDeprecated().

◆ setTOCHTML()

ParserOutput::setTOCHTML (   $tochtml)

Definition at line 551 of file ParserOutput.php.

References wfSetVar().

◆ unsetProperty()

ParserOutput::unsetProperty (   $name)

Definition at line 958 of file ParserOutput.php.

References $name.

◆ updateRuntimeAdaptiveExpiry()

ParserOutput::updateRuntimeAdaptiveExpiry (   $ttl)

Lower the runtime adaptive TTL to at most this value.

Parameters
int$ttl
Since
1.28

Definition at line 1183 of file ParserOutput.php.

References CacheTime\updateCacheExpiry().

Member Data Documentation

◆ $mAccessedOptions

ParserOutput::$mAccessedOptions = []
private

Definition at line 182 of file ParserOutput.php.

◆ $mCategories

ParserOutput::$mCategories

Definition at line 47 of file ParserOutput.php.

Referenced by getCategories().

◆ $mEnableOOUI

ParserOutput::$mEnableOOUI = false

Definition at line 172 of file ParserOutput.php.

Referenced by getEnableOOUI().

◆ $mExtensionData

ParserOutput::$mExtensionData = []
private

Definition at line 187 of file ParserOutput.php.

◆ $mExternalLinks

ParserOutput::$mExternalLinks = []

Definition at line 90 of file ParserOutput.php.

Referenced by getExternalLinks().

◆ $mFileSearchOptions

ParserOutput::$mFileSearchOptions = []

Definition at line 85 of file ParserOutput.php.

Referenced by getFileSearchOptions().

◆ $mFlags

ParserOutput::$mFlags = []
private

Definition at line 210 of file ParserOutput.php.

◆ $mHeadItems

ParserOutput::$mHeadItems = []

Definition at line 116 of file ParserOutput.php.

Referenced by getHeadItems().

◆ $mHideNewSection

ParserOutput::$mHideNewSection = false

Definition at line 106 of file ParserOutput.php.

Referenced by getHideNewSection().

◆ $mImages

ParserOutput::$mImages = []

Definition at line 80 of file ParserOutput.php.

Referenced by getImages().

◆ $mIndexPolicy

ParserOutput::$mIndexPolicy = ''
private

Definition at line 177 of file ParserOutput.php.

Referenced by getIndexPolicy().

◆ $mIndicators

ParserOutput::$mIndicators = []

Definition at line 52 of file ParserOutput.php.

Referenced by getIndicators().

◆ $mInterwikiLinks

ParserOutput::$mInterwikiLinks = []

Definition at line 96 of file ParserOutput.php.

Referenced by getInterwikiLinks().

◆ $mJsConfigVars

ParserOutput::$mJsConfigVars = []

Definition at line 136 of file ParserOutput.php.

Referenced by getJsConfigVars().

◆ $mLanguageLinks

ParserOutput::$mLanguageLinks

Definition at line 42 of file ParserOutput.php.

Referenced by getLanguageLinks().

◆ $mLimitReportData

ParserOutput::$mLimitReportData = []
private

Definition at line 192 of file ParserOutput.php.

Referenced by getLimitReportData().

◆ $mLimitReportJSData

array ParserOutput::$mLimitReportJSData = []
private

Parser limit report data for JSON.

Definition at line 195 of file ParserOutput.php.

Referenced by getLimitReportJSData().

◆ $mLinks

ParserOutput::$mLinks = []

Definition at line 63 of file ParserOutput.php.

Referenced by getLinks().

◆ $mMaxAdaptiveExpiry

int ParserOutput::$mMaxAdaptiveExpiry = INF
private

Upper bound of expiry based on parse duration.

Definition at line 216 of file ParserOutput.php.

◆ $mModules

ParserOutput::$mModules = []

Definition at line 121 of file ParserOutput.php.

Referenced by getModules().

◆ $mModuleScripts

ParserOutput::$mModuleScripts = []

Definition at line 126 of file ParserOutput.php.

Referenced by getModuleScripts().

◆ $mModuleStyles

ParserOutput::$mModuleStyles = []

Definition at line 131 of file ParserOutput.php.

Referenced by getModuleStyles().

◆ $mNewSection

ParserOutput::$mNewSection = false

Definition at line 101 of file ParserOutput.php.

Referenced by getNewSection().

◆ $mNoGallery

ParserOutput::$mNoGallery = false

Definition at line 111 of file ParserOutput.php.

Referenced by getNoGallery().

◆ $mOutputHooks

ParserOutput::$mOutputHooks = []

Definition at line 141 of file ParserOutput.php.

Referenced by getOutputHooks().

◆ $mParseStartTime

ParserOutput::$mParseStartTime = []
private

Definition at line 200 of file ParserOutput.php.

◆ $mPreventClickjacking

ParserOutput::$mPreventClickjacking = false
private

Definition at line 205 of file ParserOutput.php.

◆ $mProperties

ParserOutput::$mProperties = []

Definition at line 157 of file ParserOutput.php.

Referenced by getProperties().

◆ $mSections

ParserOutput::$mSections = []

Definition at line 152 of file ParserOutput.php.

Referenced by getSections().

◆ $mSpeculativeRevId

int null ParserOutput::$mSpeculativeRevId
private

Assumed rev ID for {{REVISIONID}} if no revision is set.

Definition at line 213 of file ParserOutput.php.

Referenced by getSpeculativeRevIdUsed().

◆ $mTemplateIds

ParserOutput::$mTemplateIds = []

Definition at line 75 of file ParserOutput.php.

Referenced by getTemplateIds().

◆ $mTemplates

ParserOutput::$mTemplates = []

Definition at line 69 of file ParserOutput.php.

Referenced by getTemplates().

◆ $mText

ParserOutput::$mText

Definition at line 36 of file ParserOutput.php.

Referenced by getRawText(), and getText().

◆ $mTimestamp

ParserOutput::$mTimestamp

Definition at line 167 of file ParserOutput.php.

Referenced by getTimestamp().

◆ $mTitleText

ParserOutput::$mTitleText

Definition at line 57 of file ParserOutput.php.

Referenced by getTitleText().

◆ $mTOCHTML

ParserOutput::$mTOCHTML = ''

Definition at line 162 of file ParserOutput.php.

Referenced by getTOCHTML().

◆ $mWarnings

ParserOutput::$mWarnings = []

Definition at line 147 of file ParserOutput.php.

◆ EDITSECTION_REGEX

const ParserOutput::EDITSECTION_REGEX
Initial value:
=
'#<(?:mw:)?editsection page="(.*?)" section="(.*?)"(?:/>|>(.*?)(</(?:mw:)?editsection>))#s'

Definition at line 218 of file ParserOutput.php.

Referenced by MediaWiki\Tidy\RaggettWrapper\getWrapped().

◆ FAST_AR_TTL

const ParserOutput::FAST_AR_TTL = 60

Definition at line 226 of file ParserOutput.php.

Referenced by finalizeAdaptiveCacheExpiry().

◆ MIN_AR_TTL

const ParserOutput::MIN_AR_TTL = 15

Definition at line 228 of file ParserOutput.php.

◆ PARSE_FAST_SEC

const ParserOutput::PARSE_FAST_SEC = 0.100

Definition at line 224 of file ParserOutput.php.

◆ PARSE_SLOW_SEC

const ParserOutput::PARSE_SLOW_SEC = 1.0

Definition at line 225 of file ParserOutput.php.

◆ SLOW_AR_TTL

const ParserOutput::SLOW_AR_TTL = 3600

Definition at line 227 of file ParserOutput.php.

◆ SUPPORTS_STATELESS_TRANSFORMS

const ParserOutput::SUPPORTS_STATELESS_TRANSFORMS = 1

Feature flags to indicate to extensions that MediaWiki core supports and uses getText() stateless transforms.

Definition at line 30 of file ParserOutput.php.

◆ SUPPORTS_UNWRAP_TRANSFORM

const ParserOutput::SUPPORTS_UNWRAP_TRANSFORM = 1

Definition at line 31 of file ParserOutput.php.


The documentation for this class was generated from the following file:
$output
static configuration should be added through ResourceLoaderGetConfigVars instead can be used to get the real title after the basic globals have been set but before ordinary actions take place $output
Definition: hooks.txt:2255
$parser
do that in ParserLimitReportFormat instead $parser
Definition: hooks.txt:2603