Make ApiFeedWatchlist obey $wgFeed, and also die with an error if an invalid feed...
authorSam Reed <reedy@users.mediawiki.org>
Mon, 6 Jun 2011 14:06:37 +0000 (14:06 +0000)
committerSam Reed <reedy@users.mediawiki.org>
Mon, 6 Jun 2011 14:06:37 +0000 (14:06 +0000)
includes/api/ApiFeedWatchlist.php

index d8c1019..83cea0c 100644 (file)
@@ -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',