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

Public Attributes

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

Private Member Functions

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

Private Attributes

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

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.

References as.

◆ 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, and captcha-old\count.

◆ adoptionAgency()

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

◆ 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 captcha-old\count, and MediaWiki\Tidy\BalanceStack\pop().

◆ fosterParent()

◆ 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, and as.

◆ 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.

References captcha-old\count.

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, and as.

◆ 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 captcha-old\count, and 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()

◆ 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()

MediaWiki\Tidy\BalanceStack::insertText (   $value,
  $isComment = false 
)

◆ 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.

References as.

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.

References captcha-old\count.

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 captcha-old\count, and 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.

References captcha-old\count, and MediaWiki\Tidy\BalanceElement\flatten().

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.

References captcha-old\count.

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: