From: Daniel Kinzler Date: Thu, 10 Jun 2010 15:16:15 +0000 (+0000) Subject: added newPartNodeArray for creating a node with a list of parts form a php array... X-Git-Tag: 1.31.0-rc.0~36550 X-Git-Url: http://git.cyclocoop.org/%22%2C%20generer_url_ecrire%28?a=commitdiff_plain;h=b9febe41616218b00e4a284e822a90e063459076;p=lhc%2Fweb%2Fwiklou.git added newPartNodeArray for creating a node with a list of parts form a php array; useful for programatically constructing template parameters --- 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().