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 public function getCustomPrinter() {
41 return new ApiFormatFeedWrapper( $this->getMain() );
44 public function execute() {
45 $params = $this->extractRequestParams();
47 global $wgFeed, $wgFeedClasses, $wgSitename, $wgLanguageCode;
50 $this->dieUsage( 'Syndication feeds are not available', 'feed-unavailable' );
53 if( !isset( $wgFeedClasses[ $params['feedformat'] ] ) ) {
54 $this->dieUsage( 'Invalid subscription feed type', 'feed-invalid' );
58 if ( $params['showsizediff'] && $wgMiserMode ) {
59 $this->dieUsage( 'Size difference is disabled in Miser Mode', 'sizediffdisabled' );
62 $msg = wfMsgForContent( 'Contributions' );
63 $feedTitle = $wgSitename . ' - ' . $msg . ' [' . $wgLanguageCode . ']';
64 $feedUrl = SpecialPage
::getTitleFor( 'Contributions', $params['user'] )->getFullURL();
66 $target = $params['user'] == 'newbies'
68 : Title
::makeTitleSafe( NS_USER
, $params['user'] )->getText();
70 $feed = new $wgFeedClasses[$params['feedformat']] (
72 htmlspecialchars( $msg ),
76 $pager = new ContribsPager( array(
78 'namespace' => $params['namespace'],
79 'year' => $params['year'],
80 'month' => $params['month'],
81 'tagFilter' => $params['tagfilter'],
82 'deletedOnly' => $params['deletedonly'],
83 'topOnly' => $params['toponly'],
84 'showSizeDiff' => $params['showsizediff'],
88 if( $pager->getNumRows() > 0 ) {
89 foreach ( $pager->mResult
as $row ) {
90 $feedItems[] = $this->feedItem( $row );
94 ApiFormatFeedWrapper
::setResult( $this->getResult(), $feed, $feedItems );
97 protected function feedItem( $row ) {
98 $title = Title
::MakeTitle( intval( $row->page_namespace
), $row->page_title
);
100 $date = $row->rev_timestamp
;
101 $comments = $title->getTalkPage()->getFullURL();
102 $revision = Revision
::newFromTitle( $title, $row->rev_id
);
105 $title->getPrefixedText(),
106 $this->feedItemDesc( $revision ),
107 $title->getFullURL(),
109 $this->feedItemAuthor( $revision ),
118 * @param $revision Revision
121 protected function feedItemAuthor( $revision ) {
122 return $revision->getUserText();
126 * @param $revision Revision
129 protected function feedItemDesc( $revision ) {
131 return '<p>' . htmlspecialchars( $revision->getUserText() ) . wfMsgForContent( 'colon-separator' ) .
132 htmlspecialchars( FeedItem
::stripComment( $revision->getComment() ) ) .
133 "</p>\n<hr />\n<div>" .
134 nl2br( htmlspecialchars( $revision->getText() ) ) . "</div>";
139 public function getAllowedParams() {
140 global $wgFeedClasses;
141 $feedFormatNames = array_keys( $wgFeedClasses );
143 'feedformat' => array(
144 ApiBase
::PARAM_DFLT
=> 'rss',
145 ApiBase
::PARAM_TYPE
=> $feedFormatNames
148 ApiBase
::PARAM_TYPE
=> 'user',
149 ApiBase
::PARAM_REQUIRED
=> true,
151 'namespace' => array(
152 ApiBase
::PARAM_TYPE
=> 'namespace',
153 ApiBase
::PARAM_ISMULTI
=> true
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 protected function getExamples() {
200 'api.php?action=feedcontributions&user=Reedy',
204 public function getHelpUrls() {
208 public function getVersion() {
209 return __CLASS__
. ': $Id$';