Merge "User: Bypass repeatable-read when creating an actor_id"
[lhc/web/wiklou.git] / includes / api / ApiQueryUserContribs.php
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 use MediaWiki\MediaWikiServices;
24 use MediaWiki\Revision\RevisionRecord;
25 use MediaWiki\Storage\NameTableAccessException;
26
27 /**
28 * This query action adds a list of a specified user's contributions to the output.
29 *
30 * @ingroup API
31 */
32 class ApiQueryUserContribs extends ApiQueryBase {
33
34 public function __construct( ApiQuery $query, $moduleName ) {
35 parent::__construct( $query, $moduleName, 'uc' );
36 }
37
38 private $params, $multiUserMode, $orderBy, $parentLens, $commentStore;
39
40 private $fld_ids = false, $fld_title = false, $fld_timestamp = false,
41 $fld_comment = false, $fld_parsedcomment = false, $fld_flags = false,
42 $fld_patrolled = false, $fld_tags = false, $fld_size = false, $fld_sizediff = false;
43
44 public function execute() {
45 global $wgActorTableSchemaMigrationStage;
46
47 // Parse some parameters
48 $this->params = $this->extractRequestParams();
49
50 $this->commentStore = CommentStore::getStore();
51
52 $prop = array_flip( $this->params['prop'] );
53 $this->fld_ids = isset( $prop['ids'] );
54 $this->fld_title = isset( $prop['title'] );
55 $this->fld_comment = isset( $prop['comment'] );
56 $this->fld_parsedcomment = isset( $prop['parsedcomment'] );
57 $this->fld_size = isset( $prop['size'] );
58 $this->fld_sizediff = isset( $prop['sizediff'] );
59 $this->fld_flags = isset( $prop['flags'] );
60 $this->fld_timestamp = isset( $prop['timestamp'] );
61 $this->fld_patrolled = isset( $prop['patrolled'] );
62 $this->fld_tags = isset( $prop['tags'] );
63
64 // Most of this code will use the 'contributions' group DB, which can map to replica DBs
65 // with extra user based indexes or partioning by user. The additional metadata
66 // queries should use a regular replica DB since the lookup pattern is not all by user.
67 $dbSecondary = $this->getDB(); // any random replica DB
68
69 // TODO: if the query is going only against the revision table, should this be done?
70 $this->selectNamedDB( 'contributions', DB_REPLICA, 'contributions' );
71
72 $sort = ( $this->params['dir'] == 'newer' ? '' : ' DESC' );
73 $op = ( $this->params['dir'] == 'older' ? '<' : '>' );
74
75 // Create an Iterator that produces the UserIdentity objects we need, depending
76 // on which of the 'userprefix', 'userids', or 'user' params was
77 // specified.
78 $this->requireOnlyOneParameter( $this->params, 'userprefix', 'userids', 'user' );
79 if ( isset( $this->params['userprefix'] ) ) {
80 $this->multiUserMode = true;
81 $this->orderBy = 'name';
82 $fname = __METHOD__;
83
84 // Because 'userprefix' might produce a huge number of users (e.g.
85 // a wiki with users "Test00000001" to "Test99999999"), use a
86 // generator with batched lookup and continuation.
87 $userIter = call_user_func( function () use ( $dbSecondary, $sort, $op, $fname ) {
88 global $wgActorTableSchemaMigrationStage;
89
90 $fromName = false;
91 if ( !is_null( $this->params['continue'] ) ) {
92 $continue = explode( '|', $this->params['continue'] );
93 $this->dieContinueUsageIf( count( $continue ) != 4 );
94 $this->dieContinueUsageIf( $continue[0] !== 'name' );
95 $fromName = $continue[1];
96 }
97 $like = $dbSecondary->buildLike( $this->params['userprefix'], $dbSecondary->anyString() );
98
99 $limit = 501;
100
101 do {
102 $from = $fromName ? "$op= " . $dbSecondary->addQuotes( $fromName ) : false;
103
104 // For the new schema, pull from the actor table. For the
105 // old, pull from rev_user.
106 if ( $wgActorTableSchemaMigrationStage & SCHEMA_COMPAT_READ_NEW ) {
107 $res = $dbSecondary->select(
108 'actor',
109 [ 'actor_id', 'user_id' => 'COALESCE(actor_user,0)', 'user_name' => 'actor_name' ],
110 array_merge( [ "actor_name$like" ], $from ? [ "actor_name $from" ] : [] ),
111 $fname,
112 [ 'ORDER BY' => [ "user_name $sort" ], 'LIMIT' => $limit ]
113 );
114 } else {
115 $res = $dbSecondary->select(
116 'revision',
117 [ 'actor_id' => 'NULL', 'user_id' => 'rev_user', 'user_name' => 'rev_user_text' ],
118 array_merge( [ "rev_user_text$like" ], $from ? [ "rev_user_text $from" ] : [] ),
119 $fname,
120 [ 'DISTINCT', 'ORDER BY' => [ "rev_user_text $sort" ], 'LIMIT' => $limit ]
121 );
122 }
123
124 $count = 0;
125 $fromName = false;
126 foreach ( $res as $row ) {
127 if ( ++$count >= $limit ) {
128 $fromName = $row->user_name;
129 break;
130 }
131 yield User::newFromRow( $row );
132 }
133 } while ( $fromName !== false );
134 } );
135 // Do the actual sorting client-side, because otherwise
136 // prepareQuery might try to sort by actor and confuse everything.
137 $batchSize = 1;
138 } elseif ( isset( $this->params['userids'] ) ) {
139 if ( !count( $this->params['userids'] ) ) {
140 $encParamName = $this->encodeParamName( 'userids' );
141 $this->dieWithError( [ 'apierror-paramempty', $encParamName ], "paramempty_$encParamName" );
142 }
143
144 $ids = [];
145 foreach ( $this->params['userids'] as $uid ) {
146 if ( $uid <= 0 ) {
147 $this->dieWithError( [ 'apierror-invaliduserid', $uid ], 'invaliduserid' );
148 }
149 $ids[] = $uid;
150 }
151
152 $this->orderBy = 'id';
153 $this->multiUserMode = count( $ids ) > 1;
154
155 $from = $fromId = false;
156 if ( $this->multiUserMode && !is_null( $this->params['continue'] ) ) {
157 $continue = explode( '|', $this->params['continue'] );
158 $this->dieContinueUsageIf( count( $continue ) != 4 );
159 $this->dieContinueUsageIf( $continue[0] !== 'id' && $continue[0] !== 'actor' );
160 $fromId = (int)$continue[1];
161 $this->dieContinueUsageIf( $continue[1] !== (string)$fromId );
162 $from = "$op= $fromId";
163 }
164
165 // For the new schema, just select from the actor table. For the
166 // old, select from user.
167 if ( $wgActorTableSchemaMigrationStage & SCHEMA_COMPAT_READ_NEW ) {
168 $res = $dbSecondary->select(
169 'actor',
170 [ 'actor_id', 'user_id' => 'actor_user', 'user_name' => 'actor_name' ],
171 array_merge( [ 'actor_user' => $ids ], $from ? [ "actor_id $from" ] : [] ),
172 __METHOD__,
173 [ 'ORDER BY' => "user_id $sort" ]
174 );
175 } else {
176 $res = $dbSecondary->select(
177 'user',
178 [ 'actor_id' => 'NULL', 'user_id' => 'user_id', 'user_name' => 'user_name' ],
179 array_merge( [ 'user_id' => $ids ], $from ? [ "user_id $from" ] : [] ),
180 __METHOD__,
181 [ 'ORDER BY' => "user_id $sort" ]
182 );
183 }
184 $userIter = UserArray::newFromResult( $res );
185 $batchSize = count( $ids );
186 } else {
187 $names = [];
188 if ( !count( $this->params['user'] ) ) {
189 $encParamName = $this->encodeParamName( 'user' );
190 $this->dieWithError(
191 [ 'apierror-paramempty', $encParamName ], "paramempty_$encParamName"
192 );
193 }
194 foreach ( $this->params['user'] as $u ) {
195 if ( $u === '' ) {
196 $encParamName = $this->encodeParamName( 'user' );
197 $this->dieWithError(
198 [ 'apierror-paramempty', $encParamName ], "paramempty_$encParamName"
199 );
200 }
201
202 if ( User::isIP( $u ) || ExternalUserNames::isExternal( $u ) ) {
203 $names[$u] = null;
204 } else {
205 $name = User::getCanonicalName( $u, 'valid' );
206 if ( $name === false ) {
207 $encParamName = $this->encodeParamName( 'user' );
208 $this->dieWithError(
209 [ 'apierror-baduser', $encParamName, wfEscapeWikiText( $u ) ], "baduser_$encParamName"
210 );
211 }
212 $names[$name] = null;
213 }
214 }
215
216 $this->orderBy = 'name';
217 $this->multiUserMode = count( $names ) > 1;
218
219 $from = $fromName = false;
220 if ( $this->multiUserMode && !is_null( $this->params['continue'] ) ) {
221 $continue = explode( '|', $this->params['continue'] );
222 $this->dieContinueUsageIf( count( $continue ) != 4 );
223 $this->dieContinueUsageIf( $continue[0] !== 'name' && $continue[0] !== 'actor' );
224 $fromName = $continue[1];
225 $from = "$op= " . $dbSecondary->addQuotes( $fromName );
226 }
227
228 // For the new schema, just select from the actor table. For the
229 // old, select from user then merge in any unknown users (IPs and imports).
230 if ( $wgActorTableSchemaMigrationStage & SCHEMA_COMPAT_READ_NEW ) {
231 $res = $dbSecondary->select(
232 'actor',
233 [ 'actor_id', 'user_id' => 'actor_user', 'user_name' => 'actor_name' ],
234 array_merge( [ 'actor_name' => array_keys( $names ) ], $from ? [ "actor_id $from" ] : [] ),
235 __METHOD__,
236 [ 'ORDER BY' => "actor_name $sort" ]
237 );
238 $userIter = UserArray::newFromResult( $res );
239 } else {
240 $res = $dbSecondary->select(
241 'user',
242 [ 'actor_id' => 'NULL', 'user_id', 'user_name' ],
243 array_merge( [ 'user_name' => array_keys( $names ) ], $from ? [ "user_name $from" ] : [] ),
244 __METHOD__
245 );
246 foreach ( $res as $row ) {
247 $names[$row->user_name] = $row;
248 }
249 if ( $this->params['dir'] == 'newer' ) {
250 ksort( $names, SORT_STRING );
251 } else {
252 krsort( $names, SORT_STRING );
253 }
254 $neg = $op === '>' ? -1 : 1;
255 $userIter = call_user_func( function () use ( $names, $fromName, $neg ) {
256 foreach ( $names as $name => $row ) {
257 if ( $fromName === false || $neg * strcmp( $name, $fromName ) <= 0 ) {
258 $user = $row ? User::newFromRow( $row ) : User::newFromName( $name, false );
259 yield $user;
260 }
261 }
262 } );
263 }
264 $batchSize = count( $names );
265 }
266
267 // With the new schema, the DB query will order by actor so update $this->orderBy to match.
268 if ( $batchSize > 1 && ( $wgActorTableSchemaMigrationStage & SCHEMA_COMPAT_READ_NEW ) ) {
269 $this->orderBy = 'actor';
270 }
271
272 $count = 0;
273 $limit = $this->params['limit'];
274 $userIter->rewind();
275 while ( $userIter->valid() ) {
276 $users = [];
277 while ( count( $users ) < $batchSize && $userIter->valid() ) {
278 $users[] = $userIter->current();
279 $userIter->next();
280 }
281
282 $hookData = [];
283 $this->prepareQuery( $users, $limit - $count );
284 $res = $this->select( __METHOD__, [], $hookData );
285
286 if ( $this->fld_sizediff ) {
287 $revIds = [];
288 foreach ( $res as $row ) {
289 if ( $row->rev_parent_id ) {
290 $revIds[] = $row->rev_parent_id;
291 }
292 }
293 $this->parentLens = MediaWikiServices::getInstance()->getRevisionStore()
294 ->listRevisionSizes( $dbSecondary, $revIds );
295 }
296
297 foreach ( $res as $row ) {
298 if ( ++$count > $limit ) {
299 // We've reached the one extra which shows that there are
300 // additional pages to be had. Stop here...
301 $this->setContinueEnumParameter( 'continue', $this->continueStr( $row ) );
302 break 2;
303 }
304
305 $vals = $this->extractRowInfo( $row );
306 $fit = $this->processRow( $row, $vals, $hookData ) &&
307 $this->getResult()->addValue( [ 'query', $this->getModuleName() ], null, $vals );
308 if ( !$fit ) {
309 $this->setContinueEnumParameter( 'continue', $this->continueStr( $row ) );
310 break 2;
311 }
312 }
313 }
314
315 $this->getResult()->addIndexedTagName( [ 'query', $this->getModuleName() ], 'item' );
316 }
317
318 /**
319 * Prepares the query and returns the limit of rows requested
320 * @param User[] $users
321 * @param int $limit
322 */
323 private function prepareQuery( array $users, $limit ) {
324 global $wgActorTableSchemaMigrationStage;
325
326 $this->resetQueryParams();
327 $db = $this->getDB();
328
329 $revQuery = MediaWikiServices::getInstance()->getRevisionStore()->getQueryInfo( [ 'page' ] );
330 $this->addTables( $revQuery['tables'] );
331 $this->addJoinConds( $revQuery['joins'] );
332 $this->addFields( $revQuery['fields'] );
333
334 if ( $wgActorTableSchemaMigrationStage & SCHEMA_COMPAT_READ_NEW ) {
335 $revWhere = ActorMigration::newMigration()->getWhere( $db, 'rev_user', $users );
336 $orderUserField = 'rev_actor';
337 $userField = $this->orderBy === 'actor' ? 'revactor_actor' : 'actor_name';
338 $tsField = 'revactor_timestamp';
339 $idField = 'revactor_rev';
340 } else {
341 // If we're dealing with user names (rather than IDs) in read-old mode,
342 // pass false for ActorMigration::getWhere()'s $useId parameter so
343 // $revWhere['conds'] isn't an OR.
344 $revWhere = ActorMigration::newMigration()
345 ->getWhere( $db, 'rev_user', $users, $this->orderBy === 'id' );
346 $orderUserField = $this->orderBy === 'id' ? 'rev_user' : 'rev_user_text';
347 $userField = $revQuery['fields'][$orderUserField];
348 $tsField = 'rev_timestamp';
349 $idField = 'rev_id';
350 }
351
352 $this->addWhere( $revWhere['conds'] );
353
354 // Handle continue parameter
355 if ( !is_null( $this->params['continue'] ) ) {
356 $continue = explode( '|', $this->params['continue'] );
357 if ( $this->multiUserMode ) {
358 $this->dieContinueUsageIf( count( $continue ) != 4 );
359 $modeFlag = array_shift( $continue );
360 $this->dieContinueUsageIf( $modeFlag !== $this->orderBy );
361 $encUser = $db->addQuotes( array_shift( $continue ) );
362 } else {
363 $this->dieContinueUsageIf( count( $continue ) != 2 );
364 }
365 $encTS = $db->addQuotes( $db->timestamp( $continue[0] ) );
366 $encId = (int)$continue[1];
367 $this->dieContinueUsageIf( $encId != $continue[1] );
368 $op = ( $this->params['dir'] == 'older' ? '<' : '>' );
369 if ( $this->multiUserMode ) {
370 $this->addWhere(
371 "$userField $op $encUser OR " .
372 "($userField = $encUser AND " .
373 "($tsField $op $encTS OR " .
374 "($tsField = $encTS AND " .
375 "$idField $op= $encId)))"
376 );
377 } else {
378 $this->addWhere(
379 "$tsField $op $encTS OR " .
380 "($tsField = $encTS AND " .
381 "$idField $op= $encId)"
382 );
383 }
384 }
385
386 // Don't include any revisions where we're not supposed to be able to
387 // see the username.
388 $user = $this->getUser();
389 if ( !$user->isAllowed( 'deletedhistory' ) ) {
390 $bitmask = RevisionRecord::DELETED_USER;
391 } elseif ( !$user->isAllowedAny( 'suppressrevision', 'viewsuppressed' ) ) {
392 $bitmask = RevisionRecord::DELETED_USER | RevisionRecord::DELETED_RESTRICTED;
393 } else {
394 $bitmask = 0;
395 }
396 if ( $bitmask ) {
397 $this->addWhere( $db->bitAnd( 'rev_deleted', $bitmask ) . " != $bitmask" );
398 }
399
400 // Add the user field to ORDER BY if there are multiple users
401 if ( count( $users ) > 1 ) {
402 $this->addWhereRange( $orderUserField, $this->params['dir'], null, null );
403 }
404
405 // Then timestamp
406 $this->addTimestampWhereRange( $tsField,
407 $this->params['dir'], $this->params['start'], $this->params['end'] );
408
409 // Then rev_id for a total ordering
410 $this->addWhereRange( $idField, $this->params['dir'], null, null );
411
412 $this->addWhereFld( 'page_namespace', $this->params['namespace'] );
413
414 $show = $this->params['show'];
415 if ( $this->params['toponly'] ) { // deprecated/old param
416 $show[] = 'top';
417 }
418 if ( !is_null( $show ) ) {
419 $show = array_flip( $show );
420
421 if ( ( isset( $show['minor'] ) && isset( $show['!minor'] ) )
422 || ( isset( $show['patrolled'] ) && isset( $show['!patrolled'] ) )
423 || ( isset( $show['autopatrolled'] ) && isset( $show['!autopatrolled'] ) )
424 || ( isset( $show['autopatrolled'] ) && isset( $show['!patrolled'] ) )
425 || ( isset( $show['top'] ) && isset( $show['!top'] ) )
426 || ( isset( $show['new'] ) && isset( $show['!new'] ) )
427 ) {
428 $this->dieWithError( 'apierror-show' );
429 }
430
431 $this->addWhereIf( 'rev_minor_edit = 0', isset( $show['!minor'] ) );
432 $this->addWhereIf( 'rev_minor_edit != 0', isset( $show['minor'] ) );
433 $this->addWhereIf(
434 'rc_patrolled = ' . RecentChange::PRC_UNPATROLLED,
435 isset( $show['!patrolled'] )
436 );
437 $this->addWhereIf(
438 'rc_patrolled != ' . RecentChange::PRC_UNPATROLLED,
439 isset( $show['patrolled'] )
440 );
441 $this->addWhereIf(
442 'rc_patrolled != ' . RecentChange::PRC_AUTOPATROLLED,
443 isset( $show['!autopatrolled'] )
444 );
445 $this->addWhereIf(
446 'rc_patrolled = ' . RecentChange::PRC_AUTOPATROLLED,
447 isset( $show['autopatrolled'] )
448 );
449 $this->addWhereIf( $idField . ' != page_latest', isset( $show['!top'] ) );
450 $this->addWhereIf( $idField . ' = page_latest', isset( $show['top'] ) );
451 $this->addWhereIf( 'rev_parent_id != 0', isset( $show['!new'] ) );
452 $this->addWhereIf( 'rev_parent_id = 0', isset( $show['new'] ) );
453 }
454 $this->addOption( 'LIMIT', $limit + 1 );
455
456 if ( isset( $show['patrolled'] ) || isset( $show['!patrolled'] ) ||
457 isset( $show['autopatrolled'] ) || isset( $show['!autopatrolled'] ) || $this->fld_patrolled
458 ) {
459 if ( !$user->useRCPatrol() && !$user->useNPPatrol() ) {
460 $this->dieWithError( 'apierror-permissiondenied-patrolflag', 'permissiondenied' );
461 }
462
463 $isFilterset = isset( $show['patrolled'] ) || isset( $show['!patrolled'] ) ||
464 isset( $show['autopatrolled'] ) || isset( $show['!autopatrolled'] );
465 $this->addTables( 'recentchanges' );
466 $this->addJoinConds( [ 'recentchanges' => [
467 $isFilterset ? 'JOIN' : 'LEFT JOIN',
468 [
469 // This is a crazy hack. recentchanges has no index on rc_this_oldid, so instead of adding
470 // one T19237 did a join using rc_user_text and rc_timestamp instead. Now rc_user_text is
471 // probably unavailable, so just do rc_timestamp.
472 'rc_timestamp = ' . $tsField,
473 'rc_this_oldid = ' . $idField,
474 ]
475 ] ] );
476 }
477
478 $this->addFieldsIf( 'rc_patrolled', $this->fld_patrolled );
479
480 if ( $this->fld_tags ) {
481 $this->addFields( [ 'ts_tags' => ChangeTags::makeTagSummarySubquery( 'revision' ) ] );
482 }
483
484 if ( isset( $this->params['tag'] ) ) {
485 $this->addTables( 'change_tag' );
486 $this->addJoinConds(
487 [ 'change_tag' => [ 'INNER JOIN', [ $idField . ' = ct_rev_id' ] ] ]
488 );
489 $changeTagDefStore = MediaWikiServices::getInstance()->getChangeTagDefStore();
490 try {
491 $this->addWhereFld( 'ct_tag_id', $changeTagDefStore->getId( $this->params['tag'] ) );
492 } catch ( NameTableAccessException $exception ) {
493 // Return nothing.
494 $this->addWhere( '1=0' );
495 }
496 }
497 }
498
499 /**
500 * Extract fields from the database row and append them to a result array
501 *
502 * @param stdClass $row
503 * @return array
504 */
505 private function extractRowInfo( $row ) {
506 $vals = [];
507 $anyHidden = false;
508
509 if ( $row->rev_deleted & RevisionRecord::DELETED_TEXT ) {
510 $vals['texthidden'] = true;
511 $anyHidden = true;
512 }
513
514 // Any rows where we can't view the user were filtered out in the query.
515 $vals['userid'] = (int)$row->rev_user;
516 $vals['user'] = $row->rev_user_text;
517 if ( $row->rev_deleted & RevisionRecord::DELETED_USER ) {
518 $vals['userhidden'] = true;
519 $anyHidden = true;
520 }
521 if ( $this->fld_ids ) {
522 $vals['pageid'] = intval( $row->rev_page );
523 $vals['revid'] = intval( $row->rev_id );
524 // $vals['textid'] = intval( $row->rev_text_id ); // todo: Should this field be exposed?
525
526 if ( !is_null( $row->rev_parent_id ) ) {
527 $vals['parentid'] = intval( $row->rev_parent_id );
528 }
529 }
530
531 $title = Title::makeTitle( $row->page_namespace, $row->page_title );
532
533 if ( $this->fld_title ) {
534 ApiQueryBase::addTitleInfo( $vals, $title );
535 }
536
537 if ( $this->fld_timestamp ) {
538 $vals['timestamp'] = wfTimestamp( TS_ISO_8601, $row->rev_timestamp );
539 }
540
541 if ( $this->fld_flags ) {
542 $vals['new'] = $row->rev_parent_id == 0 && !is_null( $row->rev_parent_id );
543 $vals['minor'] = (bool)$row->rev_minor_edit;
544 $vals['top'] = $row->page_latest == $row->rev_id;
545 }
546
547 if ( $this->fld_comment || $this->fld_parsedcomment ) {
548 if ( $row->rev_deleted & RevisionRecord::DELETED_COMMENT ) {
549 $vals['commenthidden'] = true;
550 $anyHidden = true;
551 }
552
553 $userCanView = RevisionRecord::userCanBitfield(
554 $row->rev_deleted,
555 RevisionRecord::DELETED_COMMENT, $this->getUser()
556 );
557
558 if ( $userCanView ) {
559 $comment = $this->commentStore->getComment( 'rev_comment', $row )->text;
560 if ( $this->fld_comment ) {
561 $vals['comment'] = $comment;
562 }
563
564 if ( $this->fld_parsedcomment ) {
565 $vals['parsedcomment'] = Linker::formatComment( $comment, $title );
566 }
567 }
568 }
569
570 if ( $this->fld_patrolled ) {
571 $vals['patrolled'] = $row->rc_patrolled != RecentChange::PRC_UNPATROLLED;
572 $vals['autopatrolled'] = $row->rc_patrolled == RecentChange::PRC_AUTOPATROLLED;
573 }
574
575 if ( $this->fld_size && !is_null( $row->rev_len ) ) {
576 $vals['size'] = intval( $row->rev_len );
577 }
578
579 if ( $this->fld_sizediff
580 && !is_null( $row->rev_len )
581 && !is_null( $row->rev_parent_id )
582 ) {
583 $parentLen = $this->parentLens[$row->rev_parent_id] ?? 0;
584 $vals['sizediff'] = intval( $row->rev_len - $parentLen );
585 }
586
587 if ( $this->fld_tags ) {
588 if ( $row->ts_tags ) {
589 $tags = explode( ',', $row->ts_tags );
590 ApiResult::setIndexedTagName( $tags, 'tag' );
591 $vals['tags'] = $tags;
592 } else {
593 $vals['tags'] = [];
594 }
595 }
596
597 if ( $anyHidden && ( $row->rev_deleted & RevisionRecord::DELETED_RESTRICTED ) ) {
598 $vals['suppressed'] = true;
599 }
600
601 return $vals;
602 }
603
604 private function continueStr( $row ) {
605 if ( $this->multiUserMode ) {
606 switch ( $this->orderBy ) {
607 case 'id':
608 return "id|$row->rev_user|$row->rev_timestamp|$row->rev_id";
609 case 'name':
610 return "name|$row->rev_user_text|$row->rev_timestamp|$row->rev_id";
611 case 'actor':
612 return "actor|$row->rev_actor|$row->rev_timestamp|$row->rev_id";
613 }
614 } else {
615 return "$row->rev_timestamp|$row->rev_id";
616 }
617 }
618
619 public function getCacheMode( $params ) {
620 // This module provides access to deleted revisions and patrol flags if
621 // the requester is logged in
622 return 'anon-public-user-private';
623 }
624
625 public function getAllowedParams() {
626 return [
627 'limit' => [
628 ApiBase::PARAM_DFLT => 10,
629 ApiBase::PARAM_TYPE => 'limit',
630 ApiBase::PARAM_MIN => 1,
631 ApiBase::PARAM_MAX => ApiBase::LIMIT_BIG1,
632 ApiBase::PARAM_MAX2 => ApiBase::LIMIT_BIG2
633 ],
634 'start' => [
635 ApiBase::PARAM_TYPE => 'timestamp'
636 ],
637 'end' => [
638 ApiBase::PARAM_TYPE => 'timestamp'
639 ],
640 'continue' => [
641 ApiBase::PARAM_HELP_MSG => 'api-help-param-continue',
642 ],
643 'user' => [
644 ApiBase::PARAM_TYPE => 'user',
645 ApiBase::PARAM_ISMULTI => true
646 ],
647 'userids' => [
648 ApiBase::PARAM_TYPE => 'integer',
649 ApiBase::PARAM_ISMULTI => true
650 ],
651 'userprefix' => null,
652 'dir' => [
653 ApiBase::PARAM_DFLT => 'older',
654 ApiBase::PARAM_TYPE => [
655 'newer',
656 'older'
657 ],
658 ApiBase::PARAM_HELP_MSG => 'api-help-param-direction',
659 ],
660 'namespace' => [
661 ApiBase::PARAM_ISMULTI => true,
662 ApiBase::PARAM_TYPE => 'namespace'
663 ],
664 'prop' => [
665 ApiBase::PARAM_ISMULTI => true,
666 ApiBase::PARAM_DFLT => 'ids|title|timestamp|comment|size|flags',
667 ApiBase::PARAM_TYPE => [
668 'ids',
669 'title',
670 'timestamp',
671 'comment',
672 'parsedcomment',
673 'size',
674 'sizediff',
675 'flags',
676 'patrolled',
677 'tags'
678 ],
679 ApiBase::PARAM_HELP_MSG_PER_VALUE => [],
680 ],
681 'show' => [
682 ApiBase::PARAM_ISMULTI => true,
683 ApiBase::PARAM_TYPE => [
684 'minor',
685 '!minor',
686 'patrolled',
687 '!patrolled',
688 'autopatrolled',
689 '!autopatrolled',
690 'top',
691 '!top',
692 'new',
693 '!new',
694 ],
695 ApiBase::PARAM_HELP_MSG => [
696 'apihelp-query+usercontribs-param-show',
697 $this->getConfig()->get( 'RCMaxAge' )
698 ],
699 ],
700 'tag' => null,
701 'toponly' => [
702 ApiBase::PARAM_DFLT => false,
703 ApiBase::PARAM_DEPRECATED => true,
704 ],
705 ];
706 }
707
708 protected function getExamplesMessages() {
709 return [
710 'action=query&list=usercontribs&ucuser=Example'
711 => 'apihelp-query+usercontribs-example-user',
712 'action=query&list=usercontribs&ucuserprefix=192.0.2.'
713 => 'apihelp-query+usercontribs-example-ipprefix',
714 ];
715 }
716
717 public function getHelpUrls() {
718 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Usercontribs';
719 }
720 }
721
722 /**
723 * @since 1.9
724 * @deprecated since 1.32
725 */
726 class_alias( ApiQueryUserContribs::class, 'ApiQueryContributions' );