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'] );
84 $this->dieUsageMsg( array( 'invalidtitle', $this->params
['target'] ) );
87 $feed = new ChangesFeed( $feedFormat, false );
88 $feedObj = $feed->getFeedObject(
89 $this->msg( 'recentchangeslinked-title', $title->getPrefixedText() )
90 ->inContentLanguage()->text(),
91 $this->msg( 'recentchangeslinked-feed' )->inContentLanguage()->text(),
92 SpecialPage
::getTitleFor( 'Recentchangeslinked' )->getFullURL()
95 $feed = new ChangesFeed( $feedFormat, 'rcfeed' );
96 $feedObj = $feed->getFeedObject(
97 $this->msg( 'recentchanges' )->inContentLanguage()->text(),
98 $this->msg( 'recentchanges-feed-description' )->inContentLanguage()->text(),
99 SpecialPage
::getTitleFor( 'Recentchanges' )->getFullURL()
106 public function getAllowedParams() {
107 global $wgFeedClasses, $wgAllowCategorizedRecentChanges, $wgFeedLimit;
108 $feedFormatNames = array_keys( $wgFeedClasses );
111 'feedformat' => array(
112 ApiBase
::PARAM_DFLT
=> 'rss',
113 ApiBase
::PARAM_TYPE
=> $feedFormatNames,
116 'namespace' => array(
117 ApiBase
::PARAM_TYPE
=> 'namespace',
120 'associated' => false,
123 ApiBase
::PARAM_DFLT
=> 7,
124 ApiBase
::PARAM_MIN
=> 1,
125 ApiBase
::PARAM_TYPE
=> 'integer',
128 ApiBase
::PARAM_DFLT
=> 50,
129 ApiBase
::PARAM_MIN
=> 1,
130 ApiBase
::PARAM_MAX
=> $wgFeedLimit,
131 ApiBase
::PARAM_TYPE
=> 'integer',
134 ApiBase
::PARAM_TYPE
=> 'timestamp',
137 'hideminor' => false,
139 'hideanons' => false,
141 'hidepatrolled' => false,
142 'hidemyself' => false,
144 'tagfilter' => array(
145 ApiBase
::PARAM_TYPE
=> 'string',
149 ApiBase
::PARAM_TYPE
=> 'string',
151 'showlinkedto' => false,
154 if ( $wgAllowCategorizedRecentChanges ) {
156 'categories' => array(
157 ApiBase
::PARAM_TYPE
=> 'string',
158 ApiBase
::PARAM_ISMULTI
=> true,
160 'categories_any' => false,
167 public function getParamDescription() {
169 'feedformat' => 'The format of the feed',
170 'namespace' => 'Namespace to limit the results to',
171 'invert' => 'All namespaces but the selected one',
172 'associated' => 'Include associated (talk or main) namespace',
173 'days' => 'Days to limit the results to',
174 'limit' => 'Maximum number of results to return',
175 'from' => 'Show changes since then',
176 'hideminor' => 'Hide minor changes',
177 'hidebots' => 'Hide changes made by bots',
178 'hideanons' => 'Hide changes made by anonymous users',
179 'hideliu' => 'Hide changes made by registered users',
180 'hidepatrolled' => 'Hide patrolled changes',
181 'hidemyself' => 'Hide changes made by yourself',
182 'tagfilter' => 'Filter by tag',
183 'target' => 'Show only changes on pages linked from this page',
184 'showlinkedto' => 'Show changes on pages linked to the selected page instead',
185 'categories' => 'Show only changes on pages in all of these categories',
186 'categories_any' => 'Show only changes on pages in any of the categories instead',
190 public function getDescription() {
191 return 'Returns a recent changes feed';
194 public function getPossibleErrors() {
195 return array_merge( parent
::getPossibleErrors(), array(
196 array( 'code' => 'feed-unavailable', 'info' => 'Syndication feeds are not available' ),
197 array( 'code' => 'feed-invalid', 'info' => 'Invalid subscription feed type' ),
201 public function getExamples() {
203 'api.php?action=feedrecentchanges',
204 'api.php?action=feedrecentchanges&days=30'