Merge "Fix some omitted colons in Spanish magic word l10n"
[lhc/web/wiklou.git] / includes / api / ApiFeedRecentChanges.php
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.
7 *
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.
12 *
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
17 *
18 * @file
19 * @since 1.23
20 */
21
22 /**
23 * Recent changes feed.
24 *
25 * @ingroup API
26 */
27 class ApiFeedRecentChanges extends ApiBase {
28
29 /**
30 * This module uses a custom feed wrapper printer.
31 *
32 * @return ApiFormatFeedWrapper
33 */
34 public function getCustomPrinter() {
35 return new ApiFormatFeedWrapper( $this->getMain() );
36 }
37
38 /**
39 * Format the rows (generated by SpecialRecentchanges or SpecialRecentchangeslinked)
40 * as an RSS/Atom feed.
41 */
42 public function execute() {
43 global $wgFeed, $wgFeedClasses;
44
45 $this->params = $this->extractRequestParams();
46
47 if ( !$wgFeed ) {
48 $this->dieUsage( 'Syndication feeds are not available', 'feed-unavailable' );
49 }
50
51 if ( !isset( $wgFeedClasses[$this->params['feedformat']] ) ) {
52 $this->dieUsage( 'Invalid subscription feed type', 'feed-invalid' );
53 }
54
55 $feedFormat = $this->params['feedformat'];
56 $specialClass = $this->params['target'] !== null
57 ? 'SpecialRecentchangeslinked'
58 : 'SpecialRecentchanges';
59
60 $formatter = $this->getFeedObject( $feedFormat, $specialClass );
61
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();
66
67 $feedItems = $rows ? ChangesFeed::buildItems( $rows ) : array();
68
69 ApiFormatFeedWrapper::setResult( $this->getResult(), $formatter, $feedItems );
70 }
71
72 /**
73 * Return a ChannelFeed object.
74 *
75 * @param string $feedFormat Feed's format (either 'rss' or 'atom')
76 * @param string $specialClass Relevant special page name (either 'SpecialRecentchanges' or
77 * 'SpecialRecentchangeslinked')
78 * @return ChannelFeed
79 */
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()
89 );
90 } else {
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()
96 );
97 }
98
99 return $feedObj;
100 }
101
102 public function getAllowedParams() {
103 global $wgFeedClasses, $wgAllowCategorizedRecentChanges, $wgFeedLimit;
104 $feedFormatNames = array_keys( $wgFeedClasses );
105
106 $ret = array(
107 'feedformat' => array(
108 ApiBase::PARAM_DFLT => 'rss',
109 ApiBase::PARAM_TYPE => $feedFormatNames,
110 ),
111
112 'namespace' => array(
113 ApiBase::PARAM_TYPE => 'namespace',
114 ),
115 'invert' => false,
116 'associated' => false,
117
118 'days' => array(
119 ApiBase::PARAM_DFLT => 7,
120 ApiBase::PARAM_MIN => 1,
121 ApiBase::PARAM_TYPE => 'integer',
122 ),
123 'limit' => array(
124 ApiBase::PARAM_DFLT => 50,
125 ApiBase::PARAM_MIN => 1,
126 ApiBase::PARAM_MAX => $wgFeedLimit,
127 ApiBase::PARAM_TYPE => 'integer',
128 ),
129 'from' => array(
130 ApiBase::PARAM_TYPE => 'timestamp',
131 ),
132
133 'hideminor' => false,
134 'hidebots' => false,
135 'hideanons' => false,
136 'hideliu' => false,
137 'hidepatrolled' => false,
138 'hidemyself' => false,
139
140 'tagfilter' => array(
141 ApiBase::PARAM_TYPE => 'string',
142 ),
143
144 'target' => array(
145 ApiBase::PARAM_TYPE => 'string',
146 ),
147 'showlinkedto' => false,
148 );
149
150 if ( $wgAllowCategorizedRecentChanges ) {
151 $ret += array(
152 'categories' => array(
153 ApiBase::PARAM_TYPE => 'string',
154 ApiBase::PARAM_ISMULTI => true,
155 ),
156 'categories_any' => false,
157 );
158 }
159
160 return $ret;
161 }
162
163 public function getParamDescription() {
164 return array(
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',
183 );
184 }
185
186 public function getDescription() {
187 return 'Returns a recent changes feed';
188 }
189
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' ),
194 ) );
195 }
196
197 public function getExamples() {
198 return array(
199 'api.php?action=feedrecentchanges',
200 'api.php?action=feedrecentchanges&days=30'
201 );
202 }
203 }