MediaWiki master
MediaWiki\Parser\ContentHolder Class Reference

Public Member Functions

 __clone ()
 
 addFragment (string $name=self::BODY_FRAGMENT, ?string $html=null)
 
 createFragment (?string $html=null)
 
 getAsDom (string $fragmentName=self::BODY_FRAGMENT)
 Returns the designated fragment as a DOM DocumentFragment, or null if it is not present.
 
 getAsHtmlString (string $fragmentName=self::BODY_FRAGMENT)
 Returns the designated fragment as an HTML string version, or null if it is not present.
 
 getBasePageBundle ()
 Return the BasePageBundle of the ContentHolder.
 
 has (string $fragmentName)
 Returns false if the designated fragment is not present in the ContentHolder.
 
 ignoreForObjectEquality ()
 
 isParsoidContent ()
 Returns true if this ContentHolder contains Parsoid-generated content.
 
 preferDom ()
 Given a ContentHolderTransformStage that has two valid transform options, returns true if the state of the ContentHolder calls for a DOM transform, false if it calls for a text transform.
 
 setAsDom (string $fragmentName=self::BODY_FRAGMENT, ?DocumentFragment $fragment=null)
 Sets or removes a fragment, provided as a DOM DocumentFragment.
 
 setAsHtmlString (string $fragmentName=self::BODY_FRAGMENT, ?string $html=null)
 Sets or removes a fragment, provided as an HTML string.
 

Static Public Member Functions

static createEmpty ()
 Creates an empty ContentHolder that can be used as a placeholder.
 
static createFromLegacyString (string $html)
 Create a ContentHolder from a legacy body HTML string, typically returned by the legacy parser.
 
static createFromParsoidPageBundle (HtmlPageBundle $pb)
 Create a ContentHolder from a Parsoid HtmlPageBundle.
 

Public Attributes

const BODY_FRAGMENT = "body"
 

Detailed Description

Access: internal
Stability: unstable
Since
1.45

A ContentHolder holds a map of fragments that can be HTML string or DOM fragments. It should, as much as possible, be used in a consistent format and/or limit format switches, as conversions of all the fragments happen on all accessors, which has a performance impact.

ContentHolder currently makes no guarantee on the preservation of the document outside of the <body> tag. In particular, if a full Parsoid document with a <head> tag is passed as a string, and converted to DOM, the <head> content is lost. This must be taken into account in particular if we create an ExtractBody DOM pass, in which case the <base> tag contained in the <head> must be handled before conversion. OutputTransform steps after ExtractBody should however be unaffected.

Definition at line 38 of file ContentHolder.php.

Member Function Documentation

◆ __clone()

MediaWiki\Parser\ContentHolder::__clone ( )

Definition at line 314 of file ContentHolder.php.

◆ addFragment()

MediaWiki\Parser\ContentHolder::addFragment ( string $name = self::BODY_FRAGMENT,
?string $html = null )

Definition at line 231 of file ContentHolder.php.

◆ createEmpty()

static MediaWiki\Parser\ContentHolder::createEmpty ( )
static

Creates an empty ContentHolder that can be used as a placeholder.

This does not contain any body content.

Definition at line 94 of file ContentHolder.php.

Referenced by MediaWiki\Parser\ParserOutput\__construct().

◆ createFragment()

MediaWiki\Parser\ContentHolder::createFragment ( ?string $html = null)

Definition at line 218 of file ContentHolder.php.

◆ createFromLegacyString()

static MediaWiki\Parser\ContentHolder::createFromLegacyString ( string $html)
static

Create a ContentHolder from a legacy body HTML string, typically returned by the legacy parser.

Definition at line 64 of file ContentHolder.php.

Referenced by MediaWiki\Parser\ParserOutput\__construct().

◆ createFromParsoidPageBundle()

static MediaWiki\Parser\ContentHolder::createFromParsoidPageBundle ( HtmlPageBundle $pb)
static

Create a ContentHolder from a Parsoid HtmlPageBundle.

Definition at line 76 of file ContentHolder.php.

◆ getAsDom()

MediaWiki\Parser\ContentHolder::getAsDom ( string $fragmentName = self::BODY_FRAGMENT)

Returns the designated fragment as a DOM DocumentFragment, or null if it is not present.

Note
If a conversion is needed, at present all fragments of the document are converted to DOM DocumentFragments.

Definition at line 143 of file ContentHolder.php.

◆ getAsHtmlString()

MediaWiki\Parser\ContentHolder::getAsHtmlString ( string $fragmentName = self::BODY_FRAGMENT)

Returns the designated fragment as an HTML string version, or null if it is not present.

Note
If a conversion is needed, at present all fragments of the document are converted to HTML strings.

Definition at line 129 of file ContentHolder.php.

◆ getBasePageBundle()

MediaWiki\Parser\ContentHolder::getBasePageBundle ( )

Return the BasePageBundle of the ContentHolder.

Access: internal

Definition at line 241 of file ContentHolder.php.

◆ has()

MediaWiki\Parser\ContentHolder::has ( string $fragmentName)

Returns false if the designated fragment is not present in the ContentHolder.

Definition at line 118 of file ContentHolder.php.

◆ ignoreForObjectEquality()

MediaWiki\Parser\ContentHolder::ignoreForObjectEquality ( )

Definition at line 324 of file ContentHolder.php.

◆ isParsoidContent()

MediaWiki\Parser\ContentHolder::isParsoidContent ( )

Returns true if this ContentHolder contains Parsoid-generated content.

Definition at line 105 of file ContentHolder.php.

◆ preferDom()

MediaWiki\Parser\ContentHolder::preferDom ( )

Given a ContentHolderTransformStage that has two valid transform options, returns true if the state of the ContentHolder calls for a DOM transform, false if it calls for a text transform.

Right now, this is strictly directed by whether the ContentHolder is in DOM format or in HTML format; this might change in the future if we maintain both formats in some cases.

Definition at line 334 of file ContentHolder.php.

◆ setAsDom()

MediaWiki\Parser\ContentHolder::setAsDom ( string $fragmentName = self::BODY_FRAGMENT,
?DocumentFragment $fragment = null )

Sets or removes a fragment, provided as a DOM DocumentFragment.

Parameters
string$fragmentNamename of the fragment to set
DocumentFragment | null$fragmentthe fragment to set, or null to remove a fragment.
Returns
void
Note
The self::BODY_FRAGMENT should not contain the top-level <body> tag.
All fragments may be converted to DOM DocumentFragments as a side-effect.

Definition at line 193 of file ContentHolder.php.

◆ setAsHtmlString()

MediaWiki\Parser\ContentHolder::setAsHtmlString ( string $fragmentName = self::BODY_FRAGMENT,
?string $html = null )

Sets or removes a fragment, provided as an HTML string.

Parameters
string$fragmentNamename of the fragment to set
string | null$htmlstring of the fragment to set, or null to remove a fragment.
Returns
void
Note
The self::BODY_FRAGMENT should not contain the top-level <body> tag.
All fragments may be converted to HTML strings as a side-effect.

Definition at line 161 of file ContentHolder.php.

Member Data Documentation

◆ BODY_FRAGMENT

const MediaWiki\Parser\ContentHolder::BODY_FRAGMENT = "body"

Definition at line 39 of file ContentHolder.php.


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