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 $config = $this->getConfig();
45 $this->params
= $this->extractRequestParams();
47 if ( !$config->get( 'Feed' ) ) {
48 $this->dieUsage( 'Syndication feeds are not available', 'feed-unavailable' );
51 $feedClasses = $config->get( 'FeedClasses' );
52 if ( !isset( $feedClasses[$this->params
['feedformat']] ) ) {
53 $this->dieUsage( 'Invalid subscription feed type', 'feed-invalid' );
56 $this->getMain()->setCacheMode( 'public' );
57 if ( !$this->getMain()->getParameter( 'smaxage' ) ) {
58 // bug 63249: This page gets hit a lot, cache at least 15 seconds.
59 $this->getMain()->setCacheMaxAge( 15 );
62 $feedFormat = $this->params
['feedformat'];
63 $specialClass = $this->params
['target'] !== null
64 ?
'SpecialRecentchangeslinked'
65 : 'SpecialRecentchanges';
67 $formatter = $this->getFeedObject( $feedFormat, $specialClass );
69 // Everything is passed implicitly via $wgRequest… :(
70 // The row-getting functionality should maybe be factored out of ChangesListSpecialPage too…
71 $rc = new $specialClass();
72 $rows = $rc->getRows();
74 $feedItems = $rows ? ChangesFeed
::buildItems( $rows ) : array();
76 ApiFormatFeedWrapper
::setResult( $this->getResult(), $formatter, $feedItems );
80 * Return a ChannelFeed object.
82 * @param string $feedFormat Feed's format (either 'rss' or 'atom')
83 * @param string $specialClass Relevant special page name (either 'SpecialRecentchanges' or
84 * 'SpecialRecentchangeslinked')
87 public function getFeedObject( $feedFormat, $specialClass ) {
88 if ( $specialClass === 'SpecialRecentchangeslinked' ) {
89 $title = Title
::newFromText( $this->params
['target'] );
91 $this->dieUsageMsg( array( 'invalidtitle', $this->params
['target'] ) );
94 $feed = new ChangesFeed( $feedFormat, false );
95 $feedObj = $feed->getFeedObject(
96 $this->msg( 'recentchangeslinked-title', $title->getPrefixedText() )
97 ->inContentLanguage()->text(),
98 $this->msg( 'recentchangeslinked-feed' )->inContentLanguage()->text(),
99 SpecialPage
::getTitleFor( 'Recentchangeslinked' )->getFullURL()
102 $feed = new ChangesFeed( $feedFormat, 'rcfeed' );
103 $feedObj = $feed->getFeedObject(
104 $this->msg( 'recentchanges' )->inContentLanguage()->text(),
105 $this->msg( 'recentchanges-feed-description' )->inContentLanguage()->text(),
106 SpecialPage
::getTitleFor( 'Recentchanges' )->getFullURL()
113 public function getAllowedParams() {
114 $config = $this->getConfig();
115 $feedFormatNames = array_keys( $config->get( 'FeedClasses' ) );
118 'feedformat' => array(
119 ApiBase
::PARAM_DFLT
=> 'rss',
120 ApiBase
::PARAM_TYPE
=> $feedFormatNames,
123 'namespace' => array(
124 ApiBase
::PARAM_TYPE
=> 'namespace',
127 'associated' => false,
130 ApiBase
::PARAM_DFLT
=> 7,
131 ApiBase
::PARAM_MIN
=> 1,
132 ApiBase
::PARAM_TYPE
=> 'integer',
135 ApiBase
::PARAM_DFLT
=> 50,
136 ApiBase
::PARAM_MIN
=> 1,
137 ApiBase
::PARAM_MAX
=> $config->get( 'FeedLimit' ),
138 ApiBase
::PARAM_TYPE
=> 'integer',
141 ApiBase
::PARAM_TYPE
=> 'timestamp',
144 'hideminor' => false,
146 'hideanons' => false,
148 'hidepatrolled' => false,
149 'hidemyself' => false,
151 'tagfilter' => array(
152 ApiBase
::PARAM_TYPE
=> 'string',
156 ApiBase
::PARAM_TYPE
=> 'string',
158 'showlinkedto' => false,
161 if ( $config->get( 'AllowCategorizedRecentChanges' ) ) {
163 'categories' => array(
164 ApiBase
::PARAM_TYPE
=> 'string',
165 ApiBase
::PARAM_ISMULTI
=> true,
167 'categories_any' => false,
174 protected function getExamplesMessages() {
176 'action=feedrecentchanges'
177 => 'apihelp-feedrecentchanges-example-simple',
178 'action=feedrecentchanges&days=30'
179 => 'apihelp-feedrecentchanges-example-30days',