From 4e4be177e402dc30dbd684ed3a642da903a835d5 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Thu, 3 Jul 2008 21:25:20 +0000 Subject: [PATCH] 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. --- includes/api/ApiFormatXml.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) 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)); -- 2.20.1