diff options
Diffstat (limited to 'includes/api/ApiFormatXml.php')
-rw-r--r-- | includes/api/ApiFormatXml.php | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/includes/api/ApiFormatXml.php b/includes/api/ApiFormatXml.php index 45ab73ef..3bdfdfa3 100644 --- a/includes/api/ApiFormatXml.php +++ b/includes/api/ApiFormatXml.php @@ -1,6 +1,6 @@ <?php /** - * API for MediaWiki 1.8+ + * * * Created on Sep 19, 2006 * @@ -36,7 +36,9 @@ if ( !defined( 'MEDIAWIKI' ) ) { class ApiFormatXml extends ApiFormatBase { private $mRootElemName = 'api'; + public static $namespace = 'http://www.mediawiki.org/xml/api/'; private $mDoubleQuote = false; + private $mIncludeNamespace = false; private $mXslt = null; public function __construct( $main, $format ) { @@ -58,15 +60,22 @@ class ApiFormatXml extends ApiFormatBase { public function execute() { $params = $this->extractRequestParams(); $this->mDoubleQuote = $params['xmldoublequote']; + $this->mIncludeNamespace = $params['includexmlnamespace']; $this->mXslt = $params['xslt']; $this->printText( '<?xml version="1.0"?>' ); if ( !is_null( $this->mXslt ) ) { $this->addXslt(); } + if ( $this->mIncludeNamespace ) { + $data = array( 'xmlns' => self::$namespace ) + $this->getResultData(); + } else { + $data = $this->getResultData(); + } + $this->printText( self::recXmlPrint( $this->mRootElemName, - $this->getResultData(), + $data, $this->getIsHtml() ? - 2 : null, $this->mDoubleQuote ) @@ -85,6 +94,13 @@ class ApiFormatXml extends ApiFormatBase { * * If neither key is found, all keys become element names, and values become element content. * The method is recursive, so the same rules apply to any sub-arrays. + * + * @param $elemName + * @param $elemValue + * @param $indent + * @param $doublequote bool + * + * @return string */ public static function recXmlPrint( $elemName, $elemValue, $indent, $doublequote = false ) { $retval = ''; @@ -193,6 +209,7 @@ class ApiFormatXml extends ApiFormatBase { return array( 'xmldoublequote' => false, 'xslt' => null, + 'includexmlnamespace' => false, ); } @@ -200,6 +217,7 @@ class ApiFormatXml extends ApiFormatBase { return array( 'xmldoublequote' => 'If specified, double quotes all attributes and content', 'xslt' => 'If specified, adds <xslt> as stylesheet', + 'includexmlnamespace' => 'If specified, adds an XML namespace' ); } @@ -208,6 +226,6 @@ class ApiFormatXml extends ApiFormatBase { } public function getVersion() { - return __CLASS__ . ': $Id: ApiFormatXml.php 73753 2010-09-25 16:56:03Z reedy $'; + return __CLASS__ . ': $Id: ApiFormatXml.php 104476 2011-11-28 20:08:17Z reedy $'; } } |