From 59c87066fbe5a7bd262abe8495738f0f608b8944 Mon Sep 17 00:00:00 2001 From: Sam Reed Date: Mon, 6 Jun 2011 14:06:37 +0000 Subject: [PATCH] Make ApiFeedWatchlist obey $wgFeed, and also die with an error if an invalid feed formatter is given --- includes/api/ApiFeedWatchlist.php | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/includes/api/ApiFeedWatchlist.php b/includes/api/ApiFeedWatchlist.php index d8c1019ba4..83cea0cb38 100644 --- a/includes/api/ApiFeedWatchlist.php +++ b/includes/api/ApiFeedWatchlist.php @@ -56,11 +56,19 @@ class ApiFeedWatchlist extends ApiBase { * Wrap the result as an RSS/Atom feed. */ public function execute() { - global $wgFeedClasses, $wgFeedLimit, $wgSitename, $wgLanguageCode; + global $wgFeed, $wgFeedClasses, $wgFeedLimit, $wgSitename, $wgLanguageCode; try { $params = $this->extractRequestParams(); + if( !$wgFeed ) { + $this->dieUsage( 'Syndication feeds are not available', 'feed-unavailable' ); + } + + if( !isset( $wgFeedClasses[ $params['feed'] ] ) ) { + $this->dieUsage( 'Invalid subscription feed type', 'feed-invalid' ); + } + // limit to the number of hours going from now back $endTime = wfTimestamp( TS_MW, time() - intval( $params['hours'] * 60 * 60 ) ); @@ -197,6 +205,13 @@ class ApiFeedWatchlist extends ApiBase { return 'Returns a watchlist feed'; } + public function getPossibleErrors() { + return array_merge( parent::getPossibleErrors(), array( + array( 'code' => 'feed-unavailable', 'info' => 'Syndication feeds are not available' ), + array( 'code' => 'feed-invalid', 'info' => 'Invalid subscription feed type' ), + ) ); + } + protected function getExamples() { return array( 'api.php?action=feedwatchlist', -- 2.20.1