33 private $mRootElemName =
'api';
34 public static $namespace =
'http://www.mediawiki.org/xml/api/';
35 private $mIncludeNamespace =
false;
36 private $mXslt =
null;
46 public function setRootElement( $rootElemName ) {
47 $this->mRootElemName = $rootElemName;
52 $this->mIncludeNamespace =
$params[
'includexmlnamespace'];
55 $this->
printText(
'<?xml version="1.0"?>' );
56 if ( !is_null( $this->mXslt ) ) {
59 if ( $this->mIncludeNamespace ) {
70 self::recXmlPrint( $this->mRootElemName,
120 public static function recXmlPrint( $elemName, $elemValue, $indent ) {
122 if ( !is_null( $indent ) ) {
124 $indstr =
"\n" . str_repeat(
' ', $indent );
128 $elemName = str_replace(
' ',
'_', $elemName );
130 if ( is_array( $elemValue ) ) {
131 if ( isset( $elemValue[
'*'] ) ) {
132 $subElemContent = $elemValue[
'*'];
133 unset( $elemValue[
'*'] );
138 $elemValue[
'xml:space'] =
'preserve';
140 $subElemContent =
null;
143 if ( isset( $elemValue[
'_element'] ) ) {
144 $subElemIndName = $elemValue[
'_element'];
145 unset( $elemValue[
'_element'] );
147 $subElemIndName =
null;
150 $indElements =
array();
151 $subElements =
array();
152 foreach ( $elemValue
as $subElemId => & $subElemValue ) {
153 if ( is_int( $subElemId ) ) {
154 $indElements[] = $subElemValue;
155 unset( $elemValue[$subElemId] );
156 } elseif ( is_array( $subElemValue ) ) {
157 $subElements[$subElemId] = $subElemValue;
158 unset( $elemValue[$subElemId] );
159 } elseif ( is_bool( $subElemValue ) ) {
161 if ( $subElemValue ===
true ) {
164 unset( $elemValue[$subElemId] );
169 if ( is_null( $subElemIndName ) && count( $indElements ) ) {
171 "without _element value. Use ApiResult::setIndexedTagName()." );
174 if ( count( $subElements ) && count( $indElements ) && !is_null( $subElemContent ) ) {
178 if ( !is_null( $subElemContent ) ) {
180 } elseif ( !count( $indElements ) && !count( $subElements ) ) {
185 foreach ( $subElements
as $subElemId => & $subElemValue ) {
186 $retval .= self::recXmlPrint( $subElemId, $subElemValue, $indent );
189 foreach ( $indElements
as &$subElemValue ) {
190 $retval .= self::recXmlPrint( $subElemIndName, $subElemValue, $indent );
195 } elseif ( !is_object( $elemValue ) ) {
198 if ( $elemValue ===
null ) {
210 if ( is_null( $nt ) || !$nt->exists() ) {
211 $this->
setWarning(
'Invalid or non-existent stylesheet specified' );
216 $this->
setWarning(
'Stylesheet should be in the MediaWiki namespace.' );
220 if ( substr( $nt->getText(), -4 ) !==
'.xsl' ) {
221 $this->
setWarning(
'Stylesheet should have .xsl extension.' );
225 $this->
printText(
'<?xml-stylesheet href="' .
226 htmlspecialchars( $nt->getLocalURL(
'action=raw' ) ) .
'" type="text/xsl" ?>' );
232 'includexmlnamespace' =>
false,
238 'xslt' =>
'If specified, adds <xslt> as stylesheet. This should be a wiki page '
239 .
'in the MediaWiki namespace whose page name ends with ".xsl"',
240 'includexmlnamespace' =>
'If specified, adds an XML namespace'
245 return 'Output data in XML format' . parent::getDescription();