MediaWiki  1.23.8
ApiFeedContributions.php
Go to the documentation of this file.
1 <?php
31 
37  public function getCustomPrinter() {
38  return new ApiFormatFeedWrapper( $this->getMain() );
39  }
40 
41  public function execute() {
42  $params = $this->extractRequestParams();
43 
44  global $wgFeed, $wgFeedClasses, $wgFeedLimit, $wgSitename, $wgLanguageCode;
45 
46  if ( !$wgFeed ) {
47  $this->dieUsage( 'Syndication feeds are not available', 'feed-unavailable' );
48  }
49 
50  if ( !isset( $wgFeedClasses[$params['feedformat']] ) ) {
51  $this->dieUsage( 'Invalid subscription feed type', 'feed-invalid' );
52  }
53 
54  global $wgMiserMode;
55  if ( $params['showsizediff'] && $wgMiserMode ) {
56  $this->dieUsage( 'Size difference is disabled in Miser Mode', 'sizediffdisabled' );
57  }
58 
59  $msg = wfMessage( 'Contributions' )->inContentLanguage()->text();
60  $feedTitle = $wgSitename . ' - ' . $msg . ' [' . $wgLanguageCode . ']';
61  $feedUrl = SpecialPage::getTitleFor( 'Contributions', $params['user'] )->getFullURL();
62 
63  $target = $params['user'] == 'newbies'
64  ? 'newbies'
65  : Title::makeTitleSafe( NS_USER, $params['user'] )->getText();
66 
67  $feed = new $wgFeedClasses[$params['feedformat']] (
68  $feedTitle,
69  htmlspecialchars( $msg ),
70  $feedUrl
71  );
72 
73  $pager = new ContribsPager( $this->getContext(), array(
74  'target' => $target,
75  'namespace' => $params['namespace'],
76  'year' => $params['year'],
77  'month' => $params['month'],
78  'tagFilter' => $params['tagfilter'],
79  'deletedOnly' => $params['deletedonly'],
80  'topOnly' => $params['toponly'],
81  'newOnly' => $params['newonly'],
82  'showSizeDiff' => $params['showsizediff'],
83  ) );
84 
85  if ( $pager->getLimit() > $wgFeedLimit ) {
86  $pager->setLimit( $wgFeedLimit );
87  }
88 
89  $feedItems = array();
90  if ( $pager->getNumRows() > 0 ) {
91  $count = 0;
92  $limit = $pager->getLimit();
93  foreach ( $pager->mResult as $row ) {
94  // ContribsPager selects one more row for navigation, skip that row
95  if ( ++$count > $limit ) {
96  break;
97  }
98  $feedItems[] = $this->feedItem( $row );
99  }
100  }
101 
102  ApiFormatFeedWrapper::setResult( $this->getResult(), $feed, $feedItems );
103  }
104 
105  protected function feedItem( $row ) {
106  $title = Title::makeTitle( intval( $row->page_namespace ), $row->page_title );
107  if ( $title && $title->userCan( 'read', $this->getUser() ) ) {
108  $date = $row->rev_timestamp;
109  $comments = $title->getTalkPage()->getFullURL();
110  $revision = Revision::newFromRow( $row );
111 
112  return new FeedItem(
113  $title->getPrefixedText(),
114  $this->feedItemDesc( $revision ),
115  $title->getFullURL(),
116  $date,
117  $this->feedItemAuthor( $revision ),
118  $comments
119  );
120  }
121 
122  return null;
123  }
124 
129  protected function feedItemAuthor( $revision ) {
130  return $revision->getUserText();
131  }
132 
137  protected function feedItemDesc( $revision ) {
138  if ( $revision ) {
139  $msg = wfMessage( 'colon-separator' )->inContentLanguage()->text();
140  $content = $revision->getContent();
141 
142  if ( $content instanceof TextContent ) {
143  // only textual content has a "source view".
144  $html = nl2br( htmlspecialchars( $content->getNativeData() ) );
145  } else {
146  //XXX: we could get an HTML representation of the content via getParserOutput, but that may
147  // contain JS magic and generally may not be suitable for inclusion in a feed.
148  // Perhaps Content should have a getDescriptiveHtml method and/or a getSourceText method.
149  //Compare also FeedUtils::formatDiffRow.
150  $html = '';
151  }
152 
153  return '<p>' . htmlspecialchars( $revision->getUserText() ) . $msg .
154  htmlspecialchars( FeedItem::stripComment( $revision->getComment() ) ) .
155  "</p>\n<hr />\n<div>" . $html . "</div>";
156  }
157 
158  return '';
159  }
160 
161  public function getAllowedParams() {
162  global $wgFeedClasses;
163  $feedFormatNames = array_keys( $wgFeedClasses );
164 
165  return array(
166  'feedformat' => array(
167  ApiBase::PARAM_DFLT => 'rss',
168  ApiBase::PARAM_TYPE => $feedFormatNames
169  ),
170  'user' => array(
171  ApiBase::PARAM_TYPE => 'user',
172  ApiBase::PARAM_REQUIRED => true,
173  ),
174  'namespace' => array(
175  ApiBase::PARAM_TYPE => 'namespace'
176  ),
177  'year' => array(
178  ApiBase::PARAM_TYPE => 'integer'
179  ),
180  'month' => array(
181  ApiBase::PARAM_TYPE => 'integer'
182  ),
183  'tagfilter' => array(
184  ApiBase::PARAM_ISMULTI => true,
186  ApiBase::PARAM_DFLT => '',
187  ),
188  'deletedonly' => false,
189  'toponly' => false,
190  'newonly' => false,
191  'showsizediff' => false,
192  );
193  }
194 
195  public function getParamDescription() {
196  return array(
197  'feedformat' => 'The format of the feed',
198  'user' => 'What users to get the contributions for',
199  'namespace' => 'What namespace to filter the contributions by',
200  'year' => 'From year (and earlier)',
201  'month' => 'From month (and earlier)',
202  'tagfilter' => 'Filter contributions that have these tags',
203  'deletedonly' => 'Show only deleted contributions',
204  'toponly' => 'Only show edits that are latest revisions',
205  'newonly' => 'Only show edits that are page creations',
206  'showsizediff' => 'Show the size difference between revisions. Disabled in Miser Mode',
207  );
208  }
209 
210  public function getDescription() {
211  return 'Returns a user contributions feed.';
212  }
213 
214  public function getPossibleErrors() {
215  return array_merge( parent::getPossibleErrors(), array(
216  array( 'code' => 'feed-unavailable', 'info' => 'Syndication feeds are not available' ),
217  array( 'code' => 'feed-invalid', 'info' => 'Invalid subscription feed type' ),
218  array( 'code' => 'sizediffdisabled', 'info' => 'Size difference is disabled in Miser Mode' ),
219  ) );
220  }
221 
222  public function getExamples() {
223  return array(
224  'api.php?action=feedcontributions&user=Reedy',
225  );
226  }
227 }
ApiFeedContributions\getPossibleErrors
getPossibleErrors()
Returns a list of all possible errors returned by the module.
Definition: ApiFeedContributions.php:214
Title\makeTitle
static & makeTitle( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:398
FeedItem
A base class for basic support for outputting syndication feeds in RSS and other formats.
Definition: Feed.php:38
ContextSource\getContext
getContext()
Get the RequestContext object.
Definition: ContextSource.php:40
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
ApiBase\PARAM_REQUIRED
const PARAM_REQUIRED
Definition: ApiBase.php:62
$html
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return an< a > element with HTML attributes $attribs and contents $html will be returned If you return $ret will be returned and may include noclasses & $html
Definition: hooks.txt:1530
ApiFeedContributions\getCustomPrinter
getCustomPrinter()
This module uses a custom feed wrapper printer.
Definition: ApiFeedContributions.php:37
ApiFeedContributions\feedItemAuthor
feedItemAuthor( $revision)
Definition: ApiFeedContributions.php:129
ApiBase\PARAM_TYPE
const PARAM_TYPE
Definition: ApiBase.php:50
ApiBase\getResult
getResult()
Get the result object.
Definition: ApiBase.php:205
ApiFeedContributions\execute
execute()
Evaluates the parameters, performs the requested query, and sets up the result.
Definition: ApiFeedContributions.php:41
FeedItem\stripComment
static stripComment( $text)
Quickie hack...
Definition: Feed.php:175
$params
$params
Definition: styleTest.css.php:40
$limit
if( $sleep) $limit
Definition: importImages.php:99
SpecialPage\getTitleFor
static getTitleFor( $name, $subpage=false, $fragment='')
Get a localised Title object for a specified special page name.
Definition: SpecialPage.php:74
ApiBase
This abstract class implements many basic API functions, and is the base of all API classes.
Definition: ApiBase.php:42
ApiFeedContributions\getDescription
getDescription()
Returns the description string for this module.
Definition: ApiFeedContributions.php:210
ApiFeedContributions\feedItemDesc
feedItemDesc( $revision)
Definition: ApiFeedContributions.php:137
ApiFormatFeedWrapper
This printer is used to wrap an instance of the Feed class.
Definition: ApiFormatBase.php:348
ApiFeedContributions\getParamDescription
getParamDescription()
Returns an array of parameter descriptions.
Definition: ApiFeedContributions.php:195
wfMessage
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return an< a > element with HTML attributes $attribs and contents $html will be returned If you return $ret will be returned and may include noclasses after processing after in associative array form externallinks including delete and has completed for all link tables default is conds Array Extra conditions for the No matching items in log is displayed if loglist is empty msgKey Array If you want a nice box with a set this to the key of the message First element is the message additional optional elements are parameters for the key that are processed with wfMessage() -> params() ->parseAsBlock() - offset Set to overwrite offset parameter in $wgRequest set to '' to unset offset - wrap String Wrap the message in html(usually something like "&lt
ApiFeedContributions
Definition: ApiFeedContributions.php:30
ChangeTags\listDefinedTags
static listDefinedTags()
Basically lists defined tags which count even if they aren't applied to anything.
Definition: ChangeTags.php:302
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
global
when a variable name is used in a it is silently declared as a new masking the global
Definition: design.txt:93
ContribsPager
Pager for Special:Contributions.
Definition: SpecialContributions.php:644
Title\makeTitleSafe
static makeTitleSafe( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:422
ApiBase\extractRequestParams
extractRequestParams( $parseLimit=true)
Using getAllowedParams(), this function makes an array of the values provided by the user,...
Definition: ApiBase.php:687
$title
presenting them properly to the user as errors is done by the caller $title
Definition: hooks.txt:1324
ApiBase\dieUsage
dieUsage( $description, $errorCode, $httpRespCode=0, $extradata=null)
Throw a UsageException, which will (if uncaught) call the main module's error handler and die with an...
Definition: ApiBase.php:1363
Revision\newFromRow
static newFromRow( $row)
Definition: Revision.php:206
TextContent
Content object implementation for representing flat text.
Definition: TextContent.php:35
ApiFeedContributions\getExamples
getExamples()
Returns usage examples for this module.
Definition: ApiFeedContributions.php:222
$count
$count
Definition: UtfNormalTest2.php:96
ApiBase\PARAM_DFLT
const PARAM_DFLT
Definition: ApiBase.php:46
as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
ApiBase\PARAM_ISMULTI
const PARAM_ISMULTI
Definition: ApiBase.php:48
NS_USER
const NS_USER
Definition: Defines.php:81
ApiFeedContributions\feedItem
feedItem( $row)
Definition: ApiFeedContributions.php:105
ApiBase\getMain
getMain()
Get the main module.
Definition: ApiBase.php:188
ApiFeedContributions\getAllowedParams
getAllowedParams()
Returns an array of allowed parameters (parameter name) => (default value) or (parameter name) => (ar...
Definition: ApiFeedContributions.php:161
ApiFormatFeedWrapper\setResult
static setResult( $result, $feed, $feedItems)
Call this method to initialize output data.
Definition: ApiFormatBase.php:360