Debian Codegraph @

includes/api/ApiQueryUserContribs.php

raw symbols SCIP
1 <?php
2 /**
3 * Copyright © 2006 Yuri Astrakhan "<Firstname><Lastname>@gmail.com"
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
19 *
20 * @file
21 */
22
23 namespace MediaWiki\Api;
24
25 use MediaWiki\CommentFormatter\CommentFormatter;
26 use MediaWiki\CommentStore\CommentStore;
27 use MediaWiki\MainConfigNames;
28 use MediaWiki\MediaWikiServices;
29 use MediaWiki\ParamValidator\TypeDef\UserDef;
30 use MediaWiki\Revision\RevisionRecord;
31 use MediaWiki\Revision\RevisionStore;
32 use MediaWiki\Storage\NameTableAccessException;
33 use MediaWiki\Storage\NameTableStore;
34 use MediaWiki\Title\Title;
35 use MediaWiki\User\ActorMigration;
36 use MediaWiki\User\ExternalUserNames;
37 use MediaWiki\User\UserIdentity;
38 use MediaWiki\User\UserIdentityLookup;
39 use MediaWiki\User\UserIdentityValue;
40 use MediaWiki\User\UserNameUtils;
41 use RecentChange;
42 use stdClass;
43 use Wikimedia\IPUtils;
44 use Wikimedia\ParamValidator\ParamValidator;
45 use Wikimedia\ParamValidator\TypeDef\IntegerDef;
46 use Wikimedia\Rdbms\SelectQueryBuilder;
47
48 /**
49 * This query action adds a list of a specified user's contributions to the output.
50 *
51 * @ingroup API
52 */
53 class ApiQueryUserContribs extends ApiQueryBase {
54
55 private CommentStore $commentStore;
56 private UserIdentityLookup $userIdentityLookup;
57 private UserNameUtils $userNameUtils;
58 private RevisionStore $revisionStore;
59 private NameTableStore $changeTagDefStore;
60 private ActorMigration $actorMigration;
61 private CommentFormatter $commentFormatter;
62
63 public function __construct(
64 ApiQuery $query,
65 string $moduleName,
66 CommentStore $commentStore,
67 UserIdentityLookup $userIdentityLookup,
68 UserNameUtils $userNameUtils,
69 RevisionStore $revisionStore,
70 NameTableStore $changeTagDefStore,
71 ActorMigration $actorMigration,
72 CommentFormatter $commentFormatter
73 ) {
74 parent::__construct( $query, $moduleName, 'uc' );
75 $this->commentStore = $commentStore;
76 $this->userIdentityLookup = $userIdentityLookup;
77 $this->userNameUtils = $userNameUtils;
78 $this->revisionStore = $revisionStore;
79 $this->changeTagDefStore = $changeTagDefStore;
80 $this->actorMigration = $actorMigration;
81 $this->commentFormatter = $commentFormatter;
82 }
83
84 private array $params;
85 private bool $multiUserMode;
86 private string $orderBy;
87 private array $parentLens;
88
89 private bool $fld_ids = false;
90 private bool $fld_title = false;
91 private bool $fld_timestamp = false;
92 private bool $fld_comment = false;
93 private bool $fld_parsedcomment = false;
94 private bool $fld_flags = false;
95 private bool $fld_patrolled = false;
96 private bool $fld_tags = false;
97 private bool $fld_size = false;
98 private bool $fld_sizediff = false;
99
100 public function execute() {
101 // Parse some parameters
102 $this->params = $this->extractRequestParams();
103
104 $prop = array_fill_keys( $this->params['prop'], true );
105 $this->fld_ids = isset( $prop['ids'] );
106 $this->fld_title = isset( $prop['title'] );
107 $this->fld_comment = isset( $prop['comment'] );
108 $this->fld_parsedcomment = isset( $prop['parsedcomment'] );
109 $this->fld_size = isset( $prop['size'] );
110 $this->fld_sizediff = isset( $prop['sizediff'] );
111 $this->fld_flags = isset( $prop['flags'] );
112 $this->fld_timestamp = isset( $prop['timestamp'] );
113 $this->fld_patrolled = isset( $prop['patrolled'] );
114 $this->fld_tags = isset( $prop['tags'] );
115
116 $dbSecondary = $this->getDB(); // any random replica DB
117
118 $sort = ( $this->params['dir'] == 'newer' ?
119 SelectQueryBuilder::SORT_ASC : SelectQueryBuilder::SORT_DESC );
120 $op = ( $this->params['dir'] == 'older' ? '<=' : '>=' );
121
122 // Create an Iterator that produces the UserIdentity objects we need, depending
123 // on which of the 'userprefix', 'userids', 'iprange', or 'user' params
124 // was specified.
125 $this->requireOnlyOneParameter( $this->params, 'userprefix', 'userids', 'iprange', 'user' );
126 if ( isset( $this->params['userprefix'] ) ) {
127 $this->multiUserMode = true;
128 $this->orderBy = 'name';
129 $fname = __METHOD__;
130
131 // Because 'userprefix' might produce a huge number of users (e.g.
132 // a wiki with users "Test00000001" to "Test99999999"), use a
133 // generator with batched lookup and continuation.
134 $userIter = call_user_func( function () use ( $dbSecondary, $sort, $op, $fname ) {
135 $fromName = false;
136 if ( $this->params['continue'] !== null ) {
137 $continue = $this->parseContinueParamOrDie( $this->params['continue'],
138 [ 'string', 'string', 'string', 'int' ] );
139 $this->dieContinueUsageIf( $continue[0] !== 'name' );
140 $fromName = $continue[1];
141 }
142
143 $limit = 501;
144 do {
145 $usersBatch = $this->userIdentityLookup
146 ->newSelectQueryBuilder()
147 ->caller( $fname )
148 ->limit( $limit )
149 ->whereUserNamePrefix( $this->params['userprefix'] )
150 ->where( $fromName !== false
151 ? $dbSecondary->buildComparison( $op, [ 'actor_name' => $fromName ] )
152 : [] )
153 ->orderByName( $sort )
154 ->fetchUserIdentities();
155
156 $count = 0;
157 $fromName = false;
158 foreach ( $usersBatch as $user ) {
159 if ( ++$count >= $limit ) {
160 $fromName = $user->getName();
161 break;
162 }
163 yield $user;
164 }
165 } while ( $fromName !== false );
166 } );
167 // Do the actual sorting client-side, because otherwise
168 // prepareQuery might try to sort by actor and confuse everything.
169 $batchSize = 1;
170 } elseif ( isset( $this->params['userids'] ) ) {
171 if ( $this->params['userids'] === [] ) {
172 $encParamName = $this->encodeParamName( 'userids' );
173 $this->dieWithError( [ 'apierror-paramempty', $encParamName ], "paramempty_$encParamName" );
174 }
175
176 $ids = [];
177 foreach ( $this->params['userids'] as $uid ) {
178 if ( $uid <= 0 ) {
179 $this->dieWithError( [ 'apierror-invaliduserid', $uid ], 'invaliduserid' );
180 }
181 $ids[] = $uid;
182 }
183
184 $this->orderBy = 'actor';
185 $this->multiUserMode = count( $ids ) > 1;
186
187 $fromId = false;
188 if ( $this->multiUserMode && $this->params['continue'] !== null ) {
189 $continue = $this->parseContinueParamOrDie( $this->params['continue'],
190 [ 'string', 'int', 'string', 'int' ] );
191 $this->dieContinueUsageIf( $continue[0] !== 'actor' );
192 $fromId = $continue[1];
193 }
194
195 $userIter = $this->userIdentityLookup
196 ->newSelectQueryBuilder()
197 ->caller( __METHOD__ )
198 ->whereUserIds( $ids )
199 ->orderByUserId( $sort )
200 ->where( $fromId ? $dbSecondary->buildComparison( $op, [ 'actor_id' => $fromId ] ) : [] )
201 ->fetchUserIdentities();
202 $batchSize = count( $ids );
203 } elseif ( isset( $this->params['iprange'] ) ) {
204 // Make sure it is a valid range and within the CIDR limit
205 $ipRange = $this->params['iprange'];
206 $contribsCIDRLimit = $this->getConfig()->get( MainConfigNames::RangeContributionsCIDRLimit );
207 if ( IPUtils::isIPv4( $ipRange ) ) {
208 $type = 'IPv4';
209 $cidrLimit = $contribsCIDRLimit['IPv4'];
210 } elseif ( IPUtils::isIPv6( $ipRange ) ) {
211 $type = 'IPv6';
212 $cidrLimit = $contribsCIDRLimit['IPv6'];
213 } else {
214 $this->dieWithError( [ 'apierror-invalidiprange', $ipRange ], 'invalidiprange' );
215 }
216 $range = IPUtils::parseCIDR( $ipRange )[1];
217 if ( $range === false ) {
218 $this->dieWithError( [ 'apierror-invalidiprange', $ipRange ], 'invalidiprange' );
219 } elseif ( $range < $cidrLimit ) {
220 $this->dieWithError( [ 'apierror-cidrtoobroad', $type, $cidrLimit ] );
221 }
222
223 $this->multiUserMode = true;
224 $this->orderBy = 'name';
225 $fname = __METHOD__;
226
227 // Because 'iprange' might produce a huge number of ips, use a
228 // generator with batched lookup and continuation.
229 $userIter = call_user_func( function () use ( $dbSecondary, $sort, $op, $fname, $ipRange ) {
230 [ $start, $end ] = IPUtils::parseRange( $ipRange );
231 if ( $this->params['continue'] !== null ) {
232 $continue = $this->parseContinueParamOrDie( $this->params['continue'],
233 [ 'string', 'string', 'string', 'int' ] );
234 $this->dieContinueUsageIf( $continue[0] !== 'name' );
235 $fromName = $continue[1];
236 $fromIPHex = IPUtils::toHex( $fromName );
237 $this->dieContinueUsageIf( $fromIPHex === false );
238 if ( $op == '<=' ) {
239 $end = $fromIPHex;
240 } else {
241 $start = $fromIPHex;
242 }
243 }
244
245 $limit = 501;
246
247 do {
248 $res = $dbSecondary->newSelectQueryBuilder()
249 ->select( 'ipc_hex' )
250 ->from( 'ip_changes' )
251 ->where( $dbSecondary->expr( 'ipc_hex', '>=', $start )->and( 'ipc_hex', '<=', $end ) )
252 ->groupBy( 'ipc_hex' )
253 ->orderBy( 'ipc_hex', $sort )
254 ->limit( $limit )
255 ->caller( $fname )
256 ->fetchResultSet();
257
258 $count = 0;
259 $fromName = false;
260 foreach ( $res as $row ) {
261 $ipAddr = IPUtils::formatHex( $row->ipc_hex );
262 if ( ++$count >= $limit ) {
263 $fromName = $ipAddr;
264 break;
265 }
266 yield UserIdentityValue::newAnonymous( $ipAddr );
267 }
268 } while ( $fromName !== false );
269 } );
270 // Do the actual sorting client-side, because otherwise
271 // prepareQuery might try to sort by actor and confuse everything.
272 $batchSize = 1;
273 } else {
274 $names = [];
275 if ( !count( $this->params['user'] ) ) {
276 $encParamName = $this->encodeParamName( 'user' );
277 $this->dieWithError(
278 [ 'apierror-paramempty', $encParamName ], "paramempty_$encParamName"
279 );
280 }
281 foreach ( $this->params['user'] as $u ) {
282 if ( $u === '' ) {
283 $encParamName = $this->encodeParamName( 'user' );
284 $this->dieWithError(
285 [ 'apierror-paramempty', $encParamName ], "paramempty_$encParamName"
286 );
287 }
288
289 if ( $this->userNameUtils->isIP( $u ) || ExternalUserNames::isExternal( $u ) ) {
290 $names[$u] = null;
291 } else {
292 $name = $this->userNameUtils->getCanonical( $u );
293 if ( $name === false ) {
294 $encParamName = $this->encodeParamName( 'user' );
295 $this->dieWithError(
296 [ 'apierror-baduser', $encParamName, wfEscapeWikiText( $u ) ], "baduser_$encParamName"
297 );
298 }
299 $names[$name] = null;
300 }
301 }
302
303 $this->orderBy = 'actor';
304 $this->multiUserMode = count( $names ) > 1;
305
306 $fromId = false;
307 if ( $this->multiUserMode && $this->params['continue'] !== null ) {
308 $continue = $this->parseContinueParamOrDie( $this->params['continue'],
309 [ 'string', 'int', 'string', 'int' ] );
310 $this->dieContinueUsageIf( $continue[0] !== 'actor' );
311 $fromId = $continue[1];
312 }
313
314 $userIter = $this->userIdentityLookup
315 ->newSelectQueryBuilder()
316 ->caller( __METHOD__ )
317 ->whereUserNames( array_keys( $names ) )
318 ->orderByName( $sort )
319 ->where( $fromId ? $dbSecondary->buildComparison( $op, [ 'actor_id' => $fromId ] ) : [] )
320 ->fetchUserIdentities();
321 $batchSize = count( $names );
322 }
323
324 $count = 0;
325 $limit = $this->params['limit'];
326 $userIter->rewind();
327 while ( $userIter->valid() ) {
328 $users = [];
329 while ( count( $users ) < $batchSize && $userIter->valid() ) {
330 $users[] = $userIter->current();
331 $userIter->next();
332 }
333
334 $hookData = [];
335 $this->prepareQuery( $users, $limit - $count );
336 $res = $this->select( __METHOD__, [], $hookData );
337
338 if ( $this->fld_title ) {
339 $this->executeGenderCacheFromResultWrapper( $res, __METHOD__ );
340 }
341
342 if ( $this->fld_sizediff ) {
343 $revIds = [];
344 foreach ( $res as $row ) {
345 if ( $row->rev_parent_id ) {
346 $revIds[] = (int)$row->rev_parent_id;
347 }
348 }
349 $this->parentLens = $this->revisionStore->getRevisionSizes( $revIds );
350 }
351
352 foreach ( $res as $row ) {
353 if ( ++$count > $limit ) {
354 // We've reached the one extra which shows that there are
355 // additional pages to be had. Stop here...
356 $this->setContinueEnumParameter( 'continue', $this->continueStr( $row ) );
357 break 2;
358 }
359
360 $vals = $this->extractRowInfo( $row );
361 $fit = $this->processRow( $row, $vals, $hookData ) &&
362 $this->getResult()->addValue( [ 'query', $this->getModuleName() ], null, $vals );
363 if ( !$fit ) {
364 $this->setContinueEnumParameter( 'continue', $this->continueStr( $row ) );
365 break 2;
366 }
367 }
368 }
369
370 $this->getResult()->addIndexedTagName( [ 'query', $this->getModuleName() ], 'item' );
371 }
372
373 /**
374 * Prepares the query and returns the limit of rows requested
375 * @param UserIdentity[] $users
376 * @param int $limit
377 */
378 private function prepareQuery( array $users, $limit ) {
379 $this->resetQueryParams();
380 $db = $this->getDB();
381
382 $queryBuilder = $this->revisionStore->newSelectQueryBuilder( $db )->joinComment()->joinPage();
383 $revWhere = $this->actorMigration->getWhere( $db, 'rev_user', $users );
384
385 $orderUserField = 'rev_actor';
386 $userField = $this->orderBy === 'actor' ? 'rev_actor' : 'actor_name';
387 $tsField = 'rev_timestamp';
388 $idField = 'rev_id';
389
390 $this->getQueryBuilder()->merge( $queryBuilder );
391 $this->addWhere( $revWhere['conds'] );
392 // Force the appropriate index to avoid bad query plans (T307815 and T307295)
393 if ( isset( $revWhere['orconds']['newactor'] ) ) {
394 $this->addOption( 'USE INDEX', [ 'revision' => 'rev_actor_timestamp' ] );
395 }
396
397 // Handle continue parameter
398 if ( $this->params['continue'] !== null ) {
399 if ( $this->multiUserMode ) {
400 $continue = $this->parseContinueParamOrDie( $this->params['continue'],
401 [ 'string', 'string', 'timestamp', 'int' ] );
402 $modeFlag = array_shift( $continue );
403 $this->dieContinueUsageIf( $modeFlag !== $this->orderBy );
404 $encUser = array_shift( $continue );
405 } else {
406 $continue = $this->parseContinueParamOrDie( $this->params['continue'],
407 [ 'timestamp', 'int' ] );
408 }
409 $op = ( $this->params['dir'] == 'older' ? '<=' : '>=' );
410 if ( $this->multiUserMode ) {
411 $this->addWhere( $db->buildComparison( $op, [
412 // @phan-suppress-next-line PhanPossiblyUndeclaredVariable encUser is set when used
413 $userField => $encUser,
414 $tsField => $db->timestamp( $continue[0] ),
415 $idField => $continue[1],
416 ] ) );
417 } else {
418 $this->addWhere( $db->buildComparison( $op, [
419 $tsField => $db->timestamp( $continue[0] ),
420 $idField => $continue[1],
421 ] ) );
422 }
423 }
424
425 // Don't include any revisions where we're not supposed to be able to
426 // see the username.
427 if ( !$this->getAuthority()->isAllowed( 'deletedhistory' ) ) {
428 $bitmask = RevisionRecord::DELETED_USER;
429 } elseif ( !$this->getAuthority()->isAllowedAny( 'suppressrevision', 'viewsuppressed' ) ) {
430 $bitmask = RevisionRecord::DELETED_USER | RevisionRecord::DELETED_RESTRICTED;
431 } else {
432 $bitmask = 0;
433 }
434 if ( $bitmask ) {
435 $this->addWhere( $db->bitAnd( 'rev_deleted', $bitmask ) . " != $bitmask" );
436 }
437
438 // Add the user field to ORDER BY if there are multiple users
439 if ( count( $users ) > 1 ) {
440 $this->addWhereRange( $orderUserField, $this->params['dir'], null, null );
441 }
442
443 // Then timestamp
444 $this->addTimestampWhereRange( $tsField,
445 $this->params['dir'], $this->params['start'], $this->params['end'] );
446
447 // Then rev_id for a total ordering
448 $this->addWhereRange( $idField, $this->params['dir'], null, null );
449
450 $this->addWhereFld( 'page_namespace', $this->params['namespace'] );
451
452 $show = $this->params['show'];
453 if ( $this->params['toponly'] ) { // deprecated/old param
454 $show[] = 'top';
455 }
456 if ( $show !== null ) {
457 $show = array_fill_keys( $show, true );
458
459 if ( ( isset( $show['minor'] ) && isset( $show['!minor'] ) )
460 || ( isset( $show['patrolled'] ) && isset( $show['!patrolled'] ) )
461 || ( isset( $show['autopatrolled'] ) && isset( $show['!autopatrolled'] ) )
462 || ( isset( $show['autopatrolled'] ) && isset( $show['!patrolled'] ) )
463 || ( isset( $show['top'] ) && isset( $show['!top'] ) )
464 || ( isset( $show['new'] ) && isset( $show['!new'] ) )
465 ) {
466 $this->dieWithError( 'apierror-show' );
467 }
468
469 $this->addWhereIf( [ 'rev_minor_edit' => 0 ], isset( $show['!minor'] ) );
470 $this->addWhereIf( $db->expr( 'rev_minor_edit', '!=', 0 ), isset( $show['minor'] ) );
471 $this->addWhereIf(
472 [ 'rc_patrolled' => RecentChange::PRC_UNPATROLLED ],
473 isset( $show['!patrolled'] )
474 );
475 $this->addWhereIf(
476 $db->expr( 'rc_patrolled', '!=', RecentChange::PRC_UNPATROLLED ),
477 isset( $show['patrolled'] )
478 );
479 $this->addWhereIf(
480 $db->expr( 'rc_patrolled', '!=', RecentChange::PRC_AUTOPATROLLED ),
481 isset( $show['!autopatrolled'] )
482 );
483 $this->addWhereIf(
484 [ 'rc_patrolled' => RecentChange::PRC_AUTOPATROLLED ],
485 isset( $show['autopatrolled'] )
486 );
487 $this->addWhereIf( $idField . ' != page_latest', isset( $show['!top'] ) );
488 $this->addWhereIf( $idField . ' = page_latest', isset( $show['top'] ) );
489 $this->addWhereIf( $db->expr( 'rev_parent_id', '!=', 0 ), isset( $show['!new'] ) );
490 $this->addWhereIf( [ 'rev_parent_id' => 0 ], isset( $show['new'] ) );
491 }
492 $this->addOption( 'LIMIT', $limit + 1 );
493
494 if ( isset( $show['patrolled'] ) || isset( $show['!patrolled'] ) ||
495 isset( $show['autopatrolled'] ) || isset( $show['!autopatrolled'] ) || $this->fld_patrolled
496 ) {
497 $user = $this->getUser();
498 if ( !$user->useRCPatrol() && !$user->useNPPatrol() ) {
499 $this->dieWithError( 'apierror-permissiondenied-patrolflag', 'permissiondenied' );
500 }
501
502 $isFilterset = isset( $show['patrolled'] ) || isset( $show['!patrolled'] ) ||
503 isset( $show['autopatrolled'] ) || isset( $show['!autopatrolled'] );
504 $this->addTables( 'recentchanges' );
505 $this->addJoinConds( [ 'recentchanges' => [
506 $isFilterset ? 'JOIN' : 'LEFT JOIN',
507 [ 'rc_this_oldid = ' . $idField ]
508 ] ] );
509 }
510
511 $this->addFieldsIf( 'rc_patrolled', $this->fld_patrolled );
512
513 if ( $this->fld_tags ) {
514 $this->addFields( [
515 'ts_tags' => MediaWikiServices::getInstance()->getChangeTagsStore()
516 ->makeTagSummarySubquery( 'revision' )
517 ] );
518 }
519
520 if ( isset( $this->params['tag'] ) ) {
521 $this->addTables( 'change_tag' );
522 $this->addJoinConds(
523 [ 'change_tag' => [ 'JOIN', [ $idField . ' = ct_rev_id' ] ] ]
524 );
525 try {
526 $this->addWhereFld( 'ct_tag_id', $this->changeTagDefStore->getId( $this->params['tag'] ) );
527 } catch ( NameTableAccessException $exception ) {
528 // Return nothing.
529 $this->addWhere( '1=0' );
530 }
531 }
532 $this->addOption(
533 'MAX_EXECUTION_TIME',
534 $this->getConfig()->get( MainConfigNames::MaxExecutionTimeForExpensiveQueries )
535 );
536 }
537
538 /**
539 * Extract fields from the database row and append them to a result array
540 *
541 * @param stdClass $row
542 * @return array
543 */
544 private function extractRowInfo( $row ) {
545 $vals = [];
546 $anyHidden = false;
547
548 if ( $row->rev_deleted & RevisionRecord::DELETED_TEXT ) {
549 $vals['texthidden'] = true;
550 $anyHidden = true;
551 }
552
553 // Any rows where we can't view the user were filtered out in the query.
554 $vals['userid'] = (int)$row->rev_user;
555 $vals['user'] = $row->rev_user_text;
556 if ( $row->rev_deleted & RevisionRecord::DELETED_USER ) {
557 $vals['userhidden'] = true;
558 $anyHidden = true;
559 }
560 if ( $this->fld_ids ) {
561 $vals['pageid'] = (int)$row->rev_page;
562 $vals['revid'] = (int)$row->rev_id;
563
564 if ( $row->rev_parent_id !== null ) {
565 $vals['parentid'] = (int)$row->rev_parent_id;
566 }
567 }
568
569 $title = Title::makeTitle( $row->page_namespace, $row->page_title );
570
571 if ( $this->fld_title ) {
572 ApiQueryBase::addTitleInfo( $vals, $title );
573 }
574
575 if ( $this->fld_timestamp ) {
576 $vals['timestamp'] = wfTimestamp( TS_ISO_8601, $row->rev_timestamp );
577 }
578
579 if ( $this->fld_flags ) {
580 $vals['new'] = $row->rev_parent_id == 0 && $row->rev_parent_id !== null;
581 $vals['minor'] = (bool)$row->rev_minor_edit;
582 $vals['top'] = $row->page_latest == $row->rev_id;
583 }
584
585 if ( $this->fld_comment || $this->fld_parsedcomment ) {
586 if ( $row->rev_deleted & RevisionRecord::DELETED_COMMENT ) {
587 $vals['commenthidden'] = true;
588 $anyHidden = true;
589 }
590
591 $userCanView = RevisionRecord::userCanBitfield(
592 $row->rev_deleted,
593 RevisionRecord::DELETED_COMMENT, $this->getAuthority()
594 );
595
596 if ( $userCanView ) {
597 $comment = $this->commentStore->getComment( 'rev_comment', $row )->text;
598 if ( $this->fld_comment ) {
599 $vals['comment'] = $comment;
600 }
601
602 if ( $this->fld_parsedcomment ) {
603 $vals['parsedcomment'] = $this->commentFormatter->format( $comment, $title );
604 }
605 }
606 }
607
608 if ( $this->fld_patrolled ) {
609 $vals['patrolled'] = $row->rc_patrolled != RecentChange::PRC_UNPATROLLED;
610 $vals['autopatrolled'] = $row->rc_patrolled == RecentChange::PRC_AUTOPATROLLED;
611 }
612
613 if ( $this->fld_size && $row->rev_len !== null ) {
614 $vals['size'] = (int)$row->rev_len;
615 }
616
617 if ( $this->fld_sizediff
618 && $row->rev_len !== null
619 && $row->rev_parent_id !== null
620 ) {
621 $parentLen = $this->parentLens[$row->rev_parent_id] ?? 0;
622 $vals['sizediff'] = (int)$row->rev_len - $parentLen;
623 }
624
625 if ( $this->fld_tags ) {
626 if ( $row->ts_tags ) {
627 $tags = explode( ',', $row->ts_tags );
628 ApiResult::setIndexedTagName( $tags, 'tag' );
629 $vals['tags'] = $tags;
630 } else {
631 $vals['tags'] = [];
632 }
633 }
634
635 if ( $anyHidden && ( $row->rev_deleted & RevisionRecord::DELETED_RESTRICTED ) ) {
636 $vals['suppressed'] = true;
637 }
638
639 return $vals;
640 }
641
642 private function continueStr( $row ) {
643 if ( $this->multiUserMode ) {
644 switch ( $this->orderBy ) {
645 case 'name':
646 return "name|$row->rev_user_text|$row->rev_timestamp|$row->rev_id";
647 case 'actor':
648 return "actor|$row->rev_actor|$row->rev_timestamp|$row->rev_id";
649 }
650 } else {
651 return "$row->rev_timestamp|$row->rev_id";
652 }
653 }
654
655 public function getCacheMode( $params ) {
656 // This module provides access to deleted revisions and patrol flags if
657 // the requester is logged in
658 return 'anon-public-user-private';
659 }
660
661 public function getAllowedParams() {
662 return [
663 'limit' => [
664 ParamValidator::PARAM_DEFAULT => 10,
665 ParamValidator::PARAM_TYPE => 'limit',
666 IntegerDef::PARAM_MIN => 1,
667 IntegerDef::PARAM_MAX => ApiBase::LIMIT_BIG1,
668 IntegerDef::PARAM_MAX2 => ApiBase::LIMIT_BIG2
669 ],
670 'start' => [
671 ParamValidator::PARAM_TYPE => 'timestamp'
672 ],
673 'end' => [
674 ParamValidator::PARAM_TYPE => 'timestamp'
675 ],
676 'continue' => [
677 ApiBase::PARAM_HELP_MSG => 'api-help-param-continue',
678 ],
679 'user' => [
680 ParamValidator::PARAM_TYPE => 'user',
681 UserDef::PARAM_ALLOWED_USER_TYPES => [ 'name', 'ip', 'temp', 'interwiki' ],
682 ParamValidator::PARAM_ISMULTI => true
683 ],
684 'userids' => [
685 ParamValidator::PARAM_TYPE => 'integer',
686 ParamValidator::PARAM_ISMULTI => true
687 ],
688 'userprefix' => null,
689 'iprange' => null,
690 'dir' => [
691 ParamValidator::PARAM_DEFAULT => 'older',
692 ParamValidator::PARAM_TYPE => [
693 'newer',
694 'older'
695 ],
696 ApiBase::PARAM_HELP_MSG => 'api-help-param-direction',
697 ApiBase::PARAM_HELP_MSG_PER_VALUE => [
698 'newer' => 'api-help-paramvalue-direction-newer',
699 'older' => 'api-help-paramvalue-direction-older',
700 ],
701 ],
702 'namespace' => [
703 ParamValidator::PARAM_ISMULTI => true,
704 ParamValidator::PARAM_TYPE => 'namespace'
705 ],
706 'prop' => [
707 ParamValidator::PARAM_ISMULTI => true,
708 ParamValidator::PARAM_DEFAULT => 'ids|title|timestamp|comment|size|flags',
709 ParamValidator::PARAM_TYPE => [
710 'ids',
711 'title',
712 'timestamp',
713 'comment',
714 'parsedcomment',
715 'size',
716 'sizediff',
717 'flags',
718 'patrolled',
719 'tags'
720 ],
721 ApiBase::PARAM_HELP_MSG_PER_VALUE => [],
722 ],
723 'show' => [
724 ParamValidator::PARAM_ISMULTI => true,
725 ParamValidator::PARAM_TYPE => [
726 'minor',
727 '!minor',
728 'patrolled',
729 '!patrolled',
730 'autopatrolled',
731 '!autopatrolled',
732 'top',
733 '!top',
734 'new',
735 '!new',
736 ],
737 ApiBase::PARAM_HELP_MSG => [
738 'apihelp-query+usercontribs-param-show',
739 $this->getConfig()->get( MainConfigNames::RCMaxAge )
740 ],
741 ],
742 'tag' => null,
743 'toponly' => [
744 ParamValidator::PARAM_DEFAULT => false,
745 ParamValidator::PARAM_DEPRECATED => true,
746 ],
747 ];
748 }
749
750 protected function getExamplesMessages() {
751 return [
752 'action=query&list=usercontribs&ucuser=Example'
753 => 'apihelp-query+usercontribs-example-user',
754 'action=query&list=usercontribs&ucuserprefix=192.0.2.'
755 => 'apihelp-query+usercontribs-example-ipprefix',
756 ];
757 }
758
759 public function getHelpUrls() {
760 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Usercontribs';
761 }
762 }
763
764 /** @deprecated class alias since 1.43 */
765 class_alias( ApiQueryUserContribs::class, 'ApiQueryUserContribs' );