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 ApiQueryContributions
extends ApiQueryBase
{
30 public function __construct( ApiQuery
$query, $moduleName ) {
31 parent
::__construct( $query, $moduleName, 'uc' );
34 private $params, $multiUserMode, $orderBy, $parentLens;
35 private $fld_ids = false, $fld_title = false, $fld_timestamp = false,
36 $fld_comment = false, $fld_parsedcomment = false, $fld_flags = false,
37 $fld_patrolled = false, $fld_tags = false, $fld_size = false, $fld_sizediff = false;
39 public function execute() {
40 global $wgActorTableSchemaMigrationStage;
42 // Parse some parameters
43 $this->params
= $this->extractRequestParams();
45 $this->commentStore
= CommentStore
::getStore();
47 $prop = array_flip( $this->params
['prop'] );
48 $this->fld_ids
= isset( $prop['ids'] );
49 $this->fld_title
= isset( $prop['title'] );
50 $this->fld_comment
= isset( $prop['comment'] );
51 $this->fld_parsedcomment
= isset( $prop['parsedcomment'] );
52 $this->fld_size
= isset( $prop['size'] );
53 $this->fld_sizediff
= isset( $prop['sizediff'] );
54 $this->fld_flags
= isset( $prop['flags'] );
55 $this->fld_timestamp
= isset( $prop['timestamp'] );
56 $this->fld_patrolled
= isset( $prop['patrolled'] );
57 $this->fld_tags
= isset( $prop['tags'] );
59 // Most of this code will use the 'contributions' group DB, which can map to replica DBs
60 // with extra user based indexes or partioning by user. The additional metadata
61 // queries should use a regular replica DB since the lookup pattern is not all by user.
62 $dbSecondary = $this->getDB(); // any random replica DB
64 // TODO: if the query is going only against the revision table, should this be done?
65 $this->selectNamedDB( 'contributions', DB_REPLICA
, 'contributions' );
67 $sort = ( $this->params
['dir'] == 'newer' ?
'' : ' DESC' );
68 $op = ( $this->params
['dir'] == 'older' ?
'<' : '>' );
70 // Create an Iterator that produces the UserIdentity objects we need, depending
71 // on which of the 'userprefix', 'userids', or 'user' params was
73 $this->requireOnlyOneParameter( $this->params
, 'userprefix', 'userids', 'user' );
74 if ( isset( $this->params
['userprefix'] ) ) {
75 $this->multiUserMode
= true;
76 $this->orderBy
= 'name';
79 // Because 'userprefix' might produce a huge number of users (e.g.
80 // a wiki with users "Test00000001" to "Test99999999"), use a
81 // generator with batched lookup and continuation.
82 $userIter = call_user_func( function () use ( $dbSecondary, $sort, $op, $fname ) {
83 global $wgActorTableSchemaMigrationStage;
85 $from = $fromName = false;
86 if ( !is_null( $this->params
['continue'] ) ) {
87 $continue = explode( '|', $this->params
['continue'] );
88 $this->dieContinueUsageIf( count( $continue ) != 4 );
89 $this->dieContinueUsageIf( $continue[0] !== 'name' );
90 $fromName = $continue[1];
91 $from = "$op= " . $dbSecondary->addQuotes( $fromName );
93 $like = $dbSecondary->buildLike( $this->params
['userprefix'], $dbSecondary->anyString() );
98 // For the new schema, pull from the actor table. For the
99 // old, pull from rev_user. For migration a FULL [OUTER]
100 // JOIN would be what we want, except MySQL doesn't support
101 // that so we have to UNION instead.
102 if ( $wgActorTableSchemaMigrationStage === MIGRATION_NEW
) {
103 $res = $dbSecondary->select(
105 [ 'actor_id', 'user_id' => 'COALESCE(actor_user,0)', 'user_name' => 'actor_name' ],
106 array_merge( [ "actor_name$like" ], $from ?
[ "actor_name $from" ] : [] ),
108 [ 'ORDER BY' => [ "user_name $sort" ], 'LIMIT' => $limit ]
110 } elseif ( $wgActorTableSchemaMigrationStage === MIGRATION_OLD
) {
111 $res = $dbSecondary->select(
113 [ 'actor_id' => 'NULL', 'user_id' => 'rev_user', 'user_name' => 'rev_user_text' ],
114 array_merge( [ "rev_user_text$like" ], $from ?
[ "rev_user_text $from" ] : [] ),
116 [ 'DISTINCT', 'ORDER BY' => [ "rev_user_text $sort" ], 'LIMIT' => $limit ]
119 // There are three queries we have to combine to be sure of getting all results:
120 // - actor table (any rows that have been migrated will have empty rev_user_text)
121 // - revision+actor by user id
122 // - revision+actor by name for anons
123 $options = $dbSecondary->unionSupportsOrderAndLimit()
124 ?
[ 'ORDER BY' => [ "user_name $sort" ], 'LIMIT' => $limit ] : [];
126 $subsql[] = $dbSecondary->selectSQLText(
128 [ 'actor_id', 'user_id' => 'COALESCE(actor_user,0)', 'user_name' => 'actor_name' ],
129 array_merge( [ "actor_name$like" ], $from ?
[ "actor_name $from" ] : [] ),
133 $subsql[] = $dbSecondary->selectSQLText(
134 [ 'revision', 'actor' ],
135 [ 'actor_id', 'user_id' => 'rev_user', 'user_name' => 'rev_user_text' ],
137 [ "rev_user_text$like", 'rev_user != 0' ],
138 $from ?
[ "rev_user_text $from" ] : []
141 array_merge( [ 'DISTINCT' ], $options ),
142 [ 'actor' => [ 'LEFT JOIN', 'rev_user = actor_user' ] ]
144 $subsql[] = $dbSecondary->selectSQLText(
145 [ 'revision', 'actor' ],
146 [ 'actor_id', 'user_id' => 'rev_user', 'user_name' => 'rev_user_text' ],
148 [ "rev_user_text$like", 'rev_user = 0' ],
149 $from ?
[ "rev_user_text $from" ] : []
152 array_merge( [ 'DISTINCT' ], $options ),
153 [ 'actor' => [ 'LEFT JOIN', 'rev_user_text = actor_name' ] ]
155 $sql = $dbSecondary->unionQueries( $subsql, false ) . " ORDER BY user_name $sort";
156 $sql = $dbSecondary->limitResult( $sql, $limit );
157 $res = $dbSecondary->query( $sql, $fname );
162 foreach ( $res as $row ) {
163 if ( ++
$count >= $limit ) {
164 $from = $row->user_name
;
167 yield User
::newFromRow( $row );
169 } while ( $from !== null );
171 // Do the actual sorting client-side, because otherwise
172 // prepareQuery might try to sort by actor and confuse everything.
174 } elseif ( isset( $this->params
['userids'] ) ) {
175 if ( !count( $this->params
['userids'] ) ) {
176 $encParamName = $this->encodeParamName( 'userids' );
177 $this->dieWithError( [ 'apierror-paramempty', $encParamName ], "paramempty_$encParamName" );
181 foreach ( $this->params
['userids'] as $uid ) {
183 $this->dieWithError( [ 'apierror-invaliduserid', $uid ], 'invaliduserid' );
188 $this->orderBy
= 'id';
189 $this->multiUserMode
= count( $ids ) > 1;
191 $from = $fromId = false;
192 if ( $this->multiUserMode
&& !is_null( $this->params
['continue'] ) ) {
193 $continue = explode( '|', $this->params
['continue'] );
194 $this->dieContinueUsageIf( count( $continue ) != 4 );
195 $this->dieContinueUsageIf( $continue[0] !== 'id' && $continue[0] !== 'actor' );
196 $fromId = (int)$continue[1];
197 $this->dieContinueUsageIf( $continue[1] !== (string)$fromId );
198 $from = "$op= $fromId";
201 // For the new schema, just select from the actor table. For the
202 // old and transitional schemas, select from user and left join
203 // actor if it exists.
204 if ( $wgActorTableSchemaMigrationStage === MIGRATION_NEW
) {
205 $res = $dbSecondary->select(
207 [ 'actor_id', 'user_id' => 'actor_user', 'user_name' => 'actor_name' ],
208 array_merge( [ 'actor_user' => $ids ], $from ?
[ "actor_id $from" ] : [] ),
210 [ 'ORDER BY' => "user_id $sort" ]
212 } elseif ( $wgActorTableSchemaMigrationStage === MIGRATION_OLD
) {
213 $res = $dbSecondary->select(
215 [ 'actor_id' => 'NULL', 'user_id' => 'user_id', 'user_name' => 'user_name' ],
216 array_merge( [ 'user_id' => $ids ], $from ?
[ "user_id $from" ] : [] ),
218 [ 'ORDER BY' => "user_id $sort" ]
221 $res = $dbSecondary->select(
223 [ 'actor_id', 'user_id', 'user_name' ],
224 array_merge( [ 'user_id' => $ids ], $from ?
[ "user_id $from" ] : [] ),
226 [ 'ORDER BY' => "user_id $sort" ],
227 [ 'actor' => [ 'LEFT JOIN', 'actor_user = user_id' ] ]
230 $userIter = UserArray
::newFromResult( $res );
231 $batchSize = count( $ids );
234 if ( !count( $this->params
['user'] ) ) {
235 $encParamName = $this->encodeParamName( 'user' );
237 [ 'apierror-paramempty', $encParamName ], "paramempty_$encParamName"
240 foreach ( $this->params
['user'] as $u ) {
242 $encParamName = $this->encodeParamName( 'user' );
244 [ 'apierror-paramempty', $encParamName ], "paramempty_$encParamName"
248 if ( User
::isIP( $u ) ) {
251 $name = User
::getCanonicalName( $u, 'valid' );
252 if ( $name === false ) {
253 $encParamName = $this->encodeParamName( 'user' );
255 [ 'apierror-baduser', $encParamName, wfEscapeWikiText( $u ) ], "baduser_$encParamName"
258 $names[$name] = null;
262 $this->orderBy
= 'name';
263 $this->multiUserMode
= count( $names ) > 1;
265 $from = $fromName = false;
266 if ( $this->multiUserMode
&& !is_null( $this->params
['continue'] ) ) {
267 $continue = explode( '|', $this->params
['continue'] );
268 $this->dieContinueUsageIf( count( $continue ) != 4 );
269 $this->dieContinueUsageIf( $continue[0] !== 'name' && $continue[0] !== 'actor' );
270 $fromName = $continue[1];
271 $from = "$op= " . $dbSecondary->addQuotes( $fromName );
274 // For the new schema, just select from the actor table. For the
275 // old and transitional schemas, select from user and left join
276 // actor if it exists then merge in any unknown users (IPs and imports).
277 if ( $wgActorTableSchemaMigrationStage === MIGRATION_NEW
) {
278 $res = $dbSecondary->select(
280 [ 'actor_id', 'user_id' => 'actor_user', 'user_name' => 'actor_name' ],
281 array_merge( [ 'actor_name' => array_keys( $names ) ], $from ?
[ "actor_id $from" ] : [] ),
283 [ 'ORDER BY' => "actor_name $sort" ]
285 $userIter = UserArray
::newFromResult( $res );
287 if ( $wgActorTableSchemaMigrationStage === MIGRATION_OLD
) {
288 $res = $dbSecondary->select(
290 [ 'actor_id' => 'NULL', 'user_id', 'user_name' ],
291 array_merge( [ 'user_name' => array_keys( $names ) ], $from ?
[ "user_name $from" ] : [] ),
295 $res = $dbSecondary->select(
297 [ 'actor_id', 'user_id', 'user_name' ],
298 array_merge( [ 'user_name' => array_keys( $names ) ], $from ?
[ "user_name $from" ] : [] ),
301 [ 'actor' => [ 'LEFT JOIN', 'actor_user = user_id' ] ]
304 foreach ( $res as $row ) {
305 $names[$row->user_name
] = $row;
307 call_user_func_array(
308 $this->params
['dir'] == 'newer' ?
'ksort' : 'krsort', [ &$names, SORT_STRING
]
310 $neg = $op === '>' ?
-1 : 1;
311 $userIter = call_user_func( function () use ( $names, $fromName, $neg ) {
312 foreach ( $names as $name => $row ) {
313 if ( $fromName === false ||
$neg * strcmp( $name, $fromName ) <= 0 ) {
314 $user = $row ? User
::newFromRow( $row ) : User
::newFromName( $name, false );
320 $batchSize = count( $names );
323 // During migration, force ordering on the client side because we're
324 // having to combine multiple queries that would otherwise have
325 // different sort orders.
326 if ( $wgActorTableSchemaMigrationStage === MIGRATION_WRITE_BOTH ||
327 $wgActorTableSchemaMigrationStage === MIGRATION_WRITE_NEW
332 // With the new schema, the DB query will order by actor so update $this->orderBy to match.
333 if ( $batchSize > 1 && $wgActorTableSchemaMigrationStage === MIGRATION_NEW
) {
334 $this->orderBy
= 'actor';
338 $limit = $this->params
['limit'];
340 while ( $userIter->valid() ) {
342 while ( count( $users ) < $batchSize && $userIter->valid() ) {
343 $users[] = $userIter->current();
347 // Ugh. We have to run the query three times, once for each
348 // possible 'orcond' from ActorMigration, and then merge them all
349 // together in the proper order. And preserving the correct
350 // $hookData for each one.
351 // @todo When ActorMigration is removed, this can go back to a
352 // single prepare and select.
354 foreach ( [ 'actor', 'userid', 'username' ] as $which ) {
355 if ( $this->prepareQuery( $users, $limit - $count, $which ) ) {
357 $res = $this->select( __METHOD__
, [], $hookData );
358 foreach ( $res as $row ) {
359 $merged[] = [ $row, &$hookData ];
363 $neg = $this->params
['dir'] == 'newer' ?
1 : -1;
364 usort( $merged, function ( $a, $b ) use ( $neg, $batchSize ) {
365 if ( $batchSize === 1 ) { // One user, can't be different
367 } elseif ( $this->orderBy
=== 'id' ) {
368 $ret = $a[0]->rev_user
- $b[0]->rev_user
;
369 } elseif ( $this->orderBy
=== 'name' ) {
370 $ret = strcmp( $a[0]->rev_user_text
, $b[0]->rev_user_text
);
372 $ret = $a[0]->rev_actor
- $b[0]->rev_actor
;
377 wfTimestamp( TS_MW
, $a[0]->rev_timestamp
),
378 wfTimestamp( TS_MW
, $b[0]->rev_timestamp
)
383 $ret = $a[0]->rev_id
- $b[0]->rev_id
;
388 $merged = array_slice( $merged, 0, $limit - $count +
1 );
391 if ( $this->fld_sizediff
) {
393 foreach ( $merged as $data ) {
394 if ( $data[0]->rev_parent_id
) {
395 $revIds[] = $data[0]->rev_parent_id
;
398 $this->parentLens
= Revision
::getParentLengths( $dbSecondary, $revIds );
401 foreach ( $merged as $data ) {
403 $hookData = &$data[1];
404 if ( ++
$count > $limit ) {
405 // We've reached the one extra which shows that there are
406 // additional pages to be had. Stop here...
407 $this->setContinueEnumParameter( 'continue', $this->continueStr( $row ) );
411 $vals = $this->extractRowInfo( $row );
412 $fit = $this->processRow( $row, $vals, $hookData ) &&
413 $this->getResult()->addValue( [ 'query', $this->getModuleName() ], null, $vals );
415 $this->setContinueEnumParameter( 'continue', $this->continueStr( $row ) );
421 $this->getResult()->addIndexedTagName( [ 'query', $this->getModuleName() ], 'item' );
425 * Prepares the query and returns the limit of rows requested
426 * @param User[] $users
428 * @param string $which 'actor', 'userid', or 'username'
431 private function prepareQuery( array $users, $limit, $which ) {
432 global $wgActorTableSchemaMigrationStage;
434 $this->resetQueryParams();
435 $db = $this->getDB();
437 $revQuery = Revision
::getQueryInfo( [ 'page' ] );
438 $this->addTables( $revQuery['tables'] );
439 $this->addJoinConds( $revQuery['joins'] );
440 $this->addFields( $revQuery['fields'] );
442 $revWhere = ActorMigration
::newMigration()->getWhere( $db, 'rev_user', $users );
443 if ( !isset( $revWhere['orconds'][$which] ) ) {
446 $this->addWhere( $revWhere['orconds'][$which] );
448 if ( $wgActorTableSchemaMigrationStage === MIGRATION_NEW
) {
449 $orderUserField = 'rev_actor';
450 $userField = $this->orderBy
=== 'actor' ?
'revactor_actor' : 'actor_name';
452 $orderUserField = $this->orderBy
=== 'id' ?
'rev_user' : 'rev_user_text';
453 $userField = $revQuery['fields'][$orderUserField];
455 if ( $which === 'actor' ) {
456 $tsField = 'revactor_timestamp';
457 $idField = 'revactor_rev';
459 $tsField = 'rev_timestamp';
463 // Handle continue parameter
464 if ( !is_null( $this->params
['continue'] ) ) {
465 $continue = explode( '|', $this->params
['continue'] );
466 if ( $this->multiUserMode
) {
467 $this->dieContinueUsageIf( count( $continue ) != 4 );
468 $modeFlag = array_shift( $continue );
469 $this->dieContinueUsageIf( $modeFlag !== $this->orderBy
);
470 $encUser = $db->addQuotes( array_shift( $continue ) );
472 $this->dieContinueUsageIf( count( $continue ) != 2 );
474 $encTS = $db->addQuotes( $db->timestamp( $continue[0] ) );
475 $encId = (int)$continue[1];
476 $this->dieContinueUsageIf( $encId != $continue[1] );
477 $op = ( $this->params
['dir'] == 'older' ?
'<' : '>' );
478 if ( $this->multiUserMode
) {
480 "$userField $op $encUser OR " .
481 "($userField = $encUser AND " .
482 "($tsField $op $encTS OR " .
483 "($tsField = $encTS AND " .
484 "$idField $op= $encId)))"
488 "$tsField $op $encTS OR " .
489 "($tsField = $encTS AND " .
490 "$idField $op= $encId)"
495 // Don't include any revisions where we're not supposed to be able to
497 $user = $this->getUser();
498 if ( !$user->isAllowed( 'deletedhistory' ) ) {
499 $bitmask = Revision
::DELETED_USER
;
500 } elseif ( !$user->isAllowedAny( 'suppressrevision', 'viewsuppressed' ) ) {
501 $bitmask = Revision
::DELETED_USER | Revision
::DELETED_RESTRICTED
;
506 $this->addWhere( $db->bitAnd( 'rev_deleted', $bitmask ) . " != $bitmask" );
509 // Add the user field to ORDER BY if there are multiple users
510 if ( count( $users ) > 1 ) {
511 $this->addWhereRange( $orderUserField, $this->params
['dir'], null, null );
515 $this->addTimestampWhereRange( $tsField,
516 $this->params
['dir'], $this->params
['start'], $this->params
['end'] );
518 // Then rev_id for a total ordering
519 $this->addWhereRange( $idField, $this->params
['dir'], null, null );
521 $this->addWhereFld( 'page_namespace', $this->params
['namespace'] );
523 $show = $this->params
['show'];
524 if ( $this->params
['toponly'] ) { // deprecated/old param
527 if ( !is_null( $show ) ) {
528 $show = array_flip( $show );
530 if ( ( isset( $show['minor'] ) && isset( $show['!minor'] ) )
531 ||
( isset( $show['patrolled'] ) && isset( $show['!patrolled'] ) )
532 ||
( isset( $show['top'] ) && isset( $show['!top'] ) )
533 ||
( isset( $show['new'] ) && isset( $show['!new'] ) )
535 $this->dieWithError( 'apierror-show' );
538 $this->addWhereIf( 'rev_minor_edit = 0', isset( $show['!minor'] ) );
539 $this->addWhereIf( 'rev_minor_edit != 0', isset( $show['minor'] ) );
540 $this->addWhereIf( 'rc_patrolled = 0', isset( $show['!patrolled'] ) );
541 $this->addWhereIf( 'rc_patrolled != 0', isset( $show['patrolled'] ) );
542 $this->addWhereIf( $idField . ' != page_latest', isset( $show['!top'] ) );
543 $this->addWhereIf( $idField . ' = page_latest', isset( $show['top'] ) );
544 $this->addWhereIf( 'rev_parent_id != 0', isset( $show['!new'] ) );
545 $this->addWhereIf( 'rev_parent_id = 0', isset( $show['new'] ) );
547 $this->addOption( 'LIMIT', $limit +
1 );
549 if ( isset( $show['patrolled'] ) ||
isset( $show['!patrolled'] ) ||
552 if ( !$user->useRCPatrol() && !$user->useNPPatrol() ) {
553 $this->dieWithError( 'apierror-permissiondenied-patrolflag', 'permissiondenied' );
556 $this->addTables( 'recentchanges' );
557 $this->addJoinConds( [ 'recentchanges' => [
558 isset( $show['patrolled'] ) ||
isset( $show['!patrolled'] ) ?
'JOIN' : 'LEFT JOIN',
560 // This is a crazy hack. recentchanges has no index on rc_this_oldid, so instead of adding
561 // one T19237 did a join using rc_user_text and rc_timestamp instead. Now rc_user_text is
562 // probably unavailable, so just do rc_timestamp.
563 'rc_timestamp = ' . $tsField,
564 'rc_this_oldid = ' . $idField,
569 $this->addFieldsIf( 'rc_patrolled', $this->fld_patrolled
);
571 if ( $this->fld_tags
) {
572 $this->addTables( 'tag_summary' );
574 [ 'tag_summary' => [ 'LEFT JOIN', [ $idField . ' = ts_rev_id' ] ] ]
576 $this->addFields( 'ts_tags' );
579 if ( isset( $this->params
['tag'] ) ) {
580 $this->addTables( 'change_tag' );
582 [ 'change_tag' => [ 'INNER JOIN', [ $idField . ' = ct_rev_id' ] ] ]
584 $this->addWhereFld( 'ct_tag', $this->params
['tag'] );
591 * Extract fields from the database row and append them to a result array
593 * @param stdClass $row
596 private function extractRowInfo( $row ) {
600 if ( $row->rev_deleted
& Revision
::DELETED_TEXT
) {
601 $vals['texthidden'] = true;
605 // Any rows where we can't view the user were filtered out in the query.
606 $vals['userid'] = (int)$row->rev_user
;
607 $vals['user'] = $row->rev_user_text
;
608 if ( $row->rev_deleted
& Revision
::DELETED_USER
) {
609 $vals['userhidden'] = true;
612 if ( $this->fld_ids
) {
613 $vals['pageid'] = intval( $row->rev_page
);
614 $vals['revid'] = intval( $row->rev_id
);
615 // $vals['textid'] = intval( $row->rev_text_id ); // todo: Should this field be exposed?
617 if ( !is_null( $row->rev_parent_id
) ) {
618 $vals['parentid'] = intval( $row->rev_parent_id
);
622 $title = Title
::makeTitle( $row->page_namespace
, $row->page_title
);
624 if ( $this->fld_title
) {
625 ApiQueryBase
::addTitleInfo( $vals, $title );
628 if ( $this->fld_timestamp
) {
629 $vals['timestamp'] = wfTimestamp( TS_ISO_8601
, $row->rev_timestamp
);
632 if ( $this->fld_flags
) {
633 $vals['new'] = $row->rev_parent_id
== 0 && !is_null( $row->rev_parent_id
);
634 $vals['minor'] = (bool)$row->rev_minor_edit
;
635 $vals['top'] = $row->page_latest
== $row->rev_id
;
638 if ( $this->fld_comment ||
$this->fld_parsedcomment
) {
639 if ( $row->rev_deleted
& Revision
::DELETED_COMMENT
) {
640 $vals['commenthidden'] = true;
644 $userCanView = Revision
::userCanBitfield(
646 Revision
::DELETED_COMMENT
, $this->getUser()
649 if ( $userCanView ) {
650 $comment = $this->commentStore
->getComment( 'rev_comment', $row )->text
;
651 if ( $this->fld_comment
) {
652 $vals['comment'] = $comment;
655 if ( $this->fld_parsedcomment
) {
656 $vals['parsedcomment'] = Linker
::formatComment( $comment, $title );
661 if ( $this->fld_patrolled
) {
662 $vals['patrolled'] = (bool)$row->rc_patrolled
;
665 if ( $this->fld_size
&& !is_null( $row->rev_len
) ) {
666 $vals['size'] = intval( $row->rev_len
);
669 if ( $this->fld_sizediff
670 && !is_null( $row->rev_len
)
671 && !is_null( $row->rev_parent_id
)
673 $parentLen = isset( $this->parentLens
[$row->rev_parent_id
] )
674 ?
$this->parentLens
[$row->rev_parent_id
]
676 $vals['sizediff'] = intval( $row->rev_len
- $parentLen );
679 if ( $this->fld_tags
) {
680 if ( $row->ts_tags
) {
681 $tags = explode( ',', $row->ts_tags
);
682 ApiResult
::setIndexedTagName( $tags, 'tag' );
683 $vals['tags'] = $tags;
689 if ( $anyHidden && $row->rev_deleted
& Revision
::DELETED_RESTRICTED
) {
690 $vals['suppressed'] = true;
696 private function continueStr( $row ) {
697 if ( $this->multiUserMode
) {
698 switch ( $this->orderBy
) {
700 return "id|$row->rev_user|$row->rev_timestamp|$row->rev_id";
702 return "name|$row->rev_user_text|$row->rev_timestamp|$row->rev_id";
704 return "actor|$row->rev_actor|$row->rev_timestamp|$row->rev_id";
707 return "$row->rev_timestamp|$row->rev_id";
711 public function getCacheMode( $params ) {
712 // This module provides access to deleted revisions and patrol flags if
713 // the requester is logged in
714 return 'anon-public-user-private';
717 public function getAllowedParams() {
720 ApiBase
::PARAM_DFLT
=> 10,
721 ApiBase
::PARAM_TYPE
=> 'limit',
722 ApiBase
::PARAM_MIN
=> 1,
723 ApiBase
::PARAM_MAX
=> ApiBase
::LIMIT_BIG1
,
724 ApiBase
::PARAM_MAX2
=> ApiBase
::LIMIT_BIG2
727 ApiBase
::PARAM_TYPE
=> 'timestamp'
730 ApiBase
::PARAM_TYPE
=> 'timestamp'
733 ApiBase
::PARAM_HELP_MSG
=> 'api-help-param-continue',
736 ApiBase
::PARAM_TYPE
=> 'user',
737 ApiBase
::PARAM_ISMULTI
=> true
740 ApiBase
::PARAM_TYPE
=> 'integer',
741 ApiBase
::PARAM_ISMULTI
=> true
743 'userprefix' => null,
745 ApiBase
::PARAM_DFLT
=> 'older',
746 ApiBase
::PARAM_TYPE
=> [
750 ApiBase
::PARAM_HELP_MSG
=> 'api-help-param-direction',
753 ApiBase
::PARAM_ISMULTI
=> true,
754 ApiBase
::PARAM_TYPE
=> 'namespace'
757 ApiBase
::PARAM_ISMULTI
=> true,
758 ApiBase
::PARAM_DFLT
=> 'ids|title|timestamp|comment|size|flags',
759 ApiBase
::PARAM_TYPE
=> [
771 ApiBase
::PARAM_HELP_MSG_PER_VALUE
=> [],
774 ApiBase
::PARAM_ISMULTI
=> true,
775 ApiBase
::PARAM_TYPE
=> [
785 ApiBase
::PARAM_HELP_MSG
=> [
786 'apihelp-query+usercontribs-param-show',
787 $this->getConfig()->get( 'RCMaxAge' )
792 ApiBase
::PARAM_DFLT
=> false,
793 ApiBase
::PARAM_DEPRECATED
=> true,
798 protected function getExamplesMessages() {
800 'action=query&list=usercontribs&ucuser=Example'
801 => 'apihelp-query+usercontribs-example-user',
802 'action=query&list=usercontribs&ucuserprefix=192.0.2.'
803 => 'apihelp-query+usercontribs-example-ipprefix',
807 public function getHelpUrls() {
808 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Usercontribs';