00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 if ( !defined( 'MEDIAWIKI' ) ) {
00027
00028 require_once ( 'ApiFormatBase.php' );
00029 }
00030
00034 class ApiFormatWddx extends ApiFormatBase {
00035
00036 public function __construct( $main, $format ) {
00037 parent :: __construct( $main, $format );
00038 }
00039
00040 public function getMimeType() {
00041 return 'text/xml';
00042 }
00043
00044 public function execute() {
00045
00046
00047
00048 $expected = "<wddxPacket version='1.0'><header/><data><string>\xc2\xa0</string></data></wddxPacket>";
00049 if ( function_exists( 'wddx_serialize_value' )
00050 && !$this->getIsHtml()
00051 && wddx_serialize_value( "\xc2\xa0" ) == $expected ) {
00052 $this->printText( wddx_serialize_value( $this->getResultData() ) );
00053 } else {
00054
00055
00056 $nl = ( $this->getIsHtml() ? "" : "\n" );
00057 $indstr = " ";
00058 $this->printText( "<?xml version=\"1.0\"?>$nl" );
00059 $this->printText( "<wddxPacket version=\"1.0\">$nl" );
00060 $this->printText( "$indstr<header/>$nl" );
00061 $this->printText( "$indstr<data>$nl" );
00062 $this->slowWddxPrinter( $this->getResultData(), 4 );
00063 $this->printText( "$indstr</data>$nl" );
00064 $this->printText( "</wddxPacket>$nl" );
00065 }
00066 }
00067
00071 function slowWddxPrinter( $elemValue, $indent = 0 ) {
00072 $indstr = ( $this->getIsHtml() ? "" : str_repeat( ' ', $indent ) );
00073 $indstr2 = ( $this->getIsHtml() ? "" : str_repeat( ' ', $indent + 2 ) );
00074 $nl = ( $this->getIsHtml() ? "" : "\n" );
00075 switch ( gettype( $elemValue ) ) {
00076 case 'array' :
00077
00078
00079 $cnt = count( $elemValue );
00080 if ( $cnt == 0 || array_keys( $elemValue ) === range( 0, $cnt - 1 ) ) {
00081
00082 $this->printText( $indstr . Xml::element( 'array', array(
00083 'length' => $cnt ), null ) . $nl );
00084 foreach ( $elemValue as $subElemValue )
00085 $this->slowWddxPrinter( $subElemValue, $indent + 2 );
00086 $this->printText( "$indstr</array>$nl" );
00087 } else {
00088
00089 $this->printText( "$indstr<struct>$nl" );
00090 foreach ( $elemValue as $subElemName => $subElemValue ) {
00091 $this->printText( $indstr2 . Xml::element( 'var', array(
00092 'name' => $subElemName
00093 ), null ) . $nl );
00094 $this->slowWddxPrinter( $subElemValue, $indent + 4 );
00095 $this->printText( "$indstr2</var>$nl" );
00096 }
00097 $this->printText( "$indstr</struct>$nl" );
00098 }
00099 break;
00100 case 'integer' :
00101 case 'double' :
00102 $this->printText( $indstr . Xml::element( 'number', null, $elemValue ) . $nl );
00103 break;
00104 case 'string' :
00105 $this->printText( $indstr . Xml::element( 'string', null, $elemValue ) . $nl );
00106 break;
00107 default :
00108 ApiBase :: dieDebug( __METHOD__, 'Unknown type ' . gettype( $elemValue ) );
00109 }
00110 }
00111
00112 public function getDescription() {
00113 return 'Output data in WDDX format' . parent :: getDescription();
00114 }
00115
00116 public function getVersion() {
00117 return __CLASS__ . ': $Id: ApiFormatWddx.php 61437 2010-01-23 22:26:40Z reedy $';
00118 }
00119 }