1 | <?php |
||
30 | class ApiFeedContributions extends ApiBase { |
||
31 | |||
32 | /** |
||
33 | * This module uses a custom feed wrapper printer. |
||
34 | * |
||
35 | * @return ApiFormatFeedWrapper |
||
36 | */ |
||
37 | public function getCustomPrinter() { |
||
40 | |||
41 | public function execute() { |
||
42 | $params = $this->extractRequestParams(); |
||
43 | |||
44 | $config = $this->getConfig(); |
||
45 | if ( !$config->get( 'Feed' ) ) { |
||
46 | $this->dieUsage( 'Syndication feeds are not available', 'feed-unavailable' ); |
||
47 | } |
||
48 | |||
49 | $feedClasses = $config->get( 'FeedClasses' ); |
||
50 | if ( !isset( $feedClasses[$params['feedformat']] ) ) { |
||
51 | $this->dieUsage( 'Invalid subscription feed type', 'feed-invalid' ); |
||
52 | } |
||
53 | |||
54 | if ( $params['showsizediff'] && $this->getConfig()->get( 'MiserMode' ) ) { |
||
55 | $this->dieUsage( 'Size difference is disabled in Miser Mode', 'sizediffdisabled' ); |
||
56 | } |
||
57 | |||
58 | $msg = wfMessage( 'Contributions' )->inContentLanguage()->text(); |
||
59 | $feedTitle = $config->get( 'Sitename' ) . ' - ' . $msg . |
||
60 | ' [' . $config->get( 'LanguageCode' ) . ']'; |
||
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 $feedClasses[$params['feedformat']] ( |
||
68 | $feedTitle, |
||
69 | htmlspecialchars( $msg ), |
||
70 | $feedUrl |
||
71 | ); |
||
72 | |||
73 | $pager = new ContribsPager( $this->getContext(), [ |
||
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 | 'hideMinor' => $params['hideminor'], |
||
83 | 'showSizeDiff' => $params['showsizediff'], |
||
84 | ] ); |
||
85 | |||
86 | $feedLimit = $this->getConfig()->get( 'FeedLimit' ); |
||
87 | if ( $pager->getLimit() > $feedLimit ) { |
||
88 | $pager->setLimit( $feedLimit ); |
||
89 | } |
||
90 | |||
91 | $feedItems = []; |
||
92 | if ( $pager->getNumRows() > 0 ) { |
||
93 | $count = 0; |
||
94 | $limit = $pager->getLimit(); |
||
95 | foreach ( $pager->mResult as $row ) { |
||
96 | // ContribsPager selects one more row for navigation, skip that row |
||
97 | if ( ++$count > $limit ) { |
||
98 | break; |
||
99 | } |
||
100 | $item = $this->feedItem( $row ); |
||
101 | if ( $item !== null ) { |
||
102 | $feedItems[] = $item; |
||
103 | } |
||
104 | } |
||
105 | } |
||
106 | |||
107 | ApiFormatFeedWrapper::setResult( $this->getResult(), $feed, $feedItems ); |
||
108 | } |
||
109 | |||
110 | protected function feedItem( $row ) { |
||
146 | |||
147 | /** |
||
148 | * @param Revision $revision |
||
149 | * @return string |
||
150 | */ |
||
151 | protected function feedItemAuthor( $revision ) { |
||
154 | |||
155 | /** |
||
156 | * @param Revision $revision |
||
157 | * @return string |
||
158 | */ |
||
159 | protected function feedItemDesc( $revision ) { |
||
182 | |||
183 | public function getAllowedParams() { |
||
184 | $feedFormatNames = array_keys( $this->getConfig()->get( 'FeedClasses' ) ); |
||
185 | |||
186 | $ret = [ |
||
187 | 'feedformat' => [ |
||
188 | ApiBase::PARAM_DFLT => 'rss', |
||
189 | ApiBase::PARAM_TYPE => $feedFormatNames |
||
190 | ], |
||
191 | 'user' => [ |
||
192 | ApiBase::PARAM_TYPE => 'user', |
||
193 | ApiBase::PARAM_REQUIRED => true, |
||
194 | ], |
||
195 | 'namespace' => [ |
||
196 | ApiBase::PARAM_TYPE => 'namespace' |
||
197 | ], |
||
198 | 'year' => [ |
||
199 | ApiBase::PARAM_TYPE => 'integer' |
||
200 | ], |
||
201 | 'month' => [ |
||
202 | ApiBase::PARAM_TYPE => 'integer' |
||
203 | ], |
||
204 | 'tagfilter' => [ |
||
205 | ApiBase::PARAM_ISMULTI => true, |
||
206 | ApiBase::PARAM_TYPE => array_values( ChangeTags::listDefinedTags() ), |
||
207 | ApiBase::PARAM_DFLT => '', |
||
208 | ], |
||
209 | 'deletedonly' => false, |
||
210 | 'toponly' => false, |
||
211 | 'newonly' => false, |
||
212 | 'hideminor' => false, |
||
213 | 'showsizediff' => [ |
||
214 | ApiBase::PARAM_DFLT => false, |
||
215 | ], |
||
216 | ]; |
||
217 | |||
218 | if ( $this->getConfig()->get( 'MiserMode' ) ) { |
||
219 | $ret['showsizediff'][ApiBase::PARAM_HELP_MSG] = 'api-help-param-disabled-in-miser-mode'; |
||
220 | } |
||
221 | |||
222 | return $ret; |
||
223 | } |
||
224 | |||
225 | protected function getExamplesMessages() { |
||
231 | } |
||
232 |
This check looks at variables that are passed out again to other methods.
If the outgoing method call has stricter type requirements than the method itself, an issue is raised.
An additional type check may prevent trouble.