MediaWiki REL1_31
ApiQueryRecentChanges.php
Go to the documentation of this file.
1<?php
30
31 public function __construct( ApiQuery $query, $moduleName ) {
32 parent::__construct( $query, $moduleName, 'rc' );
33 }
34
36
37 private $fld_comment = false, $fld_parsedcomment = false, $fld_user = false, $fld_userid = false,
38 $fld_flags = false, $fld_timestamp = false, $fld_title = false, $fld_ids = false,
39 $fld_sizes = false, $fld_redirect = false, $fld_patrolled = false, $fld_loginfo = false,
40 $fld_tags = false, $fld_sha1 = false, $token = [];
41
43
51 protected function getTokenFunctions() {
52 // Don't call the hooks twice
53 if ( isset( $this->tokenFunctions ) ) {
55 }
56
57 // If we're in a mode that breaks the same-origin policy, no tokens can
58 // be obtained
59 if ( $this->lacksSameOriginSecurity() ) {
60 return [];
61 }
62
63 $this->tokenFunctions = [
64 'patrol' => [ self::class, 'getPatrolToken' ]
65 ];
66 Hooks::run( 'APIQueryRecentChangesTokens', [ &$this->tokenFunctions ] );
67
69 }
70
78 public static function getPatrolToken( $pageid, $title, $rc = null ) {
80
81 $validTokenUser = false;
82
83 if ( $rc ) {
84 if ( ( $wgUser->useRCPatrol() && $rc->getAttribute( 'rc_type' ) == RC_EDIT ) ||
85 ( $wgUser->useNPPatrol() && $rc->getAttribute( 'rc_type' ) == RC_NEW )
86 ) {
87 $validTokenUser = true;
88 }
89 } elseif ( $wgUser->useRCPatrol() || $wgUser->useNPPatrol() ) {
90 $validTokenUser = true;
91 }
92
93 if ( $validTokenUser ) {
94 // The patrol token is always the same, let's exploit that
95 static $cachedPatrolToken = null;
96
97 if ( is_null( $cachedPatrolToken ) ) {
98 $cachedPatrolToken = $wgUser->getEditToken( 'patrol' );
99 }
100
101 return $cachedPatrolToken;
102 }
103
104 return false;
105 }
106
111 public function initProperties( $prop ) {
112 $this->fld_comment = isset( $prop['comment'] );
113 $this->fld_parsedcomment = isset( $prop['parsedcomment'] );
114 $this->fld_user = isset( $prop['user'] );
115 $this->fld_userid = isset( $prop['userid'] );
116 $this->fld_flags = isset( $prop['flags'] );
117 $this->fld_timestamp = isset( $prop['timestamp'] );
118 $this->fld_title = isset( $prop['title'] );
119 $this->fld_ids = isset( $prop['ids'] );
120 $this->fld_sizes = isset( $prop['sizes'] );
121 $this->fld_redirect = isset( $prop['redirect'] );
122 $this->fld_patrolled = isset( $prop['patrolled'] );
123 $this->fld_loginfo = isset( $prop['loginfo'] );
124 $this->fld_tags = isset( $prop['tags'] );
125 $this->fld_sha1 = isset( $prop['sha1'] );
126 }
127
128 public function execute() {
129 $this->run();
130 }
131
132 public function executeGenerator( $resultPageSet ) {
133 $this->run( $resultPageSet );
134 }
135
141 public function run( $resultPageSet = null ) {
142 $user = $this->getUser();
143 /* Get the parameters of the request. */
144 $params = $this->extractRequestParams();
145
146 /* Build our basic query. Namely, something along the lines of:
147 * SELECT * FROM recentchanges WHERE rc_timestamp > $start
148 * AND rc_timestamp < $end AND rc_namespace = $namespace
149 */
150 $this->addTables( 'recentchanges' );
151 $this->addTimestampWhereRange( 'rc_timestamp', $params['dir'], $params['start'], $params['end'] );
152
153 if ( !is_null( $params['continue'] ) ) {
154 $cont = explode( '|', $params['continue'] );
155 $this->dieContinueUsageIf( count( $cont ) != 2 );
156 $db = $this->getDB();
157 $timestamp = $db->addQuotes( $db->timestamp( $cont[0] ) );
158 $id = intval( $cont[1] );
159 $this->dieContinueUsageIf( $id != $cont[1] );
160 $op = $params['dir'] === 'older' ? '<' : '>';
161 $this->addWhere(
162 "rc_timestamp $op $timestamp OR " .
163 "(rc_timestamp = $timestamp AND " .
164 "rc_id $op= $id)"
165 );
166 }
167
168 $order = $params['dir'] === 'older' ? 'DESC' : 'ASC';
169 $this->addOption( 'ORDER BY', [
170 "rc_timestamp $order",
171 "rc_id $order",
172 ] );
173
174 $this->addWhereFld( 'rc_namespace', $params['namespace'] );
175
176 if ( !is_null( $params['type'] ) ) {
177 try {
178 $this->addWhereFld( 'rc_type', RecentChange::parseToRCType( $params['type'] ) );
179 } catch ( Exception $e ) {
180 ApiBase::dieDebug( __METHOD__, $e->getMessage() );
181 }
182 }
183
184 if ( !is_null( $params['show'] ) ) {
185 $show = array_flip( $params['show'] );
186
187 /* Check for conflicting parameters. */
188 if ( ( isset( $show['minor'] ) && isset( $show['!minor'] ) )
189 || ( isset( $show['bot'] ) && isset( $show['!bot'] ) )
190 || ( isset( $show['anon'] ) && isset( $show['!anon'] ) )
191 || ( isset( $show['redirect'] ) && isset( $show['!redirect'] ) )
192 || ( isset( $show['patrolled'] ) && isset( $show['!patrolled'] ) )
193 || ( isset( $show['patrolled'] ) && isset( $show['unpatrolled'] ) )
194 || ( isset( $show['!patrolled'] ) && isset( $show['unpatrolled'] ) )
195 || ( isset( $show['autopatrolled'] ) && isset( $show['!autopatrolled'] ) )
196 || ( isset( $show['autopatrolled'] ) && isset( $show['unpatrolled'] ) )
197 || ( isset( $show['autopatrolled'] ) && isset( $show['!patrolled'] ) )
198 ) {
199 $this->dieWithError( 'apierror-show' );
200 }
201
202 // Check permissions
203 if ( $this->includesPatrollingFlags( $show ) ) {
204 if ( !$user->useRCPatrol() && !$user->useNPPatrol() ) {
205 $this->dieWithError( 'apierror-permissiondenied-patrolflag', 'permissiondenied' );
206 }
207 }
208
209 /* Add additional conditions to query depending upon parameters. */
210 $this->addWhereIf( 'rc_minor = 0', isset( $show['!minor'] ) );
211 $this->addWhereIf( 'rc_minor != 0', isset( $show['minor'] ) );
212 $this->addWhereIf( 'rc_bot = 0', isset( $show['!bot'] ) );
213 $this->addWhereIf( 'rc_bot != 0', isset( $show['bot'] ) );
214 if ( isset( $show['anon'] ) || isset( $show['!anon'] ) ) {
215 $actorMigration = ActorMigration::newMigration();
216 $actorQuery = $actorMigration->getJoin( 'rc_user' );
217 $this->addTables( $actorQuery['tables'] );
218 $this->addJoinConds( $actorQuery['joins'] );
219 $this->addWhereIf(
220 $actorMigration->isAnon( $actorQuery['fields']['rc_user'] ), isset( $show['anon'] )
221 );
222 $this->addWhereIf(
223 $actorMigration->isNotAnon( $actorQuery['fields']['rc_user'] ), isset( $show['!anon'] )
224 );
225 }
226 $this->addWhereIf( 'rc_patrolled = 0', isset( $show['!patrolled'] ) );
227 $this->addWhereIf( 'rc_patrolled != 0', isset( $show['patrolled'] ) );
228 $this->addWhereIf( 'page_is_redirect = 1', isset( $show['redirect'] ) );
229
230 if ( isset( $show['unpatrolled'] ) ) {
231 // See ChangesList::isUnpatrolled
232 if ( $user->useRCPatrol() ) {
233 $this->addWhere( 'rc_patrolled = ' . RecentChange::PRC_UNPATROLLED );
234 } elseif ( $user->useNPPatrol() ) {
235 $this->addWhere( 'rc_patrolled = ' . RecentChange::PRC_UNPATROLLED );
236 $this->addWhereFld( 'rc_type', RC_NEW );
237 }
238 }
239
240 $this->addWhereIf(
241 'rc_patrolled != ' . RecentChange::PRC_AUTOPATROLLED,
242 isset( $show['!autopatrolled'] )
243 );
244 $this->addWhereIf(
245 'rc_patrolled = ' . RecentChange::PRC_AUTOPATROLLED,
246 isset( $show['autopatrolled'] )
247 );
248
249 // Don't throw log entries out the window here
250 $this->addWhereIf(
251 'page_is_redirect = 0 OR page_is_redirect IS NULL',
252 isset( $show['!redirect'] )
253 );
254 }
255
256 $this->requireMaxOneParameter( $params, 'user', 'excludeuser' );
257
258 if ( !is_null( $params['user'] ) ) {
259 // Don't query by user ID here, it might be able to use the rc_user_text index.
260 $actorQuery = ActorMigration::newMigration()
261 ->getWhere( $this->getDB(), 'rc_user', User::newFromName( $params['user'], false ), false );
262 $this->addTables( $actorQuery['tables'] );
263 $this->addJoinConds( $actorQuery['joins'] );
264 $this->addWhere( $actorQuery['conds'] );
265 }
266
267 if ( !is_null( $params['excludeuser'] ) ) {
268 // Here there's no chance to use the rc_user_text index, so allow ID to be used.
269 $actorQuery = ActorMigration::newMigration()
270 ->getWhere( $this->getDB(), 'rc_user', User::newFromName( $params['excludeuser'], false ) );
271 $this->addTables( $actorQuery['tables'] );
272 $this->addJoinConds( $actorQuery['joins'] );
273 $this->addWhere( 'NOT(' . $actorQuery['conds'] . ')' );
274 }
275
276 /* Add the fields we're concerned with to our query. */
277 $this->addFields( [
278 'rc_id',
279 'rc_timestamp',
280 'rc_namespace',
281 'rc_title',
282 'rc_cur_id',
283 'rc_type',
284 'rc_deleted'
285 ] );
286
287 $showRedirects = false;
288 /* Determine what properties we need to display. */
289 if ( !is_null( $params['prop'] ) ) {
290 $prop = array_flip( $params['prop'] );
291
292 /* Set up internal members based upon params. */
293 $this->initProperties( $prop );
294
295 if ( $this->fld_patrolled && !$user->useRCPatrol() && !$user->useNPPatrol() ) {
296 $this->dieWithError( 'apierror-permissiondenied-patrolflag', 'permissiondenied' );
297 }
298
299 /* Add fields to our query if they are specified as a needed parameter. */
300 $this->addFieldsIf( [ 'rc_this_oldid', 'rc_last_oldid' ], $this->fld_ids );
301 if ( $this->fld_user || $this->fld_userid ) {
302 $actorQuery = ActorMigration::newMigration()->getJoin( 'rc_user' );
303 $this->addTables( $actorQuery['tables'] );
304 $this->addFields( $actorQuery['fields'] );
305 $this->addJoinConds( $actorQuery['joins'] );
306 }
307 $this->addFieldsIf( [ 'rc_minor', 'rc_type', 'rc_bot' ], $this->fld_flags );
308 $this->addFieldsIf( [ 'rc_old_len', 'rc_new_len' ], $this->fld_sizes );
309 $this->addFieldsIf( [ 'rc_patrolled', 'rc_log_type' ], $this->fld_patrolled );
310 $this->addFieldsIf(
311 [ 'rc_logid', 'rc_log_type', 'rc_log_action', 'rc_params' ],
312 $this->fld_loginfo
313 );
314 $showRedirects = $this->fld_redirect || isset( $show['redirect'] )
315 || isset( $show['!redirect'] );
316 }
317 $this->addFieldsIf( [ 'rc_this_oldid' ],
318 $resultPageSet && $params['generaterevisions'] );
319
320 if ( $this->fld_tags ) {
321 $this->addTables( 'tag_summary' );
322 $this->addJoinConds( [ 'tag_summary' => [ 'LEFT JOIN', [ 'rc_id=ts_rc_id' ] ] ] );
323 $this->addFields( 'ts_tags' );
324 }
325
326 if ( $this->fld_sha1 ) {
327 $this->addTables( 'revision' );
328 $this->addJoinConds( [ 'revision' => [ 'LEFT JOIN',
329 [ 'rc_this_oldid=rev_id' ] ] ] );
330 $this->addFields( [ 'rev_sha1', 'rev_deleted' ] );
331 }
332
333 if ( $params['toponly'] || $showRedirects ) {
334 $this->addTables( 'page' );
335 $this->addJoinConds( [ 'page' => [ 'LEFT JOIN',
336 [ 'rc_namespace=page_namespace', 'rc_title=page_title' ] ] ] );
337 $this->addFields( 'page_is_redirect' );
338
339 if ( $params['toponly'] ) {
340 $this->addWhere( 'rc_this_oldid = page_latest' );
341 }
342 }
343
344 if ( !is_null( $params['tag'] ) ) {
345 $this->addTables( 'change_tag' );
346 $this->addJoinConds( [ 'change_tag' => [ 'INNER JOIN', [ 'rc_id=ct_rc_id' ] ] ] );
347 $this->addWhereFld( 'ct_tag', $params['tag'] );
348 }
349
350 // Paranoia: avoid brute force searches (T19342)
351 if ( !is_null( $params['user'] ) || !is_null( $params['excludeuser'] ) ) {
352 if ( !$user->isAllowed( 'deletedhistory' ) ) {
353 $bitmask = Revision::DELETED_USER;
354 } elseif ( !$user->isAllowedAny( 'suppressrevision', 'viewsuppressed' ) ) {
355 $bitmask = Revision::DELETED_USER | Revision::DELETED_RESTRICTED;
356 } else {
357 $bitmask = 0;
358 }
359 if ( $bitmask ) {
360 $this->addWhere( $this->getDB()->bitAnd( 'rc_deleted', $bitmask ) . " != $bitmask" );
361 }
362 }
363 if ( $this->getRequest()->getCheck( 'namespace' ) ) {
364 // LogPage::DELETED_ACTION hides the affected page, too.
365 if ( !$user->isAllowed( 'deletedhistory' ) ) {
366 $bitmask = LogPage::DELETED_ACTION;
367 } elseif ( !$user->isAllowedAny( 'suppressrevision', 'viewsuppressed' ) ) {
369 } else {
370 $bitmask = 0;
371 }
372 if ( $bitmask ) {
373 $this->addWhere( $this->getDB()->makeList( [
374 'rc_type != ' . RC_LOG,
375 $this->getDB()->bitAnd( 'rc_deleted', $bitmask ) . " != $bitmask",
376 ], LIST_OR ) );
377 }
378 }
379
380 $this->token = $params['token'];
381
382 if ( $this->fld_comment || $this->fld_parsedcomment || $this->token ) {
383 $this->commentStore = CommentStore::getStore();
384 $commentQuery = $this->commentStore->getJoin( 'rc_comment' );
385 $this->addTables( $commentQuery['tables'] );
386 $this->addFields( $commentQuery['fields'] );
387 $this->addJoinConds( $commentQuery['joins'] );
388 }
389
390 $this->addOption( 'LIMIT', $params['limit'] + 1 );
391
392 $hookData = [];
393 $count = 0;
394 /* Perform the actual query. */
395 $res = $this->select( __METHOD__, [], $hookData );
396
397 $revids = [];
398 $titles = [];
399
400 $result = $this->getResult();
401
402 /* Iterate through the rows, adding data extracted from them to our query result. */
403 foreach ( $res as $row ) {
404 if ( $count === 0 && $resultPageSet !== null ) {
405 // Set the non-continue since the list of recentchanges is
406 // prone to having entries added at the start frequently.
407 $this->getContinuationManager()->addGeneratorNonContinueParam(
408 $this, 'continue', "$row->rc_timestamp|$row->rc_id"
409 );
410 }
411 if ( ++$count > $params['limit'] ) {
412 // We've reached the one extra which shows that there are
413 // additional pages to be had. Stop here...
414 $this->setContinueEnumParameter( 'continue', "$row->rc_timestamp|$row->rc_id" );
415 break;
416 }
417
418 if ( is_null( $resultPageSet ) ) {
419 /* Extract the data from a single row. */
420 $vals = $this->extractRowInfo( $row );
421
422 /* Add that row's data to our final output. */
423 $fit = $this->processRow( $row, $vals, $hookData ) &&
424 $result->addValue( [ 'query', $this->getModuleName() ], null, $vals );
425 if ( !$fit ) {
426 $this->setContinueEnumParameter( 'continue', "$row->rc_timestamp|$row->rc_id" );
427 break;
428 }
429 } elseif ( $params['generaterevisions'] ) {
430 $revid = (int)$row->rc_this_oldid;
431 if ( $revid > 0 ) {
432 $revids[] = $revid;
433 }
434 } else {
435 $titles[] = Title::makeTitle( $row->rc_namespace, $row->rc_title );
436 }
437 }
438
439 if ( is_null( $resultPageSet ) ) {
440 /* Format the result */
441 $result->addIndexedTagName( [ 'query', $this->getModuleName() ], 'rc' );
442 } elseif ( $params['generaterevisions'] ) {
443 $resultPageSet->populateFromRevisionIDs( $revids );
444 } else {
445 $resultPageSet->populateFromTitles( $titles );
446 }
447 }
448
456 public function extractRowInfo( $row ) {
457 /* Determine the title of the page that has been changed. */
458 $title = Title::makeTitle( $row->rc_namespace, $row->rc_title );
459 $user = $this->getUser();
460
461 /* Our output data. */
462 $vals = [];
463
464 $type = intval( $row->rc_type );
465 $vals['type'] = RecentChange::parseFromRCType( $type );
466
467 $anyHidden = false;
468
469 /* Create a new entry in the result for the title. */
470 if ( $this->fld_title || $this->fld_ids ) {
471 if ( $type === RC_LOG && ( $row->rc_deleted & LogPage::DELETED_ACTION ) ) {
472 $vals['actionhidden'] = true;
473 $anyHidden = true;
474 }
475 if ( $type !== RC_LOG ||
477 ) {
478 if ( $this->fld_title ) {
480 }
481 if ( $this->fld_ids ) {
482 $vals['pageid'] = intval( $row->rc_cur_id );
483 $vals['revid'] = intval( $row->rc_this_oldid );
484 $vals['old_revid'] = intval( $row->rc_last_oldid );
485 }
486 }
487 }
488
489 if ( $this->fld_ids ) {
490 $vals['rcid'] = intval( $row->rc_id );
491 }
492
493 /* Add user data and 'anon' flag, if user is anonymous. */
494 if ( $this->fld_user || $this->fld_userid ) {
495 if ( $row->rc_deleted & Revision::DELETED_USER ) {
496 $vals['userhidden'] = true;
497 $anyHidden = true;
498 }
499 if ( Revision::userCanBitfield( $row->rc_deleted, Revision::DELETED_USER, $user ) ) {
500 if ( $this->fld_user ) {
501 $vals['user'] = $row->rc_user_text;
502 }
503
504 if ( $this->fld_userid ) {
505 $vals['userid'] = (int)$row->rc_user;
506 }
507
508 if ( !$row->rc_user ) {
509 $vals['anon'] = true;
510 }
511 }
512 }
513
514 /* Add flags, such as new, minor, bot. */
515 if ( $this->fld_flags ) {
516 $vals['bot'] = (bool)$row->rc_bot;
517 $vals['new'] = $row->rc_type == RC_NEW;
518 $vals['minor'] = (bool)$row->rc_minor;
519 }
520
521 /* Add sizes of each revision. (Only available on 1.10+) */
522 if ( $this->fld_sizes ) {
523 $vals['oldlen'] = intval( $row->rc_old_len );
524 $vals['newlen'] = intval( $row->rc_new_len );
525 }
526
527 /* Add the timestamp. */
528 if ( $this->fld_timestamp ) {
529 $vals['timestamp'] = wfTimestamp( TS_ISO_8601, $row->rc_timestamp );
530 }
531
532 /* Add edit summary / log summary. */
533 if ( $this->fld_comment || $this->fld_parsedcomment ) {
534 if ( $row->rc_deleted & Revision::DELETED_COMMENT ) {
535 $vals['commenthidden'] = true;
536 $anyHidden = true;
537 }
538 if ( Revision::userCanBitfield( $row->rc_deleted, Revision::DELETED_COMMENT, $user ) ) {
539 $comment = $this->commentStore->getComment( 'rc_comment', $row )->text;
540 if ( $this->fld_comment ) {
541 $vals['comment'] = $comment;
542 }
543
544 if ( $this->fld_parsedcomment ) {
545 $vals['parsedcomment'] = Linker::formatComment( $comment, $title );
546 }
547 }
548 }
549
550 if ( $this->fld_redirect ) {
551 $vals['redirect'] = (bool)$row->page_is_redirect;
552 }
553
554 /* Add the patrolled flag */
555 if ( $this->fld_patrolled ) {
556 $vals['patrolled'] = $row->rc_patrolled != RecentChange::PRC_UNPATROLLED;
557 $vals['unpatrolled'] = ChangesList::isUnpatrolled( $row, $user );
558 $vals['autopatrolled'] = $row->rc_patrolled == RecentChange::PRC_AUTOPATROLLED;
559 }
560
561 if ( $this->fld_loginfo && $row->rc_type == RC_LOG ) {
562 if ( $row->rc_deleted & LogPage::DELETED_ACTION ) {
563 $vals['actionhidden'] = true;
564 $anyHidden = true;
565 }
567 $vals['logid'] = intval( $row->rc_logid );
568 $vals['logtype'] = $row->rc_log_type;
569 $vals['logaction'] = $row->rc_log_action;
570 $vals['logparams'] = LogFormatter::newFromRow( $row )->formatParametersForApi();
571 }
572 }
573
574 if ( $this->fld_tags ) {
575 if ( $row->ts_tags ) {
576 $tags = explode( ',', $row->ts_tags );
577 ApiResult::setIndexedTagName( $tags, 'tag' );
578 $vals['tags'] = $tags;
579 } else {
580 $vals['tags'] = [];
581 }
582 }
583
584 if ( $this->fld_sha1 && $row->rev_sha1 !== null ) {
585 if ( $row->rev_deleted & Revision::DELETED_TEXT ) {
586 $vals['sha1hidden'] = true;
587 $anyHidden = true;
588 }
589 if ( Revision::userCanBitfield( $row->rev_deleted, Revision::DELETED_TEXT, $user ) ) {
590 if ( $row->rev_sha1 !== '' ) {
591 $vals['sha1'] = Wikimedia\base_convert( $row->rev_sha1, 36, 16, 40 );
592 } else {
593 $vals['sha1'] = '';
594 }
595 }
596 }
597
598 if ( !is_null( $this->token ) ) {
600 foreach ( $this->token as $t ) {
601 $val = call_user_func( $tokenFunctions[$t], $row->rc_cur_id,
602 $title, RecentChange::newFromRow( $row ) );
603 if ( $val === false ) {
604 $this->addWarning( [ 'apiwarn-tokennotallowed', $t ] );
605 } else {
606 $vals[$t . 'token'] = $val;
607 }
608 }
609 }
610
611 if ( $anyHidden && ( $row->rc_deleted & Revision::DELETED_RESTRICTED ) ) {
612 $vals['suppressed'] = true;
613 }
614
615 return $vals;
616 }
617
622 private function includesPatrollingFlags( array $flagsArray ) {
623 return isset( $flagsArray['patrolled'] ) ||
624 isset( $flagsArray['!patrolled'] ) ||
625 isset( $flagsArray['unpatrolled'] ) ||
626 isset( $flagsArray['autopatrolled'] ) ||
627 isset( $flagsArray['!autopatrolled'] );
628 }
629
630 public function getCacheMode( $params ) {
631 if ( isset( $params['show'] ) &&
632 $this->includesPatrollingFlags( array_flip( $params['show'] ) )
633 ) {
634 return 'private';
635 }
636 if ( isset( $params['token'] ) ) {
637 return 'private';
638 }
639 if ( $this->userCanSeeRevDel() ) {
640 return 'private';
641 }
642 if ( !is_null( $params['prop'] ) && in_array( 'parsedcomment', $params['prop'] ) ) {
643 // formatComment() calls wfMessage() among other things
644 return 'anon-public-user-private';
645 }
646
647 return 'public';
648 }
649
650 public function getAllowedParams() {
651 return [
652 'start' => [
653 ApiBase::PARAM_TYPE => 'timestamp'
654 ],
655 'end' => [
656 ApiBase::PARAM_TYPE => 'timestamp'
657 ],
658 'dir' => [
659 ApiBase::PARAM_DFLT => 'older',
661 'newer',
662 'older'
663 ],
664 ApiBase::PARAM_HELP_MSG => 'api-help-param-direction',
665 ],
666 'namespace' => [
668 ApiBase::PARAM_TYPE => 'namespace',
670 ],
671 'user' => [
672 ApiBase::PARAM_TYPE => 'user'
673 ],
674 'excludeuser' => [
675 ApiBase::PARAM_TYPE => 'user'
676 ],
677 'tag' => null,
678 'prop' => [
680 ApiBase::PARAM_DFLT => 'title|timestamp|ids',
682 'user',
683 'userid',
684 'comment',
685 'parsedcomment',
686 'flags',
687 'timestamp',
688 'title',
689 'ids',
690 'sizes',
691 'redirect',
692 'patrolled',
693 'loginfo',
694 'tags',
695 'sha1',
696 ],
698 ],
699 'token' => [
701 ApiBase::PARAM_TYPE => array_keys( $this->getTokenFunctions() ),
703 ],
704 'show' => [
707 'minor',
708 '!minor',
709 'bot',
710 '!bot',
711 'anon',
712 '!anon',
713 'redirect',
714 '!redirect',
715 'patrolled',
716 '!patrolled',
717 'unpatrolled',
718 'autopatrolled',
719 '!autopatrolled',
720 ]
721 ],
722 'limit' => [
724 ApiBase::PARAM_TYPE => 'limit',
728 ],
729 'type' => [
730 ApiBase::PARAM_DFLT => 'edit|new|log|categorize',
732 ApiBase::PARAM_TYPE => RecentChange::getChangeTypes()
733 ],
734 'toponly' => false,
735 'continue' => [
736 ApiBase::PARAM_HELP_MSG => 'api-help-param-continue',
737 ],
738 'generaterevisions' => false,
739 ];
740 }
741
742 protected function getExamplesMessages() {
743 return [
744 'action=query&list=recentchanges'
745 => 'apihelp-query+recentchanges-example-simple',
746 'action=query&generator=recentchanges&grcshow=!patrolled&prop=info'
747 => 'apihelp-query+recentchanges-example-generator',
748 ];
749 }
750
751 public function getHelpUrls() {
752 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Recentchanges';
753 }
754}
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
$wgUser
Definition Setup.php:902
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:1895
dieContinueUsageIf( $condition)
Die with the 'badcontinue' error.
Definition ApiBase.php:2066
static dieDebug( $method, $message)
Internal code errors should be reported with this method.
Definition ApiBase.php:2078
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
extractRequestParams( $parseLimit=true)
Using getAllowedParams(), this function makes an array of the values provided by the user,...
Definition ApiBase.php:749
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:234
getResult()
Get the result object.
Definition ApiBase.php:641
requireMaxOneParameter( $params, $required)
Die if more than one of a certain set of parameters is set and not false.
Definition ApiBase.php:823
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:1819
const LIMIT_BIG2
Fast query, apihighlimits limit.
Definition ApiBase.php:236
getModuleName()
Get the name of the module being executed by this instance.
Definition ApiBase.php:521
getContinuationManager()
Get the continuation manager.
Definition ApiBase.php:681
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:569
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:1109
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:35
const DELETED_ACTION
Definition LogPage.php:32
static newFromName( $name, $validate='valid')
Static factory method for creation from username.
Definition User.php:591
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
when a variable name is used in a it is silently declared as a new local masking the global
Definition design.txt:95
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 RC_NEW
Definition Defines.php:153
const NS_SPECIAL
Definition Defines.php:63
const LIST_OR
Definition Defines.php:56
const RC_LOG
Definition Defines.php:154
const NS_MEDIA
Definition Defines.php:62
const RC_EDIT
Definition Defines.php:152
the array() calling protocol came about after MediaWiki 1.4rc1.
The index of the header message $result[1]=The index of the body text message $result[2 through n]=Parameters passed to body text message. Please note the header message cannot receive/use parameters. 'ImgAuthModifyHeaders':Executed just before a file is streamed to a user via img_auth.php, allowing headers to be modified beforehand. $title:LinkTarget object & $headers:HTTP headers(name=> value, names are case insensitive). Two headers get special handling:If-Modified-Since(value must be a valid HTTP date) and Range(must be of the form "bytes=(\d*-\d*)") will be honored when streaming the file. 'ImportHandleLogItemXMLTag':When parsing a XML tag in a log item. Return false to stop further processing of the tag $reader:XMLReader object $logInfo:Array of information 'ImportHandlePageXMLTag':When parsing a XML tag in a page. Return false to stop further processing of the tag $reader:XMLReader object & $pageInfo:Array of information 'ImportHandleRevisionXMLTag':When parsing a XML tag in a page revision. Return false to stop further processing of the tag $reader:XMLReader object $pageInfo:Array of page information $revisionInfo:Array of revision information 'ImportHandleToplevelXMLTag':When parsing a top level XML tag. Return false to stop further processing of the tag $reader:XMLReader object 'ImportHandleUnknownUser':When a user doesn 't exist locally, this hook is called to give extensions an opportunity to auto-create it. If the auto-creation is successful, return false. $name:User name 'ImportHandleUploadXMLTag':When parsing a XML tag in a file upload. Return false to stop further processing of the tag $reader:XMLReader object $revisionInfo:Array of information 'ImportLogInterwikiLink':Hook to change the interwiki link used in log entries and edit summaries for transwiki imports. & $fullInterwikiPrefix:Interwiki prefix, may contain colons. & $pageTitle:String that contains page title. 'ImportSources':Called when reading from the $wgImportSources configuration variable. Can be used to lazy-load the import sources list. & $importSources:The value of $wgImportSources. Modify as necessary. See the comment in DefaultSettings.php for the detail of how to structure this array. 'InfoAction':When building information to display on the action=info page. $context:IContextSource object & $pageInfo:Array of information 'InitializeArticleMaybeRedirect':MediaWiki check to see if title is a redirect. & $title:Title object for the current page & $request:WebRequest & $ignoreRedirect:boolean to skip redirect check & $target:Title/string of redirect target & $article:Article object 'InternalParseBeforeLinks':during Parser 's internalParse method before links but after nowiki/noinclude/includeonly/onlyinclude and other processings. & $parser:Parser object & $text:string containing partially parsed text & $stripState:Parser 's internal StripState object 'InternalParseBeforeSanitize':during Parser 's internalParse method just before the parser removes unwanted/dangerous HTML tags and after nowiki/noinclude/includeonly/onlyinclude and other processings. Ideal for syntax-extensions after template/parser function execution which respect nowiki and HTML-comments. & $parser:Parser object & $text:string containing partially parsed text & $stripState:Parser 's internal StripState object 'InterwikiLoadPrefix':When resolving if a given prefix is an interwiki or not. Return true without providing an interwiki to continue interwiki search. $prefix:interwiki prefix we are looking for. & $iwData:output array describing the interwiki with keys iw_url, iw_local, iw_trans and optionally iw_api and iw_wikiid. 'InvalidateEmailComplete':Called after a user 's email has been invalidated successfully. $user:user(object) whose email is being invalidated 'IRCLineURL':When constructing the URL to use in an IRC notification. Callee may modify $url and $query, URL will be constructed as $url . $query & $url:URL to index.php & $query:Query string $rc:RecentChange object that triggered url generation 'IsFileCacheable':Override the result of Article::isFileCacheable()(if true) & $article:article(object) being checked 'IsTrustedProxy':Override the result of IP::isTrustedProxy() & $ip:IP being check & $result:Change this value to override the result of IP::isTrustedProxy() 'IsUploadAllowedFromUrl':Override the result of UploadFromUrl::isAllowedUrl() $url:URL used to upload from & $allowed:Boolean indicating if uploading is allowed for given URL 'isValidEmailAddr':Override the result of Sanitizer::validateEmail(), for instance to return false if the domain name doesn 't match your organization. $addr:The e-mail address entered by the user & $result:Set this and return false to override the internal checks 'isValidPassword':Override the result of User::isValidPassword() $password:The password entered by the user & $result:Set this and return false to override the internal checks $user:User the password is being validated for 'Language::getMessagesFileName':$code:The language code or the language we 're looking for a messages file for & $file:The messages file path, you can override this to change the location. 'LanguageGetMagic':DEPRECATED! Use $magicWords in a file listed in $wgExtensionMessagesFiles instead. Use this to define synonyms of magic words depending of the language & $magicExtensions:associative array of magic words synonyms $lang:language code(string) 'LanguageGetNamespaces':Provide custom ordering for namespaces or remove namespaces. Do not use this hook to add namespaces. Use CanonicalNamespaces for that. & $namespaces:Array of namespaces indexed by their numbers 'LanguageGetSpecialPageAliases':DEPRECATED! Use $specialPageAliases in a file listed in $wgExtensionMessagesFiles instead. Use to define aliases of special pages names depending of the language & $specialPageAliases:associative array of magic words synonyms $lang:language code(string) 'LanguageGetTranslatedLanguageNames':Provide translated language names. & $names:array of language code=> language name $code:language of the preferred translations 'LanguageLinks':Manipulate a page 's language links. This is called in various places to allow extensions to define the effective language links for a page. $title:The page 's Title. & $links:Array with elements of the form "language:title" in the order that they will be output. & $linkFlags:Associative array mapping prefixed links to arrays of flags. Currently unused, but planned to provide support for marking individual language links in the UI, e.g. for featured articles. 'LanguageSelector':Hook to change the language selector available on a page. $out:The output page. $cssClassName:CSS class name of the language selector. 'LinkBegin':DEPRECATED! Use HtmlPageLinkRendererBegin instead. Used when generating internal and interwiki links in Linker::link(), before processing starts. Return false to skip default processing and return $ret. See documentation for Linker::link() for details on the expected meanings of parameters. $skin:the Skin object $target:the Title that the link is pointing to & $html:the contents that the< a > tag should have(raw HTML) $result
Definition hooks.txt:1993
namespace and then decline to actually register it file or subcat img or subcat $title
Definition hooks.txt:964
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
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:1620
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
returning false will NOT prevent logging $e
Definition hooks.txt:2176
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
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
$params