MediaWiki REL1_40
ApiQueryUserContribs.php
Go to the documentation of this file.
1<?php
36use Wikimedia\IPUtils;
40
47
49 private $commentStore;
50
52 private $userIdentityLookup;
53
55 private $userNameUtils;
56
58 private $revisionStore;
59
61 private $changeTagDefStore;
62
64 private $actorMigration;
65
67 private $commentFormatter;
68
80 public function __construct(
81 ApiQuery $query,
82 $moduleName,
83 CommentStore $commentStore,
84 UserIdentityLookup $userIdentityLookup,
85 UserNameUtils $userNameUtils,
86 RevisionStore $revisionStore,
87 NameTableStore $changeTagDefStore,
88 ActorMigration $actorMigration,
89 CommentFormatter $commentFormatter
90 ) {
91 parent::__construct( $query, $moduleName, 'uc' );
92 $this->commentStore = $commentStore;
93 $this->userIdentityLookup = $userIdentityLookup;
94 $this->userNameUtils = $userNameUtils;
95 $this->revisionStore = $revisionStore;
96 $this->changeTagDefStore = $changeTagDefStore;
97 $this->actorMigration = $actorMigration;
98 $this->commentFormatter = $commentFormatter;
99 }
100
101 private $params, $multiUserMode, $orderBy, $parentLens;
102
103 private $fld_ids = false, $fld_title = false, $fld_timestamp = false,
104 $fld_comment = false, $fld_parsedcomment = false, $fld_flags = false,
105 $fld_patrolled = false, $fld_tags = false, $fld_size = false, $fld_sizediff = false;
106
107 public function execute() {
108 // Parse some parameters
109 $this->params = $this->extractRequestParams();
110
111 $prop = array_fill_keys( $this->params['prop'], true );
112 $this->fld_ids = isset( $prop['ids'] );
113 $this->fld_title = isset( $prop['title'] );
114 $this->fld_comment = isset( $prop['comment'] );
115 $this->fld_parsedcomment = isset( $prop['parsedcomment'] );
116 $this->fld_size = isset( $prop['size'] );
117 $this->fld_sizediff = isset( $prop['sizediff'] );
118 $this->fld_flags = isset( $prop['flags'] );
119 $this->fld_timestamp = isset( $prop['timestamp'] );
120 $this->fld_patrolled = isset( $prop['patrolled'] );
121 $this->fld_tags = isset( $prop['tags'] );
122
123 $dbSecondary = $this->getDB(); // any random replica DB
124
125 $sort = ( $this->params['dir'] == 'newer' ?
126 SelectQueryBuilder::SORT_ASC : SelectQueryBuilder::SORT_DESC );
127 $op = ( $this->params['dir'] == 'older' ? '<=' : '>=' );
128
129 // Create an Iterator that produces the UserIdentity objects we need, depending
130 // on which of the 'userprefix', 'userids', 'iprange', or 'user' params
131 // was specified.
132 $this->requireOnlyOneParameter( $this->params, 'userprefix', 'userids', 'iprange', 'user' );
133 if ( isset( $this->params['userprefix'] ) ) {
134 $this->multiUserMode = true;
135 $this->orderBy = 'name';
136 $fname = __METHOD__;
137
138 // Because 'userprefix' might produce a huge number of users (e.g.
139 // a wiki with users "Test00000001" to "Test99999999"), use a
140 // generator with batched lookup and continuation.
141 $userIter = call_user_func( function () use ( $dbSecondary, $sort, $op, $fname ) {
142 $fromName = false;
143 if ( $this->params['continue'] !== null ) {
144 $continue = $this->parseContinueParamOrDie( $this->params['continue'],
145 [ 'string', 'string', 'string', 'int' ] );
146 $this->dieContinueUsageIf( $continue[0] !== 'name' );
147 $fromName = $continue[1];
148 }
149
150 $limit = 501;
151 do {
152 $usersBatch = $this->userIdentityLookup
153 ->newSelectQueryBuilder()
154 ->caller( $fname )
155 ->limit( $limit )
156 ->whereUserNamePrefix( $this->params['userprefix'] )
157 ->where( $fromName ? $dbSecondary->buildComparison( $op, [ 'actor_name' => $fromName ] ) : [] )
158 ->orderByName( $sort )
159 ->fetchUserIdentities();
160
161 $count = 0;
162 $fromName = false;
163 foreach ( $usersBatch as $user ) {
164 if ( ++$count >= $limit ) {
165 $fromName = $user->getName();
166 break;
167 }
168 yield $user;
169 }
170 } while ( $fromName !== false );
171 } );
172 // Do the actual sorting client-side, because otherwise
173 // prepareQuery might try to sort by actor and confuse everything.
174 $batchSize = 1;
175 } elseif ( isset( $this->params['userids'] ) ) {
176 if ( $this->params['userids'] === [] ) {
177 $encParamName = $this->encodeParamName( 'userids' );
178 $this->dieWithError( [ 'apierror-paramempty', $encParamName ], "paramempty_$encParamName" );
179 }
180
181 $ids = [];
182 foreach ( $this->params['userids'] as $uid ) {
183 if ( $uid <= 0 ) {
184 $this->dieWithError( [ 'apierror-invaliduserid', $uid ], 'invaliduserid' );
185 }
186 $ids[] = $uid;
187 }
188
189 $this->orderBy = 'actor';
190 $this->multiUserMode = count( $ids ) > 1;
191
192 $fromId = false;
193 if ( $this->multiUserMode && $this->params['continue'] !== null ) {
194 $continue = $this->parseContinueParamOrDie( $this->params['continue'],
195 [ 'string', 'int', 'string', 'int' ] );
196 $this->dieContinueUsageIf( $continue[0] !== 'actor' );
197 $fromId = $continue[1];
198 }
199
200 $userIter = $this->userIdentityLookup
201 ->newSelectQueryBuilder()
202 ->caller( __METHOD__ )
203 ->whereUserIds( $ids )
204 ->orderByUserId( $sort )
205 ->where( $fromId ? $dbSecondary->buildComparison( $op, [ 'actor_id' => $fromId ] ) : [] )
206 ->fetchUserIdentities();
207 $batchSize = count( $ids );
208 } elseif ( isset( $this->params['iprange'] ) ) {
209 // Make sure it is a valid range and within the CIDR limit
210 $ipRange = $this->params['iprange'];
211 $contribsCIDRLimit = $this->getConfig()->get( MainConfigNames::RangeContributionsCIDRLimit );
212 if ( IPUtils::isIPv4( $ipRange ) ) {
213 $type = 'IPv4';
214 $cidrLimit = $contribsCIDRLimit['IPv4'];
215 } elseif ( IPUtils::isIPv6( $ipRange ) ) {
216 $type = 'IPv6';
217 $cidrLimit = $contribsCIDRLimit['IPv6'];
218 } else {
219 $this->dieWithError( [ 'apierror-invalidiprange', $ipRange ], 'invalidiprange' );
220 }
221 $range = IPUtils::parseCIDR( $ipRange )[1];
222 if ( $range === false ) {
223 $this->dieWithError( [ 'apierror-invalidiprange', $ipRange ], 'invalidiprange' );
224 } elseif ( $range < $cidrLimit ) {
225 $this->dieWithError( [ 'apierror-cidrtoobroad', $type, $cidrLimit ] );
226 }
227
228 $this->multiUserMode = true;
229 $this->orderBy = 'name';
230 $fname = __METHOD__;
231
232 // Because 'iprange' might produce a huge number of ips, use a
233 // generator with batched lookup and continuation.
234 $userIter = call_user_func( function () use ( $dbSecondary, $sort, $op, $fname, $ipRange ) {
235 [ $start, $end ] = IPUtils::parseRange( $ipRange );
236 if ( $this->params['continue'] !== null ) {
237 $continue = $this->parseContinueParamOrDie( $this->params['continue'],
238 [ 'string', 'string', 'string', 'int' ] );
239 $this->dieContinueUsageIf( $continue[0] !== 'name' );
240 $fromName = $continue[1];
241 $fromIPHex = IPUtils::toHex( $fromName );
242 $this->dieContinueUsageIf( $fromIPHex === false );
243 if ( $op == '<=' ) {
244 $end = $fromIPHex;
245 } else {
246 $start = $fromIPHex;
247 }
248 }
249
250 $limit = 501;
251
252 do {
253 $res = $dbSecondary->newSelectQueryBuilder()
254 ->select( 'ipc_hex' )
255 ->from( 'ip_changes' )
256 ->where( [ 'ipc_hex BETWEEN ' . $dbSecondary->addQuotes( $start ) .
257 ' AND ' . $dbSecondary->addQuotes( $end )
258 ] )
259 ->groupBy( 'ipc_hex' )
260 ->orderBy( 'ipc_hex', $sort )
261 ->limit( $limit )
262 ->caller( $fname )
263 ->fetchResultSet();
264
265 $count = 0;
266 $fromName = false;
267 foreach ( $res as $row ) {
268 $ipAddr = IPUtils::formatHex( $row->ipc_hex );
269 if ( ++$count >= $limit ) {
270 $fromName = $ipAddr;
271 break;
272 }
273 yield User::newFromName( $ipAddr, false );
274 }
275 } while ( $fromName !== false );
276 } );
277 // Do the actual sorting client-side, because otherwise
278 // prepareQuery might try to sort by actor and confuse everything.
279 $batchSize = 1;
280 } else {
281 $names = [];
282 if ( !count( $this->params['user'] ) ) {
283 $encParamName = $this->encodeParamName( 'user' );
284 $this->dieWithError(
285 [ 'apierror-paramempty', $encParamName ], "paramempty_$encParamName"
286 );
287 }
288 foreach ( $this->params['user'] as $u ) {
289 if ( $u === '' ) {
290 $encParamName = $this->encodeParamName( 'user' );
291 $this->dieWithError(
292 [ 'apierror-paramempty', $encParamName ], "paramempty_$encParamName"
293 );
294 }
295
296 if ( $this->userNameUtils->isIP( $u ) || ExternalUserNames::isExternal( $u ) ) {
297 $names[$u] = null;
298 } else {
299 $name = $this->userNameUtils->getCanonical( $u );
300 if ( $name === false ) {
301 $encParamName = $this->encodeParamName( 'user' );
302 $this->dieWithError(
303 [ 'apierror-baduser', $encParamName, wfEscapeWikiText( $u ) ], "baduser_$encParamName"
304 );
305 }
306 $names[$name] = null;
307 }
308 }
309
310 $this->orderBy = 'actor';
311 $this->multiUserMode = count( $names ) > 1;
312
313 $fromId = false;
314 if ( $this->multiUserMode && $this->params['continue'] !== null ) {
315 $continue = $this->parseContinueParamOrDie( $this->params['continue'],
316 [ 'string', 'int', 'string', 'int' ] );
317 $this->dieContinueUsageIf( $continue[0] !== 'actor' );
318 $fromId = $continue[1];
319 }
320
321 $userIter = $this->userIdentityLookup
322 ->newSelectQueryBuilder()
323 ->caller( __METHOD__ )
324 ->whereUserNames( array_keys( $names ) )
325 ->orderByName( $sort )
326 ->where( $fromId ? $dbSecondary->buildComparison( $op, [ 'actor_id' => $fromId ] ) : [] )
327 ->fetchUserIdentities();
328 $batchSize = count( $names );
329 }
330
331 $count = 0;
332 $limit = $this->params['limit'];
333 $userIter->rewind();
334 while ( $userIter->valid() ) {
335 $users = [];
336 while ( count( $users ) < $batchSize && $userIter->valid() ) {
337 $users[] = $userIter->current();
338 $userIter->next();
339 }
340
341 $hookData = [];
342 $this->prepareQuery( $users, $limit - $count );
343 $res = $this->select( __METHOD__, [], $hookData );
344
345 if ( $this->fld_title ) {
346 $this->executeGenderCacheFromResultWrapper( $res, __METHOD__ );
347 }
348
349 if ( $this->fld_sizediff ) {
350 $revIds = [];
351 foreach ( $res as $row ) {
352 if ( $row->rev_parent_id ) {
353 $revIds[] = (int)$row->rev_parent_id;
354 }
355 }
356 $this->parentLens = $this->revisionStore->getRevisionSizes( $revIds );
357 }
358
359 foreach ( $res as $row ) {
360 if ( ++$count > $limit ) {
361 // We've reached the one extra which shows that there are
362 // additional pages to be had. Stop here...
363 $this->setContinueEnumParameter( 'continue', $this->continueStr( $row ) );
364 break 2;
365 }
366
367 $vals = $this->extractRowInfo( $row );
368 $fit = $this->processRow( $row, $vals, $hookData ) &&
369 $this->getResult()->addValue( [ 'query', $this->getModuleName() ], null, $vals );
370 if ( !$fit ) {
371 $this->setContinueEnumParameter( 'continue', $this->continueStr( $row ) );
372 break 2;
373 }
374 }
375 }
376
377 $this->getResult()->addIndexedTagName( [ 'query', $this->getModuleName() ], 'item' );
378 }
379
385 private function prepareQuery( array $users, $limit ) {
386 $this->resetQueryParams();
387 $db = $this->getDB();
388
389 $revQuery = $this->revisionStore->getQueryInfo( [ 'page' ] );
390 $revWhere = $this->actorMigration->getWhere( $db, 'rev_user', $users );
391
392 $orderUserField = 'rev_actor';
393 $userField = $this->orderBy === 'actor' ? 'rev_actor' : 'actor_name';
394 $tsField = 'rev_timestamp';
395 $idField = 'rev_id';
396
397 $this->addTables( $revQuery['tables'] );
398 $this->addJoinConds( $revQuery['joins'] );
399 $this->addFields( $revQuery['fields'] );
400 $this->addWhere( $revWhere['conds'] );
401 // Force the appropriate index to avoid bad query plans (T307815 and T307295)
402 if ( isset( $revWhere['orconds']['newactor'] ) ) {
403 $this->addOption( 'USE INDEX', [ 'revision' => 'rev_actor_timestamp' ] );
404 }
405
406 // Handle continue parameter
407 if ( $this->params['continue'] !== null ) {
408 if ( $this->multiUserMode ) {
409 $continue = $this->parseContinueParamOrDie( $this->params['continue'],
410 [ 'string', 'string', 'timestamp', 'int' ] );
411 $modeFlag = array_shift( $continue );
412 $this->dieContinueUsageIf( $modeFlag !== $this->orderBy );
413 $encUser = array_shift( $continue );
414 } else {
415 $continue = $this->parseContinueParamOrDie( $this->params['continue'],
416 [ 'timestamp', 'int' ] );
417 }
418 $op = ( $this->params['dir'] == 'older' ? '<=' : '>=' );
419 if ( $this->multiUserMode ) {
420 $this->addWhere( $db->buildComparison( $op, [
421 // @phan-suppress-next-line PhanPossiblyUndeclaredVariable encUser is set when used
422 $userField => $encUser,
423 $tsField => $db->timestamp( $continue[0] ),
424 $idField => $continue[1],
425 ] ) );
426 } else {
427 $this->addWhere( $db->buildComparison( $op, [
428 $tsField => $db->timestamp( $continue[0] ),
429 $idField => $continue[1],
430 ] ) );
431 }
432 }
433
434 // Don't include any revisions where we're not supposed to be able to
435 // see the username.
436 if ( !$this->getAuthority()->isAllowed( 'deletedhistory' ) ) {
437 $bitmask = RevisionRecord::DELETED_USER;
438 } elseif ( !$this->getAuthority()->isAllowedAny( 'suppressrevision', 'viewsuppressed' ) ) {
439 $bitmask = RevisionRecord::DELETED_USER | RevisionRecord::DELETED_RESTRICTED;
440 } else {
441 $bitmask = 0;
442 }
443 if ( $bitmask ) {
444 $this->addWhere( $db->bitAnd( 'rev_deleted', $bitmask ) . " != $bitmask" );
445 }
446
447 // Add the user field to ORDER BY if there are multiple users
448 if ( count( $users ) > 1 ) {
449 $this->addWhereRange( $orderUserField, $this->params['dir'], null, null );
450 }
451
452 // Then timestamp
453 $this->addTimestampWhereRange( $tsField,
454 $this->params['dir'], $this->params['start'], $this->params['end'] );
455
456 // Then rev_id for a total ordering
457 $this->addWhereRange( $idField, $this->params['dir'], null, null );
458
459 $this->addWhereFld( 'page_namespace', $this->params['namespace'] );
460
461 $show = $this->params['show'];
462 if ( $this->params['toponly'] ) { // deprecated/old param
463 $show[] = 'top';
464 }
465 if ( $show !== null ) {
466 $show = array_fill_keys( $show, true );
467
468 if ( ( isset( $show['minor'] ) && isset( $show['!minor'] ) )
469 || ( isset( $show['patrolled'] ) && isset( $show['!patrolled'] ) )
470 || ( isset( $show['autopatrolled'] ) && isset( $show['!autopatrolled'] ) )
471 || ( isset( $show['autopatrolled'] ) && isset( $show['!patrolled'] ) )
472 || ( isset( $show['top'] ) && isset( $show['!top'] ) )
473 || ( isset( $show['new'] ) && isset( $show['!new'] ) )
474 ) {
475 $this->dieWithError( 'apierror-show' );
476 }
477
478 $this->addWhereIf( 'rev_minor_edit = 0', isset( $show['!minor'] ) );
479 $this->addWhereIf( 'rev_minor_edit != 0', isset( $show['minor'] ) );
480 $this->addWhereIf(
481 'rc_patrolled = ' . RecentChange::PRC_UNPATROLLED,
482 isset( $show['!patrolled'] )
483 );
484 $this->addWhereIf(
485 'rc_patrolled != ' . RecentChange::PRC_UNPATROLLED,
486 isset( $show['patrolled'] )
487 );
488 $this->addWhereIf(
489 'rc_patrolled != ' . RecentChange::PRC_AUTOPATROLLED,
490 isset( $show['!autopatrolled'] )
491 );
492 $this->addWhereIf(
493 'rc_patrolled = ' . RecentChange::PRC_AUTOPATROLLED,
494 isset( $show['autopatrolled'] )
495 );
496 $this->addWhereIf( $idField . ' != page_latest', isset( $show['!top'] ) );
497 $this->addWhereIf( $idField . ' = page_latest', isset( $show['top'] ) );
498 $this->addWhereIf( 'rev_parent_id != 0', isset( $show['!new'] ) );
499 $this->addWhereIf( 'rev_parent_id = 0', isset( $show['new'] ) );
500 }
501 $this->addOption( 'LIMIT', $limit + 1 );
502
503 if ( isset( $show['patrolled'] ) || isset( $show['!patrolled'] ) ||
504 isset( $show['autopatrolled'] ) || isset( $show['!autopatrolled'] ) || $this->fld_patrolled
505 ) {
506 $user = $this->getUser();
507 if ( !$user->useRCPatrol() && !$user->useNPPatrol() ) {
508 $this->dieWithError( 'apierror-permissiondenied-patrolflag', 'permissiondenied' );
509 }
510
511 $isFilterset = isset( $show['patrolled'] ) || isset( $show['!patrolled'] ) ||
512 isset( $show['autopatrolled'] ) || isset( $show['!autopatrolled'] );
513 $this->addTables( 'recentchanges' );
514 $this->addJoinConds( [ 'recentchanges' => [
515 $isFilterset ? 'JOIN' : 'LEFT JOIN',
516 [ 'rc_this_oldid = ' . $idField ]
517 ] ] );
518 }
519
520 $this->addFieldsIf( 'rc_patrolled', $this->fld_patrolled );
521
522 if ( $this->fld_tags ) {
523 $this->addFields( [ 'ts_tags' => ChangeTags::makeTagSummarySubquery( 'revision' ) ] );
524 }
525
526 if ( isset( $this->params['tag'] ) ) {
527 $this->addTables( 'change_tag' );
528 $this->addJoinConds(
529 [ 'change_tag' => [ 'JOIN', [ $idField . ' = ct_rev_id' ] ] ]
530 );
531 try {
532 $this->addWhereFld( 'ct_tag_id', $this->changeTagDefStore->getId( $this->params['tag'] ) );
533 } catch ( NameTableAccessException $exception ) {
534 // Return nothing.
535 $this->addWhere( '1=0' );
536 }
537 }
538 $this->addOption(
539 'MAX_EXECUTION_TIME',
540 $this->getConfig()->get( MainConfigNames::MaxExecutionTimeForExpensiveQueries )
541 );
542 }
543
550 private function extractRowInfo( $row ) {
551 $vals = [];
552 $anyHidden = false;
553
554 if ( $row->rev_deleted & RevisionRecord::DELETED_TEXT ) {
555 $vals['texthidden'] = true;
556 $anyHidden = true;
557 }
558
559 // Any rows where we can't view the user were filtered out in the query.
560 $vals['userid'] = (int)$row->rev_user;
561 $vals['user'] = $row->rev_user_text;
562 if ( $row->rev_deleted & RevisionRecord::DELETED_USER ) {
563 $vals['userhidden'] = true;
564 $anyHidden = true;
565 }
566 if ( $this->fld_ids ) {
567 $vals['pageid'] = (int)$row->rev_page;
568 $vals['revid'] = (int)$row->rev_id;
569
570 if ( $row->rev_parent_id !== null ) {
571 $vals['parentid'] = (int)$row->rev_parent_id;
572 }
573 }
574
575 $title = Title::makeTitle( $row->page_namespace, $row->page_title );
576
577 if ( $this->fld_title ) {
579 }
580
581 if ( $this->fld_timestamp ) {
582 $vals['timestamp'] = wfTimestamp( TS_ISO_8601, $row->rev_timestamp );
583 }
584
585 if ( $this->fld_flags ) {
586 $vals['new'] = $row->rev_parent_id == 0 && $row->rev_parent_id !== null;
587 $vals['minor'] = (bool)$row->rev_minor_edit;
588 $vals['top'] = $row->page_latest == $row->rev_id;
589 }
590
591 if ( $this->fld_comment || $this->fld_parsedcomment ) {
592 if ( $row->rev_deleted & RevisionRecord::DELETED_COMMENT ) {
593 $vals['commenthidden'] = true;
594 $anyHidden = true;
595 }
596
597 $userCanView = RevisionRecord::userCanBitfield(
598 $row->rev_deleted,
599 RevisionRecord::DELETED_COMMENT, $this->getAuthority()
600 );
601
602 if ( $userCanView ) {
603 $comment = $this->commentStore->getComment( 'rev_comment', $row )->text;
604 if ( $this->fld_comment ) {
605 $vals['comment'] = $comment;
606 }
607
608 if ( $this->fld_parsedcomment ) {
609 $vals['parsedcomment'] = $this->commentFormatter->format( $comment, $title );
610 }
611 }
612 }
613
614 if ( $this->fld_patrolled ) {
615 $vals['patrolled'] = $row->rc_patrolled != RecentChange::PRC_UNPATROLLED;
616 $vals['autopatrolled'] = $row->rc_patrolled == RecentChange::PRC_AUTOPATROLLED;
617 }
618
619 if ( $this->fld_size && $row->rev_len !== null ) {
620 $vals['size'] = (int)$row->rev_len;
621 }
622
623 if ( $this->fld_sizediff
624 && $row->rev_len !== null
625 && $row->rev_parent_id !== null
626 ) {
627 $parentLen = $this->parentLens[$row->rev_parent_id] ?? 0;
628 $vals['sizediff'] = (int)$row->rev_len - $parentLen;
629 }
630
631 if ( $this->fld_tags ) {
632 if ( $row->ts_tags ) {
633 $tags = explode( ',', $row->ts_tags );
634 ApiResult::setIndexedTagName( $tags, 'tag' );
635 $vals['tags'] = $tags;
636 } else {
637 $vals['tags'] = [];
638 }
639 }
640
641 if ( $anyHidden && ( $row->rev_deleted & RevisionRecord::DELETED_RESTRICTED ) ) {
642 $vals['suppressed'] = true;
643 }
644
645 return $vals;
646 }
647
648 private function continueStr( $row ) {
649 if ( $this->multiUserMode ) {
650 switch ( $this->orderBy ) {
651 case 'name':
652 return "name|$row->rev_user_text|$row->rev_timestamp|$row->rev_id";
653 case 'actor':
654 return "actor|$row->rev_actor|$row->rev_timestamp|$row->rev_id";
655 }
656 } else {
657 return "$row->rev_timestamp|$row->rev_id";
658 }
659 }
660
661 public function getCacheMode( $params ) {
662 // This module provides access to deleted revisions and patrol flags if
663 // the requester is logged in
664 return 'anon-public-user-private';
665 }
666
667 public function getAllowedParams() {
668 return [
669 'limit' => [
670 ParamValidator::PARAM_DEFAULT => 10,
671 ParamValidator::PARAM_TYPE => 'limit',
672 IntegerDef::PARAM_MIN => 1,
673 IntegerDef::PARAM_MAX => ApiBase::LIMIT_BIG1,
674 IntegerDef::PARAM_MAX2 => ApiBase::LIMIT_BIG2
675 ],
676 'start' => [
677 ParamValidator::PARAM_TYPE => 'timestamp'
678 ],
679 'end' => [
680 ParamValidator::PARAM_TYPE => 'timestamp'
681 ],
682 'continue' => [
683 ApiBase::PARAM_HELP_MSG => 'api-help-param-continue',
684 ],
685 'user' => [
686 ParamValidator::PARAM_TYPE => 'user',
687 UserDef::PARAM_ALLOWED_USER_TYPES => [ 'name', 'ip', 'interwiki' ],
688 ParamValidator::PARAM_ISMULTI => true
689 ],
690 'userids' => [
691 ParamValidator::PARAM_TYPE => 'integer',
692 ParamValidator::PARAM_ISMULTI => true
693 ],
694 'userprefix' => null,
695 'iprange' => null,
696 'dir' => [
697 ParamValidator::PARAM_DEFAULT => 'older',
698 ParamValidator::PARAM_TYPE => [
699 'newer',
700 'older'
701 ],
702 ApiBase::PARAM_HELP_MSG => 'api-help-param-direction',
704 'newer' => 'api-help-paramvalue-direction-newer',
705 'older' => 'api-help-paramvalue-direction-older',
706 ],
707 ],
708 'namespace' => [
709 ParamValidator::PARAM_ISMULTI => true,
710 ParamValidator::PARAM_TYPE => 'namespace'
711 ],
712 'prop' => [
713 ParamValidator::PARAM_ISMULTI => true,
714 ParamValidator::PARAM_DEFAULT => 'ids|title|timestamp|comment|size|flags',
715 ParamValidator::PARAM_TYPE => [
716 'ids',
717 'title',
718 'timestamp',
719 'comment',
720 'parsedcomment',
721 'size',
722 'sizediff',
723 'flags',
724 'patrolled',
725 'tags'
726 ],
728 ],
729 'show' => [
730 ParamValidator::PARAM_ISMULTI => true,
731 ParamValidator::PARAM_TYPE => [
732 'minor',
733 '!minor',
734 'patrolled',
735 '!patrolled',
736 'autopatrolled',
737 '!autopatrolled',
738 'top',
739 '!top',
740 'new',
741 '!new',
742 ],
744 'apihelp-query+usercontribs-param-show',
745 $this->getConfig()->get( MainConfigNames::RCMaxAge )
746 ],
747 ],
748 'tag' => null,
749 'toponly' => [
750 ParamValidator::PARAM_DEFAULT => false,
751 ParamValidator::PARAM_DEPRECATED => true,
752 ],
753 ];
754 }
755
756 protected function getExamplesMessages() {
757 return [
758 'action=query&list=usercontribs&ucuser=Example'
759 => 'apihelp-query+usercontribs-example-user',
760 'action=query&list=usercontribs&ucuserprefix=192.0.2.'
761 => 'apihelp-query+usercontribs-example-ipprefix',
762 ];
763 }
764
765 public function getHelpUrls() {
766 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Usercontribs';
767 }
768}
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
wfEscapeWikiText( $text)
Escapes the given text so that it may be output using addWikiText() without any linking,...
dieWithError( $msg, $code=null, $data=null, $httpCode=0)
Abort execution with an error.
Definition ApiBase.php:1460
encodeParamName( $paramName)
This method mangles parameter name based on the prefix supplied to the constructor.
Definition ApiBase.php:751
dieContinueUsageIf( $condition)
Die with the 'badcontinue' error.
Definition ApiBase.php:1688
requireOnlyOneParameter( $params,... $required)
Die if none or more than one of a certain set of parameters is set and not false.
Definition ApiBase.php:911
parseContinueParamOrDie(string $continue, array $types)
Parse the 'continue' parameter in the usual format and validate the types of each part,...
Definition ApiBase.php:1649
const PARAM_HELP_MSG_PER_VALUE
((string|array|Message)[]) When PARAM_TYPE is an array, or 'string' with PARAM_ISMULTI,...
Definition ApiBase.php:204
const LIMIT_BIG1
Fast query, standard limit.
Definition ApiBase.php:229
getResult()
Get the result object.
Definition ApiBase.php:637
extractRequestParams( $options=[])
Using getAllowedParams(), this function makes an array of the values provided by the user,...
Definition ApiBase.php:773
const PARAM_HELP_MSG
(string|array|Message) Specify an alternative i18n documentation message for this parameter.
Definition ApiBase.php:166
const LIMIT_BIG2
Fast query, apihighlimits limit.
Definition ApiBase.php:231
getModuleName()
Get the name of the module being executed by this instance.
Definition ApiBase.php:506
This is a base class for all Query modules.
static addTitleInfo(&$arr, $title, $prefix='')
Add information (title and namespace) about a Title object to a result array.
setContinueEnumParameter( $paramName, $paramValue)
Set a query-continue value.
processRow( $row, array &$data, array &$hookData)
Call the ApiQueryBaseProcessRow hook.
resetQueryParams()
Blank the internal arrays with query parameters.
addWhereIf( $value, $condition)
Same as addWhere(), but add the WHERE clauses only if a condition is met.
addWhereRange( $field, $dir, $start, $end, $sort=true)
Add a WHERE clause corresponding to a range, and an ORDER BY clause to sort in the right direction.
addFields( $value)
Add a set of fields to select to the internal array.
addOption( $name, $value=null)
Add an option such as LIMIT or USE INDEX.
addTables( $tables, $alias=null)
Add a set of tables to the internal array.
addTimestampWhereRange( $field, $dir, $start, $end, $sort=true)
Add a WHERE clause corresponding to a range, similar to addWhereRange, but converts $start and $end t...
getDB()
Get the Query database connection (read-only)
executeGenderCacheFromResultWrapper(IResultWrapper $res, $fname=__METHOD__, $fieldPrefix='page')
Preprocess the result set to fill the GenderCache with the necessary information before using self::a...
select( $method, $extraQuery=[], array &$hookData=null)
Execute a SELECT query based on the values in the internal arrays.
addFieldsIf( $value, $condition)
Same as addFields(), but add the fields only if a condition is met.
addJoinConds( $join_conds)
Add a set of JOIN conditions to the internal array.
addWhereFld( $field, $value)
Equivalent to addWhere( [ $field => $value ] )
addWhere( $value)
Add a set of WHERE clauses to the internal array.
This query action adds a list of a specified user's contributions to the output.
getAllowedParams()
Returns an array of allowed parameters (parameter name) => (default value) or (parameter name) => (ar...
getCacheMode( $params)
Get the cache mode for the data generated by this module.
getHelpUrls()
Return links to more detailed help pages about the module.
__construct(ApiQuery $query, $moduleName, CommentStore $commentStore, UserIdentityLookup $userIdentityLookup, UserNameUtils $userNameUtils, RevisionStore $revisionStore, NameTableStore $changeTagDefStore, ActorMigration $actorMigration, CommentFormatter $commentFormatter)
getExamplesMessages()
Returns usage examples for this module.
execute()
Evaluates the parameters, performs the requested query, and sets up the result.
This is the main query class.
Definition ApiQuery.php:42
static setIndexedTagName(array &$arr, $tag)
Set the tag name for numeric-keyed values in XML format.
static makeTagSummarySubquery( $tables)
Make the tag summary subquery based on the given tables and return it.
This is the main service interface for converting single-line comments from various DB comment fields...
Handle database storage of comments such as edit summaries and log reasons.
A class containing constants representing the names of configuration variables.
Type definition for user types.
Definition UserDef.php:27
Page revision base class.
Service for looking up page revisions.
Exception representing a failure to look up a row from a name table.
Represents a title within MediaWiki.
Definition Title.php:82
This is not intended to be a long-term part of MediaWiki; it will be deprecated and removed once acto...
UserNameUtils service.
const PRC_UNPATROLLED
const PRC_AUTOPATROLLED
static newFromName( $name, $validate='valid')
Definition User.php:592
Service for formatting and validating API parameters.
Type definition for integer types.
A query builder for SELECT queries with a fluent interface.
Interface for objects representing user identity.
return true
Definition router.php:92