6 * Created on June 06, 2011
8 * Copyright © 2011 Sam Reed
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License along
21 * with this program; if not, write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 * http://www.gnu.org/copyleft/gpl.html
31 class ApiFeedContributions
extends ApiBase
{
33 public function __construct( $main, $action ) {
34 parent
::__construct( $main, $action );
38 * This module uses a custom feed wrapper printer.
40 * @return ApiFormatFeedWrapper
42 public function getCustomPrinter() {
43 return new ApiFormatFeedWrapper( $this->getMain() );
46 public function execute() {
47 $params = $this->extractRequestParams();
49 global $wgFeed, $wgFeedClasses, $wgSitename, $wgLanguageCode;
52 $this->dieUsage( 'Syndication feeds are not available', 'feed-unavailable' );
55 if( !isset( $wgFeedClasses[ $params['feedformat'] ] ) ) {
56 $this->dieUsage( 'Invalid subscription feed type', 'feed-invalid' );
60 if ( $params['showsizediff'] && $wgMiserMode ) {
61 $this->dieUsage( 'Size difference is disabled in Miser Mode', 'sizediffdisabled' );
64 $msg = wfMsgForContent( 'Contributions' );
65 $feedTitle = $wgSitename . ' - ' . $msg . ' [' . $wgLanguageCode . ']';
66 $feedUrl = SpecialPage
::getTitleFor( 'Contributions', $params['user'] )->getFullURL();
68 $target = $params['user'] == 'newbies'
70 : Title
::makeTitleSafe( NS_USER
, $params['user'] )->getText();
72 $feed = new $wgFeedClasses[$params['feedformat']] (
74 htmlspecialchars( $msg ),
78 $pager = new ContribsPager( array(
80 'namespace' => $params['namespace'],
81 'year' => $params['year'],
82 'month' => $params['month'],
83 'tagFilter' => $params['tagfilter'],
84 'deletedOnly' => $params['deletedonly'],
85 'topOnly' => $params['toponly'],
86 'showSizeDiff' => $params['showsizediff'],
90 if( $pager->getNumRows() > 0 ) {
91 foreach ( $pager->mResult
as $row ) {
92 $feedItems[] = $this->feedItem( $row );
96 ApiFormatFeedWrapper
::setResult( $this->getResult(), $feed, $feedItems );
99 protected function feedItem( $row ) {
100 $title = Title
::MakeTitle( intval( $row->page_namespace
), $row->page_title
);
102 $date = $row->rev_timestamp
;
103 $comments = $title->getTalkPage()->getFullURL();
104 $revision = Revision
::newFromRow( $row );
107 $title->getPrefixedText(),
108 $this->feedItemDesc( $revision ),
109 $title->getFullURL(),
111 $this->feedItemAuthor( $revision ),
120 * @param $revision Revision
123 protected function feedItemAuthor( $revision ) {
124 return $revision->getUserText();
128 * @param $revision Revision
131 protected function feedItemDesc( $revision ) {
133 return '<p>' . htmlspecialchars( $revision->getUserText() ) . wfMsgForContent( 'colon-separator' ) .
134 htmlspecialchars( FeedItem
::stripComment( $revision->getComment() ) ) .
135 "</p>\n<hr />\n<div>" .
136 nl2br( htmlspecialchars( $revision->getText() ) ) . "</div>";
141 public function getAllowedParams() {
142 global $wgFeedClasses;
143 $feedFormatNames = array_keys( $wgFeedClasses );
145 'feedformat' => array(
146 ApiBase
::PARAM_DFLT
=> 'rss',
147 ApiBase
::PARAM_TYPE
=> $feedFormatNames
150 ApiBase
::PARAM_TYPE
=> 'user',
151 ApiBase
::PARAM_REQUIRED
=> true,
153 'namespace' => array(
154 ApiBase
::PARAM_TYPE
=> 'namespace',
155 ApiBase
::PARAM_ISMULTI
=> true
158 ApiBase
::PARAM_TYPE
=> 'integer'
161 ApiBase
::PARAM_TYPE
=> 'integer'
163 'tagfilter' => array(
164 ApiBase
::PARAM_ISMULTI
=> true,
165 ApiBase
::PARAM_TYPE
=> array_values( ChangeTags
::listDefinedTags() ),
166 ApiBase
::PARAM_DFLT
=> '',
168 'deletedonly' => false,
170 'showsizediff' => false,
174 public function getParamDescription() {
176 'feedformat' => 'The format of the feed',
177 'user' => 'What users to get the contributions for',
178 'namespace' => 'What namespace to filter the contributions by',
179 'year' => 'From year (and earlier)',
180 'month' => 'From month (and earlier)',
181 'tagfilter' => 'Filter contributions that have these tags',
182 'deletedonly' => 'Show only deleted contributions',
183 'toponly' => 'Only show edits that are latest revisions',
184 'showsizediff' => 'Show the size difference between revisions. Disabled in Miser Mode',
188 public function getDescription() {
189 return 'Returns a user contributions feed';
192 public function getPossibleErrors() {
193 return array_merge( parent
::getPossibleErrors(), array(
194 array( 'code' => 'feed-unavailable', 'info' => 'Syndication feeds are not available' ),
195 array( 'code' => 'feed-invalid', 'info' => 'Invalid subscription feed type' ),
196 array( 'code' => 'sizediffdisabled', 'info' => 'Size difference is disabled in Miser Mode' ),
200 public function getExamples() {
202 'api.php?action=feedcontributions&user=Reedy',
206 public function getVersion() {
207 return __CLASS__
. ': $Id$';