Merge "Add a dot at the end of the deprecate messages"
[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 if ( !$title ) {
84 $this->dieUsageMsg( array( 'invalidtitle', $this->params['target'] ) );
85 }
86
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()
93 );
94 } else {
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()
100 );
101 }
102
103 return $feedObj;
104 }
105
106 public function getAllowedParams() {
107 global $wgFeedClasses, $wgAllowCategorizedRecentChanges, $wgFeedLimit;
108 $feedFormatNames = array_keys( $wgFeedClasses );
109
110 $ret = array(
111 'feedformat' => array(
112 ApiBase::PARAM_DFLT => 'rss',
113 ApiBase::PARAM_TYPE => $feedFormatNames,
114 ),
115
116 'namespace' => array(
117 ApiBase::PARAM_TYPE => 'namespace',
118 ),
119 'invert' => false,
120 'associated' => false,
121
122 'days' => array(
123 ApiBase::PARAM_DFLT => 7,
124 ApiBase::PARAM_MIN => 1,
125 ApiBase::PARAM_TYPE => 'integer',
126 ),
127 'limit' => array(
128 ApiBase::PARAM_DFLT => 50,
129 ApiBase::PARAM_MIN => 1,
130 ApiBase::PARAM_MAX => $wgFeedLimit,
131 ApiBase::PARAM_TYPE => 'integer',
132 ),
133 'from' => array(
134 ApiBase::PARAM_TYPE => 'timestamp',
135 ),
136
137 'hideminor' => false,
138 'hidebots' => false,
139 'hideanons' => false,
140 'hideliu' => false,
141 'hidepatrolled' => false,
142 'hidemyself' => false,
143
144 'tagfilter' => array(
145 ApiBase::PARAM_TYPE => 'string',
146 ),
147
148 'target' => array(
149 ApiBase::PARAM_TYPE => 'string',
150 ),
151 'showlinkedto' => false,
152 );
153
154 if ( $wgAllowCategorizedRecentChanges ) {
155 $ret += array(
156 'categories' => array(
157 ApiBase::PARAM_TYPE => 'string',
158 ApiBase::PARAM_ISMULTI => true,
159 ),
160 'categories_any' => false,
161 );
162 }
163
164 return $ret;
165 }
166
167 public function getParamDescription() {
168 return array(
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',
187 );
188 }
189
190 public function getDescription() {
191 return 'Returns a recent changes feed';
192 }
193
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' ),
198 ) );
199 }
200
201 public function getExamples() {
202 return array(
203 'api.php?action=feedrecentchanges',
204 'api.php?action=feedrecentchanges&days=30'
205 );
206 }
207 }