f1c4f9407ae0f04a35382d1d73e72f537ec46177
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
24 * This query action adds a list of a specified user's contributions to the output.
28 class ApiQueryUserContribs
extends ApiQueryBase
{
30 public function __construct( ApiQuery
$query, $moduleName ) {
31 parent
::__construct( $query, $moduleName, 'uc' );
34 private $params, $multiUserMode, $orderBy, $parentLens, $commentStore;
36 private $fld_ids = false, $fld_title = false, $fld_timestamp = false,
37 $fld_comment = false, $fld_parsedcomment = false, $fld_flags = false,
38 $fld_patrolled = false, $fld_tags = false, $fld_size = false, $fld_sizediff = false;
40 public function execute() {
41 global $wgActorTableSchemaMigrationStage;
43 // Parse some parameters
44 $this->params
= $this->extractRequestParams();
46 $this->commentStore
= CommentStore
::getStore();
48 $prop = array_flip( $this->params
['prop'] );
49 $this->fld_ids
= isset( $prop['ids'] );
50 $this->fld_title
= isset( $prop['title'] );
51 $this->fld_comment
= isset( $prop['comment'] );
52 $this->fld_parsedcomment
= isset( $prop['parsedcomment'] );
53 $this->fld_size
= isset( $prop['size'] );
54 $this->fld_sizediff
= isset( $prop['sizediff'] );
55 $this->fld_flags
= isset( $prop['flags'] );
56 $this->fld_timestamp
= isset( $prop['timestamp'] );
57 $this->fld_patrolled
= isset( $prop['patrolled'] );
58 $this->fld_tags
= isset( $prop['tags'] );
60 // Most of this code will use the 'contributions' group DB, which can map to replica DBs
61 // with extra user based indexes or partioning by user. The additional metadata
62 // queries should use a regular replica DB since the lookup pattern is not all by user.
63 $dbSecondary = $this->getDB(); // any random replica DB
65 // TODO: if the query is going only against the revision table, should this be done?
66 $this->selectNamedDB( 'contributions', DB_REPLICA
, 'contributions' );
68 $sort = ( $this->params
['dir'] == 'newer' ?
'' : ' DESC' );
69 $op = ( $this->params
['dir'] == 'older' ?
'<' : '>' );
71 // Create an Iterator that produces the UserIdentity objects we need, depending
72 // on which of the 'userprefix', 'userids', or 'user' params was
74 $this->requireOnlyOneParameter( $this->params
, 'userprefix', 'userids', 'user' );
75 if ( isset( $this->params
['userprefix'] ) ) {
76 $this->multiUserMode
= true;
77 $this->orderBy
= 'name';
80 // Because 'userprefix' might produce a huge number of users (e.g.
81 // a wiki with users "Test00000001" to "Test99999999"), use a
82 // generator with batched lookup and continuation.
83 $userIter = call_user_func( function () use ( $dbSecondary, $sort, $op, $fname ) {
84 global $wgActorTableSchemaMigrationStage;
87 if ( !is_null( $this->params
['continue'] ) ) {
88 $continue = explode( '|', $this->params
['continue'] );
89 $this->dieContinueUsageIf( count( $continue ) != 4 );
90 $this->dieContinueUsageIf( $continue[0] !== 'name' );
91 $fromName = $continue[1];
93 $like = $dbSecondary->buildLike( $this->params
['userprefix'], $dbSecondary->anyString() );
98 $from = $fromName ?
"$op= " . $dbSecondary->addQuotes( $fromName ) : false;
100 // For the new schema, pull from the actor table. For the
101 // old, pull from rev_user. For migration a FULL [OUTER]
102 // JOIN would be what we want, except MySQL doesn't support
103 // that so we have to UNION instead.
104 if ( $wgActorTableSchemaMigrationStage === MIGRATION_NEW
) {
105 $res = $dbSecondary->select(
107 [ 'actor_id', 'user_id' => 'COALESCE(actor_user,0)', 'user_name' => 'actor_name' ],
108 array_merge( [ "actor_name$like" ], $from ?
[ "actor_name $from" ] : [] ),
110 [ 'ORDER BY' => [ "user_name $sort" ], 'LIMIT' => $limit ]
112 } elseif ( $wgActorTableSchemaMigrationStage === MIGRATION_OLD
) {
113 $res = $dbSecondary->select(
115 [ 'actor_id' => 'NULL', 'user_id' => 'rev_user', 'user_name' => 'rev_user_text' ],
116 array_merge( [ "rev_user_text$like" ], $from ?
[ "rev_user_text $from" ] : [] ),
118 [ 'DISTINCT', 'ORDER BY' => [ "rev_user_text $sort" ], 'LIMIT' => $limit ]
121 // There are three queries we have to combine to be sure of getting all results:
122 // - actor table (any rows that have been migrated will have empty rev_user_text)
123 // - revision+actor by user id
124 // - revision+actor by name for anons
125 $options = $dbSecondary->unionSupportsOrderAndLimit()
126 ?
[ 'ORDER BY' => [ "user_name $sort" ], 'LIMIT' => $limit ] : [];
128 $subsql[] = $dbSecondary->selectSQLText(
130 [ 'actor_id', 'user_id' => 'COALESCE(actor_user,0)', 'user_name' => 'actor_name' ],
131 array_merge( [ "actor_name$like" ], $from ?
[ "actor_name $from" ] : [] ),
135 $subsql[] = $dbSecondary->selectSQLText(
136 [ 'revision', 'actor' ],
137 [ 'actor_id', 'user_id' => 'rev_user', 'user_name' => 'rev_user_text' ],
139 [ "rev_user_text$like", 'rev_user != 0' ],
140 $from ?
[ "rev_user_text $from" ] : []
143 array_merge( [ 'DISTINCT' ], $options ),
144 [ 'actor' => [ 'LEFT JOIN', 'rev_user = actor_user' ] ]
146 $subsql[] = $dbSecondary->selectSQLText(
147 [ 'revision', 'actor' ],
148 [ 'actor_id', 'user_id' => 'rev_user', 'user_name' => 'rev_user_text' ],
150 [ "rev_user_text$like", 'rev_user = 0' ],
151 $from ?
[ "rev_user_text $from" ] : []
154 array_merge( [ 'DISTINCT' ], $options ),
155 [ 'actor' => [ 'LEFT JOIN', 'rev_user_text = actor_name' ] ]
157 $sql = $dbSecondary->unionQueries( $subsql, false ) . " ORDER BY user_name $sort";
158 $sql = $dbSecondary->limitResult( $sql, $limit );
159 $res = $dbSecondary->query( $sql, $fname );
164 foreach ( $res as $row ) {
165 if ( ++
$count >= $limit ) {
166 $fromName = $row->user_name
;
169 yield User
::newFromRow( $row );
171 } while ( $fromName !== false );
173 // Do the actual sorting client-side, because otherwise
174 // prepareQuery might try to sort by actor and confuse everything.
176 } elseif ( isset( $this->params
['userids'] ) ) {
177 if ( !count( $this->params
['userids'] ) ) {
178 $encParamName = $this->encodeParamName( 'userids' );
179 $this->dieWithError( [ 'apierror-paramempty', $encParamName ], "paramempty_$encParamName" );
183 foreach ( $this->params
['userids'] as $uid ) {
185 $this->dieWithError( [ 'apierror-invaliduserid', $uid ], 'invaliduserid' );
190 $this->orderBy
= 'id';
191 $this->multiUserMode
= count( $ids ) > 1;
193 $from = $fromId = false;
194 if ( $this->multiUserMode
&& !is_null( $this->params
['continue'] ) ) {
195 $continue = explode( '|', $this->params
['continue'] );
196 $this->dieContinueUsageIf( count( $continue ) != 4 );
197 $this->dieContinueUsageIf( $continue[0] !== 'id' && $continue[0] !== 'actor' );
198 $fromId = (int)$continue[1];
199 $this->dieContinueUsageIf( $continue[1] !== (string)$fromId );
200 $from = "$op= $fromId";
203 // For the new schema, just select from the actor table. For the
204 // old and transitional schemas, select from user and left join
205 // actor if it exists.
206 if ( $wgActorTableSchemaMigrationStage === MIGRATION_NEW
) {
207 $res = $dbSecondary->select(
209 [ 'actor_id', 'user_id' => 'actor_user', 'user_name' => 'actor_name' ],
210 array_merge( [ 'actor_user' => $ids ], $from ?
[ "actor_id $from" ] : [] ),
212 [ 'ORDER BY' => "user_id $sort" ]
214 } elseif ( $wgActorTableSchemaMigrationStage === MIGRATION_OLD
) {
215 $res = $dbSecondary->select(
217 [ 'actor_id' => 'NULL', 'user_id' => 'user_id', 'user_name' => 'user_name' ],
218 array_merge( [ 'user_id' => $ids ], $from ?
[ "user_id $from" ] : [] ),
220 [ 'ORDER BY' => "user_id $sort" ]
223 $res = $dbSecondary->select(
225 [ 'actor_id', 'user_id', 'user_name' ],
226 array_merge( [ 'user_id' => $ids ], $from ?
[ "user_id $from" ] : [] ),
228 [ 'ORDER BY' => "user_id $sort" ],
229 [ 'actor' => [ 'LEFT JOIN', 'actor_user = user_id' ] ]
232 $userIter = UserArray
::newFromResult( $res );
233 $batchSize = count( $ids );
236 if ( !count( $this->params
['user'] ) ) {
237 $encParamName = $this->encodeParamName( 'user' );
239 [ 'apierror-paramempty', $encParamName ], "paramempty_$encParamName"
242 foreach ( $this->params
['user'] as $u ) {
244 $encParamName = $this->encodeParamName( 'user' );
246 [ 'apierror-paramempty', $encParamName ], "paramempty_$encParamName"
250 if ( User
::isIP( $u ) || ExternalUserNames
::isExternal( $u ) ) {
253 $name = User
::getCanonicalName( $u, 'valid' );
254 if ( $name === false ) {
255 $encParamName = $this->encodeParamName( 'user' );
257 [ 'apierror-baduser', $encParamName, wfEscapeWikiText( $u ) ], "baduser_$encParamName"
260 $names[$name] = null;
264 $this->orderBy
= 'name';
265 $this->multiUserMode
= count( $names ) > 1;
267 $from = $fromName = false;
268 if ( $this->multiUserMode
&& !is_null( $this->params
['continue'] ) ) {
269 $continue = explode( '|', $this->params
['continue'] );
270 $this->dieContinueUsageIf( count( $continue ) != 4 );
271 $this->dieContinueUsageIf( $continue[0] !== 'name' && $continue[0] !== 'actor' );
272 $fromName = $continue[1];
273 $from = "$op= " . $dbSecondary->addQuotes( $fromName );
276 // For the new schema, just select from the actor table. For the
277 // old and transitional schemas, select from user and left join
278 // actor if it exists then merge in any unknown users (IPs and imports).
279 if ( $wgActorTableSchemaMigrationStage === MIGRATION_NEW
) {
280 $res = $dbSecondary->select(
282 [ 'actor_id', 'user_id' => 'actor_user', 'user_name' => 'actor_name' ],
283 array_merge( [ 'actor_name' => array_keys( $names ) ], $from ?
[ "actor_id $from" ] : [] ),
285 [ 'ORDER BY' => "actor_name $sort" ]
287 $userIter = UserArray
::newFromResult( $res );
289 if ( $wgActorTableSchemaMigrationStage === MIGRATION_OLD
) {
290 $res = $dbSecondary->select(
292 [ 'actor_id' => 'NULL', 'user_id', 'user_name' ],
293 array_merge( [ 'user_name' => array_keys( $names ) ], $from ?
[ "user_name $from" ] : [] ),
297 $res = $dbSecondary->select(
299 [ 'actor_id', 'user_id', 'user_name' ],
300 array_merge( [ 'user_name' => array_keys( $names ) ], $from ?
[ "user_name $from" ] : [] ),
303 [ 'actor' => [ 'LEFT JOIN', 'actor_user = user_id' ] ]
306 foreach ( $res as $row ) {
307 $names[$row->user_name
] = $row;
309 call_user_func_array(
310 $this->params
['dir'] == 'newer' ?
'ksort' : 'krsort', [ &$names, SORT_STRING
]
312 $neg = $op === '>' ?
-1 : 1;
313 $userIter = call_user_func( function () use ( $names, $fromName, $neg ) {
314 foreach ( $names as $name => $row ) {
315 if ( $fromName === false ||
$neg * strcmp( $name, $fromName ) <= 0 ) {
316 $user = $row ? User
::newFromRow( $row ) : User
::newFromName( $name, false );
322 $batchSize = count( $names );
325 // During migration, force ordering on the client side because we're
326 // having to combine multiple queries that would otherwise have
327 // different sort orders.
328 if ( $wgActorTableSchemaMigrationStage === MIGRATION_WRITE_BOTH ||
329 $wgActorTableSchemaMigrationStage === MIGRATION_WRITE_NEW
334 // With the new schema, the DB query will order by actor so update $this->orderBy to match.
335 if ( $batchSize > 1 && $wgActorTableSchemaMigrationStage === MIGRATION_NEW
) {
336 $this->orderBy
= 'actor';
340 $limit = $this->params
['limit'];
342 while ( $userIter->valid() ) {
344 while ( count( $users ) < $batchSize && $userIter->valid() ) {
345 $users[] = $userIter->current();
349 // Ugh. We have to run the query three times, once for each
350 // possible 'orcond' from ActorMigration, and then merge them all
351 // together in the proper order. And preserving the correct
352 // $hookData for each one.
353 // @todo When ActorMigration is removed, this can go back to a
354 // single prepare and select.
356 foreach ( [ 'actor', 'userid', 'username' ] as $which ) {
357 if ( $this->prepareQuery( $users, $limit - $count, $which ) ) {
359 $res = $this->select( __METHOD__
, [], $hookData );
360 foreach ( $res as $row ) {
361 $merged[] = [ $row, &$hookData ];
365 $neg = $this->params
['dir'] == 'newer' ?
1 : -1;
366 usort( $merged, function ( $a, $b ) use ( $neg, $batchSize ) {
367 if ( $batchSize === 1 ) { // One user, can't be different
369 } elseif ( $this->orderBy
=== 'id' ) {
370 $ret = $a[0]->rev_user
<=> $b[0]->rev_user
;
371 } elseif ( $this->orderBy
=== 'name' ) {
372 $ret = strcmp( $a[0]->rev_user_text
, $b[0]->rev_user_text
);
374 $ret = $a[0]->rev_actor
<=> $b[0]->rev_actor
;
379 wfTimestamp( TS_MW
, $a[0]->rev_timestamp
),
380 wfTimestamp( TS_MW
, $b[0]->rev_timestamp
)
385 $ret = $a[0]->rev_id
<=> $b[0]->rev_id
;
390 $merged = array_slice( $merged, 0, $limit - $count +
1 );
393 if ( $this->fld_sizediff
) {
395 foreach ( $merged as $data ) {
396 if ( $data[0]->rev_parent_id
) {
397 $revIds[] = $data[0]->rev_parent_id
;
400 $this->parentLens
= Revision
::getParentLengths( $dbSecondary, $revIds );
403 foreach ( $merged as $data ) {
405 $hookData = &$data[1];
406 if ( ++
$count > $limit ) {
407 // We've reached the one extra which shows that there are
408 // additional pages to be had. Stop here...
409 $this->setContinueEnumParameter( 'continue', $this->continueStr( $row ) );
413 $vals = $this->extractRowInfo( $row );
414 $fit = $this->processRow( $row, $vals, $hookData ) &&
415 $this->getResult()->addValue( [ 'query', $this->getModuleName() ], null, $vals );
417 $this->setContinueEnumParameter( 'continue', $this->continueStr( $row ) );
423 $this->getResult()->addIndexedTagName( [ 'query', $this->getModuleName() ], 'item' );
427 * Prepares the query and returns the limit of rows requested
428 * @param User[] $users
430 * @param string $which 'actor', 'userid', or 'username'
433 private function prepareQuery( array $users, $limit, $which ) {
434 global $wgActorTableSchemaMigrationStage;
436 $this->resetQueryParams();
437 $db = $this->getDB();
439 $revQuery = Revision
::getQueryInfo( [ 'page' ] );
440 $this->addTables( $revQuery['tables'] );
441 $this->addJoinConds( $revQuery['joins'] );
442 $this->addFields( $revQuery['fields'] );
444 $revWhere = ActorMigration
::newMigration()->getWhere( $db, 'rev_user', $users );
445 if ( !isset( $revWhere['orconds'][$which] ) ) {
448 $this->addWhere( $revWhere['orconds'][$which] );
450 if ( $wgActorTableSchemaMigrationStage === MIGRATION_NEW
) {
451 $orderUserField = 'rev_actor';
452 $userField = $this->orderBy
=== 'actor' ?
'revactor_actor' : 'actor_name';
454 $orderUserField = $this->orderBy
=== 'id' ?
'rev_user' : 'rev_user_text';
455 $userField = $revQuery['fields'][$orderUserField];
457 if ( $which === 'actor' ) {
458 $tsField = 'revactor_timestamp';
459 $idField = 'revactor_rev';
461 $tsField = 'rev_timestamp';
465 // Handle continue parameter
466 if ( !is_null( $this->params
['continue'] ) ) {
467 $continue = explode( '|', $this->params
['continue'] );
468 if ( $this->multiUserMode
) {
469 $this->dieContinueUsageIf( count( $continue ) != 4 );
470 $modeFlag = array_shift( $continue );
471 $this->dieContinueUsageIf( $modeFlag !== $this->orderBy
);
472 $encUser = $db->addQuotes( array_shift( $continue ) );
474 $this->dieContinueUsageIf( count( $continue ) != 2 );
476 $encTS = $db->addQuotes( $db->timestamp( $continue[0] ) );
477 $encId = (int)$continue[1];
478 $this->dieContinueUsageIf( $encId != $continue[1] );
479 $op = ( $this->params
['dir'] == 'older' ?
'<' : '>' );
480 if ( $this->multiUserMode
) {
482 "$userField $op $encUser OR " .
483 "($userField = $encUser AND " .
484 "($tsField $op $encTS OR " .
485 "($tsField = $encTS AND " .
486 "$idField $op= $encId)))"
490 "$tsField $op $encTS OR " .
491 "($tsField = $encTS AND " .
492 "$idField $op= $encId)"
497 // Don't include any revisions where we're not supposed to be able to
499 $user = $this->getUser();
500 if ( !$user->isAllowed( 'deletedhistory' ) ) {
501 $bitmask = Revision
::DELETED_USER
;
502 } elseif ( !$user->isAllowedAny( 'suppressrevision', 'viewsuppressed' ) ) {
503 $bitmask = Revision
::DELETED_USER | Revision
::DELETED_RESTRICTED
;
508 $this->addWhere( $db->bitAnd( 'rev_deleted', $bitmask ) . " != $bitmask" );
511 // Add the user field to ORDER BY if there are multiple users
512 if ( count( $users ) > 1 ) {
513 $this->addWhereRange( $orderUserField, $this->params
['dir'], null, null );
517 $this->addTimestampWhereRange( $tsField,
518 $this->params
['dir'], $this->params
['start'], $this->params
['end'] );
520 // Then rev_id for a total ordering
521 $this->addWhereRange( $idField, $this->params
['dir'], null, null );
523 $this->addWhereFld( 'page_namespace', $this->params
['namespace'] );
525 $show = $this->params
['show'];
526 if ( $this->params
['toponly'] ) { // deprecated/old param
529 if ( !is_null( $show ) ) {
530 $show = array_flip( $show );
532 if ( ( isset( $show['minor'] ) && isset( $show['!minor'] ) )
533 ||
( isset( $show['patrolled'] ) && isset( $show['!patrolled'] ) )
534 ||
( isset( $show['autopatrolled'] ) && isset( $show['!autopatrolled'] ) )
535 ||
( isset( $show['autopatrolled'] ) && isset( $show['!patrolled'] ) )
536 ||
( isset( $show['top'] ) && isset( $show['!top'] ) )
537 ||
( isset( $show['new'] ) && isset( $show['!new'] ) )
539 $this->dieWithError( 'apierror-show' );
542 $this->addWhereIf( 'rev_minor_edit = 0', isset( $show['!minor'] ) );
543 $this->addWhereIf( 'rev_minor_edit != 0', isset( $show['minor'] ) );
545 'rc_patrolled = ' . RecentChange
::PRC_UNPATROLLED
,
546 isset( $show['!patrolled'] )
549 'rc_patrolled != ' . RecentChange
::PRC_UNPATROLLED
,
550 isset( $show['patrolled'] )
553 'rc_patrolled != ' . RecentChange
::PRC_AUTOPATROLLED
,
554 isset( $show['!autopatrolled'] )
557 'rc_patrolled = ' . RecentChange
::PRC_AUTOPATROLLED
,
558 isset( $show['autopatrolled'] )
560 $this->addWhereIf( $idField . ' != page_latest', isset( $show['!top'] ) );
561 $this->addWhereIf( $idField . ' = page_latest', isset( $show['top'] ) );
562 $this->addWhereIf( 'rev_parent_id != 0', isset( $show['!new'] ) );
563 $this->addWhereIf( 'rev_parent_id = 0', isset( $show['new'] ) );
565 $this->addOption( 'LIMIT', $limit +
1 );
567 if ( isset( $show['patrolled'] ) ||
isset( $show['!patrolled'] ) ||
568 isset( $show['autopatrolled'] ) ||
isset( $show['!autopatrolled'] ) ||
$this->fld_patrolled
570 if ( !$user->useRCPatrol() && !$user->useNPPatrol() ) {
571 $this->dieWithError( 'apierror-permissiondenied-patrolflag', 'permissiondenied' );
574 $isFilterset = isset( $show['patrolled'] ) ||
isset( $show['!patrolled'] ) ||
575 isset( $show['autopatrolled'] ) ||
isset( $show['!autopatrolled'] );
576 $this->addTables( 'recentchanges' );
577 $this->addJoinConds( [ 'recentchanges' => [
578 $isFilterset ?
'JOIN' : 'LEFT JOIN',
580 // This is a crazy hack. recentchanges has no index on rc_this_oldid, so instead of adding
581 // one T19237 did a join using rc_user_text and rc_timestamp instead. Now rc_user_text is
582 // probably unavailable, so just do rc_timestamp.
583 'rc_timestamp = ' . $tsField,
584 'rc_this_oldid = ' . $idField,
589 $this->addFieldsIf( 'rc_patrolled', $this->fld_patrolled
);
591 if ( $this->fld_tags
) {
592 $this->addTables( 'tag_summary' );
594 [ 'tag_summary' => [ 'LEFT JOIN', [ $idField . ' = ts_rev_id' ] ] ]
596 $this->addFields( 'ts_tags' );
599 if ( isset( $this->params
['tag'] ) ) {
600 $this->addTables( 'change_tag' );
602 [ 'change_tag' => [ 'INNER JOIN', [ $idField . ' = ct_rev_id' ] ] ]
604 $this->addWhereFld( 'ct_tag', $this->params
['tag'] );
611 * Extract fields from the database row and append them to a result array
613 * @param stdClass $row
616 private function extractRowInfo( $row ) {
620 if ( $row->rev_deleted
& Revision
::DELETED_TEXT
) {
621 $vals['texthidden'] = true;
625 // Any rows where we can't view the user were filtered out in the query.
626 $vals['userid'] = (int)$row->rev_user
;
627 $vals['user'] = $row->rev_user_text
;
628 if ( $row->rev_deleted
& Revision
::DELETED_USER
) {
629 $vals['userhidden'] = true;
632 if ( $this->fld_ids
) {
633 $vals['pageid'] = intval( $row->rev_page
);
634 $vals['revid'] = intval( $row->rev_id
);
635 // $vals['textid'] = intval( $row->rev_text_id ); // todo: Should this field be exposed?
637 if ( !is_null( $row->rev_parent_id
) ) {
638 $vals['parentid'] = intval( $row->rev_parent_id
);
642 $title = Title
::makeTitle( $row->page_namespace
, $row->page_title
);
644 if ( $this->fld_title
) {
645 ApiQueryBase
::addTitleInfo( $vals, $title );
648 if ( $this->fld_timestamp
) {
649 $vals['timestamp'] = wfTimestamp( TS_ISO_8601
, $row->rev_timestamp
);
652 if ( $this->fld_flags
) {
653 $vals['new'] = $row->rev_parent_id
== 0 && !is_null( $row->rev_parent_id
);
654 $vals['minor'] = (bool)$row->rev_minor_edit
;
655 $vals['top'] = $row->page_latest
== $row->rev_id
;
658 if ( $this->fld_comment ||
$this->fld_parsedcomment
) {
659 if ( $row->rev_deleted
& Revision
::DELETED_COMMENT
) {
660 $vals['commenthidden'] = true;
664 $userCanView = Revision
::userCanBitfield(
666 Revision
::DELETED_COMMENT
, $this->getUser()
669 if ( $userCanView ) {
670 $comment = $this->commentStore
->getComment( 'rev_comment', $row )->text
;
671 if ( $this->fld_comment
) {
672 $vals['comment'] = $comment;
675 if ( $this->fld_parsedcomment
) {
676 $vals['parsedcomment'] = Linker
::formatComment( $comment, $title );
681 if ( $this->fld_patrolled
) {
682 $vals['patrolled'] = $row->rc_patrolled
!= RecentChange
::PRC_UNPATROLLED
;
683 $vals['autopatrolled'] = $row->rc_patrolled
== RecentChange
::PRC_AUTOPATROLLED
;
686 if ( $this->fld_size
&& !is_null( $row->rev_len
) ) {
687 $vals['size'] = intval( $row->rev_len
);
690 if ( $this->fld_sizediff
691 && !is_null( $row->rev_len
)
692 && !is_null( $row->rev_parent_id
)
694 $parentLen = isset( $this->parentLens
[$row->rev_parent_id
] )
695 ?
$this->parentLens
[$row->rev_parent_id
]
697 $vals['sizediff'] = intval( $row->rev_len
- $parentLen );
700 if ( $this->fld_tags
) {
701 if ( $row->ts_tags
) {
702 $tags = explode( ',', $row->ts_tags
);
703 ApiResult
::setIndexedTagName( $tags, 'tag' );
704 $vals['tags'] = $tags;
710 if ( $anyHidden && $row->rev_deleted
& Revision
::DELETED_RESTRICTED
) {
711 $vals['suppressed'] = true;
717 private function continueStr( $row ) {
718 if ( $this->multiUserMode
) {
719 switch ( $this->orderBy
) {
721 return "id|$row->rev_user|$row->rev_timestamp|$row->rev_id";
723 return "name|$row->rev_user_text|$row->rev_timestamp|$row->rev_id";
725 return "actor|$row->rev_actor|$row->rev_timestamp|$row->rev_id";
728 return "$row->rev_timestamp|$row->rev_id";
732 public function getCacheMode( $params ) {
733 // This module provides access to deleted revisions and patrol flags if
734 // the requester is logged in
735 return 'anon-public-user-private';
738 public function getAllowedParams() {
741 ApiBase
::PARAM_DFLT
=> 10,
742 ApiBase
::PARAM_TYPE
=> 'limit',
743 ApiBase
::PARAM_MIN
=> 1,
744 ApiBase
::PARAM_MAX
=> ApiBase
::LIMIT_BIG1
,
745 ApiBase
::PARAM_MAX2
=> ApiBase
::LIMIT_BIG2
748 ApiBase
::PARAM_TYPE
=> 'timestamp'
751 ApiBase
::PARAM_TYPE
=> 'timestamp'
754 ApiBase
::PARAM_HELP_MSG
=> 'api-help-param-continue',
757 ApiBase
::PARAM_TYPE
=> 'user',
758 ApiBase
::PARAM_ISMULTI
=> true
761 ApiBase
::PARAM_TYPE
=> 'integer',
762 ApiBase
::PARAM_ISMULTI
=> true
764 'userprefix' => null,
766 ApiBase
::PARAM_DFLT
=> 'older',
767 ApiBase
::PARAM_TYPE
=> [
771 ApiBase
::PARAM_HELP_MSG
=> 'api-help-param-direction',
774 ApiBase
::PARAM_ISMULTI
=> true,
775 ApiBase
::PARAM_TYPE
=> 'namespace'
778 ApiBase
::PARAM_ISMULTI
=> true,
779 ApiBase
::PARAM_DFLT
=> 'ids|title|timestamp|comment|size|flags',
780 ApiBase
::PARAM_TYPE
=> [
792 ApiBase
::PARAM_HELP_MSG_PER_VALUE
=> [],
795 ApiBase
::PARAM_ISMULTI
=> true,
796 ApiBase
::PARAM_TYPE
=> [
808 ApiBase
::PARAM_HELP_MSG
=> [
809 'apihelp-query+usercontribs-param-show',
810 $this->getConfig()->get( 'RCMaxAge' )
815 ApiBase
::PARAM_DFLT
=> false,
816 ApiBase
::PARAM_DEPRECATED
=> true,
821 protected function getExamplesMessages() {
823 'action=query&list=usercontribs&ucuser=Example'
824 => 'apihelp-query+usercontribs-example-user',
825 'action=query&list=usercontribs&ucuserprefix=192.0.2.'
826 => 'apihelp-query+usercontribs-example-ipprefix',
830 public function getHelpUrls() {
831 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Usercontribs';
837 * @deprecated since 1.32
839 class_alias( ApiQueryUserContribs
::class, 'ApiQueryContributions' );