From: Brion Vibber Date: Thu, 3 Jul 2008 21:25:20 +0000 (+0000) Subject: Have been playing with custom API modules and been a bit frustrated with the XML... X-Git-Tag: 1.31.0-rc.0~46763 X-Git-Url: https://git.cyclocoop.org/%28%28?a=commitdiff_plain;h=4e4be177e402dc30dbd684ed3a642da903a835d5;p=lhc%2Fweb%2Fwiklou.git 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. --- diff --git a/includes/api/ApiFormatXml.php b/includes/api/ApiFormatXml.php index b1194171bc..928e4b9c59 100644 --- a/includes/api/ApiFormatXml.php +++ b/includes/api/ApiFormatXml.php @@ -83,6 +83,13 @@ class ApiFormatXml extends ApiFormatBase { switch (gettype($elemValue)) { case 'array' : + if (isset ($elemValue['_attribs'])) { + $attribValues = $elemValue['_attribs']; + unset( $elemValue['_attribs'] ); + } else { + $attribValues = null; + } + if (isset ($elemValue['*'])) { $subElemContent = $elemValue['*']; if ($this->mDoubleQuote) @@ -113,6 +120,8 @@ class ApiFormatXml extends ApiFormatBase { unset ($elemValue[$subElemId]); } } + + $elemValue = wfArrayMerge( $attribValues, $elemValue ); // wtf if (is_null($subElemIndName) && !empty ($indElements)) ApiBase :: dieDebug(__METHOD__, "($elemName, ...) has integer keys without _element value. Use ApiResult::setIndexedTagName()."); @@ -123,7 +132,7 @@ class ApiFormatXml extends ApiFormatBase { if (!is_null($subElemContent)) { $this->printText($indstr . wfElement($elemName, $elemValue, $subElemContent)); } elseif (empty ($indElements) && empty ($subElements)) { - $this->printText($indstr . wfElement($elemName, $elemValue)); + $this->printText($indstr . wfElement($elemName, $elemValue)); } else { $this->printText($indstr . wfElement($elemName, $elemValue, null));