71 $this->store = $store;
72 $this->index = $index;
73 [
$this->name, $this->rawChildren ] = $this->store[$index];
85 public static function factory( array $store, $index ) {
86 if ( !isset( $store[$index] ) ) {
90 $descriptor = $store[$index];
91 if ( is_string( $descriptor ) ) {
92 $class = PPNode_Hash_Text::class;
93 } elseif ( is_array( $descriptor ) ) {
94 if ( $descriptor[self::NAME][0] ===
'@' ) {
95 $class = PPNode_Hash_Attr::class;
100 throw new MWException( __METHOD__ .
': invalid node descriptor' );
102 return new $class( $store, $index );
112 for ( $node = $this->
getFirstChild(); $node; $node = $node->getNextSibling() ) {
114 $attribs .=
' ' . $node->name .
115 '="' . htmlspecialchars( $node->value, ENT_COMPAT ) .
'"';
117 $inner .= $node->__toString();
120 if ( $inner ===
'' ) {
121 return "<{$this->name}$attribs/>";
123 return "<{$this->name}$attribs>$inner</{$this->name}>";
132 foreach ( $this->rawChildren as $i => $child ) {
146 if ( !isset( $this->rawChildren[0] ) ) {
172 foreach ( $this->rawChildren as $i => $child ) {
173 if ( is_array( $child ) && $child[self::NAME] ===
$name ) {
185 return $this->rawChildren;
230 foreach ( $children as $i => $child ) {
231 if ( !is_array( $child ) ) {
234 if ( $child[self::NAME] ===
'name' ) {
235 $bits[
'name'] =
new self( $children, $i );
236 if ( isset( $child[self::CHILDREN][0][self::NAME] )
241 } elseif ( $child[self::NAME] ===
'value' ) {
242 $bits[
'value'] =
new self( $children, $i );
246 if ( !isset( $bits[
'name'] ) ) {
247 throw new MWException(
'Invalid brace node passed to ' . __METHOD__ );
249 if ( !isset( $bits[
'index'] ) ) {
273 foreach ( $children as $i => $child ) {
274 if ( !is_array( $child ) ) {
277 switch ( $child[self::NAME] ) {
279 $bits[
'name'] =
new self( $children, $i );
282 $bits[
'attr'] =
new self( $children, $i );
285 $bits[
'inner'] =
new self( $children, $i );
288 $bits[
'close'] =
new self( $children, $i );
292 if ( !isset( $bits[
'name'] ) ) {
293 throw new MWException(
'Invalid ext node passed to ' . __METHOD__ );
305 if ( $this->name !==
'h' ) {
306 throw new MWException(
'Invalid h node passed to ' . __METHOD__ );
318 foreach ( $children as $child ) {
319 if ( !is_array( $child ) ) {
322 if ( $child[self::NAME] ===
'@i' ) {
324 } elseif ( $child[self::NAME] ===
'@level' ) {
328 if ( !isset( $bits[
'i'] ) ) {
329 throw new MWException(
'Invalid h node passed to ' . __METHOD__ );
352 $bits = [
'lineStart' =>
'' ];
353 foreach ( $children as $i => $child ) {
354 if ( !is_array( $child ) ) {
357 switch ( $child[self::NAME] ) {
359 $bits[
'title'] =
new self( $children, $i );
362 $parts[] =
new self( $children, $i );
365 $bits[
'lineStart'] =
'1';
369 if ( !isset( $bits[
'title'] ) ) {
370 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:
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.
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.
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: