5 * Created on Oct 22, 2006
7 * Copyright © 2006 Yuri Astrakhan "<Firstname><Lastname>@gmail.com"
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 * http://www.gnu.org/copyleft/gpl.html
28 * API WDDX output formatter
29 * @deprecated since 1.24
32 class ApiFormatWddx
extends ApiFormatBase
{
34 public function getMimeType() {
38 public function execute() {
39 $this->markDeprecated();
41 // Some versions of PHP have a broken wddx_serialize_value, see
42 // PHP bug 45314. Test encoding an affected character (U+00A0)
45 "<wddxPacket version='1.0'><header/><data><string>\xc2\xa0</string></data></wddxPacket>";
46 if ( function_exists( 'wddx_serialize_value' )
47 && !$this->getIsHtml()
48 && wddx_serialize_value( "\xc2\xa0" ) == $expected
50 $this->printText( wddx_serialize_value( $this->getResultData() ) );
52 // Don't do newlines and indentation if we weren't asked
54 $nl = ( $this->getIsHtml() ?
"\n" : '' );
56 $this->printText( "<?xml version=\"1.0\"?>$nl" );
57 $this->printText( "<wddxPacket version=\"1.0\">$nl" );
58 $this->printText( "$indstr<header/>$nl" );
59 $this->printText( "$indstr<data>$nl" );
60 $this->slowWddxPrinter( $this->getResultData(), 4 );
61 $this->printText( "$indstr</data>$nl" );
62 $this->printText( "</wddxPacket>$nl" );
67 * Recursively go through the object and output its data in WDDX format.
68 * @param mixed $elemValue
71 function slowWddxPrinter( $elemValue, $indent = 0 ) {
72 $indstr = ( $this->getIsHtml() ?
str_repeat( ' ', $indent ) : '' );
73 $indstr2 = ( $this->getIsHtml() ?
str_repeat( ' ', $indent +
2 ) : '' );
74 $nl = ( $this->getIsHtml() ?
"\n" : '' );
75 if ( is_array( $elemValue ) ) {
76 // Check whether we've got an associative array (<struct>)
77 // or a regular array (<array>)
78 $cnt = count( $elemValue );
79 if ( $cnt == 0 ||
array_keys( $elemValue ) === range( 0, $cnt - 1 ) ) {
81 $this->printText( $indstr . Xml
::element( 'array', array(
82 'length' => $cnt ), null ) . $nl );
83 foreach ( $elemValue as $subElemValue ) {
84 $this->slowWddxPrinter( $subElemValue, $indent +
2 );
86 $this->printText( "$indstr</array>$nl" );
88 // Associative array (<struct>)
89 $this->printText( "$indstr<struct>$nl" );
90 foreach ( $elemValue as $subElemName => $subElemValue ) {
91 $this->printText( $indstr2 . Xml
::element( 'var', array(
92 'name' => $subElemName
94 $this->slowWddxPrinter( $subElemValue, $indent +
4 );
95 $this->printText( "$indstr2</var>$nl" );
97 $this->printText( "$indstr</struct>$nl" );
99 } elseif ( is_int( $elemValue ) ||
is_float( $elemValue ) ) {
100 $this->printText( $indstr . Xml
::element( 'number', null, $elemValue ) . $nl );
101 } elseif ( is_string( $elemValue ) ) {
102 $this->printText( $indstr . Xml
::element( 'string', null, $elemValue ) . $nl );
103 } elseif ( is_bool( $elemValue ) ) {
104 $this->printText( $indstr . Xml
::element( 'boolean',
105 array( 'value' => $elemValue ?
'true' : 'false' ) ) . $nl
108 ApiBase
::dieDebug( __METHOD__
, 'Unknown type ' . gettype( $elemValue ) );
112 public function getDescription() {
113 return 'DEPRECATED! Output data in WDDX format' . parent
::getDescription();