5 * Created on June 06, 2011
7 * Copyright © 2011 Sam Reed
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 * http://www.gnu.org/copyleft/gpl.html
30 class ApiFeedContributions
extends ApiBase
{
32 public function __construct( $main, $action ) {
33 parent
::__construct( $main, $action );
37 * This module uses a custom feed wrapper printer.
39 * @return ApiFormatFeedWrapper
41 public function getCustomPrinter() {
42 return new ApiFormatFeedWrapper( $this->getMain() );
45 public function execute() {
46 $params = $this->extractRequestParams();
48 global $wgFeed, $wgFeedClasses, $wgSitename, $wgLanguageCode;
51 $this->dieUsage( 'Syndication feeds are not available', 'feed-unavailable' );
54 if( !isset( $wgFeedClasses[ $params['feedformat'] ] ) ) {
55 $this->dieUsage( 'Invalid subscription feed type', 'feed-invalid' );
59 if ( $params['showsizediff'] && $wgMiserMode ) {
60 $this->dieUsage( 'Size difference is disabled in Miser Mode', 'sizediffdisabled' );
63 $msg = wfMsgForContent( 'Contributions' );
64 $feedTitle = $wgSitename . ' - ' . $msg . ' [' . $wgLanguageCode . ']';
65 $feedUrl = SpecialPage
::getTitleFor( 'Contributions', $params['user'] )->getFullURL();
67 $target = $params['user'] == 'newbies'
69 : Title
::makeTitleSafe( NS_USER
, $params['user'] )->getText();
71 $feed = new $wgFeedClasses[$params['feedformat']] (
73 htmlspecialchars( $msg ),
77 $pager = new ContribsPager( $this->getContext(), array(
79 'namespace' => $params['namespace'],
80 'year' => $params['year'],
81 'month' => $params['month'],
82 'tagFilter' => $params['tagfilter'],
83 'deletedOnly' => $params['deletedonly'],
84 'topOnly' => $params['toponly'],
85 'showSizeDiff' => $params['showsizediff'],
89 if( $pager->getNumRows() > 0 ) {
90 foreach ( $pager->mResult
as $row ) {
91 $feedItems[] = $this->feedItem( $row );
95 ApiFormatFeedWrapper
::setResult( $this->getResult(), $feed, $feedItems );
98 protected function feedItem( $row ) {
99 $title = Title
::MakeTitle( intval( $row->page_namespace
), $row->page_title
);
101 $date = $row->rev_timestamp
;
102 $comments = $title->getTalkPage()->getFullURL();
103 $revision = Revision
::newFromRow( $row );
106 $title->getPrefixedText(),
107 $this->feedItemDesc( $revision ),
108 $title->getFullURL(),
110 $this->feedItemAuthor( $revision ),
119 * @param $revision Revision
122 protected function feedItemAuthor( $revision ) {
123 return $revision->getUserText();
127 * @param $revision Revision
130 protected function feedItemDesc( $revision ) {
132 return '<p>' . htmlspecialchars( $revision->getUserText() ) . wfMsgForContent( 'colon-separator' ) .
133 htmlspecialchars( FeedItem
::stripComment( $revision->getComment() ) ) .
134 "</p>\n<hr />\n<div>" .
135 nl2br( htmlspecialchars( $revision->getText() ) ) . "</div>";
140 public function getAllowedParams() {
141 global $wgFeedClasses;
142 $feedFormatNames = array_keys( $wgFeedClasses );
144 'feedformat' => array(
145 ApiBase
::PARAM_DFLT
=> 'rss',
146 ApiBase
::PARAM_TYPE
=> $feedFormatNames
149 ApiBase
::PARAM_TYPE
=> 'user',
150 ApiBase
::PARAM_REQUIRED
=> true,
152 'namespace' => array(
153 ApiBase
::PARAM_TYPE
=> 'namespace'
156 ApiBase
::PARAM_TYPE
=> 'integer'
159 ApiBase
::PARAM_TYPE
=> 'integer'
161 'tagfilter' => array(
162 ApiBase
::PARAM_ISMULTI
=> true,
163 ApiBase
::PARAM_TYPE
=> array_values( ChangeTags
::listDefinedTags() ),
164 ApiBase
::PARAM_DFLT
=> '',
166 'deletedonly' => false,
168 'showsizediff' => false,
172 public function getParamDescription() {
174 'feedformat' => 'The format of the feed',
175 'user' => 'What users to get the contributions for',
176 'namespace' => 'What namespace to filter the contributions by',
177 'year' => 'From year (and earlier)',
178 'month' => 'From month (and earlier)',
179 'tagfilter' => 'Filter contributions that have these tags',
180 'deletedonly' => 'Show only deleted contributions',
181 'toponly' => 'Only show edits that are latest revisions',
182 'showsizediff' => 'Show the size difference between revisions. Disabled in Miser Mode',
186 public function getDescription() {
187 return 'Returns a user contributions feed';
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 array( 'code' => 'sizediffdisabled', 'info' => 'Size difference is disabled in Miser Mode' ),
198 public function getExamples() {
200 'api.php?action=feedcontributions&user=Reedy',
204 public function getVersion() {
205 return __CLASS__
. ': $Id$';