MediaWiki  REL1_31
ApiQueryUserContributions.php
Go to the documentation of this file.
1 <?php
29 
30  public function __construct( ApiQuery $query, $moduleName ) {
31  parent::__construct( $query, $moduleName, 'uc' );
32  }
33 
35  private $fld_ids = false, $fld_title = false, $fld_timestamp = false,
36  $fld_comment = false, $fld_parsedcomment = false, $fld_flags = false,
37  $fld_patrolled = false, $fld_tags = false, $fld_size = false, $fld_sizediff = false;
38 
39  public function execute() {
41 
42  // Parse some parameters
43  $this->params = $this->extractRequestParams();
44 
45  $this->commentStore = CommentStore::getStore();
46 
47  $prop = array_flip( $this->params['prop'] );
48  $this->fld_ids = isset( $prop['ids'] );
49  $this->fld_title = isset( $prop['title'] );
50  $this->fld_comment = isset( $prop['comment'] );
51  $this->fld_parsedcomment = isset( $prop['parsedcomment'] );
52  $this->fld_size = isset( $prop['size'] );
53  $this->fld_sizediff = isset( $prop['sizediff'] );
54  $this->fld_flags = isset( $prop['flags'] );
55  $this->fld_timestamp = isset( $prop['timestamp'] );
56  $this->fld_patrolled = isset( $prop['patrolled'] );
57  $this->fld_tags = isset( $prop['tags'] );
58 
59  // Most of this code will use the 'contributions' group DB, which can map to replica DBs
60  // with extra user based indexes or partioning by user. The additional metadata
61  // queries should use a regular replica DB since the lookup pattern is not all by user.
62  $dbSecondary = $this->getDB(); // any random replica DB
63 
64  // TODO: if the query is going only against the revision table, should this be done?
65  $this->selectNamedDB( 'contributions', DB_REPLICA, 'contributions' );
66 
67  $sort = ( $this->params['dir'] == 'newer' ? '' : ' DESC' );
68  $op = ( $this->params['dir'] == 'older' ? '<' : '>' );
69 
70  // Create an Iterator that produces the UserIdentity objects we need, depending
71  // on which of the 'userprefix', 'userids', or 'user' params was
72  // specified.
73  $this->requireOnlyOneParameter( $this->params, 'userprefix', 'userids', 'user' );
74  if ( isset( $this->params['userprefix'] ) ) {
75  $this->multiUserMode = true;
76  $this->orderBy = 'name';
77  $fname = __METHOD__;
78 
79  // Because 'userprefix' might produce a huge number of users (e.g.
80  // a wiki with users "Test00000001" to "Test99999999"), use a
81  // generator with batched lookup and continuation.
82  $userIter = call_user_func( function () use ( $dbSecondary, $sort, $op, $fname ) {
84 
85  $fromName = false;
86  if ( !is_null( $this->params['continue'] ) ) {
87  $continue = explode( '|', $this->params['continue'] );
88  $this->dieContinueUsageIf( count( $continue ) != 4 );
89  $this->dieContinueUsageIf( $continue[0] !== 'name' );
90  $fromName = $continue[1];
91  }
92  $like = $dbSecondary->buildLike( $this->params['userprefix'], $dbSecondary->anyString() );
93 
94  $limit = 501;
95 
96  do {
97  $from = $fromName ? "$op= " . $dbSecondary->addQuotes( $fromName ) : false;
98 
99  // For the new schema, pull from the actor table. For the
100  // old, pull from rev_user. For migration a FULL [OUTER]
101  // JOIN would be what we want, except MySQL doesn't support
102  // that so we have to UNION instead.
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  );
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  } else {
120  // There are three queries we have to combine to be sure of getting all results:
121  // - actor table (any rows that have been migrated will have empty rev_user_text)
122  // - revision+actor by user id
123  // - revision+actor by name for anons
124  $options = $dbSecondary->unionSupportsOrderAndLimit()
125  ? [ 'ORDER BY' => [ "user_name $sort" ], 'LIMIT' => $limit ] : [];
126  $subsql = [];
127  $subsql[] = $dbSecondary->selectSQLText(
128  'actor',
129  [ 'actor_id', 'user_id' => 'COALESCE(actor_user,0)', 'user_name' => 'actor_name' ],
130  array_merge( [ "actor_name$like" ], $from ? [ "actor_name $from" ] : [] ),
131  $fname,
132  $options
133  );
134  $subsql[] = $dbSecondary->selectSQLText(
135  [ 'revision', 'actor' ],
136  [ 'actor_id', 'user_id' => 'rev_user', 'user_name' => 'rev_user_text' ],
137  array_merge(
138  [ "rev_user_text$like", 'rev_user != 0' ],
139  $from ? [ "rev_user_text $from" ] : []
140  ),
141  $fname,
142  array_merge( [ 'DISTINCT' ], $options ),
143  [ 'actor' => [ 'LEFT JOIN', 'rev_user = actor_user' ] ]
144  );
145  $subsql[] = $dbSecondary->selectSQLText(
146  [ 'revision', 'actor' ],
147  [ 'actor_id', 'user_id' => 'rev_user', 'user_name' => 'rev_user_text' ],
148  array_merge(
149  [ "rev_user_text$like", 'rev_user = 0' ],
150  $from ? [ "rev_user_text $from" ] : []
151  ),
152  $fname,
153  array_merge( [ 'DISTINCT' ], $options ),
154  [ 'actor' => [ 'LEFT JOIN', 'rev_user_text = actor_name' ] ]
155  );
156  $sql = $dbSecondary->unionQueries( $subsql, false ) . " ORDER BY user_name $sort";
157  $sql = $dbSecondary->limitResult( $sql, $limit );
158  $res = $dbSecondary->query( $sql, $fname );
159  }
160 
161  $count = 0;
162  $fromName = false;
163  foreach ( $res as $row ) {
164  if ( ++$count >= $limit ) {
165  $fromName = $row->user_name;
166  break;
167  }
168  yield User::newFromRow( $row );
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 ( !count( $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 = 'id';
190  $this->multiUserMode = count( $ids ) > 1;
191 
192  $from = $fromId = false;
193  if ( $this->multiUserMode && !is_null( $this->params['continue'] ) ) {
194  $continue = explode( '|', $this->params['continue'] );
195  $this->dieContinueUsageIf( count( $continue ) != 4 );
196  $this->dieContinueUsageIf( $continue[0] !== 'id' && $continue[0] !== 'actor' );
197  $fromId = (int)$continue[1];
198  $this->dieContinueUsageIf( $continue[1] !== (string)$fromId );
199  $from = "$op= $fromId";
200  }
201 
202  // For the new schema, just select from the actor table. For the
203  // old and transitional schemas, select from user and left join
204  // actor if it exists.
206  $res = $dbSecondary->select(
207  'actor',
208  [ 'actor_id', 'user_id' => 'actor_user', 'user_name' => 'actor_name' ],
209  array_merge( [ 'actor_user' => $ids ], $from ? [ "actor_id $from" ] : [] ),
210  __METHOD__,
211  [ 'ORDER BY' => "user_id $sort" ]
212  );
214  $res = $dbSecondary->select(
215  'user',
216  [ 'actor_id' => 'NULL', 'user_id' => 'user_id', 'user_name' => 'user_name' ],
217  array_merge( [ 'user_id' => $ids ], $from ? [ "user_id $from" ] : [] ),
218  __METHOD__,
219  [ 'ORDER BY' => "user_id $sort" ]
220  );
221  } else {
222  $res = $dbSecondary->select(
223  [ 'user', 'actor' ],
224  [ 'actor_id', 'user_id', 'user_name' ],
225  array_merge( [ 'user_id' => $ids ], $from ? [ "user_id $from" ] : [] ),
226  __METHOD__,
227  [ 'ORDER BY' => "user_id $sort" ],
228  [ 'actor' => [ 'LEFT JOIN', 'actor_user = user_id' ] ]
229  );
230  }
231  $userIter = UserArray::newFromResult( $res );
232  $batchSize = count( $ids );
233  } else {
234  $names = [];
235  if ( !count( $this->params['user'] ) ) {
236  $encParamName = $this->encodeParamName( 'user' );
237  $this->dieWithError(
238  [ 'apierror-paramempty', $encParamName ], "paramempty_$encParamName"
239  );
240  }
241  foreach ( $this->params['user'] as $u ) {
242  if ( $u === '' ) {
243  $encParamName = $this->encodeParamName( 'user' );
244  $this->dieWithError(
245  [ 'apierror-paramempty', $encParamName ], "paramempty_$encParamName"
246  );
247  }
248 
249  if ( User::isIP( $u ) || ExternalUserNames::isExternal( $u ) ) {
250  $names[$u] = null;
251  } else {
252  $name = User::getCanonicalName( $u, 'valid' );
253  if ( $name === false ) {
254  $encParamName = $this->encodeParamName( 'user' );
255  $this->dieWithError(
256  [ 'apierror-baduser', $encParamName, wfEscapeWikiText( $u ) ], "baduser_$encParamName"
257  );
258  }
259  $names[$name] = null;
260  }
261  }
262 
263  $this->orderBy = 'name';
264  $this->multiUserMode = count( $names ) > 1;
265 
266  $from = $fromName = false;
267  if ( $this->multiUserMode && !is_null( $this->params['continue'] ) ) {
268  $continue = explode( '|', $this->params['continue'] );
269  $this->dieContinueUsageIf( count( $continue ) != 4 );
270  $this->dieContinueUsageIf( $continue[0] !== 'name' && $continue[0] !== 'actor' );
271  $fromName = $continue[1];
272  $from = "$op= " . $dbSecondary->addQuotes( $fromName );
273  }
274 
275  // For the new schema, just select from the actor table. For the
276  // old and transitional schemas, select from user and left join
277  // actor if it exists then merge in any unknown users (IPs and imports).
279  $res = $dbSecondary->select(
280  'actor',
281  [ 'actor_id', 'user_id' => 'actor_user', 'user_name' => 'actor_name' ],
282  array_merge( [ 'actor_name' => array_keys( $names ) ], $from ? [ "actor_id $from" ] : [] ),
283  __METHOD__,
284  [ 'ORDER BY' => "actor_name $sort" ]
285  );
286  $userIter = UserArray::newFromResult( $res );
287  } else {
289  $res = $dbSecondary->select(
290  'user',
291  [ 'actor_id' => 'NULL', 'user_id', 'user_name' ],
292  array_merge( [ 'user_name' => array_keys( $names ) ], $from ? [ "user_name $from" ] : [] ),
293  __METHOD__
294  );
295  } else {
296  $res = $dbSecondary->select(
297  [ 'user', 'actor' ],
298  [ 'actor_id', 'user_id', 'user_name' ],
299  array_merge( [ 'user_name' => array_keys( $names ) ], $from ? [ "user_name $from" ] : [] ),
300  __METHOD__,
301  [],
302  [ 'actor' => [ 'LEFT JOIN', 'actor_user = user_id' ] ]
303  );
304  }
305  foreach ( $res as $row ) {
306  $names[$row->user_name] = $row;
307  }
308  call_user_func_array(
309  $this->params['dir'] == 'newer' ? 'ksort' : 'krsort', [ &$names, SORT_STRING ]
310  );
311  $neg = $op === '>' ? -1 : 1;
312  $userIter = call_user_func( function () use ( $names, $fromName, $neg ) {
313  foreach ( $names as $name => $row ) {
314  if ( $fromName === false || $neg * strcmp( $name, $fromName ) <= 0 ) {
315  $user = $row ? User::newFromRow( $row ) : User::newFromName( $name, false );
316  yield $user;
317  }
318  }
319  } );
320  }
321  $batchSize = count( $names );
322  }
323 
324  // During migration, force ordering on the client side because we're
325  // having to combine multiple queries that would otherwise have
326  // different sort orders.
329  ) {
330  $batchSize = 1;
331  }
332 
333  // With the new schema, the DB query will order by actor so update $this->orderBy to match.
334  if ( $batchSize > 1 && $wgActorTableSchemaMigrationStage === MIGRATION_NEW ) {
335  $this->orderBy = 'actor';
336  }
337 
338  $count = 0;
339  $limit = $this->params['limit'];
340  $userIter->rewind();
341  while ( $userIter->valid() ) {
342  $users = [];
343  while ( count( $users ) < $batchSize && $userIter->valid() ) {
344  $users[] = $userIter->current();
345  $userIter->next();
346  }
347 
348  // Ugh. We have to run the query three times, once for each
349  // possible 'orcond' from ActorMigration, and then merge them all
350  // together in the proper order. And preserving the correct
351  // $hookData for each one.
352  // @todo When ActorMigration is removed, this can go back to a
353  // single prepare and select.
354  $merged = [];
355  foreach ( [ 'actor', 'userid', 'username' ] as $which ) {
356  if ( $this->prepareQuery( $users, $limit - $count, $which ) ) {
357  $hookData = [];
358  $res = $this->select( __METHOD__, [], $hookData );
359  foreach ( $res as $row ) {
360  $merged[] = [ $row, &$hookData ];
361  }
362  }
363  }
364  $neg = $this->params['dir'] == 'newer' ? 1 : -1;
365  usort( $merged, function ( $a, $b ) use ( $neg, $batchSize ) {
366  if ( $batchSize === 1 ) { // One user, can't be different
367  $ret = 0;
368  } elseif ( $this->orderBy === 'id' ) {
369  $ret = $a[0]->rev_user - $b[0]->rev_user;
370  } elseif ( $this->orderBy === 'name' ) {
371  $ret = strcmp( $a[0]->rev_user_text, $b[0]->rev_user_text );
372  } else {
373  $ret = $a[0]->rev_actor - $b[0]->rev_actor;
374  }
375 
376  if ( !$ret ) {
377  $ret = strcmp(
378  wfTimestamp( TS_MW, $a[0]->rev_timestamp ),
379  wfTimestamp( TS_MW, $b[0]->rev_timestamp )
380  );
381  }
382 
383  if ( !$ret ) {
384  $ret = $a[0]->rev_id - $b[0]->rev_id;
385  }
386 
387  return $neg * $ret;
388  } );
389  $merged = array_slice( $merged, 0, $limit - $count + 1 );
390  // (end "Ugh")
391 
392  if ( $this->fld_sizediff ) {
393  $revIds = [];
394  foreach ( $merged as $data ) {
395  if ( $data[0]->rev_parent_id ) {
396  $revIds[] = $data[0]->rev_parent_id;
397  }
398  }
399  $this->parentLens = Revision::getParentLengths( $dbSecondary, $revIds );
400  }
401 
402  foreach ( $merged as $data ) {
403  $row = $data[0];
404  $hookData = &$data[1];
405  if ( ++$count > $limit ) {
406  // We've reached the one extra which shows that there are
407  // additional pages to be had. Stop here...
408  $this->setContinueEnumParameter( 'continue', $this->continueStr( $row ) );
409  break 2;
410  }
411 
412  $vals = $this->extractRowInfo( $row );
413  $fit = $this->processRow( $row, $vals, $hookData ) &&
414  $this->getResult()->addValue( [ 'query', $this->getModuleName() ], null, $vals );
415  if ( !$fit ) {
416  $this->setContinueEnumParameter( 'continue', $this->continueStr( $row ) );
417  break 2;
418  }
419  }
420  }
421 
422  $this->getResult()->addIndexedTagName( [ 'query', $this->getModuleName() ], 'item' );
423  }
424 
432  private function prepareQuery( array $users, $limit, $which ) {
434 
435  $this->resetQueryParams();
436  $db = $this->getDB();
437 
438  $revQuery = Revision::getQueryInfo( [ 'page' ] );
439  $this->addTables( $revQuery['tables'] );
440  $this->addJoinConds( $revQuery['joins'] );
441  $this->addFields( $revQuery['fields'] );
442 
443  $revWhere = ActorMigration::newMigration()->getWhere( $db, 'rev_user', $users );
444  if ( !isset( $revWhere['orconds'][$which] ) ) {
445  return false;
446  }
447  $this->addWhere( $revWhere['orconds'][$which] );
448 
450  $orderUserField = 'rev_actor';
451  $userField = $this->orderBy === 'actor' ? 'revactor_actor' : 'actor_name';
452  } else {
453  $orderUserField = $this->orderBy === 'id' ? 'rev_user' : 'rev_user_text';
454  $userField = $revQuery['fields'][$orderUserField];
455  }
456  if ( $which === 'actor' ) {
457  $tsField = 'revactor_timestamp';
458  $idField = 'revactor_rev';
459  } else {
460  $tsField = 'rev_timestamp';
461  $idField = 'rev_id';
462  }
463 
464  // Handle continue parameter
465  if ( !is_null( $this->params['continue'] ) ) {
466  $continue = explode( '|', $this->params['continue'] );
467  if ( $this->multiUserMode ) {
468  $this->dieContinueUsageIf( count( $continue ) != 4 );
469  $modeFlag = array_shift( $continue );
470  $this->dieContinueUsageIf( $modeFlag !== $this->orderBy );
471  $encUser = $db->addQuotes( array_shift( $continue ) );
472  } else {
473  $this->dieContinueUsageIf( count( $continue ) != 2 );
474  }
475  $encTS = $db->addQuotes( $db->timestamp( $continue[0] ) );
476  $encId = (int)$continue[1];
477  $this->dieContinueUsageIf( $encId != $continue[1] );
478  $op = ( $this->params['dir'] == 'older' ? '<' : '>' );
479  if ( $this->multiUserMode ) {
480  $this->addWhere(
481  "$userField $op $encUser OR " .
482  "($userField = $encUser AND " .
483  "($tsField $op $encTS OR " .
484  "($tsField = $encTS AND " .
485  "$idField $op= $encId)))"
486  );
487  } else {
488  $this->addWhere(
489  "$tsField $op $encTS OR " .
490  "($tsField = $encTS AND " .
491  "$idField $op= $encId)"
492  );
493  }
494  }
495 
496  // Don't include any revisions where we're not supposed to be able to
497  // see the username.
498  $user = $this->getUser();
499  if ( !$user->isAllowed( 'deletedhistory' ) ) {
500  $bitmask = Revision::DELETED_USER;
501  } elseif ( !$user->isAllowedAny( 'suppressrevision', 'viewsuppressed' ) ) {
503  } else {
504  $bitmask = 0;
505  }
506  if ( $bitmask ) {
507  $this->addWhere( $db->bitAnd( 'rev_deleted', $bitmask ) . " != $bitmask" );
508  }
509 
510  // Add the user field to ORDER BY if there are multiple users
511  if ( count( $users ) > 1 ) {
512  $this->addWhereRange( $orderUserField, $this->params['dir'], null, null );
513  }
514 
515  // Then timestamp
516  $this->addTimestampWhereRange( $tsField,
517  $this->params['dir'], $this->params['start'], $this->params['end'] );
518 
519  // Then rev_id for a total ordering
520  $this->addWhereRange( $idField, $this->params['dir'], null, null );
521 
522  $this->addWhereFld( 'page_namespace', $this->params['namespace'] );
523 
524  $show = $this->params['show'];
525  if ( $this->params['toponly'] ) { // deprecated/old param
526  $show[] = 'top';
527  }
528  if ( !is_null( $show ) ) {
529  $show = array_flip( $show );
530 
531  if ( ( isset( $show['minor'] ) && isset( $show['!minor'] ) )
532  || ( isset( $show['patrolled'] ) && isset( $show['!patrolled'] ) )
533  || ( isset( $show['autopatrolled'] ) && isset( $show['!autopatrolled'] ) )
534  || ( isset( $show['autopatrolled'] ) && isset( $show['!patrolled'] ) )
535  || ( isset( $show['top'] ) && isset( $show['!top'] ) )
536  || ( isset( $show['new'] ) && isset( $show['!new'] ) )
537  ) {
538  $this->dieWithError( 'apierror-show' );
539  }
540 
541  $this->addWhereIf( 'rev_minor_edit = 0', isset( $show['!minor'] ) );
542  $this->addWhereIf( 'rev_minor_edit != 0', isset( $show['minor'] ) );
543  $this->addWhereIf(
544  'rc_patrolled = ' . RecentChange::PRC_UNPATROLLED,
545  isset( $show['!patrolled'] )
546  );
547  $this->addWhereIf(
548  'rc_patrolled != ' . RecentChange::PRC_UNPATROLLED,
549  isset( $show['patrolled'] )
550  );
551  $this->addWhereIf(
552  'rc_patrolled != ' . RecentChange::PRC_AUTOPATROLLED,
553  isset( $show['!autopatrolled'] )
554  );
555  $this->addWhereIf(
556  'rc_patrolled = ' . RecentChange::PRC_AUTOPATROLLED,
557  isset( $show['autopatrolled'] )
558  );
559  $this->addWhereIf( $idField . ' != page_latest', isset( $show['!top'] ) );
560  $this->addWhereIf( $idField . ' = page_latest', isset( $show['top'] ) );
561  $this->addWhereIf( 'rev_parent_id != 0', isset( $show['!new'] ) );
562  $this->addWhereIf( 'rev_parent_id = 0', isset( $show['new'] ) );
563  }
564  $this->addOption( 'LIMIT', $limit + 1 );
565 
566  if ( isset( $show['patrolled'] ) || isset( $show['!patrolled'] ) ||
567  isset( $show['autopatrolled'] ) || isset( $show['!autopatrolled'] ) || $this->fld_patrolled
568  ) {
569  if ( !$user->useRCPatrol() && !$user->useNPPatrol() ) {
570  $this->dieWithError( 'apierror-permissiondenied-patrolflag', 'permissiondenied' );
571  }
572 
573  $isFilterset = isset( $show['patrolled'] ) || isset( $show['!patrolled'] ) ||
574  isset( $show['autopatrolled'] ) || isset( $show['!autopatrolled'] );
575  $this->addTables( 'recentchanges' );
576  $this->addJoinConds( [ 'recentchanges' => [
577  $isFilterset ? 'JOIN' : 'LEFT JOIN',
578  [
579  // This is a crazy hack. recentchanges has no index on rc_this_oldid, so instead of adding
580  // one T19237 did a join using rc_user_text and rc_timestamp instead. Now rc_user_text is
581  // probably unavailable, so just do rc_timestamp.
582  'rc_timestamp = ' . $tsField,
583  'rc_this_oldid = ' . $idField,
584  ]
585  ] ] );
586  }
587 
588  $this->addFieldsIf( 'rc_patrolled', $this->fld_patrolled );
589 
590  if ( $this->fld_tags ) {
591  $this->addTables( 'tag_summary' );
592  $this->addJoinConds(
593  [ 'tag_summary' => [ 'LEFT JOIN', [ $idField . ' = ts_rev_id' ] ] ]
594  );
595  $this->addFields( 'ts_tags' );
596  }
597 
598  if ( isset( $this->params['tag'] ) ) {
599  $this->addTables( 'change_tag' );
600  $this->addJoinConds(
601  [ 'change_tag' => [ 'INNER JOIN', [ $idField . ' = ct_rev_id' ] ] ]
602  );
603  $this->addWhereFld( 'ct_tag', $this->params['tag'] );
604  }
605 
606  return true;
607  }
608 
615  private function extractRowInfo( $row ) {
616  $vals = [];
617  $anyHidden = false;
618 
619  if ( $row->rev_deleted & Revision::DELETED_TEXT ) {
620  $vals['texthidden'] = true;
621  $anyHidden = true;
622  }
623 
624  // Any rows where we can't view the user were filtered out in the query.
625  $vals['userid'] = (int)$row->rev_user;
626  $vals['user'] = $row->rev_user_text;
627  if ( $row->rev_deleted & Revision::DELETED_USER ) {
628  $vals['userhidden'] = true;
629  $anyHidden = true;
630  }
631  if ( $this->fld_ids ) {
632  $vals['pageid'] = intval( $row->rev_page );
633  $vals['revid'] = intval( $row->rev_id );
634  // $vals['textid'] = intval( $row->rev_text_id ); // todo: Should this field be exposed?
635 
636  if ( !is_null( $row->rev_parent_id ) ) {
637  $vals['parentid'] = intval( $row->rev_parent_id );
638  }
639  }
640 
641  $title = Title::makeTitle( $row->page_namespace, $row->page_title );
642 
643  if ( $this->fld_title ) {
645  }
646 
647  if ( $this->fld_timestamp ) {
648  $vals['timestamp'] = wfTimestamp( TS_ISO_8601, $row->rev_timestamp );
649  }
650 
651  if ( $this->fld_flags ) {
652  $vals['new'] = $row->rev_parent_id == 0 && !is_null( $row->rev_parent_id );
653  $vals['minor'] = (bool)$row->rev_minor_edit;
654  $vals['top'] = $row->page_latest == $row->rev_id;
655  }
656 
657  if ( $this->fld_comment || $this->fld_parsedcomment ) {
658  if ( $row->rev_deleted & Revision::DELETED_COMMENT ) {
659  $vals['commenthidden'] = true;
660  $anyHidden = true;
661  }
662 
663  $userCanView = Revision::userCanBitfield(
664  $row->rev_deleted,
665  Revision::DELETED_COMMENT, $this->getUser()
666  );
667 
668  if ( $userCanView ) {
669  $comment = $this->commentStore->getComment( 'rev_comment', $row )->text;
670  if ( $this->fld_comment ) {
671  $vals['comment'] = $comment;
672  }
673 
674  if ( $this->fld_parsedcomment ) {
675  $vals['parsedcomment'] = Linker::formatComment( $comment, $title );
676  }
677  }
678  }
679 
680  if ( $this->fld_patrolled ) {
681  $vals['patrolled'] = $row->rc_patrolled != RecentChange::PRC_UNPATROLLED;
682  $vals['autopatrolled'] = $row->rc_patrolled == RecentChange::PRC_AUTOPATROLLED;
683  }
684 
685  if ( $this->fld_size && !is_null( $row->rev_len ) ) {
686  $vals['size'] = intval( $row->rev_len );
687  }
688 
689  if ( $this->fld_sizediff
690  && !is_null( $row->rev_len )
691  && !is_null( $row->rev_parent_id )
692  ) {
693  $parentLen = isset( $this->parentLens[$row->rev_parent_id] )
694  ? $this->parentLens[$row->rev_parent_id]
695  : 0;
696  $vals['sizediff'] = intval( $row->rev_len - $parentLen );
697  }
698 
699  if ( $this->fld_tags ) {
700  if ( $row->ts_tags ) {
701  $tags = explode( ',', $row->ts_tags );
702  ApiResult::setIndexedTagName( $tags, 'tag' );
703  $vals['tags'] = $tags;
704  } else {
705  $vals['tags'] = [];
706  }
707  }
708 
709  if ( $anyHidden && $row->rev_deleted & Revision::DELETED_RESTRICTED ) {
710  $vals['suppressed'] = true;
711  }
712 
713  return $vals;
714  }
715 
716  private function continueStr( $row ) {
717  if ( $this->multiUserMode ) {
718  switch ( $this->orderBy ) {
719  case 'id':
720  return "id|$row->rev_user|$row->rev_timestamp|$row->rev_id";
721  case 'name':
722  return "name|$row->rev_user_text|$row->rev_timestamp|$row->rev_id";
723  case 'actor':
724  return "actor|$row->rev_actor|$row->rev_timestamp|$row->rev_id";
725  }
726  } else {
727  return "$row->rev_timestamp|$row->rev_id";
728  }
729  }
730 
731  public function getCacheMode( $params ) {
732  // This module provides access to deleted revisions and patrol flags if
733  // the requester is logged in
734  return 'anon-public-user-private';
735  }
736 
737  public function getAllowedParams() {
738  return [
739  'limit' => [
740  ApiBase::PARAM_DFLT => 10,
741  ApiBase::PARAM_TYPE => 'limit',
742  ApiBase::PARAM_MIN => 1,
745  ],
746  'start' => [
747  ApiBase::PARAM_TYPE => 'timestamp'
748  ],
749  'end' => [
750  ApiBase::PARAM_TYPE => 'timestamp'
751  ],
752  'continue' => [
753  ApiBase::PARAM_HELP_MSG => 'api-help-param-continue',
754  ],
755  'user' => [
756  ApiBase::PARAM_TYPE => 'user',
758  ],
759  'userids' => [
760  ApiBase::PARAM_TYPE => 'integer',
762  ],
763  'userprefix' => null,
764  'dir' => [
765  ApiBase::PARAM_DFLT => 'older',
767  'newer',
768  'older'
769  ],
770  ApiBase::PARAM_HELP_MSG => 'api-help-param-direction',
771  ],
772  'namespace' => [
773  ApiBase::PARAM_ISMULTI => true,
774  ApiBase::PARAM_TYPE => 'namespace'
775  ],
776  'prop' => [
777  ApiBase::PARAM_ISMULTI => true,
778  ApiBase::PARAM_DFLT => 'ids|title|timestamp|comment|size|flags',
780  'ids',
781  'title',
782  'timestamp',
783  'comment',
784  'parsedcomment',
785  'size',
786  'sizediff',
787  'flags',
788  'patrolled',
789  'tags'
790  ],
792  ],
793  'show' => [
794  ApiBase::PARAM_ISMULTI => true,
796  'minor',
797  '!minor',
798  'patrolled',
799  '!patrolled',
800  'autopatrolled',
801  '!autopatrolled',
802  'top',
803  '!top',
804  'new',
805  '!new',
806  ],
808  'apihelp-query+usercontribs-param-show',
809  $this->getConfig()->get( 'RCMaxAge' )
810  ],
811  ],
812  'tag' => null,
813  'toponly' => [
814  ApiBase::PARAM_DFLT => false,
816  ],
817  ];
818  }
819 
820  protected function getExamplesMessages() {
821  return [
822  'action=query&list=usercontribs&ucuser=Example'
823  => 'apihelp-query+usercontribs-example-user',
824  'action=query&list=usercontribs&ucuserprefix=192.0.2.'
825  => 'apihelp-query+usercontribs-example-ipprefix',
826  ];
827  }
828 
829  public function getHelpUrls() {
830  return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Usercontribs';
831  }
832 }
$user
please add to it if you re going to add events to the MediaWiki code where normally authentication against an external auth plugin would be creating a account $user
Definition: hooks.txt:247
Revision\DELETED_USER
const DELETED_USER
Definition: Revision.php:49
ContextSource\getConfig
getConfig()
Definition: ContextSource.php:63
Revision\DELETED_RESTRICTED
const DELETED_RESTRICTED
Definition: Revision.php:50
ApiQueryBase\processRow
processRow( $row, array &$data, array &$hookData)
Call the ApiQueryBaseProcessRow hook.
Definition: ApiQueryBase.php:400
ApiQueryBase\addFields
addFields( $value)
Add a set of fields to select to the internal array.
Definition: ApiQueryBase.php:192
ApiQuery
This is the main query class.
Definition: ApiQuery.php:36
Revision\DELETED_COMMENT
const DELETED_COMMENT
Definition: Revision.php:48
use
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
Definition: APACHE-LICENSE-2.0.txt:10
ApiQueryContributions\$fld_patrolled
$fld_patrolled
Definition: ApiQueryUserContributions.php:37
ApiQueryBase\resetQueryParams
resetQueryParams()
Blank the internal arrays with query parameters.
Definition: ApiQueryBase.php:144
Revision\userCanBitfield
static userCanBitfield( $bitfield, $field, User $user=null, Title $title=null)
Determine if the current user is allowed to view a particular field of this revision,...
Definition: Revision.php:1205
ApiQueryContributions\getAllowedParams
getAllowedParams()
Returns an array of allowed parameters (parameter name) => (default value) or (parameter name) => (ar...
Definition: ApiQueryUserContributions.php:737
array
the array() calling protocol came about after MediaWiki 1.4rc1.
ApiBase\dieWithError
dieWithError( $msg, $code=null, $data=null, $httpCode=null)
Abort execution with an error.
Definition: ApiBase.php:1895
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:313
ApiBase\PARAM_HELP_MSG
const PARAM_HELP_MSG
(string|array|Message) Specify an alternative i18n documentation message for this parameter.
Definition: ApiBase.php:124
wfTimestamp
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
Definition: GlobalFunctions.php:1980
$ret
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 & $ret
Definition: hooks.txt:2005
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:641
ApiQueryContributions\$parentLens
$parentLens
Definition: ApiQueryUserContributions.php:34
MIGRATION_NEW
const MIGRATION_NEW
Definition: Defines.php:305
MIGRATION_WRITE_BOTH
const MIGRATION_WRITE_BOTH
Definition: Defines.php:303
User\newFromName
static newFromName( $name, $validate='valid')
Static factory method for creation from username.
Definition: User.php:591
ApiQueryContributions\$params
$params
Definition: ApiQueryUserContributions.php:34
$res
$res
Definition: database.txt:21
ApiQueryBase\addOption
addOption( $name, $value=null)
Add an option such as LIMIT or USE INDEX.
Definition: ApiQueryBase.php:325
ContextSource\getUser
getUser()
Definition: ContextSource.php:120
ApiQueryContributions\$fld_title
$fld_title
Definition: ApiQueryUserContributions.php:35
User\newFromRow
static newFromRow( $row, $data=null)
Create a new user object from a user row.
Definition: User.php:750
$revQuery
$revQuery
Definition: testCompression.php:51
ActorMigration\newMigration
static newMigration()
Static constructor.
Definition: ActorMigration.php:89
ApiQueryBase\$options
$options
Definition: ApiQueryBase.php:35
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:2006
ApiQueryBase\addFieldsIf
addFieldsIf( $value, $condition)
Same as addFields(), but add the fields only if a condition is met.
Definition: ApiQueryBase.php:206
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:37
MIGRATION_WRITE_NEW
const MIGRATION_WRITE_NEW
Definition: Defines.php:304
ApiQueryContributions\$multiUserMode
$multiUserMode
Definition: ApiQueryUserContributions.php:34
ApiQueryContributions\execute
execute()
Evaluates the parameters, performs the requested query, and sets up the result.
Definition: ApiQueryUserContributions.php:39
ApiBase\PARAM_DEPRECATED
const PARAM_DEPRECATED
(boolean) Is the parameter deprecated (will show a warning)?
Definition: ApiBase.php:105
ApiBase\PARAM_MIN
const PARAM_MIN
(integer) Lowest value allowed for the parameter, for PARAM_TYPE 'integer' and 'limit'.
Definition: ApiBase.php:99
ApiQueryContributions\$fld_sizediff
$fld_sizediff
Definition: ApiQueryUserContributions.php:37
Revision\getQueryInfo
static getQueryInfo( $options=[])
Return the tables, fields, and join conditions to be selected to create a new revision object.
Definition: Revision.php:492
if
if(file_exists("$IP/StartProfiler.php"))
Definition: Setup.php:42
ApiQueryContributions\$fld_size
$fld_size
Definition: ApiQueryUserContributions.php:37
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:234
ApiQueryContributions\$fld_ids
$fld_ids
Definition: ApiQueryUserContributions.php:35
ApiQueryBase\getDB
getDB()
Get the Query database connection (read-only)
Definition: ApiQueryBase.php:105
UserArray\newFromResult
static newFromResult( $res)
Definition: UserArray.php:30
ApiQueryContributions\$fld_timestamp
$fld_timestamp
Definition: ApiQueryUserContributions.php:35
ApiBase\PARAM_MAX
const PARAM_MAX
(integer) Max value allowed for the parameter, for PARAM_TYPE 'integer' and 'limit'.
Definition: ApiBase.php:90
ApiQueryContributions\getExamplesMessages
getExamplesMessages()
Returns usage examples for this module.
Definition: ApiQueryUserContributions.php:820
User\isIP
static isIP( $name)
Does the string match an anonymous IP address?
Definition: User.php:943
ApiQueryBase\addTables
addTables( $tables, $alias=null)
Add a set of tables to the internal array.
Definition: ApiQueryBase.php:158
ApiQueryContributions\$fld_tags
$fld_tags
Definition: ApiQueryUserContributions.php:37
ApiQueryBase\select
select( $method, $extraQuery=[], array &$hookData=null)
Execute a SELECT query based on the values in the internal arrays.
Definition: ApiQueryBase.php:350
ApiQueryContributions\prepareQuery
prepareQuery(array $users, $limit, $which)
Prepares the query and returns the limit of rows requested.
Definition: ApiQueryUserContributions.php:432
ApiQueryContributions\getCacheMode
getCacheMode( $params)
Get the cache mode for the data generated by this module.
Definition: ApiQueryUserContributions.php:731
$title
namespace and then decline to actually register it file or subcat img or subcat $title
Definition: hooks.txt:964
Title\makeTitle
static makeTitle( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:534
global
when a variable name is used in a it is silently declared as a new masking the global
Definition: design.txt:95
ApiQueryContributions\getHelpUrls
getHelpUrls()
Return links to more detailed help pages about the module.
Definition: ApiQueryUserContributions.php:829
DB_REPLICA
const DB_REPLICA
Definition: defines.php:25
ApiQueryContributions\continueStr
continueStr( $row)
Definition: ApiQueryUserContributions.php:716
$sort
$sort
Definition: profileinfo.php:317
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:278
MIGRATION_OLD
const MIGRATION_OLD
Definition: Defines.php:302
$fname
if(defined( 'MW_SETUP_CALLBACK')) $fname
Customization point after all loading (constants, functions, classes, DefaultSettings,...
Definition: Setup.php:112
ApiBase\extractRequestParams
extractRequestParams( $parseLimit=true)
Using getAllowedParams(), this function makes an array of the values provided by the user,...
Definition: ApiBase.php:749
ApiResult\setIndexedTagName
static setIndexedTagName(array &$arr, $tag)
Set the tag name for numeric-keyed values in XML format.
Definition: ApiResult.php:616
ApiQueryContributions\$fld_flags
$fld_flags
Definition: ApiQueryUserContributions.php:36
ApiBase\dieContinueUsageIf
dieContinueUsageIf( $condition)
Die with the 'badcontinue' error.
Definition: ApiBase.php:2066
ApiBase\encodeParamName
encodeParamName( $paramName)
This method mangles parameter name based on the prefix supplied to the constructor.
Definition: ApiBase.php:730
Revision\getParentLengths
static getParentLengths( $db, array $revIds)
Do a batched query to get the parent revision lengths.
Definition: Revision.php:519
ApiQueryContributions\extractRowInfo
extractRowInfo( $row)
Extract fields from the database row and append them to a result array.
Definition: ApiQueryUserContributions.php:615
ApiQueryContributions\$fld_comment
$fld_comment
Definition: ApiQueryUserContributions.php:36
ApiQueryBase\addJoinConds
addJoinConds( $join_conds)
Add a set of JOIN conditions to the internal array.
Definition: ApiQueryBase.php:181
wfEscapeWikiText
wfEscapeWikiText( $text)
Escapes the given text so that it may be output using addWikiText() without any linking,...
Definition: GlobalFunctions.php:1643
ApiQueryBase\addWhereFld
addWhereFld( $field, $value)
Equivalent to addWhere(array($field => $value))
Definition: ApiQueryBase.php:260
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:785
ApiQueryContributions\$fld_parsedcomment
$fld_parsedcomment
Definition: ApiQueryUserContributions.php:36
RecentChange\PRC_AUTOPATROLLED
const PRC_AUTOPATROLLED
Definition: RecentChange.php:79
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:1109
ApiQueryContributions\$orderBy
$orderBy
Definition: ApiQueryUserContributions.php:34
$name
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:302
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:236
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:1210
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:77
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:22
ApiBase\getModuleName
getModuleName()
Get the name of the module being executed by this instance.
Definition: ApiBase.php:521
ApiBase\PARAM_ISMULTI
const PARAM_ISMULTI
(boolean) Accept multiple pipe-separated values for this parameter (e.g.
Definition: ApiBase.php:51
ApiBase\PARAM_MAX2
const PARAM_MAX2
(integer) Max value allowed for the parameter for users with the apihighlimits right,...
Definition: ApiBase.php:96
ApiQueryBase\addWhere
addWhere( $value)
Add a set of WHERE clauses to the internal array.
Definition: ApiQueryBase.php:227
ApiQueryBase\setContinueEnumParameter
setContinueEnumParameter( $paramName, $paramValue)
Set a query-continue value.
Definition: ApiQueryBase.php:531
$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:1620
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
ExternalUserNames\isExternal
static isExternal( $username)
Tells whether the username is external or not.
Definition: ExternalUserNames.php:115
Revision\DELETED_TEXT
const DELETED_TEXT
Definition: Revision.php:47
ApiQueryBase\addWhereIf
addWhereIf( $value, $condition)
Same as addWhere(), but add the WHERE clauses only if a condition is met.
Definition: ApiQueryBase.php:245
ApiQueryBase\addTitleInfo
static addTitleInfo(&$arr, $title, $prefix='')
Add information (title and namespace) about a Title object to a result array.
Definition: ApiQueryBase.php:482
ApiQueryContributions\__construct
__construct(ApiQuery $query, $moduleName)
Definition: ApiQueryUserContributions.php:30
ApiQueryContributions
This query action adds a list of a specified user's contributions to the output.
Definition: ApiQueryUserContributions.php:28
$wgActorTableSchemaMigrationStage
int $wgActorTableSchemaMigrationStage
Actor table schema migration stage.
Definition: DefaultSettings.php:8878