MediaWiki  1.28.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 = []
 

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 654 of file Balancer.php.

Constructor & Destructor Documentation

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 683 of file Balancer.php.

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

Member Function Documentation

MediaWiki\Tidy\BalanceStack::__toString ( )

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

Returns
string

Definition at line 1356 of file Balancer.php.

References as.

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

Return the adjusted current node.

Definition at line 903 of file Balancer.php.

References MediaWiki\Tidy\BalanceStack\$currentNode.

MediaWiki\Tidy\BalanceStack::adoptionAgency (   $tag,
  $afe 
)
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 1018 of file Balancer.php.

References MediaWiki\Tidy\BalanceStack\pop().

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 885 of file Balancer.php.

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

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 913 of file Balancer.php.

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 698 of file Balancer.php.

References $out, and as.

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 816 of file Balancer.php.

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

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 953 of file Balancer.php.

References $tag.

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

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 826 of file Balancer.php.

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

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 806 of file Balancer.php.

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

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

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 846 of file Balancer.php.

References MediaWiki\Tidy\BalanceSets\$inInvertedSelectScopeSet, $tag, and as.

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 1069 of file Balancer.php.

References MediaWiki\Tidy\BalanceStack\indexOf().

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

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

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

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

Definition at line 713 of file Balancer.php.

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

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 750 of file Balancer.php.

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

Referenced by MediaWiki\Tidy\BalanceStack\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 764 of file Balancer.php.

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

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

MediaWiki\Tidy\BalanceStack::insertText (   $value,
  $isComment = false 
)
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 867 of file Balancer.php.

References $tag, and as.

Referenced by MediaWiki\Tidy\BalanceStack\inButtonScope(), MediaWiki\Tidy\BalanceStack\inListItemScope(), MediaWiki\Tidy\BalanceStack\inScope(), and MediaWiki\Tidy\BalanceStack\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 836 of file Balancer.php.

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

MediaWiki\Tidy\BalanceStack::length ( )

Return the number of elements currently in the BalanceStack.

Returns
int

Definition at line 966 of file Balancer.php.

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

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 923 of file Balancer.php.

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

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 1003 of file Balancer.php.

References $tag, and MediaWiki\Tidy\BalanceStack\pop().

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

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 991 of file Balancer.php.

References MediaWiki\Tidy\BalanceStack\pop().

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 1034 of file Balancer.php.

References MediaWiki\Tidy\BalanceElement\flatten().

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

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 932 of file Balancer.php.

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

Member Data Documentation

array MediaWiki\Tidy\BalanceStack::$config
private

Configuration options governing flattening.

See also
Balancer::__construct()

Definition at line 672 of file Balancer.php.

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

MediaWiki\Tidy\BalanceStack::$currentNode

Reference to the current element.

Definition at line 676 of file Balancer.php.

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

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

Definition at line 659 of file Balancer.php.

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 666 of file Balancer.php.


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