3 * Copyright © 2006 Yuri Astrakhan "<Firstname><Lastname>@gmail.com"
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.
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.
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
23 use MediaWiki\MediaWikiServices
;
24 use MediaWiki\Storage\RevisionRecord
;
27 * This query action adds a list of a specified user's contributions to the output.
31 class ApiQueryUserContribs
extends ApiQueryBase
{
33 public function __construct( ApiQuery
$query, $moduleName ) {
34 parent
::__construct( $query, $moduleName, 'uc' );
37 private $params, $multiUserMode, $orderBy, $parentLens, $commentStore;
39 private $fld_ids = false, $fld_title = false, $fld_timestamp = false,
40 $fld_comment = false, $fld_parsedcomment = false, $fld_flags = false,
41 $fld_patrolled = false, $fld_tags = false, $fld_size = false, $fld_sizediff = false;
43 public function execute() {
44 global $wgActorTableSchemaMigrationStage;
46 // Parse some parameters
47 $this->params
= $this->extractRequestParams();
49 $this->commentStore
= CommentStore
::getStore();
51 $prop = array_flip( $this->params
['prop'] );
52 $this->fld_ids
= isset( $prop['ids'] );
53 $this->fld_title
= isset( $prop['title'] );
54 $this->fld_comment
= isset( $prop['comment'] );
55 $this->fld_parsedcomment
= isset( $prop['parsedcomment'] );
56 $this->fld_size
= isset( $prop['size'] );
57 $this->fld_sizediff
= isset( $prop['sizediff'] );
58 $this->fld_flags
= isset( $prop['flags'] );
59 $this->fld_timestamp
= isset( $prop['timestamp'] );
60 $this->fld_patrolled
= isset( $prop['patrolled'] );
61 $this->fld_tags
= isset( $prop['tags'] );
63 // Most of this code will use the 'contributions' group DB, which can map to replica DBs
64 // with extra user based indexes or partioning by user. The additional metadata
65 // queries should use a regular replica DB since the lookup pattern is not all by user.
66 $dbSecondary = $this->getDB(); // any random replica DB
68 // TODO: if the query is going only against the revision table, should this be done?
69 $this->selectNamedDB( 'contributions', DB_REPLICA
, 'contributions' );
71 $sort = ( $this->params
['dir'] == 'newer' ?
'' : ' DESC' );
72 $op = ( $this->params
['dir'] == 'older' ?
'<' : '>' );
74 // Create an Iterator that produces the UserIdentity objects we need, depending
75 // on which of the 'userprefix', 'userids', or 'user' params was
77 $this->requireOnlyOneParameter( $this->params
, 'userprefix', 'userids', 'user' );
78 if ( isset( $this->params
['userprefix'] ) ) {
79 $this->multiUserMode
= true;
80 $this->orderBy
= 'name';
83 // Because 'userprefix' might produce a huge number of users (e.g.
84 // a wiki with users "Test00000001" to "Test99999999"), use a
85 // generator with batched lookup and continuation.
86 $userIter = call_user_func( function () use ( $dbSecondary, $sort, $op, $fname ) {
87 global $wgActorTableSchemaMigrationStage;
90 if ( !is_null( $this->params
['continue'] ) ) {
91 $continue = explode( '|', $this->params
['continue'] );
92 $this->dieContinueUsageIf( count( $continue ) != 4 );
93 $this->dieContinueUsageIf( $continue[0] !== 'name' );
94 $fromName = $continue[1];
96 $like = $dbSecondary->buildLike( $this->params
['userprefix'], $dbSecondary->anyString() );
101 $from = $fromName ?
"$op= " . $dbSecondary->addQuotes( $fromName ) : false;
103 // For the new schema, pull from the actor table. For the
104 // old, pull from rev_user. For migration a FULL [OUTER]
105 // JOIN would be what we want, except MySQL doesn't support
106 // that so we have to UNION instead.
107 if ( $wgActorTableSchemaMigrationStage === MIGRATION_NEW
) {
108 $res = $dbSecondary->select(
110 [ 'actor_id', 'user_id' => 'COALESCE(actor_user,0)', 'user_name' => 'actor_name' ],
111 array_merge( [ "actor_name$like" ], $from ?
[ "actor_name $from" ] : [] ),
113 [ 'ORDER BY' => [ "user_name $sort" ], 'LIMIT' => $limit ]
115 } elseif ( $wgActorTableSchemaMigrationStage === MIGRATION_OLD
) {
116 $res = $dbSecondary->select(
118 [ 'actor_id' => 'NULL', 'user_id' => 'rev_user', 'user_name' => 'rev_user_text' ],
119 array_merge( [ "rev_user_text$like" ], $from ?
[ "rev_user_text $from" ] : [] ),
121 [ 'DISTINCT', 'ORDER BY' => [ "rev_user_text $sort" ], 'LIMIT' => $limit ]
124 // There are three queries we have to combine to be sure of getting all results:
125 // - actor table (any rows that have been migrated will have empty rev_user_text)
126 // - revision+actor by user id
127 // - revision+actor by name for anons
128 $options = $dbSecondary->unionSupportsOrderAndLimit()
129 ?
[ 'ORDER BY' => [ "user_name $sort" ], 'LIMIT' => $limit ] : [];
131 $subsql[] = $dbSecondary->selectSQLText(
133 [ 'actor_id', 'user_id' => 'COALESCE(actor_user,0)', 'user_name' => 'actor_name' ],
134 array_merge( [ "actor_name$like" ], $from ?
[ "actor_name $from" ] : [] ),
138 $subsql[] = $dbSecondary->selectSQLText(
139 [ 'revision', 'actor' ],
140 [ 'actor_id', 'user_id' => 'rev_user', 'user_name' => 'rev_user_text' ],
142 [ "rev_user_text$like", 'rev_user != 0' ],
143 $from ?
[ "rev_user_text $from" ] : []
146 array_merge( [ 'DISTINCT' ], $options ),
147 [ 'actor' => [ 'LEFT JOIN', 'rev_user = actor_user' ] ]
149 $subsql[] = $dbSecondary->selectSQLText(
150 [ 'revision', 'actor' ],
151 [ 'actor_id', 'user_id' => 'rev_user', 'user_name' => 'rev_user_text' ],
153 [ "rev_user_text$like", 'rev_user = 0' ],
154 $from ?
[ "rev_user_text $from" ] : []
157 array_merge( [ 'DISTINCT' ], $options ),
158 [ 'actor' => [ 'LEFT JOIN', 'rev_user_text = actor_name' ] ]
160 $sql = $dbSecondary->unionQueries( $subsql, false ) . " ORDER BY user_name $sort";
161 $sql = $dbSecondary->limitResult( $sql, $limit );
162 $res = $dbSecondary->query( $sql, $fname );
167 foreach ( $res as $row ) {
168 if ( ++
$count >= $limit ) {
169 $fromName = $row->user_name
;
172 yield User
::newFromRow( $row );
174 } while ( $fromName !== false );
176 // Do the actual sorting client-side, because otherwise
177 // prepareQuery might try to sort by actor and confuse everything.
179 } elseif ( isset( $this->params
['userids'] ) ) {
180 if ( !count( $this->params
['userids'] ) ) {
181 $encParamName = $this->encodeParamName( 'userids' );
182 $this->dieWithError( [ 'apierror-paramempty', $encParamName ], "paramempty_$encParamName" );
186 foreach ( $this->params
['userids'] as $uid ) {
188 $this->dieWithError( [ 'apierror-invaliduserid', $uid ], 'invaliduserid' );
193 $this->orderBy
= 'id';
194 $this->multiUserMode
= count( $ids ) > 1;
196 $from = $fromId = false;
197 if ( $this->multiUserMode
&& !is_null( $this->params
['continue'] ) ) {
198 $continue = explode( '|', $this->params
['continue'] );
199 $this->dieContinueUsageIf( count( $continue ) != 4 );
200 $this->dieContinueUsageIf( $continue[0] !== 'id' && $continue[0] !== 'actor' );
201 $fromId = (int)$continue[1];
202 $this->dieContinueUsageIf( $continue[1] !== (string)$fromId );
203 $from = "$op= $fromId";
206 // For the new schema, just select from the actor table. For the
207 // old and transitional schemas, select from user and left join
208 // actor if it exists.
209 if ( $wgActorTableSchemaMigrationStage === MIGRATION_NEW
) {
210 $res = $dbSecondary->select(
212 [ 'actor_id', 'user_id' => 'actor_user', 'user_name' => 'actor_name' ],
213 array_merge( [ 'actor_user' => $ids ], $from ?
[ "actor_id $from" ] : [] ),
215 [ 'ORDER BY' => "user_id $sort" ]
217 } elseif ( $wgActorTableSchemaMigrationStage === MIGRATION_OLD
) {
218 $res = $dbSecondary->select(
220 [ 'actor_id' => 'NULL', 'user_id' => 'user_id', 'user_name' => 'user_name' ],
221 array_merge( [ 'user_id' => $ids ], $from ?
[ "user_id $from" ] : [] ),
223 [ 'ORDER BY' => "user_id $sort" ]
226 $res = $dbSecondary->select(
228 [ 'actor_id', 'user_id', 'user_name' ],
229 array_merge( [ 'user_id' => $ids ], $from ?
[ "user_id $from" ] : [] ),
231 [ 'ORDER BY' => "user_id $sort" ],
232 [ 'actor' => [ 'LEFT JOIN', 'actor_user = user_id' ] ]
235 $userIter = UserArray
::newFromResult( $res );
236 $batchSize = count( $ids );
239 if ( !count( $this->params
['user'] ) ) {
240 $encParamName = $this->encodeParamName( 'user' );
242 [ 'apierror-paramempty', $encParamName ], "paramempty_$encParamName"
245 foreach ( $this->params
['user'] as $u ) {
247 $encParamName = $this->encodeParamName( 'user' );
249 [ 'apierror-paramempty', $encParamName ], "paramempty_$encParamName"
253 if ( User
::isIP( $u ) || ExternalUserNames
::isExternal( $u ) ) {
256 $name = User
::getCanonicalName( $u, 'valid' );
257 if ( $name === false ) {
258 $encParamName = $this->encodeParamName( 'user' );
260 [ 'apierror-baduser', $encParamName, wfEscapeWikiText( $u ) ], "baduser_$encParamName"
263 $names[$name] = null;
267 $this->orderBy
= 'name';
268 $this->multiUserMode
= count( $names ) > 1;
270 $from = $fromName = false;
271 if ( $this->multiUserMode
&& !is_null( $this->params
['continue'] ) ) {
272 $continue = explode( '|', $this->params
['continue'] );
273 $this->dieContinueUsageIf( count( $continue ) != 4 );
274 $this->dieContinueUsageIf( $continue[0] !== 'name' && $continue[0] !== 'actor' );
275 $fromName = $continue[1];
276 $from = "$op= " . $dbSecondary->addQuotes( $fromName );
279 // For the new schema, just select from the actor table. For the
280 // old and transitional schemas, select from user and left join
281 // actor if it exists then merge in any unknown users (IPs and imports).
282 if ( $wgActorTableSchemaMigrationStage === MIGRATION_NEW
) {
283 $res = $dbSecondary->select(
285 [ 'actor_id', 'user_id' => 'actor_user', 'user_name' => 'actor_name' ],
286 array_merge( [ 'actor_name' => array_keys( $names ) ], $from ?
[ "actor_id $from" ] : [] ),
288 [ 'ORDER BY' => "actor_name $sort" ]
290 $userIter = UserArray
::newFromResult( $res );
292 if ( $wgActorTableSchemaMigrationStage === MIGRATION_OLD
) {
293 $res = $dbSecondary->select(
295 [ 'actor_id' => 'NULL', 'user_id', 'user_name' ],
296 array_merge( [ 'user_name' => array_keys( $names ) ], $from ?
[ "user_name $from" ] : [] ),
300 $res = $dbSecondary->select(
302 [ 'actor_id', 'user_id', 'user_name' ],
303 array_merge( [ 'user_name' => array_keys( $names ) ], $from ?
[ "user_name $from" ] : [] ),
306 [ 'actor' => [ 'LEFT JOIN', 'actor_user = user_id' ] ]
309 foreach ( $res as $row ) {
310 $names[$row->user_name
] = $row;
312 if ( $this->params
['dir'] == 'newer' ) {
313 ksort( $names, SORT_STRING
);
315 krsort( $names, SORT_STRING
);
317 $neg = $op === '>' ?
-1 : 1;
318 $userIter = call_user_func( function () use ( $names, $fromName, $neg ) {
319 foreach ( $names as $name => $row ) {
320 if ( $fromName === false ||
$neg * strcmp( $name, $fromName ) <= 0 ) {
321 $user = $row ? User
::newFromRow( $row ) : User
::newFromName( $name, false );
327 $batchSize = count( $names );
330 // During migration, force ordering on the client side because we're
331 // having to combine multiple queries that would otherwise have
332 // different sort orders.
333 if ( $wgActorTableSchemaMigrationStage === MIGRATION_WRITE_BOTH ||
334 $wgActorTableSchemaMigrationStage === MIGRATION_WRITE_NEW
339 // With the new schema, the DB query will order by actor so update $this->orderBy to match.
340 if ( $batchSize > 1 && $wgActorTableSchemaMigrationStage === MIGRATION_NEW
) {
341 $this->orderBy
= 'actor';
345 $limit = $this->params
['limit'];
347 while ( $userIter->valid() ) {
349 while ( count( $users ) < $batchSize && $userIter->valid() ) {
350 $users[] = $userIter->current();
354 // Ugh. We have to run the query three times, once for each
355 // possible 'orcond' from ActorMigration, and then merge them all
356 // together in the proper order. And preserving the correct
357 // $hookData for each one.
358 // @todo When ActorMigration is removed, this can go back to a
359 // single prepare and select.
361 foreach ( [ 'actor', 'userid', 'username' ] as $which ) {
362 if ( $this->prepareQuery( $users, $limit - $count, $which ) ) {
364 $res = $this->select( __METHOD__
, [], $hookData );
365 foreach ( $res as $row ) {
366 $merged[] = [ $row, &$hookData ];
370 $neg = $this->params
['dir'] == 'newer' ?
1 : -1;
371 usort( $merged, function ( $a, $b ) use ( $neg, $batchSize ) {
372 if ( $batchSize === 1 ) { // One user, can't be different
374 } elseif ( $this->orderBy
=== 'id' ) {
375 $ret = $a[0]->rev_user
<=> $b[0]->rev_user
;
376 } elseif ( $this->orderBy
=== 'name' ) {
377 $ret = strcmp( $a[0]->rev_user_text
, $b[0]->rev_user_text
);
379 $ret = $a[0]->rev_actor
<=> $b[0]->rev_actor
;
384 wfTimestamp( TS_MW
, $a[0]->rev_timestamp
),
385 wfTimestamp( TS_MW
, $b[0]->rev_timestamp
)
390 $ret = $a[0]->rev_id
<=> $b[0]->rev_id
;
395 $merged = array_slice( $merged, 0, $limit - $count +
1 );
398 if ( $this->fld_sizediff
) {
400 foreach ( $merged as $data ) {
401 if ( $data[0]->rev_parent_id
) {
402 $revIds[] = $data[0]->rev_parent_id
;
405 $this->parentLens
= MediaWikiServices
::getInstance()->getRevisionStore()
406 ->listRevisionSizes( $dbSecondary, $revIds );
409 foreach ( $merged as $data ) {
411 $hookData = &$data[1];
412 if ( ++
$count > $limit ) {
413 // We've reached the one extra which shows that there are
414 // additional pages to be had. Stop here...
415 $this->setContinueEnumParameter( 'continue', $this->continueStr( $row ) );
419 $vals = $this->extractRowInfo( $row );
420 $fit = $this->processRow( $row, $vals, $hookData ) &&
421 $this->getResult()->addValue( [ 'query', $this->getModuleName() ], null, $vals );
423 $this->setContinueEnumParameter( 'continue', $this->continueStr( $row ) );
429 $this->getResult()->addIndexedTagName( [ 'query', $this->getModuleName() ], 'item' );
433 * Prepares the query and returns the limit of rows requested
434 * @param User[] $users
436 * @param string $which 'actor', 'userid', or 'username'
439 private function prepareQuery( array $users, $limit, $which ) {
440 global $wgActorTableSchemaMigrationStage;
442 $this->resetQueryParams();
443 $db = $this->getDB();
445 $revQuery = MediaWikiServices
::getInstance()->getRevisionStore()->getQueryInfo( [ 'page' ] );
446 $this->addTables( $revQuery['tables'] );
447 $this->addJoinConds( $revQuery['joins'] );
448 $this->addFields( $revQuery['fields'] );
450 $revWhere = ActorMigration
::newMigration()->getWhere( $db, 'rev_user', $users );
451 if ( !isset( $revWhere['orconds'][$which] ) ) {
454 $this->addWhere( $revWhere['orconds'][$which] );
456 if ( $wgActorTableSchemaMigrationStage === MIGRATION_NEW
) {
457 $orderUserField = 'rev_actor';
458 $userField = $this->orderBy
=== 'actor' ?
'revactor_actor' : 'actor_name';
460 $orderUserField = $this->orderBy
=== 'id' ?
'rev_user' : 'rev_user_text';
461 $userField = $revQuery['fields'][$orderUserField];
463 if ( $which === 'actor' ) {
464 $tsField = 'revactor_timestamp';
465 $idField = 'revactor_rev';
467 $tsField = 'rev_timestamp';
471 // Handle continue parameter
472 if ( !is_null( $this->params
['continue'] ) ) {
473 $continue = explode( '|', $this->params
['continue'] );
474 if ( $this->multiUserMode
) {
475 $this->dieContinueUsageIf( count( $continue ) != 4 );
476 $modeFlag = array_shift( $continue );
477 $this->dieContinueUsageIf( $modeFlag !== $this->orderBy
);
478 $encUser = $db->addQuotes( array_shift( $continue ) );
480 $this->dieContinueUsageIf( count( $continue ) != 2 );
482 $encTS = $db->addQuotes( $db->timestamp( $continue[0] ) );
483 $encId = (int)$continue[1];
484 $this->dieContinueUsageIf( $encId != $continue[1] );
485 $op = ( $this->params
['dir'] == 'older' ?
'<' : '>' );
486 if ( $this->multiUserMode
) {
488 "$userField $op $encUser OR " .
489 "($userField = $encUser AND " .
490 "($tsField $op $encTS OR " .
491 "($tsField = $encTS AND " .
492 "$idField $op= $encId)))"
496 "$tsField $op $encTS OR " .
497 "($tsField = $encTS AND " .
498 "$idField $op= $encId)"
503 // Don't include any revisions where we're not supposed to be able to
505 $user = $this->getUser();
506 if ( !$user->isAllowed( 'deletedhistory' ) ) {
507 $bitmask = RevisionRecord
::DELETED_USER
;
508 } elseif ( !$user->isAllowedAny( 'suppressrevision', 'viewsuppressed' ) ) {
509 $bitmask = RevisionRecord
::DELETED_USER | RevisionRecord
::DELETED_RESTRICTED
;
514 $this->addWhere( $db->bitAnd( 'rev_deleted', $bitmask ) . " != $bitmask" );
517 // Add the user field to ORDER BY if there are multiple users
518 if ( count( $users ) > 1 ) {
519 $this->addWhereRange( $orderUserField, $this->params
['dir'], null, null );
523 $this->addTimestampWhereRange( $tsField,
524 $this->params
['dir'], $this->params
['start'], $this->params
['end'] );
526 // Then rev_id for a total ordering
527 $this->addWhereRange( $idField, $this->params
['dir'], null, null );
529 $this->addWhereFld( 'page_namespace', $this->params
['namespace'] );
531 $show = $this->params
['show'];
532 if ( $this->params
['toponly'] ) { // deprecated/old param
535 if ( !is_null( $show ) ) {
536 $show = array_flip( $show );
538 if ( ( isset( $show['minor'] ) && isset( $show['!minor'] ) )
539 ||
( isset( $show['patrolled'] ) && isset( $show['!patrolled'] ) )
540 ||
( isset( $show['autopatrolled'] ) && isset( $show['!autopatrolled'] ) )
541 ||
( isset( $show['autopatrolled'] ) && isset( $show['!patrolled'] ) )
542 ||
( isset( $show['top'] ) && isset( $show['!top'] ) )
543 ||
( isset( $show['new'] ) && isset( $show['!new'] ) )
545 $this->dieWithError( 'apierror-show' );
548 $this->addWhereIf( 'rev_minor_edit = 0', isset( $show['!minor'] ) );
549 $this->addWhereIf( 'rev_minor_edit != 0', isset( $show['minor'] ) );
551 'rc_patrolled = ' . RecentChange
::PRC_UNPATROLLED
,
552 isset( $show['!patrolled'] )
555 'rc_patrolled != ' . RecentChange
::PRC_UNPATROLLED
,
556 isset( $show['patrolled'] )
559 'rc_patrolled != ' . RecentChange
::PRC_AUTOPATROLLED
,
560 isset( $show['!autopatrolled'] )
563 'rc_patrolled = ' . RecentChange
::PRC_AUTOPATROLLED
,
564 isset( $show['autopatrolled'] )
566 $this->addWhereIf( $idField . ' != page_latest', isset( $show['!top'] ) );
567 $this->addWhereIf( $idField . ' = page_latest', isset( $show['top'] ) );
568 $this->addWhereIf( 'rev_parent_id != 0', isset( $show['!new'] ) );
569 $this->addWhereIf( 'rev_parent_id = 0', isset( $show['new'] ) );
571 $this->addOption( 'LIMIT', $limit +
1 );
573 if ( isset( $show['patrolled'] ) ||
isset( $show['!patrolled'] ) ||
574 isset( $show['autopatrolled'] ) ||
isset( $show['!autopatrolled'] ) ||
$this->fld_patrolled
576 if ( !$user->useRCPatrol() && !$user->useNPPatrol() ) {
577 $this->dieWithError( 'apierror-permissiondenied-patrolflag', 'permissiondenied' );
580 $isFilterset = isset( $show['patrolled'] ) ||
isset( $show['!patrolled'] ) ||
581 isset( $show['autopatrolled'] ) ||
isset( $show['!autopatrolled'] );
582 $this->addTables( 'recentchanges' );
583 $this->addJoinConds( [ 'recentchanges' => [
584 $isFilterset ?
'JOIN' : 'LEFT JOIN',
586 // This is a crazy hack. recentchanges has no index on rc_this_oldid, so instead of adding
587 // one T19237 did a join using rc_user_text and rc_timestamp instead. Now rc_user_text is
588 // probably unavailable, so just do rc_timestamp.
589 'rc_timestamp = ' . $tsField,
590 'rc_this_oldid = ' . $idField,
595 $this->addFieldsIf( 'rc_patrolled', $this->fld_patrolled
);
597 if ( $this->fld_tags
) {
598 $this->addTables( 'tag_summary' );
600 [ 'tag_summary' => [ 'LEFT JOIN', [ $idField . ' = ts_rev_id' ] ] ]
602 $this->addFields( 'ts_tags' );
605 if ( isset( $this->params
['tag'] ) ) {
606 $this->addTables( 'change_tag' );
608 [ 'change_tag' => [ 'INNER JOIN', [ $idField . ' = ct_rev_id' ] ] ]
610 $this->addWhereFld( 'ct_tag', $this->params
['tag'] );
617 * Extract fields from the database row and append them to a result array
619 * @param stdClass $row
622 private function extractRowInfo( $row ) {
626 if ( $row->rev_deleted
& RevisionRecord
::DELETED_TEXT
) {
627 $vals['texthidden'] = true;
631 // Any rows where we can't view the user were filtered out in the query.
632 $vals['userid'] = (int)$row->rev_user
;
633 $vals['user'] = $row->rev_user_text
;
634 if ( $row->rev_deleted
& RevisionRecord
::DELETED_USER
) {
635 $vals['userhidden'] = true;
638 if ( $this->fld_ids
) {
639 $vals['pageid'] = intval( $row->rev_page
);
640 $vals['revid'] = intval( $row->rev_id
);
641 // $vals['textid'] = intval( $row->rev_text_id ); // todo: Should this field be exposed?
643 if ( !is_null( $row->rev_parent_id
) ) {
644 $vals['parentid'] = intval( $row->rev_parent_id
);
648 $title = Title
::makeTitle( $row->page_namespace
, $row->page_title
);
650 if ( $this->fld_title
) {
651 ApiQueryBase
::addTitleInfo( $vals, $title );
654 if ( $this->fld_timestamp
) {
655 $vals['timestamp'] = wfTimestamp( TS_ISO_8601
, $row->rev_timestamp
);
658 if ( $this->fld_flags
) {
659 $vals['new'] = $row->rev_parent_id
== 0 && !is_null( $row->rev_parent_id
);
660 $vals['minor'] = (bool)$row->rev_minor_edit
;
661 $vals['top'] = $row->page_latest
== $row->rev_id
;
664 if ( $this->fld_comment ||
$this->fld_parsedcomment
) {
665 if ( $row->rev_deleted
& RevisionRecord
::DELETED_COMMENT
) {
666 $vals['commenthidden'] = true;
670 $userCanView = RevisionRecord
::userCanBitfield(
672 RevisionRecord
::DELETED_COMMENT
, $this->getUser()
675 if ( $userCanView ) {
676 $comment = $this->commentStore
->getComment( 'rev_comment', $row )->text
;
677 if ( $this->fld_comment
) {
678 $vals['comment'] = $comment;
681 if ( $this->fld_parsedcomment
) {
682 $vals['parsedcomment'] = Linker
::formatComment( $comment, $title );
687 if ( $this->fld_patrolled
) {
688 $vals['patrolled'] = $row->rc_patrolled
!= RecentChange
::PRC_UNPATROLLED
;
689 $vals['autopatrolled'] = $row->rc_patrolled
== RecentChange
::PRC_AUTOPATROLLED
;
692 if ( $this->fld_size
&& !is_null( $row->rev_len
) ) {
693 $vals['size'] = intval( $row->rev_len
);
696 if ( $this->fld_sizediff
697 && !is_null( $row->rev_len
)
698 && !is_null( $row->rev_parent_id
)
700 $parentLen = $this->parentLens
[$row->rev_parent_id
] ??
0;
701 $vals['sizediff'] = intval( $row->rev_len
- $parentLen );
704 if ( $this->fld_tags
) {
705 if ( $row->ts_tags
) {
706 $tags = explode( ',', $row->ts_tags
);
707 ApiResult
::setIndexedTagName( $tags, 'tag' );
708 $vals['tags'] = $tags;
714 if ( $anyHidden && ( $row->rev_deleted
& RevisionRecord
::DELETED_RESTRICTED
) ) {
715 $vals['suppressed'] = true;
721 private function continueStr( $row ) {
722 if ( $this->multiUserMode
) {
723 switch ( $this->orderBy
) {
725 return "id|$row->rev_user|$row->rev_timestamp|$row->rev_id";
727 return "name|$row->rev_user_text|$row->rev_timestamp|$row->rev_id";
729 return "actor|$row->rev_actor|$row->rev_timestamp|$row->rev_id";
732 return "$row->rev_timestamp|$row->rev_id";
736 public function getCacheMode( $params ) {
737 // This module provides access to deleted revisions and patrol flags if
738 // the requester is logged in
739 return 'anon-public-user-private';
742 public function getAllowedParams() {
745 ApiBase
::PARAM_DFLT
=> 10,
746 ApiBase
::PARAM_TYPE
=> 'limit',
747 ApiBase
::PARAM_MIN
=> 1,
748 ApiBase
::PARAM_MAX
=> ApiBase
::LIMIT_BIG1
,
749 ApiBase
::PARAM_MAX2
=> ApiBase
::LIMIT_BIG2
752 ApiBase
::PARAM_TYPE
=> 'timestamp'
755 ApiBase
::PARAM_TYPE
=> 'timestamp'
758 ApiBase
::PARAM_HELP_MSG
=> 'api-help-param-continue',
761 ApiBase
::PARAM_TYPE
=> 'user',
762 ApiBase
::PARAM_ISMULTI
=> true
765 ApiBase
::PARAM_TYPE
=> 'integer',
766 ApiBase
::PARAM_ISMULTI
=> true
768 'userprefix' => null,
770 ApiBase
::PARAM_DFLT
=> 'older',
771 ApiBase
::PARAM_TYPE
=> [
775 ApiBase
::PARAM_HELP_MSG
=> 'api-help-param-direction',
778 ApiBase
::PARAM_ISMULTI
=> true,
779 ApiBase
::PARAM_TYPE
=> 'namespace'
782 ApiBase
::PARAM_ISMULTI
=> true,
783 ApiBase
::PARAM_DFLT
=> 'ids|title|timestamp|comment|size|flags',
784 ApiBase
::PARAM_TYPE
=> [
796 ApiBase
::PARAM_HELP_MSG_PER_VALUE
=> [],
799 ApiBase
::PARAM_ISMULTI
=> true,
800 ApiBase
::PARAM_TYPE
=> [
812 ApiBase
::PARAM_HELP_MSG
=> [
813 'apihelp-query+usercontribs-param-show',
814 $this->getConfig()->get( 'RCMaxAge' )
819 ApiBase
::PARAM_DFLT
=> false,
820 ApiBase
::PARAM_DEPRECATED
=> true,
825 protected function getExamplesMessages() {
827 'action=query&list=usercontribs&ucuser=Example'
828 => 'apihelp-query+usercontribs-example-user',
829 'action=query&list=usercontribs&ucuserprefix=192.0.2.'
830 => 'apihelp-query+usercontribs-example-ipprefix',
834 public function getHelpUrls() {
835 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Usercontribs';
841 * @deprecated since 1.32
843 class_alias( ApiQueryUserContribs
::class, 'ApiQueryContributions' );