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\NameTableAccessException
;
25 use MediaWiki\Storage\RevisionRecord
;
28 * This query action adds a list of a specified user's contributions to the output.
32 class ApiQueryUserContribs
extends ApiQueryBase
{
34 public function __construct( ApiQuery
$query, $moduleName ) {
35 parent
::__construct( $query, $moduleName, 'uc' );
38 private $params, $multiUserMode, $orderBy, $parentLens, $commentStore;
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;
44 public function execute() {
45 global $wgActorTableSchemaMigrationStage;
47 // Parse some parameters
48 $this->params
= $this->extractRequestParams();
50 $this->commentStore
= CommentStore
::getStore();
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'] );
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
69 // TODO: if the query is going only against the revision table, should this be done?
70 $this->selectNamedDB( 'contributions', DB_REPLICA
, 'contributions' );
72 $sort = ( $this->params
['dir'] == 'newer' ?
'' : ' DESC' );
73 $op = ( $this->params
['dir'] == 'older' ?
'<' : '>' );
75 // Create an Iterator that produces the UserIdentity objects we need, depending
76 // on which of the 'userprefix', 'userids', or 'user' params was
78 $this->requireOnlyOneParameter( $this->params
, 'userprefix', 'userids', 'user' );
79 if ( isset( $this->params
['userprefix'] ) ) {
80 $this->multiUserMode
= true;
81 $this->orderBy
= 'name';
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;
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];
97 $like = $dbSecondary->buildLike( $this->params
['userprefix'], $dbSecondary->anyString() );
102 $from = $fromName ?
"$op= " . $dbSecondary->addQuotes( $fromName ) : false;
104 // For the new schema, pull from the actor table. For the
105 // old, pull from rev_user. For migration a FULL [OUTER]
106 // JOIN would be what we want, except MySQL doesn't support
107 // that so we have to UNION instead.
108 if ( $wgActorTableSchemaMigrationStage === MIGRATION_NEW
) {
109 $res = $dbSecondary->select(
111 [ 'actor_id', 'user_id' => 'COALESCE(actor_user,0)', 'user_name' => 'actor_name' ],
112 array_merge( [ "actor_name$like" ], $from ?
[ "actor_name $from" ] : [] ),
114 [ 'ORDER BY' => [ "user_name $sort" ], 'LIMIT' => $limit ]
116 } elseif ( $wgActorTableSchemaMigrationStage === MIGRATION_OLD
) {
117 $res = $dbSecondary->select(
119 [ 'actor_id' => 'NULL', 'user_id' => 'rev_user', 'user_name' => 'rev_user_text' ],
120 array_merge( [ "rev_user_text$like" ], $from ?
[ "rev_user_text $from" ] : [] ),
122 [ 'DISTINCT', 'ORDER BY' => [ "rev_user_text $sort" ], 'LIMIT' => $limit ]
125 // There are three queries we have to combine to be sure of getting all results:
126 // - actor table (any rows that have been migrated will have empty rev_user_text)
127 // - revision+actor by user id
128 // - revision+actor by name for anons
129 $options = $dbSecondary->unionSupportsOrderAndLimit()
130 ?
[ 'ORDER BY' => [ "user_name $sort" ], 'LIMIT' => $limit ] : [];
132 $subsql[] = $dbSecondary->selectSQLText(
134 [ 'actor_id', 'user_id' => 'COALESCE(actor_user,0)', 'user_name' => 'actor_name' ],
135 array_merge( [ "actor_name$like" ], $from ?
[ "actor_name $from" ] : [] ),
139 $subsql[] = $dbSecondary->selectSQLText(
140 [ 'revision', 'actor' ],
141 [ 'actor_id', 'user_id' => 'rev_user', 'user_name' => 'rev_user_text' ],
143 [ "rev_user_text$like", 'rev_user != 0' ],
144 $from ?
[ "rev_user_text $from" ] : []
147 array_merge( [ 'DISTINCT' ], $options ),
148 [ 'actor' => [ 'LEFT JOIN', 'rev_user = actor_user' ] ]
150 $subsql[] = $dbSecondary->selectSQLText(
151 [ 'revision', 'actor' ],
152 [ 'actor_id', 'user_id' => 'rev_user', 'user_name' => 'rev_user_text' ],
154 [ "rev_user_text$like", 'rev_user = 0' ],
155 $from ?
[ "rev_user_text $from" ] : []
158 array_merge( [ 'DISTINCT' ], $options ),
159 [ 'actor' => [ 'LEFT JOIN', 'rev_user_text = actor_name' ] ]
161 $sql = $dbSecondary->unionQueries( $subsql, false ) . " ORDER BY user_name $sort";
162 $sql = $dbSecondary->limitResult( $sql, $limit );
163 $res = $dbSecondary->query( $sql, $fname );
168 foreach ( $res as $row ) {
169 if ( ++
$count >= $limit ) {
170 $fromName = $row->user_name
;
173 yield User
::newFromRow( $row );
175 } while ( $fromName !== false );
177 // Do the actual sorting client-side, because otherwise
178 // prepareQuery might try to sort by actor and confuse everything.
180 } elseif ( isset( $this->params
['userids'] ) ) {
181 if ( !count( $this->params
['userids'] ) ) {
182 $encParamName = $this->encodeParamName( 'userids' );
183 $this->dieWithError( [ 'apierror-paramempty', $encParamName ], "paramempty_$encParamName" );
187 foreach ( $this->params
['userids'] as $uid ) {
189 $this->dieWithError( [ 'apierror-invaliduserid', $uid ], 'invaliduserid' );
194 $this->orderBy
= 'id';
195 $this->multiUserMode
= count( $ids ) > 1;
197 $from = $fromId = false;
198 if ( $this->multiUserMode
&& !is_null( $this->params
['continue'] ) ) {
199 $continue = explode( '|', $this->params
['continue'] );
200 $this->dieContinueUsageIf( count( $continue ) != 4 );
201 $this->dieContinueUsageIf( $continue[0] !== 'id' && $continue[0] !== 'actor' );
202 $fromId = (int)$continue[1];
203 $this->dieContinueUsageIf( $continue[1] !== (string)$fromId );
204 $from = "$op= $fromId";
207 // For the new schema, just select from the actor table. For the
208 // old and transitional schemas, select from user and left join
209 // actor if it exists.
210 if ( $wgActorTableSchemaMigrationStage === MIGRATION_NEW
) {
211 $res = $dbSecondary->select(
213 [ 'actor_id', 'user_id' => 'actor_user', 'user_name' => 'actor_name' ],
214 array_merge( [ 'actor_user' => $ids ], $from ?
[ "actor_id $from" ] : [] ),
216 [ 'ORDER BY' => "user_id $sort" ]
218 } elseif ( $wgActorTableSchemaMigrationStage === MIGRATION_OLD
) {
219 $res = $dbSecondary->select(
221 [ 'actor_id' => 'NULL', 'user_id' => 'user_id', 'user_name' => 'user_name' ],
222 array_merge( [ 'user_id' => $ids ], $from ?
[ "user_id $from" ] : [] ),
224 [ 'ORDER BY' => "user_id $sort" ]
227 $res = $dbSecondary->select(
229 [ 'actor_id', 'user_id', 'user_name' ],
230 array_merge( [ 'user_id' => $ids ], $from ?
[ "user_id $from" ] : [] ),
232 [ 'ORDER BY' => "user_id $sort" ],
233 [ 'actor' => [ 'LEFT JOIN', 'actor_user = user_id' ] ]
236 $userIter = UserArray
::newFromResult( $res );
237 $batchSize = count( $ids );
240 if ( !count( $this->params
['user'] ) ) {
241 $encParamName = $this->encodeParamName( 'user' );
243 [ 'apierror-paramempty', $encParamName ], "paramempty_$encParamName"
246 foreach ( $this->params
['user'] as $u ) {
248 $encParamName = $this->encodeParamName( 'user' );
250 [ 'apierror-paramempty', $encParamName ], "paramempty_$encParamName"
254 if ( User
::isIP( $u ) || ExternalUserNames
::isExternal( $u ) ) {
257 $name = User
::getCanonicalName( $u, 'valid' );
258 if ( $name === false ) {
259 $encParamName = $this->encodeParamName( 'user' );
261 [ 'apierror-baduser', $encParamName, wfEscapeWikiText( $u ) ], "baduser_$encParamName"
264 $names[$name] = null;
268 $this->orderBy
= 'name';
269 $this->multiUserMode
= count( $names ) > 1;
271 $from = $fromName = false;
272 if ( $this->multiUserMode
&& !is_null( $this->params
['continue'] ) ) {
273 $continue = explode( '|', $this->params
['continue'] );
274 $this->dieContinueUsageIf( count( $continue ) != 4 );
275 $this->dieContinueUsageIf( $continue[0] !== 'name' && $continue[0] !== 'actor' );
276 $fromName = $continue[1];
277 $from = "$op= " . $dbSecondary->addQuotes( $fromName );
280 // For the new schema, just select from the actor table. For the
281 // old and transitional schemas, select from user and left join
282 // actor if it exists then merge in any unknown users (IPs and imports).
283 if ( $wgActorTableSchemaMigrationStage === MIGRATION_NEW
) {
284 $res = $dbSecondary->select(
286 [ 'actor_id', 'user_id' => 'actor_user', 'user_name' => 'actor_name' ],
287 array_merge( [ 'actor_name' => array_keys( $names ) ], $from ?
[ "actor_id $from" ] : [] ),
289 [ 'ORDER BY' => "actor_name $sort" ]
291 $userIter = UserArray
::newFromResult( $res );
293 if ( $wgActorTableSchemaMigrationStage === MIGRATION_OLD
) {
294 $res = $dbSecondary->select(
296 [ 'actor_id' => 'NULL', 'user_id', 'user_name' ],
297 array_merge( [ 'user_name' => array_keys( $names ) ], $from ?
[ "user_name $from" ] : [] ),
301 $res = $dbSecondary->select(
303 [ 'actor_id', 'user_id', 'user_name' ],
304 array_merge( [ 'user_name' => array_keys( $names ) ], $from ?
[ "user_name $from" ] : [] ),
307 [ 'actor' => [ 'LEFT JOIN', 'actor_user = user_id' ] ]
310 foreach ( $res as $row ) {
311 $names[$row->user_name
] = $row;
313 if ( $this->params
['dir'] == 'newer' ) {
314 ksort( $names, SORT_STRING
);
316 krsort( $names, SORT_STRING
);
318 $neg = $op === '>' ?
-1 : 1;
319 $userIter = call_user_func( function () use ( $names, $fromName, $neg ) {
320 foreach ( $names as $name => $row ) {
321 if ( $fromName === false ||
$neg * strcmp( $name, $fromName ) <= 0 ) {
322 $user = $row ? User
::newFromRow( $row ) : User
::newFromName( $name, false );
328 $batchSize = count( $names );
331 // During migration, force ordering on the client side because we're
332 // having to combine multiple queries that would otherwise have
333 // different sort orders.
334 if ( $wgActorTableSchemaMigrationStage === MIGRATION_WRITE_BOTH ||
335 $wgActorTableSchemaMigrationStage === MIGRATION_WRITE_NEW
340 // With the new schema, the DB query will order by actor so update $this->orderBy to match.
341 if ( $batchSize > 1 && $wgActorTableSchemaMigrationStage === MIGRATION_NEW
) {
342 $this->orderBy
= 'actor';
346 $limit = $this->params
['limit'];
348 while ( $userIter->valid() ) {
350 while ( count( $users ) < $batchSize && $userIter->valid() ) {
351 $users[] = $userIter->current();
355 // Ugh. We have to run the query three times, once for each
356 // possible 'orcond' from ActorMigration, and then merge them all
357 // together in the proper order. And preserving the correct
358 // $hookData for each one.
359 // @todo When ActorMigration is removed, this can go back to a
360 // single prepare and select.
362 foreach ( [ 'actor', 'userid', 'username' ] as $which ) {
363 if ( $this->prepareQuery( $users, $limit - $count, $which ) ) {
365 $res = $this->select( __METHOD__
, [], $hookData );
366 foreach ( $res as $row ) {
367 $merged[] = [ $row, &$hookData ];
371 $neg = $this->params
['dir'] == 'newer' ?
1 : -1;
372 usort( $merged, function ( $a, $b ) use ( $neg, $batchSize ) {
373 if ( $batchSize === 1 ) { // One user, can't be different
375 } elseif ( $this->orderBy
=== 'id' ) {
376 $ret = $a[0]->rev_user
<=> $b[0]->rev_user
;
377 } elseif ( $this->orderBy
=== 'name' ) {
378 $ret = strcmp( $a[0]->rev_user_text
, $b[0]->rev_user_text
);
380 $ret = $a[0]->rev_actor
<=> $b[0]->rev_actor
;
385 wfTimestamp( TS_MW
, $a[0]->rev_timestamp
),
386 wfTimestamp( TS_MW
, $b[0]->rev_timestamp
)
391 $ret = $a[0]->rev_id
<=> $b[0]->rev_id
;
396 $merged = array_slice( $merged, 0, $limit - $count +
1 );
399 if ( $this->fld_sizediff
) {
401 foreach ( $merged as $data ) {
402 if ( $data[0]->rev_parent_id
) {
403 $revIds[] = $data[0]->rev_parent_id
;
406 $this->parentLens
= MediaWikiServices
::getInstance()->getRevisionStore()
407 ->listRevisionSizes( $dbSecondary, $revIds );
410 foreach ( $merged as $data ) {
412 $hookData = &$data[1];
413 if ( ++
$count > $limit ) {
414 // We've reached the one extra which shows that there are
415 // additional pages to be had. Stop here...
416 $this->setContinueEnumParameter( 'continue', $this->continueStr( $row ) );
420 $vals = $this->extractRowInfo( $row );
421 $fit = $this->processRow( $row, $vals, $hookData ) &&
422 $this->getResult()->addValue( [ 'query', $this->getModuleName() ], null, $vals );
424 $this->setContinueEnumParameter( 'continue', $this->continueStr( $row ) );
430 $this->getResult()->addIndexedTagName( [ 'query', $this->getModuleName() ], 'item' );
434 * Prepares the query and returns the limit of rows requested
435 * @param User[] $users
437 * @param string $which 'actor', 'userid', or 'username'
440 private function prepareQuery( array $users, $limit, $which ) {
441 global $wgActorTableSchemaMigrationStage, $wgChangeTagsSchemaMigrationStage;
443 $this->resetQueryParams();
444 $db = $this->getDB();
446 $revQuery = MediaWikiServices
::getInstance()->getRevisionStore()->getQueryInfo( [ 'page' ] );
447 $this->addTables( $revQuery['tables'] );
448 $this->addJoinConds( $revQuery['joins'] );
449 $this->addFields( $revQuery['fields'] );
451 $revWhere = ActorMigration
::newMigration()->getWhere( $db, 'rev_user', $users );
452 if ( !isset( $revWhere['orconds'][$which] ) ) {
455 $this->addWhere( $revWhere['orconds'][$which] );
457 if ( $wgActorTableSchemaMigrationStage === MIGRATION_NEW
) {
458 $orderUserField = 'rev_actor';
459 $userField = $this->orderBy
=== 'actor' ?
'revactor_actor' : 'actor_name';
461 $orderUserField = $this->orderBy
=== 'id' ?
'rev_user' : 'rev_user_text';
462 $userField = $revQuery['fields'][$orderUserField];
464 if ( $which === 'actor' ) {
465 $tsField = 'revactor_timestamp';
466 $idField = 'revactor_rev';
468 $tsField = 'rev_timestamp';
472 // Handle continue parameter
473 if ( !is_null( $this->params
['continue'] ) ) {
474 $continue = explode( '|', $this->params
['continue'] );
475 if ( $this->multiUserMode
) {
476 $this->dieContinueUsageIf( count( $continue ) != 4 );
477 $modeFlag = array_shift( $continue );
478 $this->dieContinueUsageIf( $modeFlag !== $this->orderBy
);
479 $encUser = $db->addQuotes( array_shift( $continue ) );
481 $this->dieContinueUsageIf( count( $continue ) != 2 );
483 $encTS = $db->addQuotes( $db->timestamp( $continue[0] ) );
484 $encId = (int)$continue[1];
485 $this->dieContinueUsageIf( $encId != $continue[1] );
486 $op = ( $this->params
['dir'] == 'older' ?
'<' : '>' );
487 if ( $this->multiUserMode
) {
489 "$userField $op $encUser OR " .
490 "($userField = $encUser AND " .
491 "($tsField $op $encTS OR " .
492 "($tsField = $encTS AND " .
493 "$idField $op= $encId)))"
497 "$tsField $op $encTS OR " .
498 "($tsField = $encTS AND " .
499 "$idField $op= $encId)"
504 // Don't include any revisions where we're not supposed to be able to
506 $user = $this->getUser();
507 if ( !$user->isAllowed( 'deletedhistory' ) ) {
508 $bitmask = RevisionRecord
::DELETED_USER
;
509 } elseif ( !$user->isAllowedAny( 'suppressrevision', 'viewsuppressed' ) ) {
510 $bitmask = RevisionRecord
::DELETED_USER | RevisionRecord
::DELETED_RESTRICTED
;
515 $this->addWhere( $db->bitAnd( 'rev_deleted', $bitmask ) . " != $bitmask" );
518 // Add the user field to ORDER BY if there are multiple users
519 if ( count( $users ) > 1 ) {
520 $this->addWhereRange( $orderUserField, $this->params
['dir'], null, null );
524 $this->addTimestampWhereRange( $tsField,
525 $this->params
['dir'], $this->params
['start'], $this->params
['end'] );
527 // Then rev_id for a total ordering
528 $this->addWhereRange( $idField, $this->params
['dir'], null, null );
530 $this->addWhereFld( 'page_namespace', $this->params
['namespace'] );
532 $show = $this->params
['show'];
533 if ( $this->params
['toponly'] ) { // deprecated/old param
536 if ( !is_null( $show ) ) {
537 $show = array_flip( $show );
539 if ( ( isset( $show['minor'] ) && isset( $show['!minor'] ) )
540 ||
( isset( $show['patrolled'] ) && isset( $show['!patrolled'] ) )
541 ||
( isset( $show['autopatrolled'] ) && isset( $show['!autopatrolled'] ) )
542 ||
( isset( $show['autopatrolled'] ) && isset( $show['!patrolled'] ) )
543 ||
( isset( $show['top'] ) && isset( $show['!top'] ) )
544 ||
( isset( $show['new'] ) && isset( $show['!new'] ) )
546 $this->dieWithError( 'apierror-show' );
549 $this->addWhereIf( 'rev_minor_edit = 0', isset( $show['!minor'] ) );
550 $this->addWhereIf( 'rev_minor_edit != 0', isset( $show['minor'] ) );
552 'rc_patrolled = ' . RecentChange
::PRC_UNPATROLLED
,
553 isset( $show['!patrolled'] )
556 'rc_patrolled != ' . RecentChange
::PRC_UNPATROLLED
,
557 isset( $show['patrolled'] )
560 'rc_patrolled != ' . RecentChange
::PRC_AUTOPATROLLED
,
561 isset( $show['!autopatrolled'] )
564 'rc_patrolled = ' . RecentChange
::PRC_AUTOPATROLLED
,
565 isset( $show['autopatrolled'] )
567 $this->addWhereIf( $idField . ' != page_latest', isset( $show['!top'] ) );
568 $this->addWhereIf( $idField . ' = page_latest', isset( $show['top'] ) );
569 $this->addWhereIf( 'rev_parent_id != 0', isset( $show['!new'] ) );
570 $this->addWhereIf( 'rev_parent_id = 0', isset( $show['new'] ) );
572 $this->addOption( 'LIMIT', $limit +
1 );
574 if ( isset( $show['patrolled'] ) ||
isset( $show['!patrolled'] ) ||
575 isset( $show['autopatrolled'] ) ||
isset( $show['!autopatrolled'] ) ||
$this->fld_patrolled
577 if ( !$user->useRCPatrol() && !$user->useNPPatrol() ) {
578 $this->dieWithError( 'apierror-permissiondenied-patrolflag', 'permissiondenied' );
581 $isFilterset = isset( $show['patrolled'] ) ||
isset( $show['!patrolled'] ) ||
582 isset( $show['autopatrolled'] ) ||
isset( $show['!autopatrolled'] );
583 $this->addTables( 'recentchanges' );
584 $this->addJoinConds( [ 'recentchanges' => [
585 $isFilterset ?
'JOIN' : 'LEFT JOIN',
587 // This is a crazy hack. recentchanges has no index on rc_this_oldid, so instead of adding
588 // one T19237 did a join using rc_user_text and rc_timestamp instead. Now rc_user_text is
589 // probably unavailable, so just do rc_timestamp.
590 'rc_timestamp = ' . $tsField,
591 'rc_this_oldid = ' . $idField,
596 $this->addFieldsIf( 'rc_patrolled', $this->fld_patrolled
);
598 if ( $this->fld_tags
) {
599 $this->addTables( 'tag_summary' );
601 [ 'tag_summary' => [ 'LEFT JOIN', [ $idField . ' = ts_rev_id' ] ] ]
603 $this->addFields( 'ts_tags' );
606 if ( isset( $this->params
['tag'] ) ) {
607 $this->addTables( 'change_tag' );
609 [ 'change_tag' => [ 'INNER JOIN', [ $idField . ' = ct_rev_id' ] ] ]
611 if ( $wgChangeTagsSchemaMigrationStage > MIGRATION_WRITE_BOTH
) {
612 $changeTagDefStore = MediaWikiServices
::getInstance()->getChangeTagDefStore();
614 $this->addWhereFld( 'ct_tag_id', $changeTagDefStore->getId( $this->params
['tag'] ) );
615 } catch ( NameTableAccessException
$exception ) {
617 $this->addWhere( '1=0' );
620 $this->addWhereFld( 'ct_tag', $this->params
['tag'] );
628 * Extract fields from the database row and append them to a result array
630 * @param stdClass $row
633 private function extractRowInfo( $row ) {
637 if ( $row->rev_deleted
& RevisionRecord
::DELETED_TEXT
) {
638 $vals['texthidden'] = true;
642 // Any rows where we can't view the user were filtered out in the query.
643 $vals['userid'] = (int)$row->rev_user
;
644 $vals['user'] = $row->rev_user_text
;
645 if ( $row->rev_deleted
& RevisionRecord
::DELETED_USER
) {
646 $vals['userhidden'] = true;
649 if ( $this->fld_ids
) {
650 $vals['pageid'] = intval( $row->rev_page
);
651 $vals['revid'] = intval( $row->rev_id
);
652 // $vals['textid'] = intval( $row->rev_text_id ); // todo: Should this field be exposed?
654 if ( !is_null( $row->rev_parent_id
) ) {
655 $vals['parentid'] = intval( $row->rev_parent_id
);
659 $title = Title
::makeTitle( $row->page_namespace
, $row->page_title
);
661 if ( $this->fld_title
) {
662 ApiQueryBase
::addTitleInfo( $vals, $title );
665 if ( $this->fld_timestamp
) {
666 $vals['timestamp'] = wfTimestamp( TS_ISO_8601
, $row->rev_timestamp
);
669 if ( $this->fld_flags
) {
670 $vals['new'] = $row->rev_parent_id
== 0 && !is_null( $row->rev_parent_id
);
671 $vals['minor'] = (bool)$row->rev_minor_edit
;
672 $vals['top'] = $row->page_latest
== $row->rev_id
;
675 if ( $this->fld_comment ||
$this->fld_parsedcomment
) {
676 if ( $row->rev_deleted
& RevisionRecord
::DELETED_COMMENT
) {
677 $vals['commenthidden'] = true;
681 $userCanView = RevisionRecord
::userCanBitfield(
683 RevisionRecord
::DELETED_COMMENT
, $this->getUser()
686 if ( $userCanView ) {
687 $comment = $this->commentStore
->getComment( 'rev_comment', $row )->text
;
688 if ( $this->fld_comment
) {
689 $vals['comment'] = $comment;
692 if ( $this->fld_parsedcomment
) {
693 $vals['parsedcomment'] = Linker
::formatComment( $comment, $title );
698 if ( $this->fld_patrolled
) {
699 $vals['patrolled'] = $row->rc_patrolled
!= RecentChange
::PRC_UNPATROLLED
;
700 $vals['autopatrolled'] = $row->rc_patrolled
== RecentChange
::PRC_AUTOPATROLLED
;
703 if ( $this->fld_size
&& !is_null( $row->rev_len
) ) {
704 $vals['size'] = intval( $row->rev_len
);
707 if ( $this->fld_sizediff
708 && !is_null( $row->rev_len
)
709 && !is_null( $row->rev_parent_id
)
711 $parentLen = $this->parentLens
[$row->rev_parent_id
] ??
0;
712 $vals['sizediff'] = intval( $row->rev_len
- $parentLen );
715 if ( $this->fld_tags
) {
716 if ( $row->ts_tags
) {
717 $tags = explode( ',', $row->ts_tags
);
718 ApiResult
::setIndexedTagName( $tags, 'tag' );
719 $vals['tags'] = $tags;
725 if ( $anyHidden && ( $row->rev_deleted
& RevisionRecord
::DELETED_RESTRICTED
) ) {
726 $vals['suppressed'] = true;
732 private function continueStr( $row ) {
733 if ( $this->multiUserMode
) {
734 switch ( $this->orderBy
) {
736 return "id|$row->rev_user|$row->rev_timestamp|$row->rev_id";
738 return "name|$row->rev_user_text|$row->rev_timestamp|$row->rev_id";
740 return "actor|$row->rev_actor|$row->rev_timestamp|$row->rev_id";
743 return "$row->rev_timestamp|$row->rev_id";
747 public function getCacheMode( $params ) {
748 // This module provides access to deleted revisions and patrol flags if
749 // the requester is logged in
750 return 'anon-public-user-private';
753 public function getAllowedParams() {
756 ApiBase
::PARAM_DFLT
=> 10,
757 ApiBase
::PARAM_TYPE
=> 'limit',
758 ApiBase
::PARAM_MIN
=> 1,
759 ApiBase
::PARAM_MAX
=> ApiBase
::LIMIT_BIG1
,
760 ApiBase
::PARAM_MAX2
=> ApiBase
::LIMIT_BIG2
763 ApiBase
::PARAM_TYPE
=> 'timestamp'
766 ApiBase
::PARAM_TYPE
=> 'timestamp'
769 ApiBase
::PARAM_HELP_MSG
=> 'api-help-param-continue',
772 ApiBase
::PARAM_TYPE
=> 'user',
773 ApiBase
::PARAM_ISMULTI
=> true
776 ApiBase
::PARAM_TYPE
=> 'integer',
777 ApiBase
::PARAM_ISMULTI
=> true
779 'userprefix' => null,
781 ApiBase
::PARAM_DFLT
=> 'older',
782 ApiBase
::PARAM_TYPE
=> [
786 ApiBase
::PARAM_HELP_MSG
=> 'api-help-param-direction',
789 ApiBase
::PARAM_ISMULTI
=> true,
790 ApiBase
::PARAM_TYPE
=> 'namespace'
793 ApiBase
::PARAM_ISMULTI
=> true,
794 ApiBase
::PARAM_DFLT
=> 'ids|title|timestamp|comment|size|flags',
795 ApiBase
::PARAM_TYPE
=> [
807 ApiBase
::PARAM_HELP_MSG_PER_VALUE
=> [],
810 ApiBase
::PARAM_ISMULTI
=> true,
811 ApiBase
::PARAM_TYPE
=> [
823 ApiBase
::PARAM_HELP_MSG
=> [
824 'apihelp-query+usercontribs-param-show',
825 $this->getConfig()->get( 'RCMaxAge' )
830 ApiBase
::PARAM_DFLT
=> false,
831 ApiBase
::PARAM_DEPRECATED
=> true,
836 protected function getExamplesMessages() {
838 'action=query&list=usercontribs&ucuser=Example'
839 => 'apihelp-query+usercontribs-example-user',
840 'action=query&list=usercontribs&ucuserprefix=192.0.2.'
841 => 'apihelp-query+usercontribs-example-ipprefix',
845 public function getHelpUrls() {
846 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Usercontribs';
852 * @deprecated since 1.32
854 class_alias( ApiQueryUserContribs
::class, 'ApiQueryContributions' );