MediaWiki master
MediaWiki\Parser\ContentHolder Class Reference

Inherits JsonCodecable.

Collaboration diagram for MediaWiki\Parser\ContentHolder:

Public Member Functions

 __clone ()
 
 addFragment (string $name=self::BODY_FRAGMENT, ?string $html=null)
 
 appendDom (DocumentFragment $df, string $fragmentName=self::BODY_FRAGMENT)
 Helper method to append the given DocumentFragment to the named content fragment.
 
 appendHtmlString (string $html, string $fragmentName=self::BODY_FRAGMENT)
 Helper method to append the given HTML string to the named content fragment.
 
 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.
 
 getFragmentNames (bool $bodyFirst=false)
 Return all the fragment names.
 
 has (string $fragmentName)
 Returns false if the designated fragment is not present in the ContentHolder.
 
 hasContent ()
 
 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.
 
 prependDom (DocumentFragment $df, string $fragmentName=self::BODY_FRAGMENT)
 Helper method to prepend the given DocumentFragment to the named content fragment.
 
 prependHtmlString (string $html, string $fragmentName=self::BODY_FRAGMENT)
 Helper method to prepend the given HTML string to the named content fragment.
 
 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.
 
 toJsonArray ()
 

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, ?SiteConfig $siteConfig=null)
 Create a ContentHolder from a Parsoid HtmlPageBundle.
 
static jsonClassHintFor (string $keyName)
 
static newFromJsonArray (array $json)
 

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.

The canonical body fragment is body-only: getAsHtmlString( BODY_FRAGMENT ) returns just the <body> contents, and the full document (with <head>) is generated when needed with PageBundleParserOutputConverter::htmlPageBundleFromParserOutput(). Pre-MW-1.47 ParserCache entries may still contain a full HTML document in the BODY_FRAGMENT, and that wrapper is stripped in ::getAsHtmlString().

Definition at line 43 of file ContentHolder.php.

Member Function Documentation

◆ __clone()

MediaWiki\Parser\ContentHolder::__clone ( )

Definition at line 482 of file ContentHolder.php.

◆ addFragment()

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

Definition at line 361 of file ContentHolder.php.

◆ appendDom()

MediaWiki\Parser\ContentHolder::appendDom ( DocumentFragment $df,
string $fragmentName = self::BODY_FRAGMENT )

Helper method to append the given DocumentFragment to the named content fragment.

Definition at line 285 of file ContentHolder.php.

◆ appendHtmlString()

MediaWiki\Parser\ContentHolder::appendHtmlString ( string $html,
string $fragmentName = self::BODY_FRAGMENT )

Helper method to append the given HTML string to the named content fragment.

Definition at line 271 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 129 of file ContentHolder.php.

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

◆ createFragment()

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

Definition at line 348 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 89 of file ContentHolder.php.

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

◆ createFromParsoidPageBundle()

static MediaWiki\Parser\ContentHolder::createFromParsoidPageBundle ( HtmlPageBundle $pb,
?SiteConfig $siteConfig = null )
static

Create a ContentHolder from a Parsoid HtmlPageBundle.

Definition at line 101 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 188 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.
The BODY_FRAGMENT will always return body-only content (T393925); use PageBundleParserOutputConverter::htmlPageBundleFromParserOutput() with bodyOnly: false to obtain a full document.

Definition at line 168 of file ContentHolder.php.

◆ getBasePageBundle()

MediaWiki\Parser\ContentHolder::getBasePageBundle ( )

Return the BasePageBundle of the ContentHolder.

Access: internal

Definition at line 397 of file ContentHolder.php.

◆ getFragmentNames()

MediaWiki\Parser\ContentHolder::getFragmentNames ( bool $bodyFirst = false)

Return all the fragment names.

You can pass bodyFirst: true in cases where the order of fragments matters, which will ensure that the first element is self::BODY_FRAGMENT (if it exists in this ContentHolder).

Parameters
bool$bodyFirstPass true to get a repeatable sorted list of fragments with the body fragment first.
Returns
list<string>

Definition at line 376 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 153 of file ContentHolder.php.

◆ hasContent()

MediaWiki\Parser\ContentHolder::hasContent ( )

Definition at line 502 of file ContentHolder.php.

◆ isParsoidContent()

MediaWiki\Parser\ContentHolder::isParsoidContent ( )

Returns true if this ContentHolder contains Parsoid-generated content.

Definition at line 140 of file ContentHolder.php.

◆ jsonClassHintFor()

static MediaWiki\Parser\ContentHolder::jsonClassHintFor ( string $keyName)
static

Definition at line 543 of file ContentHolder.php.

◆ newFromJsonArray()

static MediaWiki\Parser\ContentHolder::newFromJsonArray ( array $json)
static

Definition at line 524 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 498 of file ContentHolder.php.

◆ prependDom()

MediaWiki\Parser\ContentHolder::prependDom ( DocumentFragment $df,
string $fragmentName = self::BODY_FRAGMENT )

Helper method to prepend the given DocumentFragment to the named content fragment.

Definition at line 250 of file ContentHolder.php.

◆ prependHtmlString()

MediaWiki\Parser\ContentHolder::prependHtmlString ( string $html,
string $fragmentName = self::BODY_FRAGMENT )

Helper method to prepend the given HTML string to the named content fragment.

Definition at line 236 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 314 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 207 of file ContentHolder.php.

◆ toJsonArray()

MediaWiki\Parser\ContentHolder::toJsonArray ( )

Definition at line 509 of file ContentHolder.php.

Member Data Documentation

◆ BODY_FRAGMENT

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

Definition at line 46 of file ContentHolder.php.


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