MediaWiki  1.29.2
MediaWiki\Tidy\BalanceElement Class Reference

A BalanceElement is a simplified version of a DOM Node. More...

Public Member Functions

 __construct ( $namespaceURI, $localName, array $attribs)
 Make a new BalanceElement corresponding to the HTML DOM Element with the given localname, namespace, and attributes. More...
 
 __toString ()
 Serialize this node and all of its children to a string, as specified by the HTML serialization specification. More...
 
 adoptChildren (BalanceElement $elt)
 Transfer all of the children of $elt to $this. More...
 
 appendChild ( $elt)
 Append $elt to the end of the list of children. More...
 
 flatten (array $config)
 Flatten this node and all of its children into a string, as specified by the HTML serialization specification, and replace this node in its parent by that string. More...
 
 getNoahKey ()
 Get a string key for the Noah's Ark algorithm. More...
 
 insertBefore (BalanceElement $a, $b)
 Find $a in the list of children and insert $b before it. More...
 
 isA ( $set)
 Determine if $this represents a specific HTML tag, is a member of a tag set, or is equal to another BalanceElement. More...
 
 isHtml ()
 Determine if $this represents an element in the HTML namespace. More...
 
 isHtmlIntegrationPoint ()
 Determine if $this represents an HTML integration point, as defined in the HTML5 specification. More...
 
 isHtmlNamed ( $tagName)
 Determine if this element is an HTML element with the specified name. More...
 
 isMathmlTextIntegrationPoint ()
 Determine if $this represents a MathML text integration point, as defined in the HTML5 specification. More...
 

Public Attributes

 $attribs
 Attributes for the element, in array form. More...
 
 $children
 An array of children of this element. More...
 
 $localName
 The lower-cased name of the element. More...
 
 $namespaceURI
 The namespace of the element. More...
 
 $nextAFE
 The next active formatting element in the list, or null if this is the end of the AFE list or if the element is not in the AFE list. More...
 
 $nextNoah
 The next element in the Noah's Ark species bucket. More...
 
 $parent
 Parent of this element, or the string "flat" if this element has already been flattened into its parent. More...
 
 $prevAFE
 The previous active formatting element in the list, or null if this is the start of the list or if the element is not in the AFE list. More...
 

Private Member Functions

 removeChild (BalanceElement $elt)
 Remove the given child from this element. More...
 

Private Attributes

 $noahKey
 A unique string identifier for Noah's Ark purposes, lazy initialized. More...
 

Detailed Description

A BalanceElement is a simplified version of a DOM Node.

The main difference is that we only keep BalanceElements around for nodes currently on the BalanceStack of open elements. As soon as an element is closed, with some minor exceptions relating to the tree builder "adoption agency algorithm", the element and all its children are serialized to a string using the flatten() method. This keeps our memory usage low.

Since
1.27

Definition at line 312 of file Balancer.php.

Constructor & Destructor Documentation

◆ __construct()

MediaWiki\Tidy\BalanceElement::__construct (   $namespaceURI,
  $localName,
array  $attribs 
)

Make a new BalanceElement corresponding to the HTML DOM Element with the given localname, namespace, and attributes.

Parameters
string$namespaceURIThe namespace of the element.
string$localNameThe lowercased name of the tag.
array$attribsAttributes of the element

Definition at line 375 of file Balancer.php.

References MediaWiki\Tidy\BalanceElement\$attribs, MediaWiki\Tidy\BalanceElement\$localName, MediaWiki\Tidy\BalanceElement\$namespaceURI, and contents.

Member Function Documentation

◆ __toString()

MediaWiki\Tidy\BalanceElement::__toString ( )

Serialize this node and all of its children to a string, as specified by the HTML serialization specification.

Returns
string The serialization of the BalanceElement
See also
https://html.spec.whatwg.org/multipage/syntax.html#serialising-html-fragments

Definition at line 529 of file Balancer.php.

References MediaWiki\Tidy\BalanceSets\$emptyElementSet, $name, $out, $value, as, captcha-old\count, and MediaWiki\Tidy\BalanceElement\isA().

◆ adoptChildren()

MediaWiki\Tidy\BalanceElement::adoptChildren ( BalanceElement  $elt)

Transfer all of the children of $elt to $this.

Parameters
BalanceElement$elt

Definition at line 448 of file Balancer.php.

References MediaWiki\Tidy\BalanceElement\appendChild(), and as.

◆ appendChild()

MediaWiki\Tidy\BalanceElement::appendChild (   $elt)

Append $elt to the end of the list of children.

Parameters
BalanceElement | string$elt

Definition at line 428 of file Balancer.php.

Referenced by MediaWiki\Tidy\BalanceElement\adoptChildren().

◆ flatten()

MediaWiki\Tidy\BalanceElement::flatten ( array  $config)

Flatten this node and all of its children into a string, as specified by the HTML serialization specification, and replace this node in its parent by that string.

Parameters
array$configBalancer configuration; see Balancer::__construct().
Returns
string
See also
__toString()

Definition at line 473 of file Balancer.php.

References MediaWiki\$config, MediaWiki\Tidy\BalanceSets\$extraLinefeedSet, as, captcha-old\count, MediaWiki\Tidy\BalanceElement\isA(), and MediaWiki\Tidy\BalanceElement\isHtmlNamed().

Referenced by MediaWiki\Tidy\BalanceStack\removeElement().

◆ getNoahKey()

◆ insertBefore()

MediaWiki\Tidy\BalanceElement::insertBefore ( BalanceElement  $a,
  $b 
)

Find $a in the list of children and insert $b before it.

Parameters
BalanceElement$a
BalanceElement | string$b

Definition at line 406 of file Balancer.php.

◆ isA()

MediaWiki\Tidy\BalanceElement::isA (   $set)

Determine if $this represents a specific HTML tag, is a member of a tag set, or is equal to another BalanceElement.

Parameters
BalanceElement | array | string$setThe target BalanceElement, set (from the BalanceSets class), or string (HTML tag name).
Returns
bool

Definition at line 563 of file Balancer.php.

References MediaWiki\Tidy\BalanceElement\isHtml().

Referenced by MediaWiki\Tidy\BalanceElement\__toString(), MediaWiki\Tidy\BalanceElement\flatten(), MediaWiki\Tidy\BalanceStack\insertElement(), MediaWiki\Tidy\BalanceElement\isHtmlIntegrationPoint(), and MediaWiki\Tidy\BalanceElement\isMathmlTextIntegrationPoint().

◆ isHtml()

MediaWiki\Tidy\BalanceElement::isHtml ( )

Determine if $this represents an element in the HTML namespace.

Returns
bool

Definition at line 590 of file Balancer.php.

References MediaWiki\Tidy\BalanceSets\HTML_NAMESPACE.

Referenced by MediaWiki\Tidy\BalanceElement\isA().

◆ isHtmlIntegrationPoint()

MediaWiki\Tidy\BalanceElement::isHtmlIntegrationPoint ( )

Determine if $this represents an HTML integration point, as defined in the HTML5 specification.

Returns
bool
See also
https://html.spec.whatwg.org/multipage/syntax.html#html-integration-point

Definition at line 612 of file Balancer.php.

References MediaWiki\Tidy\BalanceSets\$htmlIntegrationPointSet, MediaWiki\Tidy\BalanceElement\isA(), and MediaWiki\Tidy\BalanceSets\MATHML_NAMESPACE.

◆ isHtmlNamed()

MediaWiki\Tidy\BalanceElement::isHtmlNamed (   $tagName)

Determine if this element is an HTML element with the specified name.

Parameters
string$tagName
Returns
bool

Definition at line 580 of file Balancer.php.

References MediaWiki\Tidy\BalanceSets\HTML_NAMESPACE.

Referenced by MediaWiki\Tidy\BalanceElement\flatten(), and MediaWiki\Tidy\BalanceStack\fosterParent().

◆ isMathmlTextIntegrationPoint()

MediaWiki\Tidy\BalanceElement::isMathmlTextIntegrationPoint ( )

Determine if $this represents a MathML text integration point, as defined in the HTML5 specification.

Returns
bool
See also
https://html.spec.whatwg.org/multipage/syntax.html#mathml-text-integration-point

Definition at line 601 of file Balancer.php.

References MediaWiki\Tidy\BalanceSets\$mathmlTextIntegrationPointSet, and MediaWiki\Tidy\BalanceElement\isA().

◆ removeChild()

MediaWiki\Tidy\BalanceElement::removeChild ( BalanceElement  $elt)
private

Remove the given child from this element.

Parameters
BalanceElement$elt

Definition at line 388 of file Balancer.php.

Member Data Documentation

◆ $attribs

array MediaWiki\Tidy\BalanceElement::$attribs

Attributes for the element, in array form.

Definition at line 327 of file Balancer.php.

Referenced by MediaWiki\Tidy\BalanceElement\__construct(), and MediaWiki\Tidy\BalanceElement\getNoahKey().

◆ $children

BalanceElement[] string[] MediaWiki\Tidy\BalanceElement::$children

An array of children of this element.

Typically only the last child will be an actual BalanceElement object; the rest will be strings, representing either text nodes or flattened BalanceElement objects.

Definition at line 343 of file Balancer.php.

◆ $localName

string MediaWiki\Tidy\BalanceElement::$localName

The lower-cased name of the element.

Definition at line 322 of file Balancer.php.

Referenced by MediaWiki\Tidy\BalanceElement\__construct().

◆ $namespaceURI

string MediaWiki\Tidy\BalanceElement::$namespaceURI

The namespace of the element.

Definition at line 317 of file Balancer.php.

Referenced by MediaWiki\Tidy\BalanceElement\__construct().

◆ $nextAFE

MediaWiki\Tidy\BalanceElement::$nextAFE

The next active formatting element in the list, or null if this is the end of the AFE list or if the element is not in the AFE list.

Definition at line 354 of file Balancer.php.

◆ $nextNoah

MediaWiki\Tidy\BalanceElement::$nextNoah

The next element in the Noah's Ark species bucket.

Definition at line 365 of file Balancer.php.

◆ $noahKey

MediaWiki\Tidy\BalanceElement::$noahKey
private

A unique string identifier for Noah's Ark purposes, lazy initialized.

Definition at line 348 of file Balancer.php.

Referenced by MediaWiki\Tidy\BalanceElement\getNoahKey().

◆ $parent

BalanceElement string null MediaWiki\Tidy\BalanceElement::$parent

Parent of this element, or the string "flat" if this element has already been flattened into its parent.

Definition at line 334 of file Balancer.php.

◆ $prevAFE

MediaWiki\Tidy\BalanceElement::$prevAFE

The previous active formatting element in the list, or null if this is the start of the list or if the element is not in the AFE list.

Definition at line 360 of file Balancer.php.


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