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
00084 ), null) . $nl);
00085 foreach($elemValue as $subElemValue)
00086 $this->slowWddxPrinter($subElemValue, $indent + 2);
00087 $this->printText("$indstr</array>$nl");
00088 } else {
00089
00090 $this->printText("$indstr<struct>$nl");
00091 foreach($elemValue as $subElemName => $subElemValue) {
00092 $this->printText($indstr2 . Xml::element('var', array(
00093 'name' => $subElemName
00094 ), null) . $nl);
00095 $this->slowWddxPrinter($subElemValue, $indent + 4);
00096 $this->printText("$indstr2</var>$nl");
00097 }
00098 $this->printText("$indstr</struct>$nl");
00099 }
00100 break;
00101 case 'integer' :
00102 case 'double' :
00103 $this->printText($indstr . Xml::element('number', null, $elemValue) . $nl);
00104 break;
00105 case 'string' :
00106 $this->printText($indstr . Xml::element('string', null, $elemValue) . $nl);
00107 break;
00108 default :
00109 ApiBase :: dieDebug(__METHOD__, 'Unknown type ' . gettype($elemValue));
00110 }
00111 }
00112
00113 public function getDescription() {
00114 return 'Output data in WDDX format' . parent :: getDescription();
00115 }
00116
00117 public function getVersion() {
00118 return __CLASS__ . ': $Id: ApiFormatWddx.php 48716 2009-03-23 20:06:16Z catrope $';
00119 }
00120 }