MediaWiki  1.33.0
ApiQueryUserContribs.php
Go to the documentation of this file.
1 <?php
26 
33 
34  public function __construct( ApiQuery $query, $moduleName ) {
35  parent::__construct( $query, $moduleName, 'uc' );
36  }
37 
39 
40  private $fld_ids = false, $fld_title = false, $fld_timestamp = false,
41  $fld_comment = false, $fld_parsedcomment = false, $fld_flags = false,
42  $fld_patrolled = false, $fld_tags = false, $fld_size = false, $fld_sizediff = false;
43 
44  public function execute() {
46 
47  // Parse some parameters
48  $this->params = $this->extractRequestParams();
49 
50  $this->commentStore = CommentStore::getStore();
51 
52  $prop = array_flip( $this->params['prop'] );
53  $this->fld_ids = isset( $prop['ids'] );
54  $this->fld_title = isset( $prop['title'] );
55  $this->fld_comment = isset( $prop['comment'] );
56  $this->fld_parsedcomment = isset( $prop['parsedcomment'] );
57  $this->fld_size = isset( $prop['size'] );
58  $this->fld_sizediff = isset( $prop['sizediff'] );
59  $this->fld_flags = isset( $prop['flags'] );
60  $this->fld_timestamp = isset( $prop['timestamp'] );
61  $this->fld_patrolled = isset( $prop['patrolled'] );
62  $this->fld_tags = isset( $prop['tags'] );
63 
64  // The main query may use the 'contributions' group DB, which can map to replica DBs
65  // with extra user based indexes or partioning by user. The additional metadata
66  // queries should use a regular replica DB since the lookup pattern is not all by user.
67  $dbSecondary = $this->getDB(); // any random replica DB
68 
69  $sort = ( $this->params['dir'] == 'newer' ? '' : ' DESC' );
70  $op = ( $this->params['dir'] == 'older' ? '<' : '>' );
71 
72  // Create an Iterator that produces the UserIdentity objects we need, depending
73  // on which of the 'userprefix', 'userids', or 'user' params was
74  // specified.
75  $this->requireOnlyOneParameter( $this->params, 'userprefix', 'userids', 'user' );
76  if ( isset( $this->params['userprefix'] ) ) {
77  $this->multiUserMode = true;
78  $this->orderBy = 'name';
79  $fname = __METHOD__;
80 
81  // Because 'userprefix' might produce a huge number of users (e.g.
82  // a wiki with users "Test00000001" to "Test99999999"), use a
83  // generator with batched lookup and continuation.
84  $userIter = call_user_func( function () use ( $dbSecondary, $sort, $op, $fname ) {
86 
87  $fromName = false;
88  if ( !is_null( $this->params['continue'] ) ) {
89  $continue = explode( '|', $this->params['continue'] );
90  $this->dieContinueUsageIf( count( $continue ) != 4 );
91  $this->dieContinueUsageIf( $continue[0] !== 'name' );
92  $fromName = $continue[1];
93  }
94  $like = $dbSecondary->buildLike( $this->params['userprefix'], $dbSecondary->anyString() );
95 
96  $limit = 501;
97 
98  do {
99  $from = $fromName ? "$op= " . $dbSecondary->addQuotes( $fromName ) : false;
100 
101  // For the new schema, pull from the actor table. For the
102  // old, pull from rev_user.
104  $res = $dbSecondary->select(
105  'actor',
106  [ 'actor_id', 'user_id' => 'COALESCE(actor_user,0)', 'user_name' => 'actor_name' ],
107  array_merge( [ "actor_name$like" ], $from ? [ "actor_name $from" ] : [] ),
108  $fname,
109  [ 'ORDER BY' => [ "user_name $sort" ], 'LIMIT' => $limit ]
110  );
111  } else {
112  $res = $dbSecondary->select(
113  'revision',
114  [ 'actor_id' => 'NULL', 'user_id' => 'rev_user', 'user_name' => 'rev_user_text' ],
115  array_merge( [ "rev_user_text$like" ], $from ? [ "rev_user_text $from" ] : [] ),
116  $fname,
117  [ 'DISTINCT', 'ORDER BY' => [ "rev_user_text $sort" ], 'LIMIT' => $limit ]
118  );
119  }
120 
121  $count = 0;
122  $fromName = false;
123  foreach ( $res as $row ) {
124  if ( ++$count >= $limit ) {
125  $fromName = $row->user_name;
126  break;
127  }
128  yield User::newFromRow( $row );
129  }
130  } while ( $fromName !== false );
131  } );
132  // Do the actual sorting client-side, because otherwise
133  // prepareQuery might try to sort by actor and confuse everything.
134  $batchSize = 1;
135  } elseif ( isset( $this->params['userids'] ) ) {
136  if ( $this->params['userids'] === [] ) {
137  $encParamName = $this->encodeParamName( 'userids' );
138  $this->dieWithError( [ 'apierror-paramempty', $encParamName ], "paramempty_$encParamName" );
139  }
140 
141  $ids = [];
142  foreach ( $this->params['userids'] as $uid ) {
143  if ( $uid <= 0 ) {
144  $this->dieWithError( [ 'apierror-invaliduserid', $uid ], 'invaliduserid' );
145  }
146  $ids[] = $uid;
147  }
148 
149  $this->orderBy = 'id';
150  $this->multiUserMode = count( $ids ) > 1;
151 
152  $from = $fromId = false;
153  if ( $this->multiUserMode && !is_null( $this->params['continue'] ) ) {
154  $continue = explode( '|', $this->params['continue'] );
155  $this->dieContinueUsageIf( count( $continue ) != 4 );
156  $this->dieContinueUsageIf( $continue[0] !== 'id' && $continue[0] !== 'actor' );
157  $fromId = (int)$continue[1];
158  $this->dieContinueUsageIf( $continue[1] !== (string)$fromId );
159  $from = "$op= $fromId";
160  }
161 
162  // For the new schema, just select from the actor table. For the
163  // old, select from user.
165  $res = $dbSecondary->select(
166  'actor',
167  [ 'actor_id', 'user_id' => 'actor_user', 'user_name' => 'actor_name' ],
168  array_merge( [ 'actor_user' => $ids ], $from ? [ "actor_id $from" ] : [] ),
169  __METHOD__,
170  [ 'ORDER BY' => "user_id $sort" ]
171  );
172  } else {
173  $res = $dbSecondary->select(
174  'user',
175  [ 'actor_id' => 'NULL', 'user_id' => 'user_id', 'user_name' => 'user_name' ],
176  array_merge( [ 'user_id' => $ids ], $from ? [ "user_id $from" ] : [] ),
177  __METHOD__,
178  [ 'ORDER BY' => "user_id $sort" ]
179  );
180  }
181  $userIter = UserArray::newFromResult( $res );
182  $batchSize = count( $ids );
183  } else {
184  $names = [];
185  if ( !count( $this->params['user'] ) ) {
186  $encParamName = $this->encodeParamName( 'user' );
187  $this->dieWithError(
188  [ 'apierror-paramempty', $encParamName ], "paramempty_$encParamName"
189  );
190  }
191  foreach ( $this->params['user'] as $u ) {
192  if ( $u === '' ) {
193  $encParamName = $this->encodeParamName( 'user' );
194  $this->dieWithError(
195  [ 'apierror-paramempty', $encParamName ], "paramempty_$encParamName"
196  );
197  }
198 
199  if ( User::isIP( $u ) || ExternalUserNames::isExternal( $u ) ) {
200  $names[$u] = null;
201  } else {
202  $name = User::getCanonicalName( $u, 'valid' );
203  if ( $name === false ) {
204  $encParamName = $this->encodeParamName( 'user' );
205  $this->dieWithError(
206  [ 'apierror-baduser', $encParamName, wfEscapeWikiText( $u ) ], "baduser_$encParamName"
207  );
208  }
209  $names[$name] = null;
210  }
211  }
212 
213  $this->orderBy = 'name';
214  $this->multiUserMode = count( $names ) > 1;
215 
216  $from = $fromName = false;
217  if ( $this->multiUserMode && !is_null( $this->params['continue'] ) ) {
218  $continue = explode( '|', $this->params['continue'] );
219  $this->dieContinueUsageIf( count( $continue ) != 4 );
220  $this->dieContinueUsageIf( $continue[0] !== 'name' && $continue[0] !== 'actor' );
221  $fromName = $continue[1];
222  $from = "$op= " . $dbSecondary->addQuotes( $fromName );
223  }
224 
225  // For the new schema, just select from the actor table. For the
226  // old, select from user then merge in any unknown users (IPs and imports).
228  $res = $dbSecondary->select(
229  'actor',
230  [ 'actor_id', 'user_id' => 'actor_user', 'user_name' => 'actor_name' ],
231  array_merge( [ 'actor_name' => array_keys( $names ) ], $from ? [ "actor_id $from" ] : [] ),
232  __METHOD__,
233  [ 'ORDER BY' => "actor_name $sort" ]
234  );
235  $userIter = UserArray::newFromResult( $res );
236  } else {
237  $res = $dbSecondary->select(
238  'user',
239  [ 'actor_id' => 'NULL', 'user_id', 'user_name' ],
240  array_merge( [ 'user_name' => array_keys( $names ) ], $from ? [ "user_name $from" ] : [] ),
241  __METHOD__
242  );
243  foreach ( $res as $row ) {
244  $names[$row->user_name] = $row;
245  }
246  if ( $this->params['dir'] == 'newer' ) {
247  ksort( $names, SORT_STRING );
248  } else {
249  krsort( $names, SORT_STRING );
250  }
251  $neg = $op === '>' ? -1 : 1;
252  $userIter = call_user_func( function () use ( $names, $fromName, $neg ) {
253  foreach ( $names as $name => $row ) {
254  if ( $fromName === false || $neg * strcmp( $name, $fromName ) <= 0 ) {
255  $user = $row ? User::newFromRow( $row ) : User::newFromName( $name, false );
256  yield $user;
257  }
258  }
259  } );
260  }
261  $batchSize = count( $names );
262  }
263 
264  // With the new schema, the DB query will order by actor so update $this->orderBy to match.
265  if ( $batchSize > 1 && ( $wgActorTableSchemaMigrationStage & SCHEMA_COMPAT_READ_NEW ) ) {
266  $this->orderBy = 'actor';
267  }
268 
269  // Use the 'contributions' replica, but only if we're querying by user ID (T216656).
270  if ( $this->orderBy === 'id' &&
272  ) {
273  $this->selectNamedDB( 'contributions', DB_REPLICA, 'contributions' );
274  }
275 
276  $count = 0;
277  $limit = $this->params['limit'];
278  $userIter->rewind();
279  while ( $userIter->valid() ) {
280  $users = [];
281  while ( count( $users ) < $batchSize && $userIter->valid() ) {
282  $users[] = $userIter->current();
283  $userIter->next();
284  }
285 
286  $hookData = [];
287  $this->prepareQuery( $users, $limit - $count );
288  $res = $this->select( __METHOD__, [], $hookData );
289 
290  if ( $this->fld_sizediff ) {
291  $revIds = [];
292  foreach ( $res as $row ) {
293  if ( $row->rev_parent_id ) {
294  $revIds[] = $row->rev_parent_id;
295  }
296  }
297  $this->parentLens = MediaWikiServices::getInstance()->getRevisionStore()
298  ->listRevisionSizes( $dbSecondary, $revIds );
299  }
300 
301  foreach ( $res as $row ) {
302  if ( ++$count > $limit ) {
303  // We've reached the one extra which shows that there are
304  // additional pages to be had. Stop here...
305  $this->setContinueEnumParameter( 'continue', $this->continueStr( $row ) );
306  break 2;
307  }
308 
309  $vals = $this->extractRowInfo( $row );
310  $fit = $this->processRow( $row, $vals, $hookData ) &&
311  $this->getResult()->addValue( [ 'query', $this->getModuleName() ], null, $vals );
312  if ( !$fit ) {
313  $this->setContinueEnumParameter( 'continue', $this->continueStr( $row ) );
314  break 2;
315  }
316  }
317  }
318 
319  $this->getResult()->addIndexedTagName( [ 'query', $this->getModuleName() ], 'item' );
320  }
321 
327  private function prepareQuery( array $users, $limit ) {
329 
330  $this->resetQueryParams();
331  $db = $this->getDB();
332 
333  $revQuery = MediaWikiServices::getInstance()->getRevisionStore()->getQueryInfo( [ 'page' ] );
334  $this->addTables( $revQuery['tables'] );
335  $this->addJoinConds( $revQuery['joins'] );
336  $this->addFields( $revQuery['fields'] );
337 
338  if ( $wgActorTableSchemaMigrationStage & SCHEMA_COMPAT_READ_NEW ) {
339  $revWhere = ActorMigration::newMigration()->getWhere( $db, 'rev_user', $users );
340  $orderUserField = 'rev_actor';
341  $userField = $this->orderBy === 'actor' ? 'revactor_actor' : 'actor_name';
342  $tsField = 'revactor_timestamp';
343  $idField = 'revactor_rev';
344  } else {
345  // If we're dealing with user names (rather than IDs) in read-old mode,
346  // pass false for ActorMigration::getWhere()'s $useId parameter so
347  // $revWhere['conds'] isn't an OR.
348  $revWhere = ActorMigration::newMigration()
349  ->getWhere( $db, 'rev_user', $users, $this->orderBy === 'id' );
350  $orderUserField = $this->orderBy === 'id' ? 'rev_user' : 'rev_user_text';
351  $userField = $revQuery['fields'][$orderUserField];
352  $tsField = 'rev_timestamp';
353  $idField = 'rev_id';
354  }
355 
356  $this->addWhere( $revWhere['conds'] );
357 
358  // Handle continue parameter
359  if ( !is_null( $this->params['continue'] ) ) {
360  $continue = explode( '|', $this->params['continue'] );
361  if ( $this->multiUserMode ) {
362  $this->dieContinueUsageIf( count( $continue ) != 4 );
363  $modeFlag = array_shift( $continue );
364  $this->dieContinueUsageIf( $modeFlag !== $this->orderBy );
365  $encUser = $db->addQuotes( array_shift( $continue ) );
366  } else {
367  $this->dieContinueUsageIf( count( $continue ) != 2 );
368  }
369  $encTS = $db->addQuotes( $db->timestamp( $continue[0] ) );
370  $encId = (int)$continue[1];
371  $this->dieContinueUsageIf( $encId != $continue[1] );
372  $op = ( $this->params['dir'] == 'older' ? '<' : '>' );
373  if ( $this->multiUserMode ) {
374  $this->addWhere(
375  "$userField $op $encUser OR " .
376  "($userField = $encUser AND " .
377  "($tsField $op $encTS OR " .
378  "($tsField = $encTS AND " .
379  "$idField $op= $encId)))"
380  );
381  } else {
382  $this->addWhere(
383  "$tsField $op $encTS OR " .
384  "($tsField = $encTS AND " .
385  "$idField $op= $encId)"
386  );
387  }
388  }
389 
390  // Don't include any revisions where we're not supposed to be able to
391  // see the username.
392  $user = $this->getUser();
393  if ( !$user->isAllowed( 'deletedhistory' ) ) {
394  $bitmask = RevisionRecord::DELETED_USER;
395  } elseif ( !$user->isAllowedAny( 'suppressrevision', 'viewsuppressed' ) ) {
396  $bitmask = RevisionRecord::DELETED_USER | RevisionRecord::DELETED_RESTRICTED;
397  } else {
398  $bitmask = 0;
399  }
400  if ( $bitmask ) {
401  $this->addWhere( $db->bitAnd( 'rev_deleted', $bitmask ) . " != $bitmask" );
402  }
403 
404  // Add the user field to ORDER BY if there are multiple users
405  if ( count( $users ) > 1 ) {
406  $this->addWhereRange( $orderUserField, $this->params['dir'], null, null );
407  }
408 
409  // Then timestamp
410  $this->addTimestampWhereRange( $tsField,
411  $this->params['dir'], $this->params['start'], $this->params['end'] );
412 
413  // Then rev_id for a total ordering
414  $this->addWhereRange( $idField, $this->params['dir'], null, null );
415 
416  $this->addWhereFld( 'page_namespace', $this->params['namespace'] );
417 
418  $show = $this->params['show'];
419  if ( $this->params['toponly'] ) { // deprecated/old param
420  $show[] = 'top';
421  }
422  if ( !is_null( $show ) ) {
423  $show = array_flip( $show );
424 
425  if ( ( isset( $show['minor'] ) && isset( $show['!minor'] ) )
426  || ( isset( $show['patrolled'] ) && isset( $show['!patrolled'] ) )
427  || ( isset( $show['autopatrolled'] ) && isset( $show['!autopatrolled'] ) )
428  || ( isset( $show['autopatrolled'] ) && isset( $show['!patrolled'] ) )
429  || ( isset( $show['top'] ) && isset( $show['!top'] ) )
430  || ( isset( $show['new'] ) && isset( $show['!new'] ) )
431  ) {
432  $this->dieWithError( 'apierror-show' );
433  }
434 
435  $this->addWhereIf( 'rev_minor_edit = 0', isset( $show['!minor'] ) );
436  $this->addWhereIf( 'rev_minor_edit != 0', isset( $show['minor'] ) );
437  $this->addWhereIf(
438  'rc_patrolled = ' . RecentChange::PRC_UNPATROLLED,
439  isset( $show['!patrolled'] )
440  );
441  $this->addWhereIf(
442  'rc_patrolled != ' . RecentChange::PRC_UNPATROLLED,
443  isset( $show['patrolled'] )
444  );
445  $this->addWhereIf(
446  'rc_patrolled != ' . RecentChange::PRC_AUTOPATROLLED,
447  isset( $show['!autopatrolled'] )
448  );
449  $this->addWhereIf(
450  'rc_patrolled = ' . RecentChange::PRC_AUTOPATROLLED,
451  isset( $show['autopatrolled'] )
452  );
453  $this->addWhereIf( $idField . ' != page_latest', isset( $show['!top'] ) );
454  $this->addWhereIf( $idField . ' = page_latest', isset( $show['top'] ) );
455  $this->addWhereIf( 'rev_parent_id != 0', isset( $show['!new'] ) );
456  $this->addWhereIf( 'rev_parent_id = 0', isset( $show['new'] ) );
457  }
458  $this->addOption( 'LIMIT', $limit + 1 );
459 
460  if ( isset( $show['patrolled'] ) || isset( $show['!patrolled'] ) ||
461  isset( $show['autopatrolled'] ) || isset( $show['!autopatrolled'] ) || $this->fld_patrolled
462  ) {
463  if ( !$user->useRCPatrol() && !$user->useNPPatrol() ) {
464  $this->dieWithError( 'apierror-permissiondenied-patrolflag', 'permissiondenied' );
465  }
466 
467  $isFilterset = isset( $show['patrolled'] ) || isset( $show['!patrolled'] ) ||
468  isset( $show['autopatrolled'] ) || isset( $show['!autopatrolled'] );
469  $this->addTables( 'recentchanges' );
470  $this->addJoinConds( [ 'recentchanges' => [
471  $isFilterset ? 'JOIN' : 'LEFT JOIN',
472  [
473  // This is a crazy hack. recentchanges has no index on rc_this_oldid, so instead of adding
474  // one T19237 did a join using rc_user_text and rc_timestamp instead. Now rc_user_text is
475  // probably unavailable, so just do rc_timestamp.
476  'rc_timestamp = ' . $tsField,
477  'rc_this_oldid = ' . $idField,
478  ]
479  ] ] );
480  }
481 
482  $this->addFieldsIf( 'rc_patrolled', $this->fld_patrolled );
483 
484  if ( $this->fld_tags ) {
485  $this->addFields( [ 'ts_tags' => ChangeTags::makeTagSummarySubquery( 'revision' ) ] );
486  }
487 
488  if ( isset( $this->params['tag'] ) ) {
489  $this->addTables( 'change_tag' );
490  $this->addJoinConds(
491  [ 'change_tag' => [ 'JOIN', [ $idField . ' = ct_rev_id' ] ] ]
492  );
493  $changeTagDefStore = MediaWikiServices::getInstance()->getChangeTagDefStore();
494  try {
495  $this->addWhereFld( 'ct_tag_id', $changeTagDefStore->getId( $this->params['tag'] ) );
496  } catch ( NameTableAccessException $exception ) {
497  // Return nothing.
498  $this->addWhere( '1=0' );
499  }
500  }
501  }
502 
509  private function extractRowInfo( $row ) {
510  $vals = [];
511  $anyHidden = false;
512 
513  if ( $row->rev_deleted & RevisionRecord::DELETED_TEXT ) {
514  $vals['texthidden'] = true;
515  $anyHidden = true;
516  }
517 
518  // Any rows where we can't view the user were filtered out in the query.
519  $vals['userid'] = (int)$row->rev_user;
520  $vals['user'] = $row->rev_user_text;
521  if ( $row->rev_deleted & RevisionRecord::DELETED_USER ) {
522  $vals['userhidden'] = true;
523  $anyHidden = true;
524  }
525  if ( $this->fld_ids ) {
526  $vals['pageid'] = (int)$row->rev_page;
527  $vals['revid'] = (int)$row->rev_id;
528 
529  if ( !is_null( $row->rev_parent_id ) ) {
530  $vals['parentid'] = (int)$row->rev_parent_id;
531  }
532  }
533 
534  $title = Title::makeTitle( $row->page_namespace, $row->page_title );
535 
536  if ( $this->fld_title ) {
538  }
539 
540  if ( $this->fld_timestamp ) {
541  $vals['timestamp'] = wfTimestamp( TS_ISO_8601, $row->rev_timestamp );
542  }
543 
544  if ( $this->fld_flags ) {
545  $vals['new'] = $row->rev_parent_id == 0 && !is_null( $row->rev_parent_id );
546  $vals['minor'] = (bool)$row->rev_minor_edit;
547  $vals['top'] = $row->page_latest == $row->rev_id;
548  }
549 
550  if ( $this->fld_comment || $this->fld_parsedcomment ) {
551  if ( $row->rev_deleted & RevisionRecord::DELETED_COMMENT ) {
552  $vals['commenthidden'] = true;
553  $anyHidden = true;
554  }
555 
556  $userCanView = RevisionRecord::userCanBitfield(
557  $row->rev_deleted,
558  RevisionRecord::DELETED_COMMENT, $this->getUser()
559  );
560 
561  if ( $userCanView ) {
562  $comment = $this->commentStore->getComment( 'rev_comment', $row )->text;
563  if ( $this->fld_comment ) {
564  $vals['comment'] = $comment;
565  }
566 
567  if ( $this->fld_parsedcomment ) {
568  $vals['parsedcomment'] = Linker::formatComment( $comment, $title );
569  }
570  }
571  }
572 
573  if ( $this->fld_patrolled ) {
574  $vals['patrolled'] = $row->rc_patrolled != RecentChange::PRC_UNPATROLLED;
575  $vals['autopatrolled'] = $row->rc_patrolled == RecentChange::PRC_AUTOPATROLLED;
576  }
577 
578  if ( $this->fld_size && !is_null( $row->rev_len ) ) {
579  $vals['size'] = (int)$row->rev_len;
580  }
581 
582  if ( $this->fld_sizediff
583  && !is_null( $row->rev_len )
584  && !is_null( $row->rev_parent_id )
585  ) {
586  $parentLen = $this->parentLens[$row->rev_parent_id] ?? 0;
587  $vals['sizediff'] = (int)$row->rev_len - $parentLen;
588  }
589 
590  if ( $this->fld_tags ) {
591  if ( $row->ts_tags ) {
592  $tags = explode( ',', $row->ts_tags );
593  ApiResult::setIndexedTagName( $tags, 'tag' );
594  $vals['tags'] = $tags;
595  } else {
596  $vals['tags'] = [];
597  }
598  }
599 
600  if ( $anyHidden && ( $row->rev_deleted & RevisionRecord::DELETED_RESTRICTED ) ) {
601  $vals['suppressed'] = true;
602  }
603 
604  return $vals;
605  }
606 
607  private function continueStr( $row ) {
608  if ( $this->multiUserMode ) {
609  switch ( $this->orderBy ) {
610  case 'id':
611  return "id|$row->rev_user|$row->rev_timestamp|$row->rev_id";
612  case 'name':
613  return "name|$row->rev_user_text|$row->rev_timestamp|$row->rev_id";
614  case 'actor':
615  return "actor|$row->rev_actor|$row->rev_timestamp|$row->rev_id";
616  }
617  } else {
618  return "$row->rev_timestamp|$row->rev_id";
619  }
620  }
621 
622  public function getCacheMode( $params ) {
623  // This module provides access to deleted revisions and patrol flags if
624  // the requester is logged in
625  return 'anon-public-user-private';
626  }
627 
628  public function getAllowedParams() {
629  return [
630  'limit' => [
631  ApiBase::PARAM_DFLT => 10,
632  ApiBase::PARAM_TYPE => 'limit',
633  ApiBase::PARAM_MIN => 1,
636  ],
637  'start' => [
638  ApiBase::PARAM_TYPE => 'timestamp'
639  ],
640  'end' => [
641  ApiBase::PARAM_TYPE => 'timestamp'
642  ],
643  'continue' => [
644  ApiBase::PARAM_HELP_MSG => 'api-help-param-continue',
645  ],
646  'user' => [
647  ApiBase::PARAM_TYPE => 'user',
649  ],
650  'userids' => [
651  ApiBase::PARAM_TYPE => 'integer',
653  ],
654  'userprefix' => null,
655  'dir' => [
656  ApiBase::PARAM_DFLT => 'older',
658  'newer',
659  'older'
660  ],
661  ApiBase::PARAM_HELP_MSG => 'api-help-param-direction',
662  ],
663  'namespace' => [
664  ApiBase::PARAM_ISMULTI => true,
665  ApiBase::PARAM_TYPE => 'namespace'
666  ],
667  'prop' => [
668  ApiBase::PARAM_ISMULTI => true,
669  ApiBase::PARAM_DFLT => 'ids|title|timestamp|comment|size|flags',
671  'ids',
672  'title',
673  'timestamp',
674  'comment',
675  'parsedcomment',
676  'size',
677  'sizediff',
678  'flags',
679  'patrolled',
680  'tags'
681  ],
683  ],
684  'show' => [
685  ApiBase::PARAM_ISMULTI => true,
687  'minor',
688  '!minor',
689  'patrolled',
690  '!patrolled',
691  'autopatrolled',
692  '!autopatrolled',
693  'top',
694  '!top',
695  'new',
696  '!new',
697  ],
699  'apihelp-query+usercontribs-param-show',
700  $this->getConfig()->get( 'RCMaxAge' )
701  ],
702  ],
703  'tag' => null,
704  'toponly' => [
705  ApiBase::PARAM_DFLT => false,
707  ],
708  ];
709  }
710 
711  protected function getExamplesMessages() {
712  return [
713  'action=query&list=usercontribs&ucuser=Example'
714  => 'apihelp-query+usercontribs-example-user',
715  'action=query&list=usercontribs&ucuserprefix=192.0.2.'
716  => 'apihelp-query+usercontribs-example-ipprefix',
717  ];
718  }
719 
720  public function getHelpUrls() {
721  return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Usercontribs';
722  }
723 }
724 
729 class_alias( ApiQueryUserContribs::class, 'ApiQueryContributions' );
ContextSource\getConfig
getConfig()
Definition: ContextSource.php:63
ChangeTags\makeTagSummarySubquery
static makeTagSummarySubquery( $tables)
Make the tag summary subquery based on the given tables and return it.
Definition: ChangeTags.php:793
$user
return true to allow those checks to and false if checking is done & $user
Definition: hooks.txt:1476
if
if($IP===false)
Definition: cleanupArchiveUserText.php:4
ApiQueryBase\processRow
processRow( $row, array &$data, array &$hookData)
Call the ApiQueryBaseProcessRow hook.
Definition: ApiQueryBase.php:422
ApiQueryBase\addFields
addFields( $value)
Add a set of fields to select to the internal array.
Definition: ApiQueryBase.php:190
ApiQueryUserContribs\$fld_timestamp
$fld_timestamp
Definition: ApiQueryUserContribs.php:40
ApiQuery
This is the main query class.
Definition: ApiQuery.php:36
Revision\RevisionRecord
Page revision base class.
Definition: RevisionRecord.php:45
SCHEMA_COMPAT_READ_NEW
const SCHEMA_COMPAT_READ_NEW
Definition: Defines.php:287
ApiQueryUserContribs\$fld_title
$fld_title
Definition: ApiQueryUserContribs.php:40
ApiQueryBase\resetQueryParams
resetQueryParams()
Blank the internal arrays with query parameters.
Definition: ApiQueryBase.php:144
captcha-old.count
count
Definition: captcha-old.py:249
ApiBase\dieWithError
dieWithError( $msg, $code=null, $data=null, $httpCode=null)
Abort execution with an error.
Definition: ApiBase.php:1990
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:335
ApiBase\PARAM_HELP_MSG
const PARAM_HELP_MSG
(string|array|Message) Specify an alternative i18n documentation message for this parameter.
Definition: ApiBase.php:124
ApiQueryUserContribs\$fld_patrolled
$fld_patrolled
Definition: ApiQueryUserContribs.php:42
wfTimestamp
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
Definition: GlobalFunctions.php:1912
ApiBase\PARAM_TYPE
const PARAM_TYPE
(string|string[]) Either an array of allowed value strings, or a string type as described below.
Definition: ApiBase.php:87
ApiBase\getResult
getResult()
Get the result object.
Definition: ApiBase.php:632
ApiQueryUserContribs\$fld_size
$fld_size
Definition: ApiQueryUserContribs.php:42
User\newFromName
static newFromName( $name, $validate='valid')
Static factory method for creation from username.
Definition: User.php:585
$res
$res
Definition: database.txt:21
ApiQueryBase\addOption
addOption( $name, $value=null)
Add an option such as LIMIT or USE INDEX.
Definition: ApiQueryBase.php:347
ContextSource\getUser
getUser()
Definition: ContextSource.php:120
User\newFromRow
static newFromRow( $row, $data=null)
Create a new user object from a user row.
Definition: User.php:772
ApiQueryUserContribs\$fld_sizediff
$fld_sizediff
Definition: ApiQueryUserContribs.php:42
$revQuery
$revQuery
Definition: testCompression.php:51
ActorMigration\newMigration
static newMigration()
Static constructor.
Definition: ActorMigration.php:111
ApiQueryBase\addFieldsIf
addFieldsIf( $value, $condition)
Same as addFields(), but add the fields only if a condition is met.
Definition: ApiQueryBase.php:204
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
ApiQueryUserContribs\__construct
__construct(ApiQuery $query, $moduleName)
Definition: ApiQueryUserContribs.php:34
ApiQueryUserContribs\$orderBy
$orderBy
Definition: ApiQueryUserContribs.php:38
ApiBase\PARAM_DEPRECATED
const PARAM_DEPRECATED
(boolean) Is the parameter deprecated (will show a warning)?
Definition: ApiBase.php:105
$query
null for the wiki Added should default to null in handler for backwards compatibility add a value to it if you want to add a cookie that have to vary cache options can modify $query
Definition: hooks.txt:1588
ApiBase\PARAM_MIN
const PARAM_MIN
(integer) Lowest value allowed for the parameter, for PARAM_TYPE 'integer' and 'limit'.
Definition: ApiBase.php:99
$title
namespace and then decline to actually register it file or subcat img or subcat $title
Definition: hooks.txt:925
ApiQueryBase
This is a base class for all Query modules.
Definition: ApiQueryBase.php:33
ApiBase\LIMIT_BIG1
const LIMIT_BIG1
Fast query, standard limit.
Definition: ApiBase.php:252
ApiQueryUserContribs
This query action adds a list of a specified user's contributions to the output.
Definition: ApiQueryUserContribs.php:32
ApiQueryBase\getDB
getDB()
Get the Query database connection (read-only)
Definition: ApiQueryBase.php:105
ApiQueryUserContribs\execute
execute()
Evaluates the parameters, performs the requested query, and sets up the result.
Definition: ApiQueryUserContribs.php:44
UserArray\newFromResult
static newFromResult( $res)
Definition: UserArray.php:30
ApiBase\PARAM_MAX
const PARAM_MAX
(integer) Max value allowed for the parameter, for PARAM_TYPE 'integer' and 'limit'.
Definition: ApiBase.php:90
ApiQueryUserContribs\$parentLens
$parentLens
Definition: ApiQueryUserContribs.php:38
User\isIP
static isIP( $name)
Does the string match an anonymous IP address?
Definition: User.php:967
ApiQueryBase\addTables
addTables( $tables, $alias=null)
Add a set of tables to the internal array.
Definition: ApiQueryBase.php:158
ApiQueryBase\select
select( $method, $extraQuery=[], array &$hookData=null)
Execute a SELECT query based on the values in the internal arrays.
Definition: ApiQueryBase.php:372
use
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
Definition: MIT-LICENSE.txt:10
ApiQueryUserContribs\$fld_parsedcomment
$fld_parsedcomment
Definition: ApiQueryUserContribs.php:41
ApiBase\extractRequestParams
extractRequestParams( $options=[])
Using getAllowedParams(), this function makes an array of the values provided by the user,...
Definition: ApiBase.php:743
Title\makeTitle
static makeTitle( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:576
DB_REPLICA
const DB_REPLICA
Definition: defines.php:25
array
The wiki should then use memcached to cache various data To use multiple just add more items to the array To increase the weight of a make its entry a array("192.168.0.1:11211", 2))
ApiQueryUserContribs\extractRowInfo
extractRowInfo( $row)
Extract fields from the database row and append them to a result array.
Definition: ApiQueryUserContribs.php:509
$sort
$sort
Definition: profileinfo.php:328
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:300
$fname
if(defined( 'MW_SETUP_CALLBACK')) $fname
Customization point after all loading (constants, functions, classes, DefaultSettings,...
Definition: Setup.php:123
$name
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:271
ApiQueryUserContribs\continueStr
continueStr( $row)
Definition: ApiQueryUserContribs.php:607
ApiQueryUserContribs\prepareQuery
prepareQuery(array $users, $limit)
Prepares the query and returns the limit of rows requested.
Definition: ApiQueryUserContribs.php:327
ApiResult\setIndexedTagName
static setIndexedTagName(array &$arr, $tag)
Set the tag name for numeric-keyed values in XML format.
Definition: ApiResult.php:616
ApiQueryUserContribs\getExamplesMessages
getExamplesMessages()
Returns usage examples for this module.
Definition: ApiQueryUserContribs.php:711
ApiBase\dieContinueUsageIf
dieContinueUsageIf( $condition)
Die with the 'badcontinue' error.
Definition: ApiBase.php:2176
ApiQueryUserContribs\$fld_comment
$fld_comment
Definition: ApiQueryUserContribs.php:41
ApiBase\encodeParamName
encodeParamName( $paramName)
This method mangles parameter name based on the prefix supplied to the constructor.
Definition: ApiBase.php:721
ApiQueryUserContribs\$params
$params
Definition: ApiQueryUserContribs.php:38
ApiQueryUserContribs\getHelpUrls
getHelpUrls()
Return links to more detailed help pages about the module.
Definition: ApiQueryUserContribs.php:720
ApiQueryUserContribs\getCacheMode
getCacheMode( $params)
Get the cache mode for the data generated by this module.
Definition: ApiQueryUserContribs.php:622
ApiQueryBase\addJoinConds
addJoinConds( $join_conds)
Add a set of JOIN conditions to the internal array.
Definition: ApiQueryBase.php:179
wfEscapeWikiText
wfEscapeWikiText( $text)
Escapes the given text so that it may be output using addWikiText() without any linking,...
Definition: GlobalFunctions.php:1577
ApiQueryBase\addWhereFld
addWhereFld( $field, $value)
Equivalent to addWhere(array($field => $value))
Definition: ApiQueryBase.php:258
ApiQueryUserContribs\getAllowedParams
getAllowedParams()
Returns an array of allowed parameters (parameter name) => (default value) or (parameter name) => (ar...
Definition: ApiQueryUserContribs.php:628
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:875
RecentChange\PRC_AUTOPATROLLED
const PRC_AUTOPATROLLED
Definition: RecentChange.php:80
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:1122
ApiQueryUserContribs\$commentStore
$commentStore
Definition: ApiQueryUserContribs.php:38
ApiQueryUserContribs\$multiUserMode
$multiUserMode
Definition: ApiQueryUserContribs.php:38
ApiQueryBase\selectNamedDB
selectNamedDB( $name, $db, $groups)
Selects the query database connection with the given name.
Definition: ApiQueryBase.php:121
ApiBase\LIMIT_BIG2
const LIMIT_BIG2
Fast query, apihighlimits limit.
Definition: ApiBase.php:254
User\getCanonicalName
static getCanonicalName( $name, $validate='valid')
Given unvalidated user input, return a canonical username, or false if the username is invalid.
Definition: User.php:1244
ApiBase\PARAM_DFLT
const PARAM_DFLT
(null|boolean|integer|string) Default value of the parameter.
Definition: ApiBase.php:48
RecentChange\PRC_UNPATROLLED
const PRC_UNPATROLLED
Definition: RecentChange.php:78
as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
ApiBase\getModuleName
getModuleName()
Get the name of the module being executed by this instance.
Definition: ApiBase.php:512
MediaWiki\Storage\NameTableAccessException
Exception representing a failure to look up a row from a name table.
Definition: NameTableAccessException.php:32
ApiBase\PARAM_ISMULTI
const PARAM_ISMULTI
(boolean) Accept multiple pipe-separated values for this parameter (e.g.
Definition: ApiBase.php:51
ApiQueryUserContribs\$fld_ids
$fld_ids
Definition: ApiQueryUserContribs.php:40
ApiBase\PARAM_MAX2
const PARAM_MAX2
(integer) Max value allowed for the parameter for users with the apihighlimits right,...
Definition: ApiBase.php:96
true
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return true
Definition: hooks.txt:1985
ApiQueryBase\addWhere
addWhere( $value)
Add a set of WHERE clauses to the internal array.
Definition: ApiQueryBase.php:225
class
you have access to all of the normal MediaWiki so you can get a DB use the etc For full docs on the Maintenance class
Definition: maintenance.txt:52
ApiQueryBase\setContinueEnumParameter
setContinueEnumParameter( $paramName, $paramValue)
Set a query-continue value.
Definition: ApiQueryBase.php:559
MediaWikiServices
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency MediaWikiServices
Definition: injection.txt:23
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:157
CommentStore\getStore
static getStore()
Definition: CommentStore.php:130
ApiQueryUserContribs\$fld_flags
$fld_flags
Definition: ApiQueryUserContribs.php:41
ExternalUserNames\isExternal
static isExternal( $username)
Tells whether the username is external or not.
Definition: ExternalUserNames.php:135
ApiQueryBase\addWhereIf
addWhereIf( $value, $condition)
Same as addWhere(), but add the WHERE clauses only if a condition is met.
Definition: ApiQueryBase.php:243
ApiQueryBase\addTitleInfo
static addTitleInfo(&$arr, $title, $prefix='')
Add information (title and namespace) about a Title object to a result array.
Definition: ApiQueryBase.php:510
ApiQueryUserContribs\$fld_tags
$fld_tags
Definition: ApiQueryUserContribs.php:42
$wgActorTableSchemaMigrationStage
int $wgActorTableSchemaMigrationStage
Actor table schema migration stage.
Definition: DefaultSettings.php:8979