r37009 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r37008‎ | r37009 | r37010 >
Date:21:25, 3 July 2008
Author:brion
Status:old
Tags:
Comment:
Have been playing with custom API modules and been a bit frustrated with the XML output mode...
Adding pseudo-element _attribs alongside _element for XML output. There doesn't seem to be a good way currently to specify both attributes *and* subelements -- '*' lets you have text and attributes, but not sub-elements and attributes. Contents of _attribs will be added as attributes without disturbing the sub-elements.
Modified paths:
  • /trunk/phase3/includes/api/ApiFormatXml.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/api/ApiFormatXml.php
@@ -83,6 +83,13 @@
8484
8585 switch (gettype($elemValue)) {
8686 case 'array' :
 87+ if (isset ($elemValue['_attribs'])) {
 88+ $attribValues = $elemValue['_attribs'];
 89+ unset( $elemValue['_attribs'] );
 90+ } else {
 91+ $attribValues = null;
 92+ }
 93+
8794 if (isset ($elemValue['*'])) {
8895 $subElemContent = $elemValue['*'];
8996 if ($this->mDoubleQuote)
@@ -113,6 +120,8 @@
114121 unset ($elemValue[$subElemId]);
115122 }
116123 }
 124+
 125+ $elemValue = wfArrayMerge( $attribValues, $elemValue ); // wtf
117126
118127 if (is_null($subElemIndName) && !empty ($indElements))
119128 ApiBase :: dieDebug(__METHOD__, "($elemName, ...) has integer keys without _element value. Use ApiResult::setIndexedTagName().");
@@ -123,7 +132,7 @@
124133 if (!is_null($subElemContent)) {
125134 $this->printText($indstr . wfElement($elemName, $elemValue, $subElemContent));
126135 } elseif (empty ($indElements) && empty ($subElements)) {
127 - $this->printText($indstr . wfElement($elemName, $elemValue));
 136+ $this->printText($indstr . wfElement($elemName, $elemValue));
128137 } else {
129138 $this->printText($indstr . wfElement($elemName, $elemValue, null));
130139

Follow-up revisions

RevisionCommit summaryAuthorDate
r37075Revert r37009 -- turns out you can do these structures, it's just very nonobv...brion22:44, 4 July 2008

Status & tagging log