MediaWiki  1.23.15
ApiFormatWddx.php
Go to the documentation of this file.
1 <?php
31 class ApiFormatWddx extends ApiFormatBase {
32 
33  public function getMimeType() {
34  return 'text/xml';
35  }
36 
37  public function execute() {
38  // Some versions of PHP have a broken wddx_serialize_value, see
39  // PHP bug 45314. Test encoding an affected character (U+00A0)
40  // to avoid this.
41  $expected =
42  "<wddxPacket version='1.0'><header/><data><string>\xc2\xa0</string></data></wddxPacket>";
43  if ( function_exists( 'wddx_serialize_value' )
44  && !$this->getIsHtml()
45  && wddx_serialize_value( "\xc2\xa0" ) == $expected
46  ) {
47  $this->printText( wddx_serialize_value( $this->getResultData() ) );
48  } else {
49  // Don't do newlines and indentation if we weren't asked
50  // for pretty output
51  $nl = ( $this->getIsHtml() ? "\n" : '' );
52  $indstr = ' ';
53  $this->printText( "<?xml version=\"1.0\"?>$nl" );
54  $this->printText( "<wddxPacket version=\"1.0\">$nl" );
55  $this->printText( "$indstr<header/>$nl" );
56  $this->printText( "$indstr<data>$nl" );
57  $this->slowWddxPrinter( $this->getResultData(), 4 );
58  $this->printText( "$indstr</data>$nl" );
59  $this->printText( "</wddxPacket>$nl" );
60  }
61  }
62 
68  function slowWddxPrinter( $elemValue, $indent = 0 ) {
69  $indstr = ( $this->getIsHtml() ? str_repeat( ' ', $indent ) : '' );
70  $indstr2 = ( $this->getIsHtml() ? str_repeat( ' ', $indent + 2 ) : '' );
71  $nl = ( $this->getIsHtml() ? "\n" : '' );
72  if ( is_array( $elemValue ) ) {
73  // Check whether we've got an associative array (<struct>)
74  // or a regular array (<array>)
75  $cnt = count( $elemValue );
76  if ( $cnt == 0 || array_keys( $elemValue ) === range( 0, $cnt - 1 ) ) {
77  // Regular array
78  $this->printText( $indstr . Xml::element( 'array', array(
79  'length' => $cnt ), null ) . $nl );
80  foreach ( $elemValue as $subElemValue ) {
81  $this->slowWddxPrinter( $subElemValue, $indent + 2 );
82  }
83  $this->printText( "$indstr</array>$nl" );
84  } else {
85  // Associative array (<struct>)
86  $this->printText( "$indstr<struct>$nl" );
87  foreach ( $elemValue as $subElemName => $subElemValue ) {
88  $this->printText( $indstr2 . Xml::element( 'var', array(
89  'name' => $subElemName
90  ), null ) . $nl );
91  $this->slowWddxPrinter( $subElemValue, $indent + 4 );
92  $this->printText( "$indstr2</var>$nl" );
93  }
94  $this->printText( "$indstr</struct>$nl" );
95  }
96  } elseif ( is_int( $elemValue ) || is_float( $elemValue ) ) {
97  $this->printText( $indstr . Xml::element( 'number', null, $elemValue ) . $nl );
98  } elseif ( is_string( $elemValue ) ) {
99  $this->printText( $indstr . Xml::element( 'string', null, $elemValue ) . $nl );
100  } elseif ( is_bool( $elemValue ) ) {
101  $this->printText( $indstr . Xml::element( 'boolean',
102  array( 'value' => $elemValue ? 'true' : 'false' ) ) . $nl
103  );
104  } else {
105  ApiBase::dieDebug( __METHOD__, 'Unknown type ' . gettype( $elemValue ) );
106  }
107  }
108 
109  public function getDescription() {
110  return 'Output data in WDDX format' . parent::getDescription();
111  }
112 }
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
ApiFormatBase
This is the abstract base class for API formatters.
Definition: ApiFormatBase.php:32
ApiFormatBase\getMimeType
getMimeType()
Overriding class returns the mime type that should be sent to the client.
Xml\element
static element( $element, $attribs=null, $contents='', $allowShortTag=true)
Format an XML element with given attributes and, optionally, text content.
Definition: Xml.php:39
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
ApiFormatBase\getDescription
getDescription()
Returns the description string for this module.
Definition: ApiFormatBase.php:339
ApiBase\getResultData
getResultData()
Get the result data array (read-only)
Definition: ApiBase.php:219
ApiFormatBase\printText
printText( $text)
The main format printing function.
Definition: ApiFormatBase.php:229
as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
ApiFormatBase\getIsHtml
getIsHtml()
Returns true when the HTML pretty-printer should be used.
Definition: ApiFormatBase.php:97
ApiBase\dieDebug
static dieDebug( $method, $message)
Internal code errors should be reported with this method.
Definition: ApiBase.php:2030
ApiBase\execute
execute()
Evaluates the parameters, performs the requested query, and sets up the result.