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
{
32 * This module uses a custom feed wrapper printer.
34 * @return ApiFormatFeedWrapper
36 public function getCustomPrinter() {
37 return new ApiFormatFeedWrapper( $this->getMain() );
41 * Format the rows (generated by SpecialRecentchanges or SpecialRecentchangeslinked)
42 * as an RSS/Atom feed.
44 public function execute() {
45 $config = $this->getConfig();
47 $this->params
= $this->extractRequestParams();
49 if ( !$config->get( 'Feed' ) ) {
50 $this->dieUsage( 'Syndication feeds are not available', 'feed-unavailable' );
53 $feedClasses = $config->get( 'FeedClasses' );
54 if ( !isset( $feedClasses[$this->params
['feedformat']] ) ) {
55 $this->dieUsage( 'Invalid subscription feed type', 'feed-invalid' );
58 $this->getMain()->setCacheMode( 'public' );
59 if ( !$this->getMain()->getParameter( 'smaxage' ) ) {
60 // bug 63249: This page gets hit a lot, cache at least 15 seconds.
61 $this->getMain()->setCacheMaxAge( 15 );
64 $feedFormat = $this->params
['feedformat'];
65 $specialClass = $this->params
['target'] !== null
66 ?
'SpecialRecentchangeslinked'
67 : 'SpecialRecentchanges';
69 $formatter = $this->getFeedObject( $feedFormat, $specialClass );
71 // Parameters are passed via the request in the context… :(
72 $context = new DerivativeContext( $this );
73 $context->setRequest( new DerivativeRequest(
76 $this->getRequest()->wasPosted()
79 // The row-getting functionality should be factored out of ChangesListSpecialPage too…
80 $rc = new $specialClass();
81 $rc->setContext( $context );
82 $rows = $rc->getRows();
84 $feedItems = $rows ? ChangesFeed
::buildItems( $rows ) : array();
86 ApiFormatFeedWrapper
::setResult( $this->getResult(), $formatter, $feedItems );
90 * Return a ChannelFeed object.
92 * @param string $feedFormat Feed's format (either 'rss' or 'atom')
93 * @param string $specialClass Relevant special page name (either 'SpecialRecentchanges' or
94 * 'SpecialRecentchangeslinked')
97 public function getFeedObject( $feedFormat, $specialClass ) {
98 if ( $specialClass === 'SpecialRecentchangeslinked' ) {
99 $title = Title
::newFromText( $this->params
['target'] );
101 $this->dieUsageMsg( array( 'invalidtitle', $this->params
['target'] ) );
104 $feed = new ChangesFeed( $feedFormat, false );
105 $feedObj = $feed->getFeedObject(
106 $this->msg( 'recentchangeslinked-title', $title->getPrefixedText() )
107 ->inContentLanguage()->text(),
108 $this->msg( 'recentchangeslinked-feed' )->inContentLanguage()->text(),
109 SpecialPage
::getTitleFor( 'Recentchangeslinked' )->getFullURL()
112 $feed = new ChangesFeed( $feedFormat, 'rcfeed' );
113 $feedObj = $feed->getFeedObject(
114 $this->msg( 'recentchanges' )->inContentLanguage()->text(),
115 $this->msg( 'recentchanges-feed-description' )->inContentLanguage()->text(),
116 SpecialPage
::getTitleFor( 'Recentchanges' )->getFullURL()
123 public function getAllowedParams() {
124 $config = $this->getConfig();
125 $feedFormatNames = array_keys( $config->get( 'FeedClasses' ) );
128 'feedformat' => array(
129 ApiBase
::PARAM_DFLT
=> 'rss',
130 ApiBase
::PARAM_TYPE
=> $feedFormatNames,
133 'namespace' => array(
134 ApiBase
::PARAM_TYPE
=> 'namespace',
137 'associated' => false,
140 ApiBase
::PARAM_DFLT
=> 7,
141 ApiBase
::PARAM_MIN
=> 1,
142 ApiBase
::PARAM_TYPE
=> 'integer',
145 ApiBase
::PARAM_DFLT
=> 50,
146 ApiBase
::PARAM_MIN
=> 1,
147 ApiBase
::PARAM_MAX
=> $config->get( 'FeedLimit' ),
148 ApiBase
::PARAM_TYPE
=> 'integer',
151 ApiBase
::PARAM_TYPE
=> 'timestamp',
154 'hideminor' => false,
156 'hideanons' => false,
158 'hidepatrolled' => false,
159 'hidemyself' => false,
160 'hidecategorization' => false,
162 'tagfilter' => array(
163 ApiBase
::PARAM_TYPE
=> 'string',
167 ApiBase
::PARAM_TYPE
=> 'string',
169 'showlinkedto' => false,
172 if ( $config->get( 'AllowCategorizedRecentChanges' ) ) {
174 'categories' => array(
175 ApiBase
::PARAM_TYPE
=> 'string',
176 ApiBase
::PARAM_ISMULTI
=> true,
178 'categories_any' => false,
185 protected function getExamplesMessages() {
187 'action=feedrecentchanges'
188 => 'apihelp-feedrecentchanges-example-simple',
189 'action=feedrecentchanges&days=30'
190 => 'apihelp-feedrecentchanges-example-30days',