3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
23 * Recent changes feed.
27 class ApiFeedRecentChanges
extends ApiBase
{
30 * This module uses a custom feed wrapper printer.
32 * @return ApiFormatFeedWrapper
34 public function getCustomPrinter() {
35 return new ApiFormatFeedWrapper( $this->getMain() );
39 * Format the rows (generated by SpecialRecentchanges or SpecialRecentchangeslinked)
40 * as an RSS/Atom feed.
42 public function execute() {
43 global $wgFeed, $wgFeedClasses;
45 $this->params
= $this->extractRequestParams();
48 $this->dieUsage( 'Syndication feeds are not available', 'feed-unavailable' );
51 if ( !isset( $wgFeedClasses[$this->params
['feedformat']] ) ) {
52 $this->dieUsage( 'Invalid subscription feed type', 'feed-invalid' );
55 $feedFormat = $this->params
['feedformat'];
56 $specialClass = $this->params
['target'] !== null
57 ?
'SpecialRecentchangeslinked'
58 : 'SpecialRecentchanges';
60 $formatter = $this->getFeedObject( $feedFormat, $specialClass );
62 // Everything is passed implicitly via $wgRequest… :(
63 // The row-getting functionality should maybe be factored out of ChangesListSpecialPage too…
64 $rc = new $specialClass();
65 $rows = $rc->getRows();
67 $feedItems = $rows ? ChangesFeed
::buildItems( $rows ) : array();
69 ApiFormatFeedWrapper
::setResult( $this->getResult(), $formatter, $feedItems );
73 * Return a ChannelFeed object.
75 * @param string $feedFormat Feed's format (either 'rss' or 'atom')
76 * @param string $specialClass Relevant special page name (either 'SpecialRecentchanges' or
77 * 'SpecialRecentchangeslinked')
80 public function getFeedObject( $feedFormat, $specialClass ) {
81 if ( $specialClass === 'SpecialRecentchangeslinked' ) {
82 $title = Title
::newFromText( $this->params
['target'] );
83 $feed = new ChangesFeed( $feedFormat, false );
84 $feedObj = $feed->getFeedObject(
85 $this->msg( 'recentchangeslinked-title', $title->getPrefixedText() )
86 ->inContentLanguage()->text(),
87 $this->msg( 'recentchangeslinked-feed' )->inContentLanguage()->text(),
88 SpecialPage
::getTitleFor( 'Recentchangeslinked' )->getFullURL()
91 $feed = new ChangesFeed( $feedFormat, 'rcfeed' );
92 $feedObj = $feed->getFeedObject(
93 $this->msg( 'recentchanges' )->inContentLanguage()->text(),
94 $this->msg( 'recentchanges-feed-description' )->inContentLanguage()->text(),
95 SpecialPage
::getTitleFor( 'Recentchanges' )->getFullURL()
102 public function getAllowedParams() {
103 global $wgFeedClasses, $wgAllowCategorizedRecentChanges, $wgFeedLimit;
104 $feedFormatNames = array_keys( $wgFeedClasses );
107 'feedformat' => array(
108 ApiBase
::PARAM_DFLT
=> 'rss',
109 ApiBase
::PARAM_TYPE
=> $feedFormatNames,
112 'namespace' => array(
113 ApiBase
::PARAM_TYPE
=> 'namespace',
116 'associated' => false,
119 ApiBase
::PARAM_DFLT
=> 7,
120 ApiBase
::PARAM_MIN
=> 1,
121 ApiBase
::PARAM_TYPE
=> 'integer',
124 ApiBase
::PARAM_DFLT
=> 50,
125 ApiBase
::PARAM_MIN
=> 1,
126 ApiBase
::PARAM_MAX
=> $wgFeedLimit,
127 ApiBase
::PARAM_TYPE
=> 'integer',
130 ApiBase
::PARAM_TYPE
=> 'timestamp',
133 'hideminor' => false,
135 'hideanons' => false,
137 'hidepatrolled' => false,
138 'hidemyself' => false,
140 'tagfilter' => array(
141 ApiBase
::PARAM_TYPE
=> 'string',
145 ApiBase
::PARAM_TYPE
=> 'string',
147 'showlinkedto' => false,
150 if ( $wgAllowCategorizedRecentChanges ) {
152 'categories' => array(
153 ApiBase
::PARAM_TYPE
=> 'string',
154 ApiBase
::PARAM_ISMULTI
=> true,
156 'categories_any' => false,
163 public function getParamDescription() {
165 'feedformat' => 'The format of the feed',
166 'namespace' => 'Namespace to limit the results to',
167 'invert' => 'All namespaces but the selected one',
168 'associated' => 'Include associated (talk or main) namespace',
169 'days' => 'Days to limit the results to',
170 'limit' => 'Maximum number of results to return',
171 'from' => 'Show changes since then',
172 'hideminor' => 'Hide minor changes',
173 'hidebots' => 'Hide changes made by bots',
174 'hideanons' => 'Hide changes made by anonymous users',
175 'hideliu' => 'Hide changes made by registered users',
176 'hidepatrolled' => 'Hide patrolled changes',
177 'hidemyself' => 'Hide changes made by yourself',
178 'tagfilter' => 'Filter by tag',
179 'target' => 'Show only changes on pages linked from this page',
180 'showlinkedto' => 'Show changes on pages linked to the selected page instead',
181 'categories' => 'Show only changes on pages in all of these categories',
182 'categories_any' => 'Show only changes on pages in any of the categories instead',
186 public function getDescription() {
187 return 'Returns a recent changes feed';
190 public function getPossibleErrors() {
191 return array_merge( parent
::getPossibleErrors(), array(
192 array( 'code' => 'feed-unavailable', 'info' => 'Syndication feeds are not available' ),
193 array( 'code' => 'feed-invalid', 'info' => 'Invalid subscription feed type' ),
197 public function getExamples() {
199 'api.php?action=feedrecentchanges',
200 'api.php?action=feedrecentchanges&days=30'