Index: trunk/phase3/includes/api/ApiFormatXml.php |
— | — | @@ -35,6 +35,7 @@ |
36 | 36 | |
37 | 37 | private $mRootElemName = 'api'; |
38 | 38 | private $mDoubleQuote = false; |
| 39 | + private $mXslt = null; |
39 | 40 | |
40 | 41 | public function __construct($main, $format) { |
41 | 42 | parent :: __construct($main, $format); |
— | — | @@ -55,8 +56,11 @@ |
56 | 57 | public function execute() { |
57 | 58 | $params = $this->extractRequestParams(); |
58 | 59 | $this->mDoubleQuote = $params['xmldoublequote']; |
| 60 | + $this->mXslt = $params['xslt']; |
59 | 61 | |
60 | 62 | $this->printText('<?xml version="1.0"?>'); |
| 63 | + if (!is_null($this->mXslt)) |
| 64 | + $this->addXslt(); |
61 | 65 | $this->recXmlPrint($this->mRootElemName, $this->getResultData(), $this->getIsHtml() ? -2 : null); |
62 | 66 | } |
63 | 67 | |
— | — | @@ -150,19 +154,38 @@ |
151 | 155 | break; |
152 | 156 | } |
153 | 157 | } |
| 158 | + function addXslt() { |
| 159 | + $nt = Title::newFromText( $this->mXslt ); |
| 160 | + if ( is_null( $nt ) || !$nt->exists() ) { |
| 161 | + $this->setWarning( 'Invalid or non-existent stylesheet specified' ); |
| 162 | + return; |
| 163 | + } |
| 164 | + if ( $nt->getNamespace() != NS_MEDIAWIKI ) { |
| 165 | + $this->setWarning( 'Stylesheet should be in the MediaWiki namespace.' ); |
| 166 | + return; |
| 167 | + } |
| 168 | + if ( substr( $nt->getText(), -4 ) !== '.xsl' ) { |
| 169 | + $this->setWarning( 'Stylesheet should have .xsl extension.' ); |
| 170 | + return; |
| 171 | + } |
| 172 | + $this->printText( '<?xml-stylesheet href="' . $nt->escapeLocalURL( 'action=raw' ) . '" type="text/xsl" ?>' ); |
| 173 | + } |
| 174 | + |
154 | 175 | private function doubleQuote( $text ) { |
155 | 176 | return Sanitizer::encodeAttribute( $text ); |
156 | 177 | } |
157 | 178 | |
158 | 179 | public function getAllowedParams() { |
159 | 180 | return array ( |
160 | | - 'xmldoublequote' => false |
| 181 | + 'xmldoublequote' => false, |
| 182 | + 'xslt' => null, |
161 | 183 | ); |
162 | 184 | } |
163 | 185 | |
164 | 186 | public function getParamDescription() { |
165 | 187 | return array ( |
166 | 188 | 'xmldoublequote' => 'If specified, double quotes all attributes and content.', |
| 189 | + 'xslt' => 'If specified, adds <xslt> as stylesheet', |
167 | 190 | ); |
168 | 191 | } |
169 | 192 | |
Index: trunk/phase3/RELEASE-NOTES |
— | — | @@ -292,6 +292,7 @@ |
293 | 293 | * Added snippet field to list=search output |
294 | 294 | * (bug 17809) Add number of users in user groups to meta=siteinfo |
295 | 295 | * (bug 18533) Add readonly reason to readonly exception |
| 296 | +* (bug 19528) Added XSLT parameter to API queries in format=xml |
296 | 297 | |
297 | 298 | === Languages updated in 1.16 === |
298 | 299 | |