r67819 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r67818‎ | r67819 | r67820 >
Date:15:02, 10 June 2010
Author:daniel
Status:resolved (Comments)
Tags:
Comment:
added newPartNodeArray for creating a node with a list of parts form a php array; useful for programatically constructing template parameters
Modified paths:
  • /trunk/phase3/includes/parser/Preprocessor_DOM.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/parser/Preprocessor_DOM.php
@@ -29,6 +29,30 @@
3030 return new PPCustomFrame_DOM( $this, $args );
3131 }
3232
 33+ function newPartNodeArray( $values ) {
 34+ //NOTE: DOM manipulation is slower than building & parsing XML! (or so Tim sais)
 35+ $xml = "";
 36+ $xml .= "<list>";
 37+
 38+ foreach ( $values as $k => $val ) {
 39+
 40+ if ( is_int( $k ) ) {
 41+ $xml .= "<part><name index=\"$k\"/><value>" . htmlspecialchars( $val ) ."</value></part>";
 42+ } else {
 43+ $xml .= "<part><name>" . htmlspecialchars( $k ) . "</name>=<value>" . htmlspecialchars( $val ) . "</value></part>";
 44+ }
 45+ }
 46+
 47+ $xml .= "</list>";
 48+
 49+ $dom = new DOMDocument();
 50+ $dom->loadXML( $xml );
 51+ $root = $dom->documentElement;
 52+
 53+ $node = new PPNode_DOM( $root->childNodes );
 54+ return $node;
 55+ }
 56+
3357 function memCheck() {
3458 if ( $this->memoryLimit === false ) {
3559 return;

Follow-up revisions

RevisionCommit summaryAuthorDate
r67821follow-up to r67820 and r67819: interface function newPartNodeArray for creat...daniel15:18, 10 June 2010
r79709Fixup fixme on r67819reedy03:24, 6 January 2011

Comments

#Comment by Duesentrieb (talk | contribs)   13:32, 15 July 2010

needed by DataTransclusion extension

#Comment by MarkAHershberger (talk | contribs)   20:31, 15 December 2010

+ $xml = "";

+		$xml .= "<list>";

Should be rewritten as:

+		$xml = "<list>";

to be (slightly) faster by eliminating the un-necessary assignment and concatenation.

#Comment by MarkAHershberger (talk | contribs)   22:42, 15 December 2010

Just noticed this, but the inclusion of the "=" between <name> and <value> seems superfluous and inconsistent.

#Comment by Catrope (talk | contribs)   13:52, 6 January 2011

The equals is needed. It's for template params, and the format is something like <name>param</name>=<value>val</value>

#Comment by MarkAHershberger (talk | contribs)   19:24, 6 January 2011

Gotcha, but it looks like (from this admittedly small sample) the code that needs this could do without the "=" and just use part/name and part/value.

Status & tagging log