MediaWiki REL1_32
ApiQueryRecentChanges.php
Go to the documentation of this file.
1<?php
26
34
35 public function __construct( ApiQuery $query, $moduleName ) {
36 parent::__construct( $query, $moduleName, 'rc' );
37 }
38
40
41 private $fld_comment = false, $fld_parsedcomment = false, $fld_user = false, $fld_userid = false,
42 $fld_flags = false, $fld_timestamp = false, $fld_title = false, $fld_ids = false,
43 $fld_sizes = false, $fld_redirect = false, $fld_patrolled = false, $fld_loginfo = false,
44 $fld_tags = false, $fld_sha1 = false, $token = [];
45
47
55 protected function getTokenFunctions() {
56 // Don't call the hooks twice
57 if ( isset( $this->tokenFunctions ) ) {
59 }
60
61 // If we're in a mode that breaks the same-origin policy, no tokens can
62 // be obtained
63 if ( $this->lacksSameOriginSecurity() ) {
64 return [];
65 }
66
67 $this->tokenFunctions = [
68 'patrol' => [ self::class, 'getPatrolToken' ]
69 ];
70 Hooks::run( 'APIQueryRecentChangesTokens', [ &$this->tokenFunctions ] );
71
73 }
74
82 public static function getPatrolToken( $pageid, $title, $rc = null ) {
83 global $wgUser;
84
85 $validTokenUser = false;
86
87 if ( $rc ) {
88 if ( ( $wgUser->useRCPatrol() && $rc->getAttribute( 'rc_type' ) == RC_EDIT ) ||
89 ( $wgUser->useNPPatrol() && $rc->getAttribute( 'rc_type' ) == RC_NEW )
90 ) {
91 $validTokenUser = true;
92 }
93 } elseif ( $wgUser->useRCPatrol() || $wgUser->useNPPatrol() ) {
94 $validTokenUser = true;
95 }
96
97 if ( $validTokenUser ) {
98 // The patrol token is always the same, let's exploit that
99 static $cachedPatrolToken = null;
100
101 if ( is_null( $cachedPatrolToken ) ) {
102 $cachedPatrolToken = $wgUser->getEditToken( 'patrol' );
103 }
104
105 return $cachedPatrolToken;
106 }
107
108 return false;
109 }
110
115 public function initProperties( $prop ) {
116 $this->fld_comment = isset( $prop['comment'] );
117 $this->fld_parsedcomment = isset( $prop['parsedcomment'] );
118 $this->fld_user = isset( $prop['user'] );
119 $this->fld_userid = isset( $prop['userid'] );
120 $this->fld_flags = isset( $prop['flags'] );
121 $this->fld_timestamp = isset( $prop['timestamp'] );
122 $this->fld_title = isset( $prop['title'] );
123 $this->fld_ids = isset( $prop['ids'] );
124 $this->fld_sizes = isset( $prop['sizes'] );
125 $this->fld_redirect = isset( $prop['redirect'] );
126 $this->fld_patrolled = isset( $prop['patrolled'] );
127 $this->fld_loginfo = isset( $prop['loginfo'] );
128 $this->fld_tags = isset( $prop['tags'] );
129 $this->fld_sha1 = isset( $prop['sha1'] );
130 }
131
132 public function execute() {
133 $this->run();
134 }
135
136 public function executeGenerator( $resultPageSet ) {
137 $this->run( $resultPageSet );
138 }
139
145 public function run( $resultPageSet = null ) {
147
148 $user = $this->getUser();
149 /* Get the parameters of the request. */
150 $params = $this->extractRequestParams();
151
152 /* Build our basic query. Namely, something along the lines of:
153 * SELECT * FROM recentchanges WHERE rc_timestamp > $start
154 * AND rc_timestamp < $end AND rc_namespace = $namespace
155 */
156 $this->addTables( 'recentchanges' );
157 $this->addTimestampWhereRange( 'rc_timestamp', $params['dir'], $params['start'], $params['end'] );
158
159 if ( !is_null( $params['continue'] ) ) {
160 $cont = explode( '|', $params['continue'] );
161 $this->dieContinueUsageIf( count( $cont ) != 2 );
162 $db = $this->getDB();
163 $timestamp = $db->addQuotes( $db->timestamp( $cont[0] ) );
164 $id = intval( $cont[1] );
165 $this->dieContinueUsageIf( $id != $cont[1] );
166 $op = $params['dir'] === 'older' ? '<' : '>';
167 $this->addWhere(
168 "rc_timestamp $op $timestamp OR " .
169 "(rc_timestamp = $timestamp AND " .
170 "rc_id $op= $id)"
171 );
172 }
173
174 $order = $params['dir'] === 'older' ? 'DESC' : 'ASC';
175 $this->addOption( 'ORDER BY', [
176 "rc_timestamp $order",
177 "rc_id $order",
178 ] );
179
180 $this->addWhereFld( 'rc_namespace', $params['namespace'] );
181
182 if ( !is_null( $params['type'] ) ) {
183 try {
184 $this->addWhereFld( 'rc_type', RecentChange::parseToRCType( $params['type'] ) );
185 } catch ( Exception $e ) {
186 ApiBase::dieDebug( __METHOD__, $e->getMessage() );
187 }
188 }
189
190 $title = $params['title'];
191 if ( !is_null( $title ) ) {
192 $titleObj = Title::newFromText( $title );
193 if ( is_null( $titleObj ) ) {
194 $this->dieWithError( [ 'apierror-invalidtitle', wfEscapeWikiText( $title ) ] );
195 }
196 $this->addWhereFld( 'rc_namespace', $titleObj->getNamespace() );
197 $this->addWhereFld( 'rc_title', $titleObj->getDBkey() );
198 }
199
200 if ( !is_null( $params['show'] ) ) {
201 $show = array_flip( $params['show'] );
202
203 /* Check for conflicting parameters. */
204 if ( ( isset( $show['minor'] ) && isset( $show['!minor'] ) )
205 || ( isset( $show['bot'] ) && isset( $show['!bot'] ) )
206 || ( isset( $show['anon'] ) && isset( $show['!anon'] ) )
207 || ( isset( $show['redirect'] ) && isset( $show['!redirect'] ) )
208 || ( isset( $show['patrolled'] ) && isset( $show['!patrolled'] ) )
209 || ( isset( $show['patrolled'] ) && isset( $show['unpatrolled'] ) )
210 || ( isset( $show['!patrolled'] ) && isset( $show['unpatrolled'] ) )
211 || ( isset( $show['autopatrolled'] ) && isset( $show['!autopatrolled'] ) )
212 || ( isset( $show['autopatrolled'] ) && isset( $show['unpatrolled'] ) )
213 || ( isset( $show['autopatrolled'] ) && isset( $show['!patrolled'] ) )
214 ) {
215 $this->dieWithError( 'apierror-show' );
216 }
217
218 // Check permissions
219 if ( $this->includesPatrollingFlags( $show ) ) {
220 if ( !$user->useRCPatrol() && !$user->useNPPatrol() ) {
221 $this->dieWithError( 'apierror-permissiondenied-patrolflag', 'permissiondenied' );
222 }
223 }
224
225 /* Add additional conditions to query depending upon parameters. */
226 $this->addWhereIf( 'rc_minor = 0', isset( $show['!minor'] ) );
227 $this->addWhereIf( 'rc_minor != 0', isset( $show['minor'] ) );
228 $this->addWhereIf( 'rc_bot = 0', isset( $show['!bot'] ) );
229 $this->addWhereIf( 'rc_bot != 0', isset( $show['bot'] ) );
230 if ( isset( $show['anon'] ) || isset( $show['!anon'] ) ) {
231 $actorMigration = ActorMigration::newMigration();
232 $actorQuery = $actorMigration->getJoin( 'rc_user' );
233 $this->addTables( $actorQuery['tables'] );
234 $this->addJoinConds( $actorQuery['joins'] );
235 $this->addWhereIf(
236 $actorMigration->isAnon( $actorQuery['fields']['rc_user'] ), isset( $show['anon'] )
237 );
238 $this->addWhereIf(
239 $actorMigration->isNotAnon( $actorQuery['fields']['rc_user'] ), isset( $show['!anon'] )
240 );
241 }
242 $this->addWhereIf( 'rc_patrolled = 0', isset( $show['!patrolled'] ) );
243 $this->addWhereIf( 'rc_patrolled != 0', isset( $show['patrolled'] ) );
244 $this->addWhereIf( 'page_is_redirect = 1', isset( $show['redirect'] ) );
245
246 if ( isset( $show['unpatrolled'] ) ) {
247 // See ChangesList::isUnpatrolled
248 if ( $user->useRCPatrol() ) {
249 $this->addWhere( 'rc_patrolled = ' . RecentChange::PRC_UNPATROLLED );
250 } elseif ( $user->useNPPatrol() ) {
251 $this->addWhere( 'rc_patrolled = ' . RecentChange::PRC_UNPATROLLED );
252 $this->addWhereFld( 'rc_type', RC_NEW );
253 }
254 }
255
256 $this->addWhereIf(
257 'rc_patrolled != ' . RecentChange::PRC_AUTOPATROLLED,
258 isset( $show['!autopatrolled'] )
259 );
260 $this->addWhereIf(
261 'rc_patrolled = ' . RecentChange::PRC_AUTOPATROLLED,
262 isset( $show['autopatrolled'] )
263 );
264
265 // Don't throw log entries out the window here
266 $this->addWhereIf(
267 'page_is_redirect = 0 OR page_is_redirect IS NULL',
268 isset( $show['!redirect'] )
269 );
270 }
271
272 $this->requireMaxOneParameter( $params, 'user', 'excludeuser' );
273
274 if ( !is_null( $params['user'] ) ) {
275 // Don't query by user ID here, it might be able to use the rc_user_text index.
276 $actorQuery = ActorMigration::newMigration()
277 ->getWhere( $this->getDB(), 'rc_user', User::newFromName( $params['user'], false ), false );
278 $this->addTables( $actorQuery['tables'] );
279 $this->addJoinConds( $actorQuery['joins'] );
280 $this->addWhere( $actorQuery['conds'] );
281 }
282
283 if ( !is_null( $params['excludeuser'] ) ) {
284 // Here there's no chance to use the rc_user_text index, so allow ID to be used.
285 $actorQuery = ActorMigration::newMigration()
286 ->getWhere( $this->getDB(), 'rc_user', User::newFromName( $params['excludeuser'], false ) );
287 $this->addTables( $actorQuery['tables'] );
288 $this->addJoinConds( $actorQuery['joins'] );
289 $this->addWhere( 'NOT(' . $actorQuery['conds'] . ')' );
290 }
291
292 /* Add the fields we're concerned with to our query. */
293 $this->addFields( [
294 'rc_id',
295 'rc_timestamp',
296 'rc_namespace',
297 'rc_title',
298 'rc_cur_id',
299 'rc_type',
300 'rc_deleted'
301 ] );
302
303 $showRedirects = false;
304 /* Determine what properties we need to display. */
305 if ( !is_null( $params['prop'] ) ) {
306 $prop = array_flip( $params['prop'] );
307
308 /* Set up internal members based upon params. */
309 $this->initProperties( $prop );
310
311 if ( $this->fld_patrolled && !$user->useRCPatrol() && !$user->useNPPatrol() ) {
312 $this->dieWithError( 'apierror-permissiondenied-patrolflag', 'permissiondenied' );
313 }
314
315 /* Add fields to our query if they are specified as a needed parameter. */
316 $this->addFieldsIf( [ 'rc_this_oldid', 'rc_last_oldid' ], $this->fld_ids );
317 if ( $this->fld_user || $this->fld_userid ) {
318 $actorQuery = ActorMigration::newMigration()->getJoin( 'rc_user' );
319 $this->addTables( $actorQuery['tables'] );
320 $this->addFields( $actorQuery['fields'] );
321 $this->addJoinConds( $actorQuery['joins'] );
322 }
323 $this->addFieldsIf( [ 'rc_minor', 'rc_type', 'rc_bot' ], $this->fld_flags );
324 $this->addFieldsIf( [ 'rc_old_len', 'rc_new_len' ], $this->fld_sizes );
325 $this->addFieldsIf( [ 'rc_patrolled', 'rc_log_type' ], $this->fld_patrolled );
326 $this->addFieldsIf(
327 [ 'rc_logid', 'rc_log_type', 'rc_log_action', 'rc_params' ],
328 $this->fld_loginfo
329 );
330 $showRedirects = $this->fld_redirect || isset( $show['redirect'] )
331 || isset( $show['!redirect'] );
332 }
333 $this->addFieldsIf( [ 'rc_this_oldid' ],
334 $resultPageSet && $params['generaterevisions'] );
335
336 if ( $this->fld_tags ) {
337 $this->addTables( 'tag_summary' );
338 $this->addJoinConds( [ 'tag_summary' => [ 'LEFT JOIN', [ 'rc_id=ts_rc_id' ] ] ] );
339 $this->addFields( 'ts_tags' );
340 }
341
342 if ( $this->fld_sha1 ) {
343 $this->addTables( 'revision' );
344 $this->addJoinConds( [ 'revision' => [ 'LEFT JOIN',
345 [ 'rc_this_oldid=rev_id' ] ] ] );
346 $this->addFields( [ 'rev_sha1', 'rev_deleted' ] );
347 }
348
349 if ( $params['toponly'] || $showRedirects ) {
350 $this->addTables( 'page' );
351 $this->addJoinConds( [ 'page' => [ 'LEFT JOIN',
352 [ 'rc_namespace=page_namespace', 'rc_title=page_title' ] ] ] );
353 $this->addFields( 'page_is_redirect' );
354
355 if ( $params['toponly'] ) {
356 $this->addWhere( 'rc_this_oldid = page_latest' );
357 }
358 }
359
360 if ( !is_null( $params['tag'] ) ) {
361 $this->addTables( 'change_tag' );
362 $this->addJoinConds( [ 'change_tag' => [ 'INNER JOIN', [ 'rc_id=ct_rc_id' ] ] ] );
363 if ( $wgChangeTagsSchemaMigrationStage > MIGRATION_WRITE_BOTH ) {
364 $changeTagDefStore = MediaWikiServices::getInstance()->getChangeTagDefStore();
365 try {
366 $this->addWhereFld( 'ct_tag_id', $changeTagDefStore->getId( $params['tag'] ) );
367 } catch ( NameTableAccessException $exception ) {
368 // Return nothing.
369 $this->addWhere( '1=0' );
370 }
371 } else {
372 $this->addWhereFld( 'ct_tag', $params['tag'] );
373 }
374 }
375
376 // Paranoia: avoid brute force searches (T19342)
377 if ( !is_null( $params['user'] ) || !is_null( $params['excludeuser'] ) ) {
378 if ( !$user->isAllowed( 'deletedhistory' ) ) {
379 $bitmask = RevisionRecord::DELETED_USER;
380 } elseif ( !$user->isAllowedAny( 'suppressrevision', 'viewsuppressed' ) ) {
381 $bitmask = RevisionRecord::DELETED_USER | RevisionRecord::DELETED_RESTRICTED;
382 } else {
383 $bitmask = 0;
384 }
385 if ( $bitmask ) {
386 $this->addWhere( $this->getDB()->bitAnd( 'rc_deleted', $bitmask ) . " != $bitmask" );
387 }
388 }
389 if ( $this->getRequest()->getCheck( 'namespace' ) ) {
390 // LogPage::DELETED_ACTION hides the affected page, too.
391 if ( !$user->isAllowed( 'deletedhistory' ) ) {
392 $bitmask = LogPage::DELETED_ACTION;
393 } elseif ( !$user->isAllowedAny( 'suppressrevision', 'viewsuppressed' ) ) {
395 } else {
396 $bitmask = 0;
397 }
398 if ( $bitmask ) {
399 $this->addWhere( $this->getDB()->makeList( [
400 'rc_type != ' . RC_LOG,
401 $this->getDB()->bitAnd( 'rc_deleted', $bitmask ) . " != $bitmask",
402 ], LIST_OR ) );
403 }
404 }
405
406 $this->token = $params['token'];
407
408 if ( $this->fld_comment || $this->fld_parsedcomment || $this->token ) {
409 $this->commentStore = CommentStore::getStore();
410 $commentQuery = $this->commentStore->getJoin( 'rc_comment' );
411 $this->addTables( $commentQuery['tables'] );
412 $this->addFields( $commentQuery['fields'] );
413 $this->addJoinConds( $commentQuery['joins'] );
414 }
415
416 $this->addOption( 'LIMIT', $params['limit'] + 1 );
417
418 $hookData = [];
419 $count = 0;
420 /* Perform the actual query. */
421 $res = $this->select( __METHOD__, [], $hookData );
422
423 $revids = [];
424 $titles = [];
425
426 $result = $this->getResult();
427
428 /* Iterate through the rows, adding data extracted from them to our query result. */
429 foreach ( $res as $row ) {
430 if ( $count === 0 && $resultPageSet !== null ) {
431 // Set the non-continue since the list of recentchanges is
432 // prone to having entries added at the start frequently.
433 $this->getContinuationManager()->addGeneratorNonContinueParam(
434 $this, 'continue', "$row->rc_timestamp|$row->rc_id"
435 );
436 }
437 if ( ++$count > $params['limit'] ) {
438 // We've reached the one extra which shows that there are
439 // additional pages to be had. Stop here...
440 $this->setContinueEnumParameter( 'continue', "$row->rc_timestamp|$row->rc_id" );
441 break;
442 }
443
444 if ( is_null( $resultPageSet ) ) {
445 /* Extract the data from a single row. */
446 $vals = $this->extractRowInfo( $row );
447
448 /* Add that row's data to our final output. */
449 $fit = $this->processRow( $row, $vals, $hookData ) &&
450 $result->addValue( [ 'query', $this->getModuleName() ], null, $vals );
451 if ( !$fit ) {
452 $this->setContinueEnumParameter( 'continue', "$row->rc_timestamp|$row->rc_id" );
453 break;
454 }
455 } elseif ( $params['generaterevisions'] ) {
456 $revid = (int)$row->rc_this_oldid;
457 if ( $revid > 0 ) {
458 $revids[] = $revid;
459 }
460 } else {
461 $titles[] = Title::makeTitle( $row->rc_namespace, $row->rc_title );
462 }
463 }
464
465 if ( is_null( $resultPageSet ) ) {
466 /* Format the result */
467 $result->addIndexedTagName( [ 'query', $this->getModuleName() ], 'rc' );
468 } elseif ( $params['generaterevisions'] ) {
469 $resultPageSet->populateFromRevisionIDs( $revids );
470 } else {
471 $resultPageSet->populateFromTitles( $titles );
472 }
473 }
474
482 public function extractRowInfo( $row ) {
483 /* Determine the title of the page that has been changed. */
484 $title = Title::makeTitle( $row->rc_namespace, $row->rc_title );
485 $user = $this->getUser();
486
487 /* Our output data. */
488 $vals = [];
489
490 $type = intval( $row->rc_type );
491 $vals['type'] = RecentChange::parseFromRCType( $type );
492
493 $anyHidden = false;
494
495 /* Create a new entry in the result for the title. */
496 if ( $this->fld_title || $this->fld_ids ) {
497 if ( $type === RC_LOG && ( $row->rc_deleted & LogPage::DELETED_ACTION ) ) {
498 $vals['actionhidden'] = true;
499 $anyHidden = true;
500 }
501 if ( $type !== RC_LOG ||
503 ) {
504 if ( $this->fld_title ) {
505 ApiQueryBase::addTitleInfo( $vals, $title );
506 }
507 if ( $this->fld_ids ) {
508 $vals['pageid'] = intval( $row->rc_cur_id );
509 $vals['revid'] = intval( $row->rc_this_oldid );
510 $vals['old_revid'] = intval( $row->rc_last_oldid );
511 }
512 }
513 }
514
515 if ( $this->fld_ids ) {
516 $vals['rcid'] = intval( $row->rc_id );
517 }
518
519 /* Add user data and 'anon' flag, if user is anonymous. */
520 if ( $this->fld_user || $this->fld_userid ) {
521 if ( $row->rc_deleted & RevisionRecord::DELETED_USER ) {
522 $vals['userhidden'] = true;
523 $anyHidden = true;
524 }
525 if ( RevisionRecord::userCanBitfield( $row->rc_deleted, RevisionRecord::DELETED_USER, $user ) ) {
526 if ( $this->fld_user ) {
527 $vals['user'] = $row->rc_user_text;
528 }
529
530 if ( $this->fld_userid ) {
531 $vals['userid'] = (int)$row->rc_user;
532 }
533
534 if ( !$row->rc_user ) {
535 $vals['anon'] = true;
536 }
537 }
538 }
539
540 /* Add flags, such as new, minor, bot. */
541 if ( $this->fld_flags ) {
542 $vals['bot'] = (bool)$row->rc_bot;
543 $vals['new'] = $row->rc_type == RC_NEW;
544 $vals['minor'] = (bool)$row->rc_minor;
545 }
546
547 /* Add sizes of each revision. (Only available on 1.10+) */
548 if ( $this->fld_sizes ) {
549 $vals['oldlen'] = intval( $row->rc_old_len );
550 $vals['newlen'] = intval( $row->rc_new_len );
551 }
552
553 /* Add the timestamp. */
554 if ( $this->fld_timestamp ) {
555 $vals['timestamp'] = wfTimestamp( TS_ISO_8601, $row->rc_timestamp );
556 }
557
558 /* Add edit summary / log summary. */
559 if ( $this->fld_comment || $this->fld_parsedcomment ) {
560 if ( $row->rc_deleted & RevisionRecord::DELETED_COMMENT ) {
561 $vals['commenthidden'] = true;
562 $anyHidden = true;
563 }
564 if ( RevisionRecord::userCanBitfield(
565 $row->rc_deleted, RevisionRecord::DELETED_COMMENT, $user
566 ) ) {
567 $comment = $this->commentStore->getComment( 'rc_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_redirect ) {
579 $vals['redirect'] = (bool)$row->page_is_redirect;
580 }
581
582 /* Add the patrolled flag */
583 if ( $this->fld_patrolled ) {
584 $vals['patrolled'] = $row->rc_patrolled != RecentChange::PRC_UNPATROLLED;
585 $vals['unpatrolled'] = ChangesList::isUnpatrolled( $row, $user );
586 $vals['autopatrolled'] = $row->rc_patrolled == RecentChange::PRC_AUTOPATROLLED;
587 }
588
589 if ( $this->fld_loginfo && $row->rc_type == RC_LOG ) {
590 if ( $row->rc_deleted & LogPage::DELETED_ACTION ) {
591 $vals['actionhidden'] = true;
592 $anyHidden = true;
593 }
594 if ( LogEventsList::userCanBitfield( $row->rc_deleted, LogPage::DELETED_ACTION, $user ) ) {
595 $vals['logid'] = intval( $row->rc_logid );
596 $vals['logtype'] = $row->rc_log_type;
597 $vals['logaction'] = $row->rc_log_action;
598 $vals['logparams'] = LogFormatter::newFromRow( $row )->formatParametersForApi();
599 }
600 }
601
602 if ( $this->fld_tags ) {
603 if ( $row->ts_tags ) {
604 $tags = explode( ',', $row->ts_tags );
605 ApiResult::setIndexedTagName( $tags, 'tag' );
606 $vals['tags'] = $tags;
607 } else {
608 $vals['tags'] = [];
609 }
610 }
611
612 if ( $this->fld_sha1 && $row->rev_sha1 !== null ) {
613 if ( $row->rev_deleted & RevisionRecord::DELETED_TEXT ) {
614 $vals['sha1hidden'] = true;
615 $anyHidden = true;
616 }
617 if ( RevisionRecord::userCanBitfield(
618 $row->rev_deleted, RevisionRecord::DELETED_TEXT, $user
619 ) ) {
620 if ( $row->rev_sha1 !== '' ) {
621 $vals['sha1'] = Wikimedia\base_convert( $row->rev_sha1, 36, 16, 40 );
622 } else {
623 $vals['sha1'] = '';
624 }
625 }
626 }
627
628 if ( !is_null( $this->token ) ) {
630 foreach ( $this->token as $t ) {
631 $val = call_user_func( $tokenFunctions[$t], $row->rc_cur_id,
632 $title, RecentChange::newFromRow( $row ) );
633 if ( $val === false ) {
634 $this->addWarning( [ 'apiwarn-tokennotallowed', $t ] );
635 } else {
636 $vals[$t . 'token'] = $val;
637 }
638 }
639 }
640
641 if ( $anyHidden && ( $row->rc_deleted & RevisionRecord::DELETED_RESTRICTED ) ) {
642 $vals['suppressed'] = true;
643 }
644
645 return $vals;
646 }
647
652 private function includesPatrollingFlags( array $flagsArray ) {
653 return isset( $flagsArray['patrolled'] ) ||
654 isset( $flagsArray['!patrolled'] ) ||
655 isset( $flagsArray['unpatrolled'] ) ||
656 isset( $flagsArray['autopatrolled'] ) ||
657 isset( $flagsArray['!autopatrolled'] );
658 }
659
660 public function getCacheMode( $params ) {
661 if ( isset( $params['show'] ) &&
662 $this->includesPatrollingFlags( array_flip( $params['show'] ) )
663 ) {
664 return 'private';
665 }
666 if ( isset( $params['token'] ) ) {
667 return 'private';
668 }
669 if ( $this->userCanSeeRevDel() ) {
670 return 'private';
671 }
672 if ( !is_null( $params['prop'] ) && in_array( 'parsedcomment', $params['prop'] ) ) {
673 // formatComment() calls wfMessage() among other things
674 return 'anon-public-user-private';
675 }
676
677 return 'public';
678 }
679
680 public function getAllowedParams() {
681 return [
682 'start' => [
683 ApiBase::PARAM_TYPE => 'timestamp'
684 ],
685 'end' => [
686 ApiBase::PARAM_TYPE => 'timestamp'
687 ],
688 'dir' => [
689 ApiBase::PARAM_DFLT => 'older',
691 'newer',
692 'older'
693 ],
694 ApiBase::PARAM_HELP_MSG => 'api-help-param-direction',
695 ],
696 'namespace' => [
698 ApiBase::PARAM_TYPE => 'namespace',
700 ],
701 'user' => [
702 ApiBase::PARAM_TYPE => 'user'
703 ],
704 'excludeuser' => [
705 ApiBase::PARAM_TYPE => 'user'
706 ],
707 'tag' => null,
708 'prop' => [
710 ApiBase::PARAM_DFLT => 'title|timestamp|ids',
712 'user',
713 'userid',
714 'comment',
715 'parsedcomment',
716 'flags',
717 'timestamp',
718 'title',
719 'ids',
720 'sizes',
721 'redirect',
722 'patrolled',
723 'loginfo',
724 'tags',
725 'sha1',
726 ],
728 ],
729 'token' => [
731 ApiBase::PARAM_TYPE => array_keys( $this->getTokenFunctions() ),
733 ],
734 'show' => [
737 'minor',
738 '!minor',
739 'bot',
740 '!bot',
741 'anon',
742 '!anon',
743 'redirect',
744 '!redirect',
745 'patrolled',
746 '!patrolled',
747 'unpatrolled',
748 'autopatrolled',
749 '!autopatrolled',
750 ]
751 ],
752 'limit' => [
754 ApiBase::PARAM_TYPE => 'limit',
758 ],
759 'type' => [
760 ApiBase::PARAM_DFLT => 'edit|new|log|categorize',
762 ApiBase::PARAM_TYPE => RecentChange::getChangeTypes()
763 ],
764 'toponly' => false,
765 'title' => null,
766 'continue' => [
767 ApiBase::PARAM_HELP_MSG => 'api-help-param-continue',
768 ],
769 'generaterevisions' => false,
770 ];
771 }
772
773 protected function getExamplesMessages() {
774 return [
775 'action=query&list=recentchanges'
776 => 'apihelp-query+recentchanges-example-simple',
777 'action=query&generator=recentchanges&grcshow=!patrolled&prop=info'
778 => 'apihelp-query+recentchanges-example-generator',
779 ];
780 }
781
782 public function getHelpUrls() {
783 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Recentchanges';
784 }
785}
and give any other recipients of the Program a copy of this License along with the Program You may charge a fee for the physical act of transferring a and you may at your option offer warranty protection in exchange for a fee You may modify your copy or copies of the Program or any portion of thus forming a work based on the and copy and distribute such modifications or work under the terms of Section provided that you also meet all of these that in whole or in part contains or is derived from the Program or any part to be licensed as a whole at no charge to all third parties under the terms of this License c If the modified program normally reads commands interactively when run
Definition COPYING.txt:104
int $wgChangeTagsSchemaMigrationStage
change_tag 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,...
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
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
static dieDebug( $method, $message)
Internal code errors should be reported with this method.
Definition ApiBase.php:2167
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
requireMaxOneParameter( $params, $required)
Die if more than one of a certain set of parameters is set and not false.
Definition ApiBase.php:939
const PARAM_EXTRA_NAMESPACES
(int[]) When PARAM_TYPE is 'namespace', include these as additional possible values.
Definition ApiBase.php:186
const PARAM_HELP_MSG
(string|array|Message) Specify an alternative i18n documentation message for this parameter.
Definition ApiBase.php:124
addWarning( $msg, $code=null, $data=null)
Add a warning for this module.
Definition ApiBase.php:1906
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
getContinuationManager()
Get the continuation manager.
Definition ApiBase.php:699
const PARAM_ISMULTI
(boolean) Accept multiple pipe-separated values for this parameter (e.g.
Definition ApiBase.php:51
lacksSameOriginSecurity()
Returns true if the current request breaks the same-origin policy.
Definition ApiBase.php:587
static addTitleInfo(&$arr, $title, $prefix='')
Add information (title and namespace) about a Title object to a result array.
processRow( $row, array &$data, array &$hookData)
Call the ApiQueryBaseProcessRow hook.
addWhereIf( $value, $condition)
Same as addWhere(), but add the WHERE clauses only if a condition is met.
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.
userCanSeeRevDel()
Check whether the current user has permission to view revision-deleted fields.
setContinueEnumParameter( $paramName, $paramValue)
Overridden to set the generator param if in generator mode.
A query action to enumerate the recent changes that were done to the wiki.
includesPatrollingFlags(array $flagsArray)
__construct(ApiQuery $query, $moduleName)
static getPatrolToken( $pageid, $title, $rc=null)
getAllowedParams()
Returns an array of allowed parameters (parameter name) => (default value) or (parameter name) => (ar...
initProperties( $prop)
Sets internal state to include the desired properties in the output.
getExamplesMessages()
Returns usage examples for this module.
execute()
Evaluates the parameters, performs the requested query, and sets up the result.
executeGenerator( $resultPageSet)
Execute this module as a generator.
run( $resultPageSet=null)
Generates and outputs the result of this query based upon the provided parameters.
getHelpUrls()
Return links to more detailed help pages about the module.
getCacheMode( $params)
Get the cache mode for the data generated by this module.
extractRowInfo( $row)
Extracts from a single sql row the data needed to describe one recent change.
getTokenFunctions()
Get an array mapping token names to their handler functions.
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 isUnpatrolled( $rc, User $user)
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
static userCanBitfield( $bitfield, $field, User $user=null)
Determine if the current user is allowed to view a particular field of this log row,...
static newFromRow( $row)
Handy shortcut for constructing a formatter directly from database row.
const DELETED_RESTRICTED
Definition LogPage.php:37
const DELETED_ACTION
Definition LogPage.php:34
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 newFromName( $name, $validate='valid')
Static factory method for creation from username.
Definition User.php:592
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
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
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
returning false will NOT prevent logging $e
Definition hooks.txt:2226
const RC_NEW
Definition Defines.php:143
const NS_SPECIAL
Definition Defines.php:53
const LIST_OR
Definition Defines.php:46
const RC_LOG
Definition Defines.php:144
const NS_MEDIA
Definition Defines.php:52
const MIGRATION_WRITE_BOTH
Definition Defines.php:316
const RC_EDIT
Definition Defines.php:142
linkcache txt The LinkCache class maintains a list of article titles and the information about whether or not the article exists in the database This is used to mark up links when displaying a page If the same link appears more than once on any page then it only has to be looked up once In most cases link lookups are done in batches with the LinkBatch class or the equivalent in so the link cache is mostly useful for short snippets of parsed and for links in the navigation areas of the skin The link cache was formerly used to track links used in a document for the purposes of updating the link tables This application is now deprecated To create a you can use the following $titles
Definition linkcache.txt:17
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
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))
$params