BlueSpice MediaWiki REL1_27
 All Classes Namespaces Files Functions Variables Groups Pages
ParserOutput Class Reference
Inheritance diagram for ParserOutput:
Collaboration diagram for ParserOutput:

Public Member Functions

 __construct ($text= '', $languageLinks=[], $categoryLinks=[], $unused=false, $titletext= '')
 
 getRawText ()
 
 getText ()
 
getLanguageLinks ()
 
 getInterwikiLinks ()
 
 getCategoryLinks ()
 
getCategories ()
 
 getIndicators ()
 
 getTitleText ()
 
 getSections ()
 
 getEditSectionTokens ()
 
getLinks ()
 
getTemplates ()
 
getTemplateIds ()
 
getImages ()
 
getFileSearchOptions ()
 
getExternalLinks ()
 
 getNoGallery ()
 
 getHeadItems ()
 
 getModules ()
 
 getModuleScripts ()
 
 getModuleStyles ()
 
 getModuleMessages ()
 
 getJsConfigVars ()
 
 getOutputHooks ()
 
 getWarnings ()
 
 getIndexPolicy ()
 
 getTOCHTML ()
 
 getTimestamp ()
 
 getLimitReportData ()
 
 getTOCEnabled ()
 
 getEnableOOUI ()
 
 setText ($text)
 
 setLanguageLinks ($ll)
 
 setCategoryLinks ($cl)
 
 setTitleText ($t)
 
 setSections ($toc)
 
 setEditSectionTokens ($t)
 
 setIndexPolicy ($policy)
 
 setTOCHTML ($tochtml)
 
 setTimestamp ($timestamp)
 
 setTOCEnabled ($flag)
 
 addCategory ($c, $sort)
 
 setIndicator ($id, $content)
 
 setEnableOOUI ($enable=false)
 
 addLanguageLink ($t)
 
 addWarning ($s)
 
 addOutputHook ($hook, $data=false)
 
 setNewSection ($value)
 
 hideNewSection ($value)
 
 getHideNewSection ()
 
 getNewSection ()
 
 addExternalLink ($url)
 
 addLink (Title $title, $id=null)
 
 addImage ($name, $timestamp=null, $sha1=null)
 
 addTemplate ($title, $page_id, $rev_id)
 
 addInterwikiLink ($title)
 
 addHeadItem ($section, $tag=false)
 
 addModules ($modules)
 
 addModuleScripts ($modules)
 
 addModuleStyles ($modules)
 
 addModuleMessages ($modules)
 
 addJsConfigVars ($keys, $value=null)
 
 addOutputPageMetadata (OutputPage $out)
 
 addTrackingCategory ($msg, $title)
 
 setDisplayTitle ($text)
 
 getDisplayTitle ()
 
 setFlag ($flag)
 
 getFlag ($flag)
 
 setProperty ($name, $value)
 
 getProperty ($name)
 
 unsetProperty ($name)
 
 getProperties ()
 
 getUsedOptions ()
 
 recordOption ($option)
 
 setExtensionData ($key, $value)
 
 getExtensionData ($key)
 
 resetParseStartTime ()
 
 getTimeSinceStart ($clock)
 
 setLimitReportData ($key, $value)
 
 hasDynamicContent ()
 
 preventClickjacking ($flag=null)
 
 __sleep ()
 
- Public Member Functions inherited from CacheTime
 getCacheTime ()
 
 setCacheTime ($t)
 
 getCacheRevisionId ()
 
 setCacheRevisionId ($id)
 
 updateCacheExpiry ($seconds)
 
 getCacheExpiry ()
 
 isCacheable ()
 
 expired ($touched)
 
 isDifferentRevision ($id)
 

Static Public Member Functions

static isLinkInternal ($internal, $url)
 

Public Attributes

 $mText
 
 $mLanguageLinks
 
 $mCategories
 
 $mIndicators = []
 
 $mTitleText
 
 $mLinks = []
 
 $mTemplates = []
 
 $mTemplateIds = []
 
 $mImages = []
 
 $mFileSearchOptions = []
 
 $mExternalLinks = []
 
 $mInterwikiLinks = []
 
 $mNewSection = false
 
 $mHideNewSection = false
 
 $mNoGallery = false
 
 $mHeadItems = []
 
 $mModules = []
 
 $mModuleScripts = []
 
 $mModuleStyles = []
 
 $mJsConfigVars = []
 
 $mOutputHooks = []
 
 $mWarnings = []
 
 $mSections = []
 
 $mEditSectionTokens = false
 
 $mProperties = []
 
 $mTOCHTML = ''
 
 $mTimestamp
 
 $mTOCEnabled = true
 
 $mEnableOOUI = false
 
const EDITSECTION_REGEX
 
- Public Attributes inherited from CacheTime
 $mUsedOptions
 
 $mVersion = Parser::VERSION
 
 $mCacheTime = ''
 
 $mCacheExpiry = null
 
 $mCacheRevisionId = null
 

Member Function Documentation

ParserOutput::__sleep ( )

Save space for serialization by removing useless values

Returns
array
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
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
ParserOutput::addInterwikiLink (   $title)
Parameters
Title$titleTitle object, must be an interwiki link
Exceptions
MWExceptionIf given invalid input
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
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
ParserOutput::addModuleMessages (   $modules)
Deprecated:
since 1.26 Use addModules() instead
Parameters
string | array$modules
ParserOutput::addOutputPageMetadata ( OutputPage  $out)

Copy items from the OutputPage object into this one

Parameters
OutputPage$out
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
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.

Parameters
string$msgMessage key
Title$titletitle of the page which is being tracked
Returns
bool Whether the addition was successful
Since
1.25
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
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.
ParserOutput::getIndicators ( )
Since
1.25
ParserOutput::getJsConfigVars ( )
Since
1.23
ParserOutput::getModuleMessages ( )
Deprecated:
since 1.26 Obsolete
Returns
array
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.
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.

Since
1.27
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
ParserOutput::getTimestamp ( )
Returns
string|null TS_MW timestamp of the revision content
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
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
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
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
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
ParserOutput::resetParseStartTime ( )

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

Since
1.22
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
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
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.
ParserOutput::setFlag (   $flag)

Fairly generic flag setter thingy.

Parameters
string$flag
ParserOutput::setIndicator (   $id,
  $content 
)
Since
1.25
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()
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 = '...';

Member Data Documentation

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

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