Index: trunk/phase3/includes/api/ApiFormatXml.php |
— | — | @@ -61,7 +61,10 @@ |
62 | 62 | $this->printText('<?xml version="1.0"?>'); |
63 | 63 | if (!is_null($this->mXslt)) |
64 | 64 | $this->addXslt(); |
65 | | - $this->recXmlPrint($this->mRootElemName, $this->getResultData(), $this->getIsHtml() ? -2 : null); |
| 65 | + $this->printText($this->recXmlPrint($this->mRootElemName, |
| 66 | + $this->getResultData(), |
| 67 | + $this->getIsHtml() ? -2 : null, |
| 68 | + $this->mDoubleQuote)); |
66 | 69 | } |
67 | 70 | |
68 | 71 | /** |
— | — | @@ -77,7 +80,8 @@ |
78 | 81 | * If neither key is found, all keys become element names, and values become element content. |
79 | 82 | * The method is recursive, so the same rules apply to any sub-arrays. |
80 | 83 | */ |
81 | | - function recXmlPrint($elemName, $elemValue, $indent) { |
| 84 | + public static function recXmlPrint($elemName, $elemValue, $indent, $doublequote = false) { |
| 85 | + $retval = ''; |
82 | 86 | if (!is_null($indent)) { |
83 | 87 | $indent += 2; |
84 | 88 | $indstr = "\n" . str_repeat(" ", $indent); |
— | — | @@ -90,8 +94,8 @@ |
91 | 95 | case 'array' : |
92 | 96 | if (isset ($elemValue['*'])) { |
93 | 97 | $subElemContent = $elemValue['*']; |
94 | | - if ($this->mDoubleQuote) |
95 | | - $subElemContent = $this->doubleQuote($subElemContent); |
| 98 | + if ($doublequote) |
| 99 | + $subElemContent = Sanitizer::encodeAttribute($subElemContent); |
96 | 100 | unset ($elemValue['*']); |
97 | 101 | |
98 | 102 | // Add xml:space="preserve" to the |
— | — | @@ -112,8 +116,8 @@ |
113 | 117 | $indElements = array (); |
114 | 118 | $subElements = array (); |
115 | 119 | foreach ($elemValue as $subElemId => & $subElemValue) { |
116 | | - if (is_string($subElemValue) && $this->mDoubleQuote) |
117 | | - $subElemValue = $this->doubleQuote($subElemValue); |
| 120 | + if (is_string($subElemValue) && $doublequote) |
| 121 | + $subElemValue = Sanitizer::encodeAttribute($subElemValue); |
118 | 122 | |
119 | 123 | if (gettype($subElemId) === 'integer') { |
120 | 124 | $indElements[] = $subElemValue; |
— | — | @@ -131,28 +135,29 @@ |
132 | 136 | ApiBase :: dieDebug(__METHOD__, "($elemName, ...) has content and subelements"); |
133 | 137 | |
134 | 138 | if (!is_null($subElemContent)) { |
135 | | - $this->printText($indstr . Xml::element($elemName, $elemValue, $subElemContent)); |
| 139 | + $retval .= $indstr . Xml::element($elemName, $elemValue, $subElemContent); |
136 | 140 | } elseif (!count($indElements) && !count($subElements)) { |
137 | | - $this->printText($indstr . Xml::element($elemName, $elemValue)); |
| 141 | + $retval .= $indstr . Xml::element($elemName, $elemValue); |
138 | 142 | } else { |
139 | | - $this->printText($indstr . Xml::element($elemName, $elemValue, null)); |
| 143 | + $retval .= $indstr . Xml::element($elemName, $elemValue, null); |
140 | 144 | |
141 | 145 | foreach ($subElements as $subElemId => & $subElemValue) |
142 | | - $this->recXmlPrint($subElemId, $subElemValue, $indent); |
| 146 | + $retval .= self::recXmlPrint($subElemId, $subElemValue, $indent); |
143 | 147 | |
144 | 148 | foreach ($indElements as $subElemId => & $subElemValue) |
145 | | - $this->recXmlPrint($subElemIndName, $subElemValue, $indent); |
| 149 | + $retval .= self::recXmlPrint($subElemIndName, $subElemValue, $indent); |
146 | 150 | |
147 | | - $this->printText($indstr . Xml::closeElement($elemName)); |
| 151 | + $retval .= $indstr . Xml::closeElement($elemName); |
148 | 152 | } |
149 | 153 | break; |
150 | 154 | case 'object' : |
151 | 155 | // ignore |
152 | 156 | break; |
153 | 157 | default : |
154 | | - $this->printText($indstr . Xml::element($elemName, null, $elemValue)); |
| 158 | + $retval .= $indstr . Xml::element($elemName, null, $elemValue); |
155 | 159 | break; |
156 | 160 | } |
| 161 | + return $retval; |
157 | 162 | } |
158 | 163 | function addXslt() { |
159 | 164 | $nt = Title::newFromText( $this->mXslt ); |
— | — | @@ -171,10 +176,6 @@ |
172 | 177 | $this->printText( '<?xml-stylesheet href="' . $nt->escapeLocalURL( 'action=raw' ) . '" type="text/xsl" ?>' ); |
173 | 178 | } |
174 | 179 | |
175 | | - private function doubleQuote( $text ) { |
176 | | - return Sanitizer::encodeAttribute( $text ); |
177 | | - } |
178 | | - |
179 | 180 | public function getAllowedParams() { |
180 | 181 | return array ( |
181 | 182 | 'xmldoublequote' => false, |