MediaWiki REL1_32
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 // Most of this code will 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 // TODO: if the query is going only against the revision table, should this be done?
70 $this->selectNamedDB( 'contributions', DB_REPLICA, 'contributions' );
71
72 $sort = ( $this->params['dir'] == 'newer' ? '' : ' DESC' );
73 $op = ( $this->params['dir'] == 'older' ? '<' : '>' );
74
75 // Create an Iterator that produces the UserIdentity objects we need, depending
76 // on which of the 'userprefix', 'userids', or 'user' params was
77 // specified.
78 $this->requireOnlyOneParameter( $this->params, 'userprefix', 'userids', 'user' );
79 if ( isset( $this->params['userprefix'] ) ) {
80 $this->multiUserMode = true;
81 $this->orderBy = 'name';
82 $fname = __METHOD__;
83
84 // Because 'userprefix' might produce a huge number of users (e.g.
85 // a wiki with users "Test00000001" to "Test99999999"), use a
86 // generator with batched lookup and continuation.
87 $userIter = call_user_func( function () use ( $dbSecondary, $sort, $op, $fname ) {
89
90 $fromName = false;
91 if ( !is_null( $this->params['continue'] ) ) {
92 $continue = explode( '|', $this->params['continue'] );
93 $this->dieContinueUsageIf( count( $continue ) != 4 );
94 $this->dieContinueUsageIf( $continue[0] !== 'name' );
95 $fromName = $continue[1];
96 }
97 $like = $dbSecondary->buildLike( $this->params['userprefix'], $dbSecondary->anyString() );
98
99 $limit = 501;
100
101 do {
102 $from = $fromName ? "$op= " . $dbSecondary->addQuotes( $fromName ) : false;
103
104 // For the new schema, pull from the actor table. For the
105 // old, pull from rev_user.
107 $res = $dbSecondary->select(
108 'actor',
109 [ 'actor_id', 'user_id' => 'COALESCE(actor_user,0)', 'user_name' => 'actor_name' ],
110 array_merge( [ "actor_name$like" ], $from ? [ "actor_name $from" ] : [] ),
111 $fname,
112 [ 'ORDER BY' => [ "user_name $sort" ], 'LIMIT' => $limit ]
113 );
114 } else {
115 $res = $dbSecondary->select(
116 'revision',
117 [ 'actor_id' => 'NULL', 'user_id' => 'rev_user', 'user_name' => 'rev_user_text' ],
118 array_merge( [ "rev_user_text$like" ], $from ? [ "rev_user_text $from" ] : [] ),
119 $fname,
120 [ 'DISTINCT', 'ORDER BY' => [ "rev_user_text $sort" ], 'LIMIT' => $limit ]
121 );
122 }
123
124 $count = 0;
125 $fromName = false;
126 foreach ( $res as $row ) {
127 if ( ++$count >= $limit ) {
128 $fromName = $row->user_name;
129 break;
130 }
131 yield User::newFromRow( $row );
132 }
133 } while ( $fromName !== false );
134 } );
135 // Do the actual sorting client-side, because otherwise
136 // prepareQuery might try to sort by actor and confuse everything.
137 $batchSize = 1;
138 } elseif ( isset( $this->params['userids'] ) ) {
139 if ( !count( $this->params['userids'] ) ) {
140 $encParamName = $this->encodeParamName( 'userids' );
141 $this->dieWithError( [ 'apierror-paramempty', $encParamName ], "paramempty_$encParamName" );
142 }
143
144 $ids = [];
145 foreach ( $this->params['userids'] as $uid ) {
146 if ( $uid <= 0 ) {
147 $this->dieWithError( [ 'apierror-invaliduserid', $uid ], 'invaliduserid' );
148 }
149 $ids[] = $uid;
150 }
151
152 $this->orderBy = 'id';
153 $this->multiUserMode = count( $ids ) > 1;
154
155 $from = $fromId = false;
156 if ( $this->multiUserMode && !is_null( $this->params['continue'] ) ) {
157 $continue = explode( '|', $this->params['continue'] );
158 $this->dieContinueUsageIf( count( $continue ) != 4 );
159 $this->dieContinueUsageIf( $continue[0] !== 'id' && $continue[0] !== 'actor' );
160 $fromId = (int)$continue[1];
161 $this->dieContinueUsageIf( $continue[1] !== (string)$fromId );
162 $from = "$op= $fromId";
163 }
164
165 // For the new schema, just select from the actor table. For the
166 // old, select from user.
168 $res = $dbSecondary->select(
169 'actor',
170 [ 'actor_id', 'user_id' => 'actor_user', 'user_name' => 'actor_name' ],
171 array_merge( [ 'actor_user' => $ids ], $from ? [ "actor_id $from" ] : [] ),
172 __METHOD__,
173 [ 'ORDER BY' => "user_id $sort" ]
174 );
175 } else {
176 $res = $dbSecondary->select(
177 'user',
178 [ 'actor_id' => 'NULL', 'user_id' => 'user_id', 'user_name' => 'user_name' ],
179 array_merge( [ 'user_id' => $ids ], $from ? [ "user_id $from" ] : [] ),
180 __METHOD__,
181 [ 'ORDER BY' => "user_id $sort" ]
182 );
183 }
184 $userIter = UserArray::newFromResult( $res );
185 $batchSize = count( $ids );
186 } else {
187 $names = [];
188 if ( !count( $this->params['user'] ) ) {
189 $encParamName = $this->encodeParamName( 'user' );
190 $this->dieWithError(
191 [ 'apierror-paramempty', $encParamName ], "paramempty_$encParamName"
192 );
193 }
194 foreach ( $this->params['user'] as $u ) {
195 if ( $u === '' ) {
196 $encParamName = $this->encodeParamName( 'user' );
197 $this->dieWithError(
198 [ 'apierror-paramempty', $encParamName ], "paramempty_$encParamName"
199 );
200 }
201
202 if ( User::isIP( $u ) || ExternalUserNames::isExternal( $u ) ) {
203 $names[$u] = null;
204 } else {
205 $name = User::getCanonicalName( $u, 'valid' );
206 if ( $name === false ) {
207 $encParamName = $this->encodeParamName( 'user' );
208 $this->dieWithError(
209 [ 'apierror-baduser', $encParamName, wfEscapeWikiText( $u ) ], "baduser_$encParamName"
210 );
211 }
212 $names[$name] = null;
213 }
214 }
215
216 $this->orderBy = 'name';
217 $this->multiUserMode = count( $names ) > 1;
218
219 $from = $fromName = false;
220 if ( $this->multiUserMode && !is_null( $this->params['continue'] ) ) {
221 $continue = explode( '|', $this->params['continue'] );
222 $this->dieContinueUsageIf( count( $continue ) != 4 );
223 $this->dieContinueUsageIf( $continue[0] !== 'name' && $continue[0] !== 'actor' );
224 $fromName = $continue[1];
225 $from = "$op= " . $dbSecondary->addQuotes( $fromName );
226 }
227
228 // For the new schema, just select from the actor table. For the
229 // old, select from user then merge in any unknown users (IPs and imports).
231 $res = $dbSecondary->select(
232 'actor',
233 [ 'actor_id', 'user_id' => 'actor_user', 'user_name' => 'actor_name' ],
234 array_merge( [ 'actor_name' => array_keys( $names ) ], $from ? [ "actor_id $from" ] : [] ),
235 __METHOD__,
236 [ 'ORDER BY' => "actor_name $sort" ]
237 );
238 $userIter = UserArray::newFromResult( $res );
239 } else {
240 $res = $dbSecondary->select(
241 'user',
242 [ 'actor_id' => 'NULL', 'user_id', 'user_name' ],
243 array_merge( [ 'user_name' => array_keys( $names ) ], $from ? [ "user_name $from" ] : [] ),
244 __METHOD__
245 );
246 foreach ( $res as $row ) {
247 $names[$row->user_name] = $row;
248 }
249 if ( $this->params['dir'] == 'newer' ) {
250 ksort( $names, SORT_STRING );
251 } else {
252 krsort( $names, SORT_STRING );
253 }
254 $neg = $op === '>' ? -1 : 1;
255 $userIter = call_user_func( function () use ( $names, $fromName, $neg ) {
256 foreach ( $names as $name => $row ) {
257 if ( $fromName === false || $neg * strcmp( $name, $fromName ) <= 0 ) {
258 $user = $row ? User::newFromRow( $row ) : User::newFromName( $name, false );
259 yield $user;
260 }
261 }
262 } );
263 }
264 $batchSize = count( $names );
265 }
266
267 // With the new schema, the DB query will order by actor so update $this->orderBy to match.
268 if ( $batchSize > 1 && ( $wgActorTableSchemaMigrationStage & SCHEMA_COMPAT_READ_NEW ) ) {
269 $this->orderBy = 'actor';
270 }
271
272 $count = 0;
273 $limit = $this->params['limit'];
274 $userIter->rewind();
275 while ( $userIter->valid() ) {
276 $users = [];
277 while ( count( $users ) < $batchSize && $userIter->valid() ) {
278 $users[] = $userIter->current();
279 $userIter->next();
280 }
281
282 $hookData = [];
283 $this->prepareQuery( $users, $limit - $count );
284 $res = $this->select( __METHOD__, [], $hookData );
285
286 if ( $this->fld_sizediff ) {
287 $revIds = [];
288 foreach ( $res as $row ) {
289 if ( $row->rev_parent_id ) {
290 $revIds[] = $row->rev_parent_id;
291 }
292 }
293 $this->parentLens = MediaWikiServices::getInstance()->getRevisionStore()
294 ->listRevisionSizes( $dbSecondary, $revIds );
295 }
296
297 foreach ( $res as $row ) {
298 if ( ++$count > $limit ) {
299 // We've reached the one extra which shows that there are
300 // additional pages to be had. Stop here...
301 $this->setContinueEnumParameter( 'continue', $this->continueStr( $row ) );
302 break 2;
303 }
304
305 $vals = $this->extractRowInfo( $row );
306 $fit = $this->processRow( $row, $vals, $hookData ) &&
307 $this->getResult()->addValue( [ 'query', $this->getModuleName() ], null, $vals );
308 if ( !$fit ) {
309 $this->setContinueEnumParameter( 'continue', $this->continueStr( $row ) );
310 break 2;
311 }
312 }
313 }
314
315 $this->getResult()->addIndexedTagName( [ 'query', $this->getModuleName() ], 'item' );
316 }
317
323 private function prepareQuery( array $users, $limit ) {
325
326 $this->resetQueryParams();
327 $db = $this->getDB();
328
329 $revQuery = MediaWikiServices::getInstance()->getRevisionStore()->getQueryInfo( [ 'page' ] );
330 $this->addTables( $revQuery['tables'] );
331 $this->addJoinConds( $revQuery['joins'] );
332 $this->addFields( $revQuery['fields'] );
333
334 if ( $wgActorTableSchemaMigrationStage & SCHEMA_COMPAT_READ_NEW ) {
335 $revWhere = ActorMigration::newMigration()->getWhere( $db, 'rev_user', $users );
336 $orderUserField = 'rev_actor';
337 $userField = $this->orderBy === 'actor' ? 'revactor_actor' : 'actor_name';
338 $tsField = 'revactor_timestamp';
339 $idField = 'revactor_rev';
340 } else {
341 // If we're dealing with user names (rather than IDs) in read-old mode,
342 // pass false for ActorMigration::getWhere()'s $useId parameter so
343 // $revWhere['conds'] isn't an OR.
344 $revWhere = ActorMigration::newMigration()
345 ->getWhere( $db, 'rev_user', $users, $this->orderBy === 'id' );
346 $orderUserField = $this->orderBy === 'id' ? 'rev_user' : 'rev_user_text';
347 $userField = $revQuery['fields'][$orderUserField];
348 $tsField = 'rev_timestamp';
349 $idField = 'rev_id';
350 }
351
352 $this->addWhere( $revWhere['conds'] );
353
354 // Handle continue parameter
355 if ( !is_null( $this->params['continue'] ) ) {
356 $continue = explode( '|', $this->params['continue'] );
357 if ( $this->multiUserMode ) {
358 $this->dieContinueUsageIf( count( $continue ) != 4 );
359 $modeFlag = array_shift( $continue );
360 $this->dieContinueUsageIf( $modeFlag !== $this->orderBy );
361 $encUser = $db->addQuotes( array_shift( $continue ) );
362 } else {
363 $this->dieContinueUsageIf( count( $continue ) != 2 );
364 }
365 $encTS = $db->addQuotes( $db->timestamp( $continue[0] ) );
366 $encId = (int)$continue[1];
367 $this->dieContinueUsageIf( $encId != $continue[1] );
368 $op = ( $this->params['dir'] == 'older' ? '<' : '>' );
369 if ( $this->multiUserMode ) {
370 $this->addWhere(
371 "$userField $op $encUser OR " .
372 "($userField = $encUser AND " .
373 "($tsField $op $encTS OR " .
374 "($tsField = $encTS AND " .
375 "$idField $op= $encId)))"
376 );
377 } else {
378 $this->addWhere(
379 "$tsField $op $encTS OR " .
380 "($tsField = $encTS AND " .
381 "$idField $op= $encId)"
382 );
383 }
384 }
385
386 // Don't include any revisions where we're not supposed to be able to
387 // see the username.
388 $user = $this->getUser();
389 if ( !$user->isAllowed( 'deletedhistory' ) ) {
390 $bitmask = RevisionRecord::DELETED_USER;
391 } elseif ( !$user->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 ( !is_null( $show ) ) {
419 $show = array_flip( $show );
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 if ( !$user->useRCPatrol() && !$user->useNPPatrol() ) {
460 $this->dieWithError( 'apierror-permissiondenied-patrolflag', 'permissiondenied' );
461 }
462
463 $isFilterset = isset( $show['patrolled'] ) || isset( $show['!patrolled'] ) ||
464 isset( $show['autopatrolled'] ) || isset( $show['!autopatrolled'] );
465 $this->addTables( 'recentchanges' );
466 $this->addJoinConds( [ 'recentchanges' => [
467 $isFilterset ? 'JOIN' : 'LEFT JOIN',
468 [
469 // This is a crazy hack. recentchanges has no index on rc_this_oldid, so instead of adding
470 // one T19237 did a join using rc_user_text and rc_timestamp instead. Now rc_user_text is
471 // probably unavailable, so just do rc_timestamp.
472 'rc_timestamp = ' . $tsField,
473 'rc_this_oldid = ' . $idField,
474 ]
475 ] ] );
476 }
477
478 $this->addFieldsIf( 'rc_patrolled', $this->fld_patrolled );
479
480 if ( $this->fld_tags ) {
481 $this->addTables( 'tag_summary' );
482 $this->addJoinConds(
483 [ 'tag_summary' => [ 'LEFT JOIN', [ $idField . ' = ts_rev_id' ] ] ]
484 );
485 $this->addFields( 'ts_tags' );
486 }
487
488 if ( isset( $this->params['tag'] ) ) {
489 $this->addTables( 'change_tag' );
490 $this->addJoinConds(
491 [ 'change_tag' => [ 'INNER JOIN', [ $idField . ' = ct_rev_id' ] ] ]
492 );
494 $changeTagDefStore = MediaWikiServices::getInstance()->getChangeTagDefStore();
495 try {
496 $this->addWhereFld( 'ct_tag_id', $changeTagDefStore->getId( $this->params['tag'] ) );
497 } catch ( NameTableAccessException $exception ) {
498 // Return nothing.
499 $this->addWhere( '1=0' );
500 }
501 } else {
502 $this->addWhereFld( 'ct_tag', $this->params['tag'] );
503 }
504 }
505 }
506
513 private function extractRowInfo( $row ) {
514 $vals = [];
515 $anyHidden = false;
516
517 if ( $row->rev_deleted & RevisionRecord::DELETED_TEXT ) {
518 $vals['texthidden'] = true;
519 $anyHidden = true;
520 }
521
522 // Any rows where we can't view the user were filtered out in the query.
523 $vals['userid'] = (int)$row->rev_user;
524 $vals['user'] = $row->rev_user_text;
525 if ( $row->rev_deleted & RevisionRecord::DELETED_USER ) {
526 $vals['userhidden'] = true;
527 $anyHidden = true;
528 }
529 if ( $this->fld_ids ) {
530 $vals['pageid'] = intval( $row->rev_page );
531 $vals['revid'] = intval( $row->rev_id );
532 // $vals['textid'] = intval( $row->rev_text_id ); // todo: Should this field be exposed?
533
534 if ( !is_null( $row->rev_parent_id ) ) {
535 $vals['parentid'] = intval( $row->rev_parent_id );
536 }
537 }
538
539 $title = Title::makeTitle( $row->page_namespace, $row->page_title );
540
541 if ( $this->fld_title ) {
543 }
544
545 if ( $this->fld_timestamp ) {
546 $vals['timestamp'] = wfTimestamp( TS_ISO_8601, $row->rev_timestamp );
547 }
548
549 if ( $this->fld_flags ) {
550 $vals['new'] = $row->rev_parent_id == 0 && !is_null( $row->rev_parent_id );
551 $vals['minor'] = (bool)$row->rev_minor_edit;
552 $vals['top'] = $row->page_latest == $row->rev_id;
553 }
554
555 if ( $this->fld_comment || $this->fld_parsedcomment ) {
556 if ( $row->rev_deleted & RevisionRecord::DELETED_COMMENT ) {
557 $vals['commenthidden'] = true;
558 $anyHidden = true;
559 }
560
561 $userCanView = RevisionRecord::userCanBitfield(
562 $row->rev_deleted,
563 RevisionRecord::DELETED_COMMENT, $this->getUser()
564 );
565
566 if ( $userCanView ) {
567 $comment = $this->commentStore->getComment( 'rev_comment', $row )->text;
568 if ( $this->fld_comment ) {
569 $vals['comment'] = $comment;
570 }
571
572 if ( $this->fld_parsedcomment ) {
573 $vals['parsedcomment'] = Linker::formatComment( $comment, $title );
574 }
575 }
576 }
577
578 if ( $this->fld_patrolled ) {
579 $vals['patrolled'] = $row->rc_patrolled != RecentChange::PRC_UNPATROLLED;
580 $vals['autopatrolled'] = $row->rc_patrolled == RecentChange::PRC_AUTOPATROLLED;
581 }
582
583 if ( $this->fld_size && !is_null( $row->rev_len ) ) {
584 $vals['size'] = intval( $row->rev_len );
585 }
586
587 if ( $this->fld_sizediff
588 && !is_null( $row->rev_len )
589 && !is_null( $row->rev_parent_id )
590 ) {
591 $parentLen = $this->parentLens[$row->rev_parent_id] ?? 0;
592 $vals['sizediff'] = intval( $row->rev_len - $parentLen );
593 }
594
595 if ( $this->fld_tags ) {
596 if ( $row->ts_tags ) {
597 $tags = explode( ',', $row->ts_tags );
598 ApiResult::setIndexedTagName( $tags, 'tag' );
599 $vals['tags'] = $tags;
600 } else {
601 $vals['tags'] = [];
602 }
603 }
604
605 if ( $anyHidden && ( $row->rev_deleted & RevisionRecord::DELETED_RESTRICTED ) ) {
606 $vals['suppressed'] = true;
607 }
608
609 return $vals;
610 }
611
612 private function continueStr( $row ) {
613 if ( $this->multiUserMode ) {
614 switch ( $this->orderBy ) {
615 case 'id':
616 return "id|$row->rev_user|$row->rev_timestamp|$row->rev_id";
617 case 'name':
618 return "name|$row->rev_user_text|$row->rev_timestamp|$row->rev_id";
619 case 'actor':
620 return "actor|$row->rev_actor|$row->rev_timestamp|$row->rev_id";
621 }
622 } else {
623 return "$row->rev_timestamp|$row->rev_id";
624 }
625 }
626
627 public function getCacheMode( $params ) {
628 // This module provides access to deleted revisions and patrol flags if
629 // the requester is logged in
630 return 'anon-public-user-private';
631 }
632
633 public function getAllowedParams() {
634 return [
635 'limit' => [
637 ApiBase::PARAM_TYPE => 'limit',
641 ],
642 'start' => [
643 ApiBase::PARAM_TYPE => 'timestamp'
644 ],
645 'end' => [
646 ApiBase::PARAM_TYPE => 'timestamp'
647 ],
648 'continue' => [
649 ApiBase::PARAM_HELP_MSG => 'api-help-param-continue',
650 ],
651 'user' => [
652 ApiBase::PARAM_TYPE => 'user',
654 ],
655 'userids' => [
656 ApiBase::PARAM_TYPE => 'integer',
658 ],
659 'userprefix' => null,
660 'dir' => [
661 ApiBase::PARAM_DFLT => 'older',
663 'newer',
664 'older'
665 ],
666 ApiBase::PARAM_HELP_MSG => 'api-help-param-direction',
667 ],
668 'namespace' => [
670 ApiBase::PARAM_TYPE => 'namespace'
671 ],
672 'prop' => [
674 ApiBase::PARAM_DFLT => 'ids|title|timestamp|comment|size|flags',
676 'ids',
677 'title',
678 'timestamp',
679 'comment',
680 'parsedcomment',
681 'size',
682 'sizediff',
683 'flags',
684 'patrolled',
685 'tags'
686 ],
688 ],
689 'show' => [
692 'minor',
693 '!minor',
694 'patrolled',
695 '!patrolled',
696 'autopatrolled',
697 '!autopatrolled',
698 'top',
699 '!top',
700 'new',
701 '!new',
702 ],
704 'apihelp-query+usercontribs-param-show',
705 $this->getConfig()->get( 'RCMaxAge' )
706 ],
707 ],
708 'tag' => null,
709 'toponly' => [
710 ApiBase::PARAM_DFLT => false,
712 ],
713 ];
714 }
715
716 protected function getExamplesMessages() {
717 return [
718 'action=query&list=usercontribs&ucuser=Example'
719 => 'apihelp-query+usercontribs-example-user',
720 'action=query&list=usercontribs&ucuserprefix=192.0.2.'
721 => 'apihelp-query+usercontribs-example-ipprefix',
722 ];
723 }
724
725 public function getHelpUrls() {
726 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Usercontribs';
727 }
728}
729
734class_alias( ApiQueryUserContribs::class, 'ApiQueryContributions' );
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
int $wgChangeTagsSchemaMigrationStage
change_tag table schema migration stage.
int $wgActorTableSchemaMigrationStage
Actor table schema migration stage.
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
wfEscapeWikiText( $text)
Escapes the given text so that it may be output using addWikiText() without any linking,...
if(defined( 'MW_SETUP_CALLBACK')) $fname
Customization point after all loading (constants, functions, classes, DefaultSettings,...
Definition Setup.php:121
const PARAM_MAX2
(integer) Max value allowed for the parameter for users with the apihighlimits right,...
Definition ApiBase.php:96
const PARAM_DEPRECATED
(boolean) Is the parameter deprecated (will show a warning)?
Definition ApiBase.php:105
encodeParamName( $paramName)
This method mangles parameter name based on the prefix supplied to the constructor.
Definition ApiBase.php:748
const PARAM_MAX
(integer) Max value allowed for the parameter, for PARAM_TYPE 'integer' and 'limit'.
Definition ApiBase.php:90
dieWithError( $msg, $code=null, $data=null, $httpCode=null)
Abort execution with an error.
Definition ApiBase.php:1987
dieContinueUsageIf( $condition)
Die with the 'badcontinue' error.
Definition ApiBase.php:2155
const PARAM_TYPE
(string|string[]) Either an array of allowed value strings, or a string type as described below.
Definition ApiBase.php:87
const PARAM_DFLT
(null|boolean|integer|string) Default value of the parameter.
Definition ApiBase.php:48
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
const PARAM_MIN
(integer) Lowest value allowed for the parameter, for PARAM_TYPE 'integer' and 'limit'.
Definition ApiBase.php:99
const LIMIT_BIG1
Fast query, standard limit.
Definition ApiBase.php:252
getResult()
Get the result object.
Definition ApiBase.php:659
extractRequestParams( $options=[])
Using getAllowedParams(), this function makes an array of the values provided by the user,...
Definition ApiBase.php:770
const PARAM_HELP_MSG
(string|array|Message) Specify an alternative i18n documentation message for this parameter.
Definition ApiBase.php:124
const LIMIT_BIG2
Fast query, apihighlimits limit.
Definition ApiBase.php:254
getModuleName()
Get the name of the module being executed by this instance.
Definition ApiBase.php:539
requireOnlyOneParameter( $params, $required)
Die if none or more than one of a certain set of parameters is set and not false.
Definition ApiBase.php:901
const PARAM_ISMULTI
(boolean) Accept multiple pipe-separated values for this parameter (e.g.
Definition ApiBase.php:51
This is a base class for all Query modules.
selectNamedDB( $name, $db, $groups)
Selects the query database connection with the given name.
static addTitleInfo(&$arr, $title, $prefix='')
Add information (title and namespace) about a Title object to a result array.
setContinueEnumParameter( $paramName, $paramValue)
Set a query-continue value.
processRow( $row, array &$data, array &$hookData)
Call the ApiQueryBaseProcessRow hook.
resetQueryParams()
Blank the internal arrays with query parameters.
addWhereIf( $value, $condition)
Same as addWhere(), but add the WHERE clauses only if a condition is met.
addWhereRange( $field, $dir, $start, $end, $sort=true)
Add a WHERE clause corresponding to a range, and an ORDER BY clause to sort in the right direction.
addFields( $value)
Add a set of fields to select to the internal array.
addOption( $name, $value=null)
Add an option such as LIMIT or USE INDEX.
addTables( $tables, $alias=null)
Add a set of tables to the internal array.
addTimestampWhereRange( $field, $dir, $start, $end, $sort=true)
Add a WHERE clause corresponding to a range, similar to addWhereRange, but converts $start and $end t...
getDB()
Get the Query database connection (read-only)
addFieldsIf( $value, $condition)
Same as addFields(), but add the fields only if a condition is met.
addJoinConds( $join_conds)
Add a set of JOIN conditions to the internal array.
addWhereFld( $field, $value)
Equivalent to addWhere(array($field => $value))
addWhere( $value)
Add a set of WHERE clauses to the internal array.
This query action adds a list of a specified user's contributions to the output.
getAllowedParams()
Returns an array of allowed parameters (parameter name) => (default value) or (parameter name) => (ar...
getCacheMode( $params)
Get the cache mode for the data generated by this module.
getHelpUrls()
Return links to more detailed help pages about the module.
getExamplesMessages()
Returns usage examples for this module.
__construct(ApiQuery $query, $moduleName)
execute()
Evaluates the parameters, performs the requested query, and sets up the result.
prepareQuery(array $users, $limit)
Prepares the query and returns the limit of rows requested.
extractRowInfo( $row)
Extract fields from the database row and append them to a result array.
This is the main query class.
Definition ApiQuery.php:36
static setIndexedTagName(array &$arr, $tag)
Set the tag name for numeric-keyed values in XML format.
static isExternal( $username)
Tells whether the username is external or not.
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:1088
MediaWikiServices is the service locator for the application scope of MediaWiki.
Page revision base class.
Exception representing a failure to look up a row from a name table.
static newFromResult( $res)
Definition UserArray.php:30
static newFromName( $name, $validate='valid')
Static factory method for creation from username.
Definition User.php:592
static getCanonicalName( $name, $validate='valid')
Given unvalidated user input, return a canonical username, or false if the username is invalid.
Definition User.php:1238
static newFromRow( $row, $data=null)
Create a new user object from a user row.
Definition User.php:778
static isIP( $name)
Does the string match an anonymous IP address?
Definition User.php:971
We use the convention $dbr for read and $dbw for write to help you keep track of whether the database object is a the world will explode Or to be a subsequent write query which succeeded on the master may fail when replicated to the slave due to a unique key collision Replication on the slave will stop and it may take hours to repair the database and get it back online Setting read_only in my cnf on the slave will avoid this but given the dire we prefer to have as many checks as possible We provide a but the wrapper functions like select() and insert() are usually more convenient. They take care of things like table prefixes and escaping for you. If you really need to make your own SQL
$res
Definition database.txt:21
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
const SCHEMA_COMPAT_READ_NEW
Definition Defines.php:287
const MIGRATION_WRITE_BOTH
Definition Defines.php:316
namespace and then decline to actually register it file or subcat img or subcat $title
Definition hooks.txt:994
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:2055
Allows to change the fields on the form that will be generated $name
Definition hooks.txt:302
null for the local 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:1656
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 local account $user
Definition hooks.txt:247
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
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))
$sort
const DB_REPLICA
Definition defines.php:25