MediaWiki  master
ApiQueryUserContribs.php
Go to the documentation of this file.
1 <?php
32 
39 
41  private $commentStore;
42 
45 
47  private $userNameUtils;
48 
50  private $revisionStore;
51 
54 
56  private $actorMigration;
57 
68  public function __construct(
69  ApiQuery $query,
70  $moduleName,
77  ) {
78  parent::__construct( $query, $moduleName, 'uc' );
79  $this->commentStore = $commentStore;
80  $this->userIdentityLookup = $userIdentityLookup;
81  $this->userNameUtils = $userNameUtils;
82  $this->revisionStore = $revisionStore;
83  $this->changeTagDefStore = $changeTagDefStore;
84  $this->actorMigration = $actorMigration;
85  }
86 
88 
89  private $fld_ids = false, $fld_title = false, $fld_timestamp = false,
90  $fld_comment = false, $fld_parsedcomment = false, $fld_flags = false,
91  $fld_patrolled = false, $fld_tags = false, $fld_size = false, $fld_sizediff = false;
92 
93  public function execute() {
94  // Parse some parameters
95  $this->params = $this->extractRequestParams();
96 
97  $prop = array_fill_keys( $this->params['prop'], true );
98  $this->fld_ids = isset( $prop['ids'] );
99  $this->fld_title = isset( $prop['title'] );
100  $this->fld_comment = isset( $prop['comment'] );
101  $this->fld_parsedcomment = isset( $prop['parsedcomment'] );
102  $this->fld_size = isset( $prop['size'] );
103  $this->fld_sizediff = isset( $prop['sizediff'] );
104  $this->fld_flags = isset( $prop['flags'] );
105  $this->fld_timestamp = isset( $prop['timestamp'] );
106  $this->fld_patrolled = isset( $prop['patrolled'] );
107  $this->fld_tags = isset( $prop['tags'] );
108 
109  // The main query may use the 'contributions' group DB, which can map to replica DBs
110  // with extra user based indexes or partioning by user. The additional metadata
111  // queries should use a regular replica DB since the lookup pattern is not all by user.
112  $dbSecondary = $this->getDB(); // any random replica DB
113 
114  $sort = ( $this->params['dir'] == 'newer' ?
115  SelectQueryBuilder::SORT_ASC : SelectQueryBuilder::SORT_DESC );
116  $op = ( $this->params['dir'] == 'older' ? '<' : '>' );
117 
118  // Create an Iterator that produces the UserIdentity objects we need, depending
119  // on which of the 'userprefix', 'userids', or 'user' params was
120  // specified.
121  $this->requireOnlyOneParameter( $this->params, 'userprefix', 'userids', 'user' );
122  if ( isset( $this->params['userprefix'] ) ) {
123  $this->multiUserMode = true;
124  $this->orderBy = 'name';
125  $fname = __METHOD__;
126 
127  // Because 'userprefix' might produce a huge number of users (e.g.
128  // a wiki with users "Test00000001" to "Test99999999"), use a
129  // generator with batched lookup and continuation.
130  $userIter = call_user_func( function () use ( $dbSecondary, $sort, $op, $fname ) {
131  $fromName = false;
132  if ( $this->params['continue'] !== null ) {
133  $continue = explode( '|', $this->params['continue'] );
134  $this->dieContinueUsageIf( count( $continue ) != 4 );
135  $this->dieContinueUsageIf( $continue[0] !== 'name' );
136  $fromName = $continue[1];
137  }
138 
139  $limit = 501;
140  do {
141  $from = $fromName ? "$op= " . $dbSecondary->addQuotes( $fromName ) : false;
142  $usersBatch = $this->userIdentityLookup
143  ->newSelectQueryBuilder()
144  ->caller( $fname )
145  ->limit( $limit )
146  ->whereUserNamePrefix( $this->params['userprefix'] )
147  ->where( $from ? [ "actor_name $from" ] : [] )
148  ->orderByName( $sort )
149  ->fetchUserIdentities();
150 
151  $count = 0;
152  $fromName = false;
153  foreach ( $usersBatch as $user ) {
154  if ( ++$count >= $limit ) {
155  $fromName = $user->getName();
156  break;
157  }
158  yield $user;
159  }
160  } while ( $fromName !== false );
161  } );
162  // Do the actual sorting client-side, because otherwise
163  // prepareQuery might try to sort by actor and confuse everything.
164  $batchSize = 1;
165  } elseif ( isset( $this->params['userids'] ) ) {
166  if ( $this->params['userids'] === [] ) {
167  $encParamName = $this->encodeParamName( 'userids' );
168  $this->dieWithError( [ 'apierror-paramempty', $encParamName ], "paramempty_$encParamName" );
169  }
170 
171  $ids = [];
172  foreach ( $this->params['userids'] as $uid ) {
173  if ( $uid <= 0 ) {
174  $this->dieWithError( [ 'apierror-invaliduserid', $uid ], 'invaliduserid' );
175  }
176  $ids[] = $uid;
177  }
178 
179  $this->orderBy = 'id';
180  $this->multiUserMode = count( $ids ) > 1;
181 
182  $from = $fromId = false;
183  if ( $this->multiUserMode && $this->params['continue'] !== null ) {
184  $continue = explode( '|', $this->params['continue'] );
185  $this->dieContinueUsageIf( count( $continue ) != 4 );
186  $this->dieContinueUsageIf( $continue[0] !== 'id' && $continue[0] !== 'actor' );
187  $fromId = (int)$continue[1];
188  $this->dieContinueUsageIf( $continue[1] !== (string)$fromId );
189  $from = "$op= $fromId";
190  }
191 
192  $userIter = $this->userIdentityLookup
193  ->newSelectQueryBuilder()
194  ->caller( __METHOD__ )
195  ->whereUserIds( $ids )
196  ->orderByUserId( $sort )
197  ->where( $from ? [ "actor_id $from" ] : [] )
198  ->fetchUserIdentities();
199  $batchSize = count( $ids );
200  } else {
201  $names = [];
202  if ( !count( $this->params['user'] ) ) {
203  $encParamName = $this->encodeParamName( 'user' );
204  $this->dieWithError(
205  [ 'apierror-paramempty', $encParamName ], "paramempty_$encParamName"
206  );
207  }
208  foreach ( $this->params['user'] as $u ) {
209  if ( $u === '' ) {
210  $encParamName = $this->encodeParamName( 'user' );
211  $this->dieWithError(
212  [ 'apierror-paramempty', $encParamName ], "paramempty_$encParamName"
213  );
214  }
215 
216  if ( $this->userNameUtils->isIP( $u ) || ExternalUserNames::isExternal( $u ) ) {
217  $names[$u] = null;
218  } else {
219  $name = $this->userNameUtils->getCanonical( $u );
220  if ( $name === false ) {
221  $encParamName = $this->encodeParamName( 'user' );
222  $this->dieWithError(
223  [ 'apierror-baduser', $encParamName, wfEscapeWikiText( $u ) ], "baduser_$encParamName"
224  );
225  }
226  $names[$name] = null;
227  }
228  }
229 
230  $this->orderBy = 'name';
231  $this->multiUserMode = count( $names ) > 1;
232 
233  $from = $fromName = false;
234  if ( $this->multiUserMode && $this->params['continue'] !== null ) {
235  $continue = explode( '|', $this->params['continue'] );
236  $this->dieContinueUsageIf( count( $continue ) != 4 );
237  $this->dieContinueUsageIf( $continue[0] !== 'name' && $continue[0] !== 'actor' );
238  $fromName = $continue[1];
239  $from = "$op= " . $dbSecondary->addQuotes( $fromName );
240  }
241 
242  $userIter = $this->userIdentityLookup
243  ->newSelectQueryBuilder()
244  ->caller( __METHOD__ )
245  ->whereUserNames( array_keys( $names ) )
246  ->where( $from ? [ "actor_id $from" ] : [] )
247  ->orderByName( $sort )
248  ->fetchUserIdentities();
249  $batchSize = count( $names );
250  }
251 
252  // The DB query will order by actor so update $this->orderBy to match.
253  if ( $batchSize > 1 ) {
254  $this->orderBy = 'actor';
255  }
256 
257  $count = 0;
258  $limit = $this->params['limit'];
259  $userIter->rewind();
260  while ( $userIter->valid() ) {
261  $users = [];
262  while ( count( $users ) < $batchSize && $userIter->valid() ) {
263  $users[] = $userIter->current();
264  $userIter->next();
265  }
266 
267  $hookData = [];
268  $this->prepareQuery( $users, $limit - $count );
269  $res = $this->select( __METHOD__, [], $hookData );
270 
271  if ( $this->fld_title ) {
272  $this->executeGenderCacheFromResultWrapper( $res, __METHOD__ );
273  }
274 
275  if ( $this->fld_sizediff ) {
276  $revIds = [];
277  foreach ( $res as $row ) {
278  if ( $row->rev_parent_id ) {
279  $revIds[] = $row->rev_parent_id;
280  }
281  }
282  $this->parentLens = $this->revisionStore->getRevisionSizes( $revIds );
283  }
284 
285  foreach ( $res as $row ) {
286  if ( ++$count > $limit ) {
287  // We've reached the one extra which shows that there are
288  // additional pages to be had. Stop here...
289  $this->setContinueEnumParameter( 'continue', $this->continueStr( $row ) );
290  break 2;
291  }
292 
293  $vals = $this->extractRowInfo( $row );
294  $fit = $this->processRow( $row, $vals, $hookData ) &&
295  $this->getResult()->addValue( [ 'query', $this->getModuleName() ], null, $vals );
296  if ( !$fit ) {
297  $this->setContinueEnumParameter( 'continue', $this->continueStr( $row ) );
298  break 2;
299  }
300  }
301  }
302 
303  $this->getResult()->addIndexedTagName( [ 'query', $this->getModuleName() ], 'item' );
304  }
305 
311  private function prepareQuery( array $users, $limit ) {
313 
314  $this->resetQueryParams();
315  $db = $this->getDB();
316 
317  $revQuery = $this->revisionStore->getQueryInfo( [ 'page' ] );
318  $revWhere = $this->actorMigration->getWhere( $db, 'rev_user', $users );
319 
321  $orderUserField = 'rev_actor';
322  $userField = $this->orderBy === 'actor' ? 'revactor_actor' : 'actor_name';
323  $tsField = 'revactor_timestamp';
324  $idField = 'revactor_rev';
325 
326  // T221511: MySQL/MariaDB (10.1.37) can sometimes irrationally decide that querying `actor`
327  // before `revision_actor_temp` and filesorting is somehow better than querying $limit+1 rows
328  // from `revision_actor_temp`. Tell it not to reorder the query (and also reorder it ourselves
329  // because as generated by RevisionStore it'll have `revision` first rather than
330  // `revision_actor_temp`). But not when uctag is used, as it seems as likely to be harmed as
331  // helped in that case, and not when there's only one User because in that case it fetches
332  // the one `actor` row as a constant and doesn't filesort.
333  if ( count( $users ) > 1 && !isset( $this->params['tag'] ) ) {
334  $revQuery['joins']['revision'] = $revQuery['joins']['temp_rev_user'];
335  unset( $revQuery['joins']['temp_rev_user'] );
336  $this->addOption( 'STRAIGHT_JOIN' );
337  // It isn't actually necesssary to reorder $revQuery['tables'] as Database does the right thing
338  // when join conditions are given for all joins, but GergÅ‘ is wary of relying on that so pull
339  // `revision_actor_temp` to the start.
340  $revQuery['tables'] =
341  [ 'temp_rev_user' => $revQuery['tables']['temp_rev_user'] ] + $revQuery['tables'];
342  }
343  } else /* SCHEMA_COMPAT_READ_NEW */ {
344  $orderUserField = 'rev_actor';
345  $userField = $this->orderBy === 'actor' ? 'rev_actor' : 'actor_name';
346  $tsField = 'rev_timestamp';
347  $idField = 'rev_id';
348  }
349 
350  $this->addTables( $revQuery['tables'] );
351  $this->addJoinConds( $revQuery['joins'] );
352  $this->addFields( $revQuery['fields'] );
353  $this->addWhere( $revWhere['conds'] );
354 
355  // Handle continue parameter
356  if ( $this->params['continue'] !== null ) {
357  $continue = explode( '|', $this->params['continue'] );
358  if ( $this->multiUserMode ) {
359  $this->dieContinueUsageIf( count( $continue ) != 4 );
360  $modeFlag = array_shift( $continue );
361  $this->dieContinueUsageIf( $modeFlag !== $this->orderBy );
362  $encUser = $db->addQuotes( array_shift( $continue ) );
363  } else {
364  $this->dieContinueUsageIf( count( $continue ) != 2 );
365  }
366  $encTS = $db->addQuotes( $db->timestamp( $continue[0] ) );
367  $encId = (int)$continue[1];
368  $this->dieContinueUsageIf( $encId != $continue[1] );
369  $op = ( $this->params['dir'] == 'older' ? '<' : '>' );
370  if ( $this->multiUserMode ) {
371  $this->addWhere(
372  "$userField $op $encUser OR " .
373  "($userField = $encUser AND " .
374  "($tsField $op $encTS OR " .
375  "($tsField = $encTS AND " .
376  "$idField $op= $encId)))"
377  );
378  } else {
379  $this->addWhere(
380  "$tsField $op $encTS OR " .
381  "($tsField = $encTS AND " .
382  "$idField $op= $encId)"
383  );
384  }
385  }
386 
387  // Don't include any revisions where we're not supposed to be able to
388  // see the username.
389  if ( !$this->getAuthority()->isAllowed( 'deletedhistory' ) ) {
390  $bitmask = RevisionRecord::DELETED_USER;
391  } elseif ( !$this->getAuthority()->isAllowedAny( 'suppressrevision', 'viewsuppressed' ) ) {
392  $bitmask = RevisionRecord::DELETED_USER | RevisionRecord::DELETED_RESTRICTED;
393  } else {
394  $bitmask = 0;
395  }
396  if ( $bitmask ) {
397  $this->addWhere( $db->bitAnd( 'rev_deleted', $bitmask ) . " != $bitmask" );
398  }
399 
400  // Add the user field to ORDER BY if there are multiple users
401  if ( count( $users ) > 1 ) {
402  $this->addWhereRange( $orderUserField, $this->params['dir'], null, null );
403  }
404 
405  // Then timestamp
406  $this->addTimestampWhereRange( $tsField,
407  $this->params['dir'], $this->params['start'], $this->params['end'] );
408 
409  // Then rev_id for a total ordering
410  $this->addWhereRange( $idField, $this->params['dir'], null, null );
411 
412  $this->addWhereFld( 'page_namespace', $this->params['namespace'] );
413 
414  $show = $this->params['show'];
415  if ( $this->params['toponly'] ) { // deprecated/old param
416  $show[] = 'top';
417  }
418  if ( $show !== null ) {
419  $show = array_fill_keys( $show, true );
420 
421  if ( ( isset( $show['minor'] ) && isset( $show['!minor'] ) )
422  || ( isset( $show['patrolled'] ) && isset( $show['!patrolled'] ) )
423  || ( isset( $show['autopatrolled'] ) && isset( $show['!autopatrolled'] ) )
424  || ( isset( $show['autopatrolled'] ) && isset( $show['!patrolled'] ) )
425  || ( isset( $show['top'] ) && isset( $show['!top'] ) )
426  || ( isset( $show['new'] ) && isset( $show['!new'] ) )
427  ) {
428  $this->dieWithError( 'apierror-show' );
429  }
430 
431  $this->addWhereIf( 'rev_minor_edit = 0', isset( $show['!minor'] ) );
432  $this->addWhereIf( 'rev_minor_edit != 0', isset( $show['minor'] ) );
433  $this->addWhereIf(
434  'rc_patrolled = ' . RecentChange::PRC_UNPATROLLED,
435  isset( $show['!patrolled'] )
436  );
437  $this->addWhereIf(
438  'rc_patrolled != ' . RecentChange::PRC_UNPATROLLED,
439  isset( $show['patrolled'] )
440  );
441  $this->addWhereIf(
442  'rc_patrolled != ' . RecentChange::PRC_AUTOPATROLLED,
443  isset( $show['!autopatrolled'] )
444  );
445  $this->addWhereIf(
446  'rc_patrolled = ' . RecentChange::PRC_AUTOPATROLLED,
447  isset( $show['autopatrolled'] )
448  );
449  $this->addWhereIf( $idField . ' != page_latest', isset( $show['!top'] ) );
450  $this->addWhereIf( $idField . ' = page_latest', isset( $show['top'] ) );
451  $this->addWhereIf( 'rev_parent_id != 0', isset( $show['!new'] ) );
452  $this->addWhereIf( 'rev_parent_id = 0', isset( $show['new'] ) );
453  }
454  $this->addOption( 'LIMIT', $limit + 1 );
455 
456  if ( isset( $show['patrolled'] ) || isset( $show['!patrolled'] ) ||
457  isset( $show['autopatrolled'] ) || isset( $show['!autopatrolled'] ) || $this->fld_patrolled
458  ) {
459  $user = $this->getUser();
460  if ( !$user->useRCPatrol() && !$user->useNPPatrol() ) {
461  $this->dieWithError( 'apierror-permissiondenied-patrolflag', 'permissiondenied' );
462  }
463 
464  $isFilterset = isset( $show['patrolled'] ) || isset( $show['!patrolled'] ) ||
465  isset( $show['autopatrolled'] ) || isset( $show['!autopatrolled'] );
466  $this->addTables( 'recentchanges' );
467  $this->addJoinConds( [ 'recentchanges' => [
468  $isFilterset ? 'JOIN' : 'LEFT JOIN',
469  [ 'rc_this_oldid = ' . $idField ]
470  ] ] );
471  }
472 
473  $this->addFieldsIf( 'rc_patrolled', $this->fld_patrolled );
474 
475  if ( $this->fld_tags ) {
476  $this->addFields( [ 'ts_tags' => ChangeTags::makeTagSummarySubquery( 'revision' ) ] );
477  }
478 
479  if ( isset( $this->params['tag'] ) ) {
480  $this->addTables( 'change_tag' );
481  $this->addJoinConds(
482  [ 'change_tag' => [ 'JOIN', [ $idField . ' = ct_rev_id' ] ] ]
483  );
484  try {
485  $this->addWhereFld( 'ct_tag_id', $this->changeTagDefStore->getId( $this->params['tag'] ) );
486  } catch ( NameTableAccessException $exception ) {
487  // Return nothing.
488  $this->addWhere( '1=0' );
489  }
490  }
491  }
492 
499  private function extractRowInfo( $row ) {
500  $vals = [];
501  $anyHidden = false;
502 
503  if ( $row->rev_deleted & RevisionRecord::DELETED_TEXT ) {
504  $vals['texthidden'] = true;
505  $anyHidden = true;
506  }
507 
508  // Any rows where we can't view the user were filtered out in the query.
509  $vals['userid'] = (int)$row->rev_user;
510  $vals['user'] = $row->rev_user_text;
511  if ( $row->rev_deleted & RevisionRecord::DELETED_USER ) {
512  $vals['userhidden'] = true;
513  $anyHidden = true;
514  }
515  if ( $this->fld_ids ) {
516  $vals['pageid'] = (int)$row->rev_page;
517  $vals['revid'] = (int)$row->rev_id;
518 
519  if ( $row->rev_parent_id !== null ) {
520  $vals['parentid'] = (int)$row->rev_parent_id;
521  }
522  }
523 
524  $title = Title::makeTitle( $row->page_namespace, $row->page_title );
525 
526  if ( $this->fld_title ) {
528  }
529 
530  if ( $this->fld_timestamp ) {
531  $vals['timestamp'] = wfTimestamp( TS_ISO_8601, $row->rev_timestamp );
532  }
533 
534  if ( $this->fld_flags ) {
535  $vals['new'] = $row->rev_parent_id == 0 && $row->rev_parent_id !== null;
536  $vals['minor'] = (bool)$row->rev_minor_edit;
537  $vals['top'] = $row->page_latest == $row->rev_id;
538  }
539 
540  if ( $this->fld_comment || $this->fld_parsedcomment ) {
541  if ( $row->rev_deleted & RevisionRecord::DELETED_COMMENT ) {
542  $vals['commenthidden'] = true;
543  $anyHidden = true;
544  }
545 
546  $userCanView = RevisionRecord::userCanBitfield(
547  $row->rev_deleted,
548  RevisionRecord::DELETED_COMMENT, $this->getUser()
549  );
550 
551  if ( $userCanView ) {
552  $comment = $this->commentStore->getComment( 'rev_comment', $row )->text;
553  if ( $this->fld_comment ) {
554  $vals['comment'] = $comment;
555  }
556 
557  if ( $this->fld_parsedcomment ) {
558  $vals['parsedcomment'] = Linker::formatComment( $comment, $title );
559  }
560  }
561  }
562 
563  if ( $this->fld_patrolled ) {
564  $vals['patrolled'] = $row->rc_patrolled != RecentChange::PRC_UNPATROLLED;
565  $vals['autopatrolled'] = $row->rc_patrolled == RecentChange::PRC_AUTOPATROLLED;
566  }
567 
568  if ( $this->fld_size && $row->rev_len !== null ) {
569  $vals['size'] = (int)$row->rev_len;
570  }
571 
572  if ( $this->fld_sizediff
573  && $row->rev_len !== null
574  && $row->rev_parent_id !== null
575  ) {
576  $parentLen = $this->parentLens[$row->rev_parent_id] ?? 0;
577  $vals['sizediff'] = (int)$row->rev_len - $parentLen;
578  }
579 
580  if ( $this->fld_tags ) {
581  if ( $row->ts_tags ) {
582  $tags = explode( ',', $row->ts_tags );
583  ApiResult::setIndexedTagName( $tags, 'tag' );
584  $vals['tags'] = $tags;
585  } else {
586  $vals['tags'] = [];
587  }
588  }
589 
590  if ( $anyHidden && ( $row->rev_deleted & RevisionRecord::DELETED_RESTRICTED ) ) {
591  $vals['suppressed'] = true;
592  }
593 
594  return $vals;
595  }
596 
597  private function continueStr( $row ) {
598  if ( $this->multiUserMode ) {
599  switch ( $this->orderBy ) {
600  case 'id':
601  return "id|$row->rev_user|$row->rev_timestamp|$row->rev_id";
602  case 'name':
603  return "name|$row->rev_user_text|$row->rev_timestamp|$row->rev_id";
604  case 'actor':
605  return "actor|$row->rev_actor|$row->rev_timestamp|$row->rev_id";
606  }
607  } else {
608  return "$row->rev_timestamp|$row->rev_id";
609  }
610  }
611 
612  public function getCacheMode( $params ) {
613  // This module provides access to deleted revisions and patrol flags if
614  // the requester is logged in
615  return 'anon-public-user-private';
616  }
617 
618  public function getAllowedParams() {
619  return [
620  'limit' => [
621  ApiBase::PARAM_DFLT => 10,
622  ApiBase::PARAM_TYPE => 'limit',
623  ApiBase::PARAM_MIN => 1,
626  ],
627  'start' => [
628  ApiBase::PARAM_TYPE => 'timestamp'
629  ],
630  'end' => [
631  ApiBase::PARAM_TYPE => 'timestamp'
632  ],
633  'continue' => [
634  ApiBase::PARAM_HELP_MSG => 'api-help-param-continue',
635  ],
636  'user' => [
637  ApiBase::PARAM_TYPE => 'user',
638  UserDef::PARAM_ALLOWED_USER_TYPES => [ 'name', 'ip', 'interwiki' ],
640  ],
641  'userids' => [
642  ApiBase::PARAM_TYPE => 'integer',
644  ],
645  'userprefix' => null,
646  'dir' => [
647  ApiBase::PARAM_DFLT => 'older',
649  'newer',
650  'older'
651  ],
652  ApiBase::PARAM_HELP_MSG => 'api-help-param-direction',
653  ],
654  'namespace' => [
655  ApiBase::PARAM_ISMULTI => true,
656  ApiBase::PARAM_TYPE => 'namespace'
657  ],
658  'prop' => [
659  ApiBase::PARAM_ISMULTI => true,
660  ApiBase::PARAM_DFLT => 'ids|title|timestamp|comment|size|flags',
662  'ids',
663  'title',
664  'timestamp',
665  'comment',
666  'parsedcomment',
667  'size',
668  'sizediff',
669  'flags',
670  'patrolled',
671  'tags'
672  ],
674  ],
675  'show' => [
676  ApiBase::PARAM_ISMULTI => true,
678  'minor',
679  '!minor',
680  'patrolled',
681  '!patrolled',
682  'autopatrolled',
683  '!autopatrolled',
684  'top',
685  '!top',
686  'new',
687  '!new',
688  ],
690  'apihelp-query+usercontribs-param-show',
691  $this->getConfig()->get( 'RCMaxAge' )
692  ],
693  ],
694  'tag' => null,
695  'toponly' => [
696  ApiBase::PARAM_DFLT => false,
698  ],
699  ];
700  }
701 
702  protected function getExamplesMessages() {
703  return [
704  'action=query&list=usercontribs&ucuser=Example'
705  => 'apihelp-query+usercontribs-example-user',
706  'action=query&list=usercontribs&ucuserprefix=192.0.2.'
707  => 'apihelp-query+usercontribs-example-ipprefix',
708  ];
709  }
710 
711  public function getHelpUrls() {
712  return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Usercontribs';
713  }
714 }
715 
720 class_alias( ApiQueryUserContribs::class, 'ApiQueryContributions' );
ContextSource\getConfig
getConfig()
Definition: ContextSource.php:72
ChangeTags\makeTagSummarySubquery
static makeTagSummarySubquery( $tables)
Make the tag summary subquery based on the given tables and return it.
Definition: ChangeTags.php:983
ApiQueryBase\processRow
processRow( $row, array &$data, array &$hookData)
Call the ApiQueryBaseProcessRow hook.
Definition: ApiQueryBase.php:449
ApiQueryBase\addFields
addFields( $value)
Add a set of fields to select to the internal array.
Definition: ApiQueryBase.php:212
ApiQueryUserContribs\$fld_timestamp
$fld_timestamp
Definition: ApiQueryUserContribs.php:89
ApiQuery
This is the main query class.
Definition: ApiQuery.php:37
MediaWiki\Revision\RevisionRecord
Page revision base class.
Definition: RevisionRecord.php:47
ApiQueryUserContribs\$fld_title
$fld_title
Definition: ApiQueryUserContribs.php:89
ApiQueryBase\resetQueryParams
resetQueryParams()
Blank the internal arrays with query parameters.
Definition: ApiQueryBase.php:156
if
if(ini_get( 'mbstring.func_overload')) if(!defined('MW_ENTRY_POINT'))
Pre-config setup: Before loading LocalSettings.php.
Definition: Setup.php:88
MediaWiki\Revision\RevisionStore
Service for looking up page revisions.
Definition: RevisionStore.php:88
ApiBase\dieWithError
dieWithError( $msg, $code=null, $data=null, $httpCode=null)
Abort execution with an error.
Definition: ApiBase.php:1379
ApiQueryBase\addTimestampWhereRange
addTimestampWhereRange( $field, $dir, $start, $end, $sort=true)
Add a WHERE clause corresponding to a range, similar to addWhereRange, but converts $start and $end t...
Definition: ApiQueryBase.php:366
ApiBase\PARAM_HELP_MSG
const PARAM_HELP_MSG
(string|array|Message) Specify an alternative i18n documentation message for this parameter.
Definition: ApiBase.php:105
true
return true
Definition: router.php:90
ApiQueryUserContribs\$fld_patrolled
$fld_patrolled
Definition: ApiQueryUserContribs.php:91
wfTimestamp
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
Definition: GlobalFunctions.php:1691
ApiBase\PARAM_TYPE
const PARAM_TYPE
Definition: ApiBase.php:72
ApiBase\getResult
getResult()
Get the result object.
Definition: ApiBase.php:571
ApiQueryUserContribs\$changeTagDefStore
NameTableStore $changeTagDefStore
Definition: ApiQueryUserContribs.php:53
CommentStore
Handle database storage of comments such as edit summaries and log reasons.
Definition: CommentStore.php:42
ApiQueryUserContribs\$fld_size
$fld_size
Definition: ApiQueryUserContribs.php:91
ApiQueryBase\addOption
addOption( $name, $value=null)
Add an option such as LIMIT or USE INDEX.
Definition: ApiQueryBase.php:378
ActorMigration
This is not intended to be a long-term part of MediaWiki; it will be deprecated and removed once acto...
Definition: ActorMigration.php:15
$res
$res
Definition: testCompression.php:57
ContextSource\getUser
getUser()
Definition: ContextSource.php:136
ApiQueryUserContribs\$fld_sizediff
$fld_sizediff
Definition: ApiQueryUserContribs.php:91
$revQuery
$revQuery
Definition: testCompression.php:56
MediaWiki\User\UserIdentity
Interface for objects representing user identity.
Definition: UserIdentity.php:39
ApiQueryBase\addFieldsIf
addFieldsIf( $value, $condition)
Same as addFields(), but add the fields only if a condition is met.
Definition: ApiQueryBase.php:222
ApiQueryUserContribs\$orderBy
$orderBy
Definition: ApiQueryUserContribs.php:87
Wikimedia\ParamValidator\ParamValidator::TypeDef\UserDef
Type definition for user types.
Definition: UserDef.php:26
ApiBase\PARAM_DEPRECATED
const PARAM_DEPRECATED
Definition: ApiBase.php:77
ApiBase\PARAM_MIN
const PARAM_MIN
Definition: ApiBase.php:75
ApiQueryBase\executeGenderCacheFromResultWrapper
executeGenderCacheFromResultWrapper(IResultWrapper $res, $fname=__METHOD__, $fieldPrefix='page')
Preprocess the result set to fill the GenderCache with the necessary information before using self::a...
Definition: ApiQueryBase.php:626
ApiQueryUserContribs\$userNameUtils
UserNameUtils $userNameUtils
Definition: ApiQueryUserContribs.php:47
ApiQueryBase
This is a base class for all Query modules.
Definition: ApiQueryBase.php:37
ApiBase\LIMIT_BIG1
const LIMIT_BIG1
Fast query, standard limit.
Definition: ApiBase.php:163
ApiQueryUserContribs
This query action adds a list of a specified user's contributions to the output.
Definition: ApiQueryUserContribs.php:38
ApiQueryUserContribs\__construct
__construct(ApiQuery $query, $moduleName, CommentStore $commentStore, UserIdentityLookup $userIdentityLookup, UserNameUtils $userNameUtils, RevisionStore $revisionStore, NameTableStore $changeTagDefStore, ActorMigration $actorMigration)
Definition: ApiQueryUserContribs.php:68
ApiQueryBase\getDB
getDB()
Get the Query database connection (read-only)
Definition: ApiQueryBase.php:117
ApiQueryUserContribs\execute
execute()
Evaluates the parameters, performs the requested query, and sets up the result.
Definition: ApiQueryUserContribs.php:93
ApiBase\PARAM_MAX
const PARAM_MAX
Definition: ApiBase.php:73
Wikimedia\Rdbms\SelectQueryBuilder
Definition: SelectQueryBuilder.php:11
ApiQueryUserContribs\$parentLens
$parentLens
Definition: ApiQueryUserContribs.php:87
ApiQueryBase\addTables
addTables( $tables, $alias=null)
Add a set of tables to the internal array.
Definition: ApiQueryBase.php:182
ApiQueryBase\select
select( $method, $extraQuery=[], array &$hookData=null)
Execute a SELECT query based on the values in the internal arrays.
Definition: ApiQueryBase.php:399
ApiQueryUserContribs\$fld_parsedcomment
$fld_parsedcomment
Definition: ApiQueryUserContribs.php:90
ApiBase\extractRequestParams
extractRequestParams( $options=[])
Using getAllowedParams(), this function makes an array of the values provided by the user,...
Definition: ApiBase.php:707
$title
$title
Definition: testCompression.php:38
Title\makeTitle
static makeTitle( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:651
ApiQueryUserContribs\extractRowInfo
extractRowInfo( $row)
Extract fields from the database row and append them to a result array.
Definition: ApiQueryUserContribs.php:499
ApiQueryBase\addWhereRange
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.
Definition: ApiQueryBase.php:337
ApiQueryUserContribs\continueStr
continueStr( $row)
Definition: ApiQueryUserContribs.php:597
MediaWiki\User\UserIdentityLookup
Definition: UserIdentityLookup.php:33
ApiQueryUserContribs\prepareQuery
prepareQuery(array $users, $limit)
Prepares the query and returns the limit of rows requested.
Definition: ApiQueryUserContribs.php:311
ApiResult\setIndexedTagName
static setIndexedTagName(array &$arr, $tag)
Set the tag name for numeric-keyed values in XML format.
Definition: ApiResult.php:603
ApiBase\requireOnlyOneParameter
requireOnlyOneParameter( $params,... $required)
Die if none or more than one of a certain set of parameters is set and not false.
Definition: ApiBase.php:844
ApiQueryUserContribs\getExamplesMessages
getExamplesMessages()
Returns usage examples for this module.
Definition: ApiQueryUserContribs.php:702
ApiBase\dieContinueUsageIf
dieContinueUsageIf( $condition)
Die with the 'badcontinue' error.
Definition: ApiBase.php:1563
ApiQueryUserContribs\$fld_comment
$fld_comment
Definition: ApiQueryUserContribs.php:90
ContextSource\getAuthority
getAuthority()
Definition: ContextSource.php:144
ApiBase\encodeParamName
encodeParamName( $paramName)
This method mangles parameter name based on the prefix supplied to the constructor.
Definition: ApiBase.php:685
ApiQueryUserContribs\$params
$params
Definition: ApiQueryUserContribs.php:87
ApiQueryUserContribs\getHelpUrls
getHelpUrls()
Return links to more detailed help pages about the module.
Definition: ApiQueryUserContribs.php:711
ApiQueryUserContribs\getCacheMode
getCacheMode( $params)
Get the cache mode for the data generated by this module.
Definition: ApiQueryUserContribs.php:612
ApiQueryBase\addJoinConds
addJoinConds( $join_conds)
Add a set of JOIN conditions to the internal array.
Definition: ApiQueryBase.php:201
wfEscapeWikiText
wfEscapeWikiText( $text)
Escapes the given text so that it may be output using addWikiText() without any linking,...
Definition: GlobalFunctions.php:1455
ApiQueryUserContribs\$userIdentityLookup
UserIdentityLookup $userIdentityLookup
Definition: ApiQueryUserContribs.php:44
ApiQueryBase\addWhereFld
addWhereFld( $field, $value)
Equivalent to addWhere( [ $field => $value ] )
Definition: ApiQueryBase.php:282
MediaWiki\Storage\NameTableStore
Definition: NameTableStore.php:36
ApiQueryUserContribs\getAllowedParams
getAllowedParams()
Returns an array of allowed parameters (parameter name) => (default value) or (parameter name) => (ar...
Definition: ApiQueryUserContribs.php:618
RecentChange\PRC_AUTOPATROLLED
const PRC_AUTOPATROLLED
Definition: RecentChange.php:93
Linker\formatComment
static formatComment( $comment, $title=null, $local=false, $wikiId=null)
This function is called by all recent changes variants, by the page history, and by the user contribu...
Definition: Linker.php:1372
ApiQueryUserContribs\$commentStore
CommentStore $commentStore
Definition: ApiQueryUserContribs.php:41
ApiQueryUserContribs\$multiUserMode
$multiUserMode
Definition: ApiQueryUserContribs.php:87
ApiQueryUserContribs\$actorMigration
ActorMigration $actorMigration
Definition: ApiQueryUserContribs.php:56
ApiBase\LIMIT_BIG2
const LIMIT_BIG2
Fast query, apihighlimits limit.
Definition: ApiBase.php:165
MediaWiki\User\UserNameUtils
UserNameUtils service.
Definition: UserNameUtils.php:42
ApiBase\PARAM_DFLT
const PARAM_DFLT
Definition: ApiBase.php:70
RecentChange\PRC_UNPATROLLED
const PRC_UNPATROLLED
Definition: RecentChange.php:91
ApiBase\getModuleName
getModuleName()
Get the name of the module being executed by this instance.
Definition: ApiBase.php:440
MediaWiki\Storage\NameTableAccessException
Exception representing a failure to look up a row from a name table.
Definition: NameTableAccessException.php:33
ApiBase\PARAM_ISMULTI
const PARAM_ISMULTI
Definition: ApiBase.php:71
ApiQueryUserContribs\$fld_ids
$fld_ids
Definition: ApiQueryUserContribs.php:89
ApiBase\PARAM_MAX2
const PARAM_MAX2
Definition: ApiBase.php:74
ApiQueryUserContribs\$revisionStore
RevisionStore $revisionStore
Definition: ApiQueryUserContribs.php:50
ApiQueryBase\addWhere
addWhere( $value)
Add a set of WHERE clauses to the internal array.
Definition: ApiQueryBase.php:245
ApiQueryBase\setContinueEnumParameter
setContinueEnumParameter( $paramName, $paramValue)
Set a query-continue value.
Definition: ApiQueryBase.php:515
ApiBase\PARAM_HELP_MSG_PER_VALUE
const PARAM_HELP_MSG_PER_VALUE
((string|array|Message)[]) When PARAM_TYPE is an array, this is an array mapping those values to $msg...
Definition: ApiBase.php:138
ApiQueryUserContribs\$fld_flags
$fld_flags
Definition: ApiQueryUserContribs.php:90
ExternalUserNames\isExternal
static isExternal( $username)
Tells whether the username is external or not.
Definition: ExternalUserNames.php:149
ApiQueryBase\addWhereIf
addWhereIf( $value, $condition)
Same as addWhere(), but add the WHERE clauses only if a condition is met.
Definition: ApiQueryBase.php:263
SCHEMA_COMPAT_READ_TEMP
const SCHEMA_COMPAT_READ_TEMP
Definition: Defines.php:265
ApiQueryBase\addTitleInfo
static addTitleInfo(&$arr, $title, $prefix='')
Add information (title and namespace) about a Title object to a result array.
Definition: ApiQueryBase.php:466
ApiQueryUserContribs\$fld_tags
$fld_tags
Definition: ApiQueryUserContribs.php:91
$wgActorTableSchemaMigrationStage
int $wgActorTableSchemaMigrationStage
Actor table schema migration stage, for migration from the temporary table revision_actor_temp to the...
Definition: DefaultSettings.php:2405