MediaWiki REL1_30
MediaWiki\Tidy\BalanceStack Class Reference

The "stack of open elements" as defined in the HTML5 tree builder spec. More...

Inheritance diagram for MediaWiki\Tidy\BalanceStack:
Collaboration diagram for MediaWiki\Tidy\BalanceStack:

Public Member Functions

 __construct (array $config)
 Create a new BalanceStack with a single BalanceElement on it, representing the root <html> node.
 
 __toString ()
 Return the contents of the open elements stack as a string for debugging.
 
 adjustedCurrentNode ( $fragmentContext)
 Return the adjusted current node.
 
 adoptionAgency ( $tag, $afe)
 Run the "adoption agency algoritm" (AAA) for the given subject tag name.
 
 clearToContext ( $set)
 Pop elements off the stack not including the first element in the specified set.
 
 generateImpliedEndTags ( $butnot=null, $thorough=false)
 Generate implied end tags.
 
 getIterator ()
 Return an iterator over this stack which visits the current node first, and the root node last.
 
 getOutput ()
 Return a string representing the output of the tree builder: all the children of the root <html> node.
 
 inButtonScope ( $tag)
 Determine if the stack has $tag in button scope.
 
 indexOf ( $tag)
 Return the position of the given BalanceElement, set, or HTML tag name string in the BalanceStack.
 
 inListItemScope ( $tag)
 Determine if the stack has $tag in list item scope.
 
 inScope ( $tag)
 Determine if the stack has $tag in scope.
 
 inSelectScope ( $tag)
 Determine if the stack has $tag in select scope.
 
 insertAfter (BalanceElement $a, BalanceElement $b)
 Find $a in the BalanceStack and insert $b after it.
 
 insertComment ( $value)
 Insert a comment at the appropriate place for inserting a node.
 
 insertElement (BalanceElement $elt)
 Insert an element at the appropriate place and push it on to the open elements stack.
 
 insertForeignElement ( $namespaceURI, $tag, $attribs)
 Insert a BalanceElement at the appropriate place, pushing it on to the open elements stack.
 
 insertHTMLElement ( $tag, $attribs)
 Insert an HTML element at the appropriate place, pushing it on to the open elements stack.
 
 insertText ( $value, $isComment=false)
 Insert text at the appropriate place for inserting a node.
 
 inSpecificScope ( $tag, $set)
 Determine if the stack has $tag in a specific scope, $set.
 
 inTableScope ( $tag)
 Determine if the stack has $tag in table scope.
 
 length ()
 Return the number of elements currently in the BalanceStack.
 
 node ( $idx)
 Return the BalanceElement at the given position $idx, where position 0 represents the root element.
 
 pop ()
 Remove the current node from the BalanceStack, flattening it in the process.
 
 popTag ( $tag)
 Pop elements off the stack up to and including the first element with the specified HTML tagname (or matching the given set).
 
 popTo ( $idx)
 Remove all nodes up to and including position $idx from the BalanceStack, flattening them in the process.
 
 removeElement (BalanceElement $elt, $flatten=true)
 Remove the given $elt from the BalanceStack, optionally flattening it in the process.
 
 replaceAt ( $idx, BalanceElement $elt)
 Replace the element at position $idx in the BalanceStack with $elt.
 

Public Attributes

 $currentNode
 Reference to the current element.
 
 $fosterParentMode = false
 Foster parent mode determines how nodes are inserted into the stack.
 

Private Member Functions

 fosterParent ( $elt)
 Foster parent the given $elt in the stack of open elements.
 

Private Attributes

 $config
 Configuration options governing flattening.
 
 $elements = []
 Backing storage for the stack.
 

Detailed Description

The "stack of open elements" as defined in the HTML5 tree builder spec.

This contains methods to ensure that content (start tags, text) are inserted at the correct place in the output string, and to flatten BalanceElements are they are closed to avoid holding onto a complete DOM tree for the document in memory.

The stack defines a PHP iterator to traverse it in "reverse order", that is, the most-recently-added element is visited first in a foreach loop.

Since
1.27
See also
https://html.spec.whatwg.org/multipage/syntax.html#the-stack-of-open-elements

Definition at line 657 of file Balancer.php.

Constructor & Destructor Documentation

◆ __construct()

MediaWiki\Tidy\BalanceStack::__construct ( array $config)

Create a new BalanceStack with a single BalanceElement on it, representing the root <html> node.

Parameters
array$configBalancer configuration; see Balancer::_construct().

Definition at line 686 of file Balancer.php.

References MediaWiki\Tidy\BalanceStack\$config, and MediaWiki\Tidy\BalanceSets\HTML_NAMESPACE.

Member Function Documentation

◆ __toString()

MediaWiki\Tidy\BalanceStack::__toString ( )

Return the contents of the open elements stack as a string for debugging.

Returns
string

Definition at line 1363 of file Balancer.php.

◆ adjustedCurrentNode()

MediaWiki\Tidy\BalanceStack::adjustedCurrentNode ( $fragmentContext)

Return the adjusted current node.

Parameters
string$fragmentContext
Returns
string

Definition at line 910 of file Balancer.php.

References MediaWiki\Tidy\BalanceStack\$currentNode.

◆ adoptionAgency()

MediaWiki\Tidy\BalanceStack::adoptionAgency ( $tag,
$afe )

Run the "adoption agency algoritm" (AAA) for the given subject tag name.

Parameters
string$tagThe subject tag name.
BalanceActiveFormattingElements$afeThe current active formatting elements list.
Returns
true if the adoption agency algorithm "did something", false if more processing is required by the caller.
See also
https://html.spec.whatwg.org/multipage/syntax.html#adoption-agency-algorithm

Definition at line 1158 of file Balancer.php.

References MediaWiki\Tidy\BalanceSets\$specialSet, MediaWiki\Tidy\BalanceSets\$tableSectionRowSet, MediaWiki\Tidy\BalanceStack\fosterParent(), MediaWiki\Tidy\BalanceStack\indexOf(), MediaWiki\Tidy\BalanceStack\inScope(), MediaWiki\Tidy\BalanceStack\insertAfter(), MediaWiki\Tidy\BalanceStack\length(), MediaWiki\Tidy\BalanceStack\node(), MediaWiki\Tidy\BalanceStack\pop(), MediaWiki\Tidy\BalanceStack\popTag(), MediaWiki\Tidy\BalanceStack\removeElement(), and MediaWiki\Tidy\BalanceStack\replaceAt().

◆ clearToContext()

MediaWiki\Tidy\BalanceStack::clearToContext ( $set)

Pop elements off the stack not including the first element in the specified set.

Parameters
BalanceElement | array | string$set

Definition at line 1025 of file Balancer.php.

References MediaWiki\Tidy\BalanceStack\pop().

◆ fosterParent()

MediaWiki\Tidy\BalanceStack::fosterParent ( $elt)
private

◆ generateImpliedEndTags()

MediaWiki\Tidy\BalanceStack::generateImpliedEndTags ( $butnot = null,
$thorough = false )

Generate implied end tags.

Parameters
string$butnot
bool$thoroughTrue if we should generate end tags thoroughly.
See also
https://html.spec.whatwg.org/multipage/syntax.html#generate-implied-end-tags

Definition at line 890 of file Balancer.php.

References MediaWiki\Tidy\BalanceSets\$impliedEndTagsSet, MediaWiki\Tidy\BalanceSets\$thoroughImpliedEndTagsSet, and MediaWiki\Tidy\BalanceStack\pop().

◆ getIterator()

MediaWiki\Tidy\BalanceStack::getIterator ( )

Return an iterator over this stack which visits the current node first, and the root node last.

Returns
\Iterator

Definition at line 920 of file Balancer.php.

◆ getOutput()

MediaWiki\Tidy\BalanceStack::getOutput ( )

Return a string representing the output of the tree builder: all the children of the root <html> node.

Returns
string

Definition at line 701 of file Balancer.php.

References $out.

◆ inButtonScope()

MediaWiki\Tidy\BalanceStack::inButtonScope ( $tag)

Determine if the stack has $tag in button scope.

Parameters
BalanceElement | array | string$tag
Returns
bool
See also
https://html.spec.whatwg.org/multipage/syntax.html#has-an-element-in-button-scope

Definition at line 821 of file Balancer.php.

References MediaWiki\Tidy\BalanceSets\inButtonScopeSet(), and MediaWiki\Tidy\BalanceStack\inSpecificScope().

◆ indexOf()

MediaWiki\Tidy\BalanceStack::indexOf ( $tag)

Return the position of the given BalanceElement, set, or HTML tag name string in the BalanceStack.

Parameters
BalanceElement | array | string$tag
Returns
int

Definition at line 960 of file Balancer.php.

Referenced by MediaWiki\Tidy\BalanceStack\adoptionAgency(), MediaWiki\Tidy\BalanceStack\fosterParent(), and MediaWiki\Tidy\BalanceStack\insertAfter().

◆ inListItemScope()

MediaWiki\Tidy\BalanceStack::inListItemScope ( $tag)

Determine if the stack has $tag in list item scope.

Parameters
BalanceElement | array | string$tag
Returns
bool
See also
https://html.spec.whatwg.org/multipage/syntax.html#has-an-element-in-list-item-scope

Definition at line 831 of file Balancer.php.

References MediaWiki\Tidy\BalanceSets\inListItemScopeSet(), and MediaWiki\Tidy\BalanceStack\inSpecificScope().

◆ inScope()

MediaWiki\Tidy\BalanceStack::inScope ( $tag)

Determine if the stack has $tag in scope.

Parameters
BalanceElement | array | string$tag
Returns
bool
See also
https://html.spec.whatwg.org/multipage/syntax.html#has-an-element-in-scope

Definition at line 811 of file Balancer.php.

References MediaWiki\Tidy\BalanceSets\$inScopeSet, and MediaWiki\Tidy\BalanceStack\inSpecificScope().

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

◆ inSelectScope()

MediaWiki\Tidy\BalanceStack::inSelectScope ( $tag)

Determine if the stack has $tag in select scope.

Parameters
BalanceElement | array | string$tag
Returns
bool
See also
https://html.spec.whatwg.org/multipage/syntax.html#has-an-element-in-select-scope

Definition at line 851 of file Balancer.php.

References MediaWiki\Tidy\BalanceSets\$inInvertedSelectScopeSet.

◆ insertAfter()

MediaWiki\Tidy\BalanceStack::insertAfter ( BalanceElement $a,
BalanceElement $b )

Find $a in the BalanceStack and insert $b after it.

Parameters
BalanceElement$a
BalanceElement$b

Definition at line 1076 of file Balancer.php.

References MediaWiki\Tidy\BalanceStack\indexOf().

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

◆ insertComment()

MediaWiki\Tidy\BalanceStack::insertComment ( $value)

Insert a comment at the appropriate place for inserting a node.

Parameters
string$valueContent of the comment.
Returns
string
See also
https://html.spec.whatwg.org/multipage/syntax.html#insert-a-comment

Definition at line 717 of file Balancer.php.

References $value, and MediaWiki\Tidy\BalanceStack\insertText().

◆ insertElement()

MediaWiki\Tidy\BalanceStack::insertElement ( BalanceElement $elt)

Insert an element at the appropriate place and push it on to the open elements stack.

Parameters
BalanceElement$elt
Returns
BalanceElement
See also
https://html.spec.whatwg.org/multipage/syntax.html#appropriate-place-for-inserting-a-node

Definition at line 782 of file Balancer.php.

References MediaWiki\Tidy\BalanceSets\$tableSectionRowSet, MediaWiki\Tidy\BalanceSets\$tidyInlineSet, MediaWiki\Tidy\BalanceStack\fosterParent(), and MediaWiki\Tidy\BalanceStack\pop().

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

◆ insertForeignElement()

MediaWiki\Tidy\BalanceStack::insertForeignElement ( $namespaceURI,
$tag,
$attribs )

Insert a BalanceElement at the appropriate place, pushing it on to the open elements stack.

Parameters
string$namespaceURIThe element namespace
string$tagThe tag name
string$attribsNormalized attributes, as a string.
Returns
BalanceElement
See also
https://html.spec.whatwg.org/multipage/syntax.html#insert-a-foreign-element

Definition at line 755 of file Balancer.php.

References $attribs, and MediaWiki\Tidy\BalanceStack\insertElement().

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

◆ insertHTMLElement()

MediaWiki\Tidy\BalanceStack::insertHTMLElement ( $tag,
$attribs )

Insert an HTML element at the appropriate place, pushing it on to the open elements stack.

Parameters
string$tagThe tag name
string$attribsNormalized attributes, as a string.
Returns
BalanceElement
See also
https://html.spec.whatwg.org/multipage/syntax.html#insert-an-html-element

Definition at line 769 of file Balancer.php.

References $attribs, MediaWiki\Tidy\BalanceSets\HTML_NAMESPACE, and MediaWiki\Tidy\BalanceStack\insertForeignElement().

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

◆ insertText()

◆ inSpecificScope()

MediaWiki\Tidy\BalanceStack::inSpecificScope ( $tag,
$set )

Determine if the stack has $tag in a specific scope, $set.

Parameters
BalanceElement | array | string$tag
BalanceElement | array | string$set
Returns
bool
See also
https://html.spec.whatwg.org/multipage/syntax.html#has-an-element-in-the-specific-scope

Definition at line 872 of file Balancer.php.

Referenced by MediaWiki\Tidy\BalanceStack\inButtonScope(), MediaWiki\Tidy\BalanceStack\inListItemScope(), MediaWiki\Tidy\BalanceStack\inScope(), and MediaWiki\Tidy\BalanceStack\inTableScope().

◆ inTableScope()

MediaWiki\Tidy\BalanceStack::inTableScope ( $tag)

Determine if the stack has $tag in table scope.

Parameters
BalanceElement | array | string$tag
Returns
bool
See also
https://html.spec.whatwg.org/multipage/syntax.html#has-an-element-in-table-scope

Definition at line 841 of file Balancer.php.

References MediaWiki\Tidy\BalanceSets\$inTableScopeSet, and MediaWiki\Tidy\BalanceStack\inSpecificScope().

◆ length()

MediaWiki\Tidy\BalanceStack::length ( )

Return the number of elements currently in the BalanceStack.

Returns
int

Definition at line 973 of file Balancer.php.

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

◆ node()

MediaWiki\Tidy\BalanceStack::node ( $idx)

Return the BalanceElement at the given position $idx, where position 0 represents the root element.

Parameters
int$idx
Returns
BalanceElement

Definition at line 930 of file Balancer.php.

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

◆ pop()

◆ popTag()

MediaWiki\Tidy\BalanceStack::popTag ( $tag)

Pop elements off the stack up to and including the first element with the specified HTML tagname (or matching the given set).

Parameters
BalanceElement | array | string$tag

Definition at line 1010 of file Balancer.php.

References MediaWiki\Tidy\BalanceStack\pop().

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

◆ popTo()

MediaWiki\Tidy\BalanceStack::popTo ( $idx)

Remove all nodes up to and including position $idx from the BalanceStack, flattening them in the process.

Parameters
int$idx

Definition at line 998 of file Balancer.php.

References MediaWiki\Tidy\BalanceStack\pop().

◆ removeElement()

MediaWiki\Tidy\BalanceStack::removeElement ( BalanceElement $elt,
$flatten = true )

Remove the given $elt from the BalanceStack, optionally flattening it in the process.

Parameters
BalanceElement$eltThe element to remove.
bool$flattenWhether to flatten the removed element.

Definition at line 1041 of file Balancer.php.

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

◆ replaceAt()

MediaWiki\Tidy\BalanceStack::replaceAt ( $idx,
BalanceElement $elt )

Replace the element at position $idx in the BalanceStack with $elt.

Parameters
int$idx
BalanceElement$elt

Definition at line 939 of file Balancer.php.

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

Member Data Documentation

◆ $config

array MediaWiki\Tidy\BalanceStack::$config
private

Configuration options governing flattening.

See also
Balancer::__construct()

Definition at line 675 of file Balancer.php.

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

◆ $currentNode

MediaWiki\Tidy\BalanceStack::$currentNode

Reference to the current element.

Definition at line 679 of file Balancer.php.

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

◆ $elements

BalanceElement[] MediaWiki\Tidy\BalanceStack::$elements = []
private

Backing storage for the stack.

Definition at line 662 of file Balancer.php.

◆ $fosterParentMode

bool MediaWiki\Tidy\BalanceStack::$fosterParentMode = false

Foster parent mode determines how nodes are inserted into the stack.

See also
https://html.spec.whatwg.org/multipage/syntax.html#foster-parent

Definition at line 669 of file Balancer.php.


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