69 list( $this->name, $this->rawChildren ) = $this->store[
$index];
87 if ( is_string( $descriptor ) ) {
88 $class = PPNode_Hash_Text::class;
89 } elseif ( is_array( $descriptor ) ) {
90 if ( $descriptor[self::NAME][0] ===
'@' ) {
91 $class = PPNode_Hash_Attr::class;
96 throw new MWException( __METHOD__ .
': invalid node descriptor' );
108 for ( $node = $this->
getFirstChild(); $node; $node = $node->getNextSibling() ) {
110 $attribs .=
' ' . $node->name .
'="' . htmlspecialchars( $node->value ) .
'"';
112 $inner .= $node->__toString();
115 if ( $inner ===
'' ) {
116 return "<{$this->name}$attribs/>";
118 return "<{$this->name}$attribs>$inner</{$this->name}>";
127 foreach ( $this->rawChildren as $i => $child ) {
141 if ( !isset( $this->rawChildren[0] ) ) {
167 foreach ( $this->rawChildren as $i => $child ) {
168 if ( is_array( $child ) && $child[self::NAME] ===
$name ) {
225 foreach ( $children as $i => $child ) {
226 if ( !is_array( $child ) ) {
229 if ( $child[self::NAME] ===
'name' ) {
230 $bits[
'name'] =
new self( $children, $i );
231 if ( isset( $child[self::CHILDREN][0][self::NAME] )
236 } elseif ( $child[self::NAME] ===
'value' ) {
237 $bits[
'value'] =
new self( $children, $i );
241 if ( !isset( $bits[
'name'] ) ) {
242 throw new MWException(
'Invalid brace node passed to ' . __METHOD__ );
244 if ( !isset( $bits[
'index'] ) ) {
268 foreach ( $children as $i => $child ) {
269 if ( !is_array( $child ) ) {
272 switch ( $child[self::NAME] ) {
274 $bits[
'name'] =
new self( $children, $i );
277 $bits[
'attr'] =
new self( $children, $i );
280 $bits[
'inner'] =
new self( $children, $i );
283 $bits[
'close'] =
new self( $children, $i );
287 if ( !isset( $bits[
'name'] ) ) {
288 throw new MWException(
'Invalid ext node passed to ' . __METHOD__ );
300 if ( $this->name !==
'h' ) {
301 throw new MWException(
'Invalid h node passed to ' . __METHOD__ );
313 foreach ( $children as $i => $child ) {
314 if ( !is_array( $child ) ) {
317 if ( $child[self::NAME] ===
'@i' ) {
319 } elseif ( $child[self::NAME] ===
'@level' ) {
323 if ( !isset( $bits[
'i'] ) ) {
324 throw new MWException(
'Invalid h node passed to ' . __METHOD__ );
346 $bits = [
'lineStart' =>
'' ];
347 foreach ( $children as $i => $child ) {
348 if ( !is_array( $child ) ) {
351 switch ( $child[self::NAME] ) {
353 $bits[
'title'] =
new self( $children, $i );
356 $parts[] =
new self( $children, $i );
359 $bits[
'lineStart'] =
'1';
363 if ( !isset( $bits[
'title'] ) ) {
364 throw new MWException(
'Invalid node passed to ' . __METHOD__ );
static factory(array $store, $index)
Construct an appropriate PPNode_Hash_* object with a class that depends on what is at the relevant st...
splitExt()
Split an "<ext>" node into an associative array containing name, attr, inner and close All values in ...
static splitRawArg(array $children)
Like splitArg() but for a raw child array.
splitArg()
Split a "<part>" node into an associative array containing:
$index
The index into $this->store which contains the descriptor of this node.
getNextSibling()
Get the next sibling, or false if there is none.
static splitRawTemplate(array $children)
Like splitTemplate() but for a raw child array.
splitHeading()
Split an "<h>" node.
splitTemplate()
Split a "<template>" or "<tplarg>" node.
static splitRawHeading(array $children)
Like splitHeading() but for a raw child array.
$store
The store array for the siblings of this node, including this node itself.
static splitRawExt(array $children)
Like splitExt() but for a raw child array.
__construct(array $store, $index)
Construct an object using the data from $store[$index].
getChildrenOfType( $name)
Get an array of the children with a given node name.
__toString()
Convert a node to XML, for debugging.
const CHILDREN
The offset of the child list within descriptors, used in some places for readability.
$rawChildren
The store array for children of this node.
getFirstChild()
Get the first child, or false if there is none.
getRawChildren()
Get the raw child array.
const NAME
The offset of the name within descriptors, used in some places for readability.
There are three types of nodes: