Parsoid
A bidirectional parser between wikitext and HTML5
Loading...
Searching...
No Matches
Wikimedia\Parsoid\Config\StubMetadataCollector Class Reference

Minimal implementation of a ContentMetadataCollector which just records all metadata in an array. More...

+ Inheritance diagram for Wikimedia\Parsoid\Config\StubMetadataCollector:
+ Collaboration diagram for Wikimedia\Parsoid\Config\StubMetadataCollector:

Public Member Functions

 __construct (SiteConfig $siteConfig)
 
 addCategory ( $c, $sort='')
 Add a category, with the given sort key.
Parameters
LinkTarget$cCategory name
string$sortSort key (pass the empty string to use the default)

 
 addWarningMsg (string $msg,... $args)
 Add a warning to the output for this page.
Parameters
string$msgThe localization message key for the warning
mixed...$args Optional arguments for the message

 
 addExternalLink (string $url)
 
Parameters
string$urlExternal link URL

 
 getExternalLinks ()
 
 setOutputFlag (string $name, bool $value=true)
 Provides a uniform interface to various boolean flags stored in the content metadata.Flags internal to MediaWiki core should have names which are constants in ParserOutputFlags. Extensions should use setExtensionData() rather than creating new flags with setOutputFlag() in order to prevent namespace conflicts.
Parameters
string$nameA flag name
bool$val

 
 appendOutputStrings (string $name, array $value)
 Provides a uniform interface to various appendable lists of strings stored in the content metadata.Strings internal to MediaWiki core should have names which are constants in ParserOutputStrings. Extensions should use setExtensionData() rather than creating new keys here in order to prevent namespace conflicts.
Parameters
string$nameA string name
string[]$value

 
 setUnsortedPageProperty (string $propName, string $value='')
 Set a page property whose value is not intended to be sorted and indexed.It is still possible to efficiently look up all the pages with a certain property (the "presence" of the property is indexed; see Special:PagesWithProp, list=pageswithprop).The page property is stored in the page_props database table. The page_props table is a key-value store indexed by the page ID. This allows the parser to set a property on a page whose value can then be quickly retrieved given the page ID or via a DB join when given the page title.The setUnsortedPageProperty() method 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 page property.
  • Overriding the displayed article title (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.)
It is recommended to use the empty string if you need a placeholder value (ie, if it is the presence of the property which is important, not the value the property is set to).
Note
Do not use setUnsortedPageProperty() 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; use setExtensionData() instead.
Example:
$parser->getOutput()->setExtensionData( 'my_ext_foo', '...' );

And then later, in the OutputPageParserOutput hook or similar:

Example:
$output->getExtensionData( 'my_ext_foo' );
Parameters
string$propNameThe name of the page property
string$valueOptional value; defaults to the empty string.
Since
1.42

 
 setNumericPageProperty (string $propName, $numericValue)
 Set a numeric page property whose value is intended to be sorted and indexed.The sort key used for the property will be the value, coerced to a number. It is also possible to efficiently look up all the pages with a certain property (the "presence" of the property is also indexed; see Special:PagesWithProp, list=pageswithprop).The page property is stored in the page_props database table. The page_props table is a key-value store indexed by the page ID. This allows the parser to set a property on a page whose value can then be quickly retrieved given the page ID or via a DB join when given the page title. The page_props table is also indexed on the numeric sort key passed as $numericValue to this method. This allows for efficient "top k" queries of pages with respect to a given property.In the future, we may allow the value to be specified independent of sort key (T357783).The setNumericPageProperty() method 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:
  • The Proofread page extension stores proofread_page_quality_level as a numeric property to allow efficient retrieval of pages of a certain quality level.
  • Keeping a count of the number of errors found in a page property to allow listing pages in order from most errors to least.
If you need a placeholder value, you likely should be using setUnsortedPageProperty() instead.
Note
Note that the PageProp service always returns strings for the value of the page property, while values retrieved from this ParserOutput will be numeric. Be careful to distinguish these two cases.
Do not use setNumericPageProperty() 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; use setExtensionData() instead.
Example:
$parser->getOutput()->setExtensionData( 'my_ext_foo', '...' );

And then later, in the OutputPageParserOutput hook or similar:

Example:
$output->getExtensionData( 'my_ext_foo' );
Parameters
string$propNameThe name of the page property
int | float | string$numericValuethe numeric value
Since
1.42

 
 setExtensionData (string $key, $value)
 Attaches arbitrary data to this content.This can be used to store some information for later use during page output. The data will be cached along with the parsed page, but unlike data set using set*PageProperty(), it is not recorded in the database.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' );
Note
Only scalar values, e.g. numbers, strings, arrays or MediaWiki\Json\JsonUnserializable instances are supported as a value. Attempt to set other class instance as a extension data will break ParserCache for the page.
As with setJsConfigVar(), setting a page property to multiple conflicting values during the parse is not supported.
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. Keys beginning with mw- are reserved for use by mediawiki core.
mixed$valueThe value to set. Setting a value to null is equivalent to removing the value.

 
 setJsConfigVar (string $key, $value)
 Add a variable to be set in mw.config in JavaScript.In order to ensure the result is independent of the parse order, the values set here must be unique – that is, you can pass the same $key multiple times but ONLY if the $value is identical each time. If you want to collect multiple pieces of data under a single key, use appendJsConfigVar().
Parameters
string$keyKey to use under mw.config
mixed | null$valueValue of the configuration variable.

 
 appendExtensionData (string $key, $value, string $strategy=self::MERGE_STRATEGY_UNION)
 Appends 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 set*PageProperty(), it is not recorded in the database.See setExtensionData() for more details on rationale and use.In order to provide for out-of-order/asynchronous/incremental parsing, this method appends values to a set. See setExtensionData() for the flag-like version of this method.
Note
Only values which can be array keys are currently supported as values. Be aware that array keys which 'look like' numbers are converted to ints by PHP, and so if you put in "0" as a value you will get [0=>true] out.
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.
int | string$valueThe value to append to the list.
string$strategyMerge strategy: only MW_MERGE_STRATEGY_UNION is currently supported and external callers should treat this parameter as

 
 appendJsConfigVar (string $key, string $value, string $strategy=self::MERGE_STRATEGY_UNION)
 Append a value to a variable to be set in mw.config in JavaScript.In order to ensure the result is independent of the parse order, the value of this key will be an associative array, mapping all of the values set under that key to true. (The array is implicitly ordered in PHP, but you should treat it as unordered.) If you want a non-array type for the key, and can ensure that only a single value will be set, you should use setJsConfigVar() instead.
Note
Only values which can be array keys are currently supported as values. Be aware that array keys which 'look like' numbers are converted to ints by PHP, and so if you put in "0" as a value you will get [0=>true] out.
Parameters
string$keyKey to use under mw.config
string$valueValue to append to the configuration variable.
string$strategyMerge strategy: only MW_MERGE_STRATEGY_UNION is currently supported and external callers should treat this parameter as

 
 addModules (array $modules)
 
See also
OutputPage::addModules
Parameters
string[]$modules
Deprecated
use ::appendOutputStrings(::MODULE, ...)

 
 addModuleStyles (array $moduleStyles)
 
See also
OutputPage::addModuleStyles
Parameters
string[]$modules
Deprecated
use ::appendOutputStrings(::MODULE_STYLE, ...)

 
 setLimitReportData (string $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.
Parameters
string$keyMessage key
mixed$valueAppropriate for Message::params()

 
 setTOCData (TOCData $tocData)
 Sets Table of Contents data for this page.Note that merging of TOCData is not supported; exactly one fragment should set TOCData.
Parameters
TOCData$tocData

 
 addLink (LinkTarget $link, $id=null)
 Record a local or interwiki inline link for saving in future link tables.
Parameters
LinkTarget$link(used to require Title until 1.38)
int | null$idOptional known page_id so we can skip the lookup (generally not used by Parsoid)

 
 addImage (LinkTarget $link, $timestamp=null, $sha1=null)
 Register a file dependency for this output.
Parameters
LinkTarget$nameTitle dbKey
string | false | null$timestampMW timestamp of file creation (or false if non-existing)
string | false | null$sha1Base 36 SHA-1 of file (or false if non-existing)

 
 addLanguageLink (LinkTarget $lt)
 Add a language link.
Parameters
LinkTarget$lt

 
 addTemplate (LinkTarget $link, int $page_id, int $rev_id)
 Add a dependency on the given template.
 
 getLinkList (string $linkType)
 
 getModules ()
 
 getModuleStyles ()
 
 getJsConfigVars ()
 
 getCategoryNames ()
 
 getCategorySortKey (string $name)
 
 getPageProperty (string $name)
 
 getExtensionData (string $key)
 Return the collected extension data under the given key.
 
 getOutputFlags ()
 Return the active output flags.
 
 getTOCData ()
 Return the collected TOC data, or null if no TOC data was collected.
 
 setIndicator ( $name, $content)
 Set the content for an indicator.
 
 getIndicators ()
 Return a "name" => "content-id" mapping of recorded indicators.
 

Public Attributes

const LINKTYPE_CATEGORY = 'category'
 
const LINKTYPE_LANGUAGE = 'language'
 
const LINKTYPE_INTERWIKI = 'interwiki'
 
const LINKTYPE_LOCAL = 'local'
 
const LINKTYPE_MEDIA = 'media'
 
const LINKTYPE_SPECIAL = 'special'
 
const LINKTYPE_TEMPLATE = 'template'
 
- Public Attributes inherited from Wikimedia\Parsoid\Core\ContentMetadataCollector
const MERGE_STRATEGY_UNION = 'union'
 Merge strategy to use for ContentMetadataCollector accumulators: "union" means that values are strings, stored as a set, and exposed as a PHP associative array mapping from values to true.
 

Detailed Description

Minimal implementation of a ContentMetadataCollector which just records all metadata in an array.

Used for testing or operation in API mode.

Constructor & Destructor Documentation

◆ __construct()

Wikimedia\Parsoid\Config\StubMetadataCollector::__construct ( SiteConfig $siteConfig)
Parameters
SiteConfig$siteConfigUsed to resolve title namespaces and to log warnings for unsafe metadata updates

Member Function Documentation

◆ addCategory()

Wikimedia\Parsoid\Config\StubMetadataCollector::addCategory ( $c,
$sort = '' )

Add a category, with the given sort key.

Parameters
LinkTarget$cCategory name
string$sortSort key (pass the empty string to use the default)

Implements Wikimedia\Parsoid\Core\ContentMetadataCollector.

◆ addExternalLink()

Wikimedia\Parsoid\Config\StubMetadataCollector::addExternalLink ( string $url)

Parameters
string$urlExternal link URL

Implements Wikimedia\Parsoid\Core\ContentMetadataCollector.

◆ addImage()

Wikimedia\Parsoid\Config\StubMetadataCollector::addImage ( LinkTarget $link,
$timestamp = null,
$sha1 = null )

Register a file dependency for this output.

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

Implements Wikimedia\Parsoid\Core\ContentMetadataCollector.

◆ addLanguageLink()

Wikimedia\Parsoid\Config\StubMetadataCollector::addLanguageLink ( LinkTarget $lt)

Add a language link.

Parameters
LinkTarget$lt

Implements Wikimedia\Parsoid\Core\ContentMetadataCollector.

◆ addLink()

Wikimedia\Parsoid\Config\StubMetadataCollector::addLink ( LinkTarget $link,
$id = null )

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

Parameters
LinkTarget$link(used to require Title until 1.38)
int | null$idOptional known page_id so we can skip the lookup (generally not used by Parsoid)

Implements Wikimedia\Parsoid\Core\ContentMetadataCollector.

◆ addModules()

Wikimedia\Parsoid\Config\StubMetadataCollector::addModules ( array $modules)

See also
OutputPage::addModules
Parameters
string[]$modules
Deprecated
use ::appendOutputStrings(::MODULE, ...)

Implements Wikimedia\Parsoid\Core\ContentMetadataCollector.

◆ addModuleStyles()

Wikimedia\Parsoid\Config\StubMetadataCollector::addModuleStyles ( array $moduleStyles)

See also
OutputPage::addModuleStyles
Parameters
string[]$modules
Deprecated
use ::appendOutputStrings(::MODULE_STYLE, ...)

Implements Wikimedia\Parsoid\Core\ContentMetadataCollector.

◆ addTemplate()

Wikimedia\Parsoid\Config\StubMetadataCollector::addTemplate ( LinkTarget $link,
int $page_id,
int $rev_id )

Add a dependency on the given template.

Parameters
LinkTarget$link
int$page_id
int$rev_id

◆ addWarningMsg()

Wikimedia\Parsoid\Config\StubMetadataCollector::addWarningMsg ( string $msg,
$args )

Add a warning to the output for this page.

Parameters
string$msgThe localization message key for the warning
mixed...$args Optional arguments for the message

Implements Wikimedia\Parsoid\Core\ContentMetadataCollector.

◆ appendExtensionData()

Wikimedia\Parsoid\Config\StubMetadataCollector::appendExtensionData ( string $key,
$value,
string $strategy = self::MERGE_STRATEGY_UNION )

Appends 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 set*PageProperty(), it is not recorded in the database.See setExtensionData() for more details on rationale and use.In order to provide for out-of-order/asynchronous/incremental parsing, this method appends values to a set. See setExtensionData() for the flag-like version of this method.

Note
Only values which can be array keys are currently supported as values. Be aware that array keys which 'look like' numbers are converted to ints by PHP, and so if you put in "0" as a value you will get [0=>true] out.
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.
int | string$valueThe value to append to the list.
string$strategyMerge strategy: only MW_MERGE_STRATEGY_UNION is currently supported and external callers should treat this parameter as

Implements Wikimedia\Parsoid\Core\ContentMetadataCollector.

◆ appendJsConfigVar()

Wikimedia\Parsoid\Config\StubMetadataCollector::appendJsConfigVar ( string $key,
string $value,
string $strategy = self::MERGE_STRATEGY_UNION )

Append a value to a variable to be set in mw.config in JavaScript.In order to ensure the result is independent of the parse order, the value of this key will be an associative array, mapping all of the values set under that key to true. (The array is implicitly ordered in PHP, but you should treat it as unordered.) If you want a non-array type for the key, and can ensure that only a single value will be set, you should use setJsConfigVar() instead.

Note
Only values which can be array keys are currently supported as values. Be aware that array keys which 'look like' numbers are converted to ints by PHP, and so if you put in "0" as a value you will get [0=>true] out.
Parameters
string$keyKey to use under mw.config
string$valueValue to append to the configuration variable.
string$strategyMerge strategy: only MW_MERGE_STRATEGY_UNION is currently supported and external callers should treat this parameter as

Implements Wikimedia\Parsoid\Core\ContentMetadataCollector.

◆ appendOutputStrings()

Wikimedia\Parsoid\Config\StubMetadataCollector::appendOutputStrings ( string $name,
array $value )

Provides a uniform interface to various appendable lists of strings stored in the content metadata.Strings internal to MediaWiki core should have names which are constants in ParserOutputStrings. Extensions should use setExtensionData() rather than creating new keys here in order to prevent namespace conflicts.

Parameters
string$nameA string name
string[]$value

Implements Wikimedia\Parsoid\Core\ContentMetadataCollector.

◆ getCategoryNames()

Wikimedia\Parsoid\Config\StubMetadataCollector::getCategoryNames ( )
Returns
list<string>

◆ getCategorySortKey()

Wikimedia\Parsoid\Config\StubMetadataCollector::getCategorySortKey ( string $name)
Parameters
string$nameCategory name
Returns
?string Sort key

◆ getExtensionData()

Wikimedia\Parsoid\Config\StubMetadataCollector::getExtensionData ( string $key)

Return the collected extension data under the given key.

Parameters
string$key
Returns
mixed|null

◆ getIndicators()

Wikimedia\Parsoid\Config\StubMetadataCollector::getIndicators ( )

Return a "name" => "content-id" mapping of recorded indicators.

Returns
array

◆ getJsConfigVars()

Wikimedia\Parsoid\Config\StubMetadataCollector::getJsConfigVars ( )
Returns
string[]

◆ getLinkList()

Wikimedia\Parsoid\Config\StubMetadataCollector::getLinkList ( string $linkType)
See also
ParserOutput::getLinkList()
Parameters
string$linkTypeA link type, which should be a constant from this class
Returns
list<array{link:LinkTarget,pageid?:int,revid?:int,sort?:string,time?:string|false,sha1?:string|false}>

◆ getModules()

Wikimedia\Parsoid\Config\StubMetadataCollector::getModules ( )
Returns
string[]

◆ getModuleStyles()

Wikimedia\Parsoid\Config\StubMetadataCollector::getModuleStyles ( )
Returns
string[]

◆ getOutputFlags()

Wikimedia\Parsoid\Config\StubMetadataCollector::getOutputFlags ( )

Return the active output flags.

Returns
string[]

◆ getPageProperty()

Wikimedia\Parsoid\Config\StubMetadataCollector::getPageProperty ( string $name)
Parameters
string$name
Returns
?string

◆ getTOCData()

Wikimedia\Parsoid\Config\StubMetadataCollector::getTOCData ( )

Return the collected TOC data, or null if no TOC data was collected.

Returns
?TOCData

◆ setExtensionData()

Wikimedia\Parsoid\Config\StubMetadataCollector::setExtensionData ( string $key,
$value )

Attaches arbitrary data to this content.This can be used to store some information for later use during page output. The data will be cached along with the parsed page, but unlike data set using set*PageProperty(), it is not recorded in the database.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' );
Note
Only scalar values, e.g. numbers, strings, arrays or MediaWiki\Json\JsonUnserializable instances are supported as a value. Attempt to set other class instance as a extension data will break ParserCache for the page.
As with setJsConfigVar(), setting a page property to multiple conflicting values during the parse is not supported.
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. Keys beginning with mw- are reserved for use by mediawiki core.
mixed$valueThe value to set. Setting a value to null is equivalent to removing the value.

Implements Wikimedia\Parsoid\Core\ContentMetadataCollector.

◆ setIndicator()

Wikimedia\Parsoid\Config\StubMetadataCollector::setIndicator ( $name,
$content )

Set the content for an indicator.

Parameters
string$name
string$content

Implements Wikimedia\Parsoid\Core\ContentMetadataCollector.

◆ setJsConfigVar()

Wikimedia\Parsoid\Config\StubMetadataCollector::setJsConfigVar ( string $key,
$value )

Add a variable to be set in mw.config in JavaScript.In order to ensure the result is independent of the parse order, the values set here must be unique – that is, you can pass the same $key multiple times but ONLY if the $value is identical each time. If you want to collect multiple pieces of data under a single key, use appendJsConfigVar().

Parameters
string$keyKey to use under mw.config
mixed | null$valueValue of the configuration variable.

Implements Wikimedia\Parsoid\Core\ContentMetadataCollector.

◆ setLimitReportData()

Wikimedia\Parsoid\Config\StubMetadataCollector::setLimitReportData ( string $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.
Parameters
string$keyMessage key
mixed$valueAppropriate for Message::params()

Implements Wikimedia\Parsoid\Core\ContentMetadataCollector.

◆ setNumericPageProperty()

Wikimedia\Parsoid\Config\StubMetadataCollector::setNumericPageProperty ( string $propName,
$numericValue )

Set a numeric page property whose value is intended to be sorted and indexed.The sort key used for the property will be the value, coerced to a number. It is also possible to efficiently look up all the pages with a certain property (the "presence" of the property is also indexed; see Special:PagesWithProp, list=pageswithprop).The page property is stored in the page_props database table. The page_props table is a key-value store indexed by the page ID. This allows the parser to set a property on a page whose value can then be quickly retrieved given the page ID or via a DB join when given the page title. The page_props table is also indexed on the numeric sort key passed as $numericValue to this method. This allows for efficient "top k" queries of pages with respect to a given property.In the future, we may allow the value to be specified independent of sort key (T357783).The setNumericPageProperty() method 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:

  • The Proofread page extension stores proofread_page_quality_level as a numeric property to allow efficient retrieval of pages of a certain quality level.
  • Keeping a count of the number of errors found in a page property to allow listing pages in order from most errors to least.
If you need a placeholder value, you likely should be using setUnsortedPageProperty() instead.
Note
Note that the PageProp service always returns strings for the value of the page property, while values retrieved from this ParserOutput will be numeric. Be careful to distinguish these two cases.
Do not use setNumericPageProperty() 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; use setExtensionData() instead.
Example:
$parser->getOutput()->setExtensionData( 'my_ext_foo', '...' );

And then later, in the OutputPageParserOutput hook or similar:

Example:
$output->getExtensionData( 'my_ext_foo' );
Parameters
string$propNameThe name of the page property
int | float | string$numericValuethe numeric value
Since
1.42

Implements Wikimedia\Parsoid\Core\ContentMetadataCollector.

◆ setOutputFlag()

Wikimedia\Parsoid\Config\StubMetadataCollector::setOutputFlag ( string $name,
bool $value = true )

Provides a uniform interface to various boolean flags stored in the content metadata.Flags internal to MediaWiki core should have names which are constants in ParserOutputFlags. Extensions should use setExtensionData() rather than creating new flags with setOutputFlag() in order to prevent namespace conflicts.

Parameters
string$nameA flag name
bool$val

Implements Wikimedia\Parsoid\Core\ContentMetadataCollector.

◆ setTOCData()

Wikimedia\Parsoid\Config\StubMetadataCollector::setTOCData ( TOCData $tocData)

Sets Table of Contents data for this page.Note that merging of TOCData is not supported; exactly one fragment should set TOCData.

Parameters
TOCData$tocData

Implements Wikimedia\Parsoid\Core\ContentMetadataCollector.

◆ setUnsortedPageProperty()

Wikimedia\Parsoid\Config\StubMetadataCollector::setUnsortedPageProperty ( string $propName,
string $value = '' )

Set a page property whose value is not intended to be sorted and indexed.It is still possible to efficiently look up all the pages with a certain property (the "presence" of the property is indexed; see Special:PagesWithProp, list=pageswithprop).The page property is stored in the page_props database table. The page_props table is a key-value store indexed by the page ID. This allows the parser to set a property on a page whose value can then be quickly retrieved given the page ID or via a DB join when given the page title.The setUnsortedPageProperty() method 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 page property.
  • Overriding the displayed article title (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.)
It is recommended to use the empty string if you need a placeholder value (ie, if it is the presence of the property which is important, not the value the property is set to).
Note
Do not use setUnsortedPageProperty() 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; use setExtensionData() instead.
Example:
$parser->getOutput()->setExtensionData( 'my_ext_foo', '...' );

And then later, in the OutputPageParserOutput hook or similar:

Example:
$output->getExtensionData( 'my_ext_foo' );
Parameters
string$propNameThe name of the page property
string$valueOptional value; defaults to the empty string.
Since
1.42

Implements Wikimedia\Parsoid\Core\ContentMetadataCollector.


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