From b9febe41616218b00e4a284e822a90e063459076 Mon Sep 17 00:00:00 2001 From: Daniel Kinzler Date: Thu, 10 Jun 2010 15:16:15 +0000 Subject: [PATCH] added newPartNodeArray for creating a node with a list of parts form a php array; useful for programatically constructing template parameters --- includes/parser/Preprocessor_Hash.php | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/includes/parser/Preprocessor_Hash.php b/includes/parser/Preprocessor_Hash.php index 5015f1250e..f029e9c687 100644 --- a/includes/parser/Preprocessor_Hash.php +++ b/includes/parser/Preprocessor_Hash.php @@ -23,6 +23,33 @@ class Preprocessor_Hash implements Preprocessor { return new PPCustomFrame_Hash( $this, $args ); } + function newPartNodeArray( $values ) { + $list = array(); + + foreach ( $values as $k => $val ) { + $partNode = new PPNode_Hash_Tree( 'part' ); + $nameNode = new PPNode_Hash_Tree( 'name' ); + + if ( is_int( $k ) ) { + $nameNode->addChild( new PPNode_Hash_Attr( 'index', $k ) ); + $partNode->addChild( $nameNode ); + } else { + $nameNode->addChild( new PPNode_Hash_Text( $k ) ); + $partNode->addChild( $nameNode ); + $partNode->addChild( new PPNode_Hash_Text( '=' ) ); + } + + $valueNode = new PPNode_Hash_Tree( 'value' ); + $valueNode->addChild( new PPNode_Hash_Text( $val ) ); + $partNode->addChild( $valueNode ); + + $list[] = $partNode; + } + + $node = new PPNode_Hash_Array( $list ); + return $node; + } + /** * Preprocess some wikitext and return the document tree. * This is the ghost of Parser::replace_variables(). -- 2.20.1