Localisation updates from https://translatewiki.net.
[mediawiki.git] / includes / api / ApiFeedRecentChanges.php
blob7239a2967f4dd3b7b98b83c9f910da2f49ab3a32
1 <?php
2 /**
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
18 * @file
19 * @since 1.23
22 /**
23 * Recent changes feed.
25 * @ingroup API
27 class ApiFeedRecentChanges extends ApiBase {
29 /**
30 * This module uses a custom feed wrapper printer.
32 * @return ApiFormatFeedWrapper
34 public function getCustomPrinter() {
35 return new ApiFormatFeedWrapper( $this->getMain() );
38 /**
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 );
79 /**
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')
85 * @return ChannelFeed
87 public function getFeedObject( $feedFormat, $specialClass ) {
88 if ( $specialClass === 'SpecialRecentchangeslinked' ) {
89 $title = Title::newFromText( $this->params['target'] );
90 if ( !$title ) {
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()
101 } else {
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()
110 return $feedObj;
113 public function getAllowedParams() {
114 $config = $this->getConfig();
115 $feedFormatNames = array_keys( $config->get( 'FeedClasses' ) );
117 $ret = array(
118 'feedformat' => array(
119 ApiBase::PARAM_DFLT => 'rss',
120 ApiBase::PARAM_TYPE => $feedFormatNames,
123 'namespace' => array(
124 ApiBase::PARAM_TYPE => 'namespace',
126 'invert' => false,
127 'associated' => false,
129 'days' => array(
130 ApiBase::PARAM_DFLT => 7,
131 ApiBase::PARAM_MIN => 1,
132 ApiBase::PARAM_TYPE => 'integer',
134 'limit' => array(
135 ApiBase::PARAM_DFLT => 50,
136 ApiBase::PARAM_MIN => 1,
137 ApiBase::PARAM_MAX => $config->get( 'FeedLimit' ),
138 ApiBase::PARAM_TYPE => 'integer',
140 'from' => array(
141 ApiBase::PARAM_TYPE => 'timestamp',
144 'hideminor' => false,
145 'hidebots' => false,
146 'hideanons' => false,
147 'hideliu' => false,
148 'hidepatrolled' => false,
149 'hidemyself' => false,
151 'tagfilter' => array(
152 ApiBase::PARAM_TYPE => 'string',
155 'target' => array(
156 ApiBase::PARAM_TYPE => 'string',
158 'showlinkedto' => false,
161 if ( $config->get( 'AllowCategorizedRecentChanges' ) ) {
162 $ret += array(
163 'categories' => array(
164 ApiBase::PARAM_TYPE => 'string',
165 ApiBase::PARAM_ISMULTI => true,
167 'categories_any' => false,
171 return $ret;
174 public function getParamDescription() {
175 return array(
176 'feedformat' => 'The format of the feed',
177 'namespace' => 'Namespace to limit the results to',
178 'invert' => 'All namespaces but the selected one',
179 'associated' => 'Include associated (talk or main) namespace',
180 'days' => 'Days to limit the results to',
181 'limit' => 'Maximum number of results to return',
182 'from' => 'Show changes since then',
183 'hideminor' => 'Hide minor changes',
184 'hidebots' => 'Hide changes made by bots',
185 'hideanons' => 'Hide changes made by anonymous users',
186 'hideliu' => 'Hide changes made by registered users',
187 'hidepatrolled' => 'Hide patrolled changes',
188 'hidemyself' => 'Hide changes made by yourself',
189 'tagfilter' => 'Filter by tag',
190 'target' => 'Show only changes on pages linked from this page',
191 'showlinkedto' => 'Show changes on pages linked to the selected page instead',
192 'categories' => 'Show only changes on pages in all of these categories',
193 'categories_any' => 'Show only changes on pages in any of the categories instead',
197 public function getDescription() {
198 return 'Returns a recent changes feed';
201 public function getExamples() {
202 return array(
203 'api.php?action=feedrecentchanges',
204 'api.php?action=feedrecentchanges&days=30'