From: Bryan Tong Minh Date: Mon, 13 Jul 2009 21:37:49 +0000 (+0000) Subject: (bug 19528) Added XSLT parameter to API queries in format=xml X-Git-Tag: 1.31.0-rc.0~40973 X-Git-Url: http://git.cyclocoop.org/%22.%24image2.%22?a=commitdiff_plain;h=e94bc9516d0736ebf28f52d36f1dc2c0739c5da5;p=lhc%2Fweb%2Fwiklou.git (bug 19528) Added XSLT parameter to API queries in format=xml --- diff --git a/RELEASE-NOTES b/RELEASE-NOTES index 23465f4764..bfe4c208d7 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -292,6 +292,7 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN * Added snippet field to list=search output * (bug 17809) Add number of users in user groups to meta=siteinfo * (bug 18533) Add readonly reason to readonly exception +* (bug 19528) Added XSLT parameter to API queries in format=xml === Languages updated in 1.16 === diff --git a/includes/api/ApiFormatXml.php b/includes/api/ApiFormatXml.php index b6f726c5aa..de6645619d 100644 --- a/includes/api/ApiFormatXml.php +++ b/includes/api/ApiFormatXml.php @@ -35,6 +35,7 @@ class ApiFormatXml extends ApiFormatBase { private $mRootElemName = 'api'; private $mDoubleQuote = false; + private $mXslt = null; public function __construct($main, $format) { parent :: __construct($main, $format); @@ -55,8 +56,11 @@ class ApiFormatXml extends ApiFormatBase { public function execute() { $params = $this->extractRequestParams(); $this->mDoubleQuote = $params['xmldoublequote']; + $this->mXslt = $params['xslt']; $this->printText(''); + if (!is_null($this->mXslt)) + $this->addXslt(); $this->recXmlPrint($this->mRootElemName, $this->getResultData(), $this->getIsHtml() ? -2 : null); } @@ -150,19 +154,38 @@ class ApiFormatXml extends ApiFormatBase { break; } } + function addXslt() { + $nt = Title::newFromText( $this->mXslt ); + if ( is_null( $nt ) || !$nt->exists() ) { + $this->setWarning( 'Invalid or non-existent stylesheet specified' ); + return; + } + if ( $nt->getNamespace() != NS_MEDIAWIKI ) { + $this->setWarning( 'Stylesheet should be in the MediaWiki namespace.' ); + return; + } + if ( substr( $nt->getText(), -4 ) !== '.xsl' ) { + $this->setWarning( 'Stylesheet should have .xsl extension.' ); + return; + } + $this->printText( 'escapeLocalURL( 'action=raw' ) . '" type="text/xsl" ?>' ); + } + private function doubleQuote( $text ) { return Sanitizer::encodeAttribute( $text ); } public function getAllowedParams() { return array ( - 'xmldoublequote' => false + 'xmldoublequote' => false, + 'xslt' => null, ); } public function getParamDescription() { return array ( 'xmldoublequote' => 'If specified, double quotes all attributes and content.', + 'xslt' => 'If specified, adds as stylesheet', ); }