3 * Utility class for creating and accessing recent change entries.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
24 * Utility class for creating new RC entries
27 * rc_id id of the row in the recentchanges table
28 * rc_timestamp time the entry was made
29 * rc_namespace namespace #
30 * rc_title non-prefixed db key
31 * rc_type is new entry, used to determine whether updating is necessary
32 * rc_source string representation of change source
34 * rc_cur_id page_id of associated page entry
35 * rc_user user id who made the entry
36 * rc_user_text user name who made the entry
37 * rc_comment edit summary
38 * rc_this_oldid rev_id associated with this entry (or zero)
39 * rc_last_oldid rev_id associated with the entry before this one (or zero)
40 * rc_bot is bot, hidden
41 * rc_ip IP address of the user in dotted quad notation
42 * rc_new obsolete, use rc_type==RC_NEW
43 * rc_patrolled boolean whether or not someone has marked this edit as patrolled
44 * rc_old_len integer byte length of the text before the edit
45 * rc_new_len the same after the edit
46 * rc_deleted partial deletion
47 * rc_logid the log_id value for this log entry (or zero)
48 * rc_log_type the log type (or null)
49 * rc_log_action the log action (or null)
50 * rc_params log params
53 * prefixedDBkey prefixed db key, used by external app via msg queue
54 * lastTimestamp timestamp of previous entry, used in WHERE clause during update
55 * oldSize text size before the change
56 * newSize text size after the change
57 * pageStatus status of the page: created, deleted, moved, restored, changed
59 * temporary: not stored in the database
60 * notificationtimestamp
61 * numberofWatchingusers
63 * @todo Deprecate access to mAttribs (direct or via getAttributes). Right now
64 * we're having to include both rc_comment and rc_comment_text/rc_comment_data
65 * so random crap works right.
68 // Constants for the rc_source field. Extensions may also have
69 // their own source constants.
70 const SRC_EDIT
= 'mw.edit';
71 const SRC_NEW
= 'mw.new';
72 const SRC_LOG
= 'mw.log';
73 const SRC_EXTERNAL
= 'mw.external'; // obsolete
74 const SRC_CATEGORIZE
= 'mw.categorize';
76 public $mAttribs = [];
82 public $mTitle = false;
87 private $mPerformer = false;
89 public $numberofWatchingusers = 0; # Dummy to prevent error message in SpecialRecentChangesLinked
90 public $notificationtimestamp;
93 * @var int Line number of recent change. Default -1.
98 * @var array List of tags to apply
103 * @var array Array of change types
105 private static $changeTypes = [
109 'external' => RC_EXTERNAL
,
110 'categorize' => RC_CATEGORIZE
,
117 * @return RecentChange
119 public static function newFromRow( $row ) {
120 $rc = new RecentChange
;
121 $rc->loadFromRow( $row );
127 * Parsing text to RC_* constants
129 * @param string|array $type
130 * @throws MWException
131 * @return int|array RC_TYPE
133 public static function parseToRCType( $type ) {
134 if ( is_array( $type ) ) {
136 foreach ( $type as $t ) {
137 $retval[] = self
::parseToRCType( $t );
143 if ( !array_key_exists( $type, self
::$changeTypes ) ) {
144 throw new MWException( "Unknown type '$type'" );
146 return self
::$changeTypes[$type];
150 * Parsing RC_* constants to human-readable test
153 * @return string $type
155 public static function parseFromRCType( $rcType ) {
156 return array_search( $rcType, self
::$changeTypes, true ) ?
: "$rcType";
160 * Get an array of all change types
166 public static function getChangeTypes() {
167 return array_keys( self
::$changeTypes );
171 * Obtain the recent change with a given rc_id value
173 * @param int $rcid The rc_id value to retrieve
174 * @return RecentChange|null
176 public static function newFromId( $rcid ) {
177 return self
::newFromConds( [ 'rc_id' => $rcid ], __METHOD__
);
181 * Find the first recent change matching some specific conditions
183 * @param array $conds Array of conditions
184 * @param mixed $fname Override the method name in profiling/logs
185 * @param int $dbType DB_* constant
187 * @return RecentChange|null
189 public static function newFromConds(
194 $db = wfGetDB( $dbType );
195 $row = $db->selectRow( 'recentchanges', self
::selectFields(), $conds, $fname );
196 if ( $row !== false ) {
197 return self
::newFromRow( $row );
204 * Return the list of recentchanges fields that should be selected to create
205 * a new recentchanges object.
206 * @todo Deprecate this in favor of a method that returns tables and joins
207 * as well, and use CommentStore::getJoin().
210 public static function selectFields() {
235 ] + CommentStore
::newKey( 'rc_comment' )->getFields();
241 * @param array $attribs
243 public function setAttribs( $attribs ) {
244 $this->mAttribs
= $attribs;
248 * @param array $extra
250 public function setExtra( $extra ) {
251 $this->mExtra
= $extra;
257 public function &getTitle() {
258 if ( $this->mTitle
=== false ) {
259 $this->mTitle
= Title
::makeTitle( $this->mAttribs
['rc_namespace'], $this->mAttribs
['rc_title'] );
262 return $this->mTitle
;
266 * Get the User object of the person who performed this change.
270 public function getPerformer() {
271 if ( $this->mPerformer
=== false ) {
272 if ( $this->mAttribs
['rc_user'] ) {
273 $this->mPerformer
= User
::newFromId( $this->mAttribs
['rc_user'] );
275 $this->mPerformer
= User
::newFromName( $this->mAttribs
['rc_user_text'], false );
279 return $this->mPerformer
;
283 * Writes the data in this object to the database
286 public function save( $noudp = false ) {
287 global $wgPutIPinRC, $wgUseEnotif, $wgShowUpdatedMarker, $wgContLang;
289 $dbw = wfGetDB( DB_MASTER
);
290 if ( !is_array( $this->mExtra
) ) {
294 if ( !$wgPutIPinRC ) {
295 $this->mAttribs
['rc_ip'] = '';
298 # Strict mode fixups (not-NULL fields)
299 foreach ( [ 'minor', 'bot', 'new', 'patrolled', 'deleted' ] as $field ) {
300 $this->mAttribs
["rc_$field"] = (int)$this->mAttribs
["rc_$field"];
302 # ...more fixups (NULL fields)
303 foreach ( [ 'old_len', 'new_len' ] as $field ) {
304 $this->mAttribs
["rc_$field"] = isset( $this->mAttribs
["rc_$field"] )
305 ?
(int)$this->mAttribs
["rc_$field"]
309 # If our database is strict about IP addresses, use NULL instead of an empty string
310 $strictIPs = in_array( $dbw->getType(), [ 'oracle', 'postgres' ] ); // legacy
311 if ( $strictIPs && $this->mAttribs
['rc_ip'] == '' ) {
312 unset( $this->mAttribs
['rc_ip'] );
315 # Trim spaces on user supplied text
316 $this->mAttribs
['rc_comment'] = trim( $this->mAttribs
['rc_comment'] );
318 # Make sure summary is truncated (whole multibyte characters)
319 $this->mAttribs
['rc_comment'] = $wgContLang->truncate( $this->mAttribs
['rc_comment'], 255 );
321 # Fixup database timestamps
322 $this->mAttribs
['rc_timestamp'] = $dbw->timestamp( $this->mAttribs
['rc_timestamp'] );
324 # # If we are using foreign keys, an entry of 0 for the page_id will fail, so use NULL
325 if ( $this->mAttribs
['rc_cur_id'] == 0 ) {
326 unset( $this->mAttribs
['rc_cur_id'] );
329 # Convert mAttribs['rc_comment'] for CommentStore
330 $row = $this->mAttribs
;
331 $comment = $row['rc_comment'];
332 unset( $row['rc_comment'], $row['rc_comment_text'], $row['rc_comment_data'] );
333 $row +
= CommentStore
::newKey( 'rc_comment' )->insert( $dbw, $comment );
335 # Don't reuse an existing rc_id for the new row, if one happens to be
336 # set for some reason.
337 unset( $row['rc_id'] );
340 $dbw->insert( 'recentchanges', $row, __METHOD__
);
343 $this->mAttribs
['rc_id'] = $dbw->insertId();
346 // Avoid PHP 7.1 warning from passing $this by reference
348 Hooks
::run( 'RecentChange_save', [ &$rc ] );
350 if ( count( $this->tags
) ) {
351 ChangeTags
::addTags( $this->tags
, $this->mAttribs
['rc_id'],
352 $this->mAttribs
['rc_this_oldid'], $this->mAttribs
['rc_logid'], null, $this );
355 # Notify external application via UDP
357 $this->notifyRCFeeds();
360 # E-mail notifications
361 if ( $wgUseEnotif ||
$wgShowUpdatedMarker ) {
362 $editor = $this->getPerformer();
363 $title = $this->getTitle();
365 // Never send an RC notification email about categorization changes
367 $this->mAttribs
['rc_type'] != RC_CATEGORIZE
&&
368 Hooks
::run( 'AbortEmailNotification', [ $editor, $title, $this ] )
370 // @FIXME: This would be better as an extension hook
371 // Send emails or email jobs once this row is safely committed
372 $dbw->onTransactionIdle(
373 function () use ( $editor, $title ) {
374 $enotif = new EmailNotification();
375 $enotif->notifyOnPageChange(
378 $this->mAttribs
['rc_timestamp'],
379 $this->mAttribs
['rc_comment'],
380 $this->mAttribs
['rc_minor'],
381 $this->mAttribs
['rc_last_oldid'],
382 $this->mExtra
['pageStatus']
390 // Update the cached list of active users
391 if ( $this->mAttribs
['rc_user'] > 0 ) {
392 JobQueueGroup
::singleton()->lazyPush( RecentChangesUpdateJob
::newCacheUpdateJob() );
397 * Notify all the feeds about the change.
398 * @param array $feeds Optional feeds to send to, defaults to $wgRCFeeds
400 public function notifyRCFeeds( array $feeds = null ) {
402 if ( $feeds === null ) {
406 $performer = $this->getPerformer();
408 foreach ( $feeds as $params ) {
410 'omit_bots' => false,
411 'omit_anon' => false,
412 'omit_user' => false,
413 'omit_minor' => false,
414 'omit_patrolled' => false,
418 ( $params['omit_bots'] && $this->mAttribs
['rc_bot'] ) ||
419 ( $params['omit_anon'] && $performer->isAnon() ) ||
420 ( $params['omit_user'] && !$performer->isAnon() ) ||
421 ( $params['omit_minor'] && $this->mAttribs
['rc_minor'] ) ||
422 ( $params['omit_patrolled'] && $this->mAttribs
['rc_patrolled'] ) ||
423 $this->mAttribs
['rc_type'] == RC_EXTERNAL
428 if ( isset( $this->mExtra
['actionCommentIRC'] ) ) {
429 $actionComment = $this->mExtra
['actionCommentIRC'];
431 $actionComment = null;
434 $feed = RCFeed
::factory( $params );
435 $feed->notify( $this, $actionComment );
441 * @deprecated since 1.29 Use RCFeed::factory() instead
442 * @param string $uri URI to get the engine object for
443 * @param array $params
444 * @return RCFeedEngine The engine object
445 * @throws MWException
447 public static function getEngine( $uri, $params = [] ) {
448 // TODO: Merge into RCFeed::factory().
450 $scheme = parse_url( $uri, PHP_URL_SCHEME
);
452 throw new MWException( "Invalid RCFeed uri: '$uri'" );
454 if ( !isset( $wgRCEngines[$scheme] ) ) {
455 throw new MWException( "Unknown RCFeedEngine scheme: '$scheme'" );
457 if ( defined( 'MW_PHPUNIT_TEST' ) && is_object( $wgRCEngines[$scheme] ) ) {
458 return $wgRCEngines[$scheme];
460 return new $wgRCEngines[$scheme]( $params );
464 * Mark a given change as patrolled
466 * @param RecentChange|int $change RecentChange or corresponding rc_id
467 * @param bool $auto For automatic patrol
468 * @param string|string[] $tags Change tags to add to the patrol log entry
469 * ($user should be able to add the specified tags before this is called)
470 * @return array See doMarkPatrolled(), or null if $change is not an existing rc_id
472 public static function markPatrolled( $change, $auto = false, $tags = null ) {
475 $change = $change instanceof RecentChange
477 : self
::newFromId( $change );
479 if ( !$change instanceof RecentChange
) {
483 return $change->doMarkPatrolled( $wgUser, $auto, $tags );
487 * Mark this RecentChange as patrolled
489 * NOTE: Can also return 'rcpatroldisabled', 'hookaborted' and
490 * 'markedaspatrollederror-noautopatrol' as errors
491 * @param User $user User object doing the action
492 * @param bool $auto For automatic patrol
493 * @param string|string[] $tags Change tags to add to the patrol log entry
494 * ($user should be able to add the specified tags before this is called)
495 * @return array Array of permissions errors, see Title::getUserPermissionsErrors()
497 public function doMarkPatrolled( User
$user, $auto = false, $tags = null ) {
498 global $wgUseRCPatrol, $wgUseNPPatrol, $wgUseFilePatrol;
501 // If recentchanges patrol is disabled, only new pages or new file versions
502 // can be patrolled, provided the appropriate config variable is set
503 if ( !$wgUseRCPatrol && ( !$wgUseNPPatrol ||
$this->getAttribute( 'rc_type' ) != RC_NEW
) &&
504 ( !$wgUseFilePatrol ||
!( $this->getAttribute( 'rc_type' ) == RC_LOG
&&
505 $this->getAttribute( 'rc_log_type' ) == 'upload' ) ) ) {
506 $errors[] = [ 'rcpatroldisabled' ];
508 // Automatic patrol needs "autopatrol", ordinary patrol needs "patrol"
509 $right = $auto ?
'autopatrol' : 'patrol';
510 $errors = array_merge( $errors, $this->getTitle()->getUserPermissionsErrors( $right, $user ) );
511 if ( !Hooks
::run( 'MarkPatrolled',
512 [ $this->getAttribute( 'rc_id' ), &$user, false, $auto ] )
514 $errors[] = [ 'hookaborted' ];
516 // Users without the 'autopatrol' right can't patrol their
518 if ( $user->getName() === $this->getAttribute( 'rc_user_text' )
519 && !$user->isAllowed( 'autopatrol' )
521 $errors[] = [ 'markedaspatrollederror-noautopatrol' ];
526 // If the change was patrolled already, do nothing
527 if ( $this->getAttribute( 'rc_patrolled' ) ) {
530 // Actually set the 'patrolled' flag in RC
531 $this->reallyMarkPatrolled();
532 // Log this patrol event
533 PatrolLog
::record( $this, $auto, $user, $tags );
536 'MarkPatrolledComplete',
537 [ $this->getAttribute( 'rc_id' ), &$user, false, $auto ]
544 * Mark this RecentChange patrolled, without error checking
545 * @return int Number of affected rows
547 public function reallyMarkPatrolled() {
548 $dbw = wfGetDB( DB_MASTER
);
555 'rc_id' => $this->getAttribute( 'rc_id' )
559 // Invalidate the page cache after the page has been patrolled
560 // to make sure that the Patrol link isn't visible any longer!
561 $this->getTitle()->invalidateCache();
563 return $dbw->affectedRows();
567 * Makes an entry in the database corresponding to an edit
569 * @param string $timestamp
570 * @param Title &$title
573 * @param string $comment
575 * @param string $lastTimestamp
578 * @param int $oldSize
579 * @param int $newSize
583 * @return RecentChange
585 public static function notifyEdit(
586 $timestamp, &$title, $minor, &$user, $comment, $oldId, $lastTimestamp,
587 $bot, $ip = '', $oldSize = 0, $newSize = 0, $newId = 0, $patrol = 0,
590 $rc = new RecentChange
;
591 $rc->mTitle
= $title;
592 $rc->mPerformer
= $user;
594 'rc_timestamp' => $timestamp,
595 'rc_namespace' => $title->getNamespace(),
596 'rc_title' => $title->getDBkey(),
597 'rc_type' => RC_EDIT
,
598 'rc_source' => self
::SRC_EDIT
,
599 'rc_minor' => $minor ?
1 : 0,
600 'rc_cur_id' => $title->getArticleID(),
601 'rc_user' => $user->getId(),
602 'rc_user_text' => $user->getName(),
603 'rc_comment' => &$comment,
604 'rc_comment_text' => &$comment,
605 'rc_comment_data' => null,
606 'rc_this_oldid' => $newId,
607 'rc_last_oldid' => $oldId,
608 'rc_bot' => $bot ?
1 : 0,
609 'rc_ip' => self
::checkIPAddress( $ip ),
610 'rc_patrolled' => intval( $patrol ),
611 'rc_new' => 0, # obsolete
612 'rc_old_len' => $oldSize,
613 'rc_new_len' => $newSize,
616 'rc_log_type' => null,
617 'rc_log_action' => '',
622 'prefixedDBkey' => $title->getPrefixedDBkey(),
623 'lastTimestamp' => $lastTimestamp,
624 'oldSize' => $oldSize,
625 'newSize' => $newSize,
626 'pageStatus' => 'changed'
629 DeferredUpdates
::addCallableUpdate(
630 function () use ( $rc, $tags ) {
631 $rc->addTags( $tags );
633 if ( $rc->mAttribs
['rc_patrolled'] ) {
634 PatrolLog
::record( $rc, true, $rc->getPerformer() );
637 DeferredUpdates
::POSTSEND
,
645 * Makes an entry in the database corresponding to page creation
646 * Note: the title object must be loaded with the new id using resetArticleID()
648 * @param string $timestamp
649 * @param Title &$title
652 * @param string $comment
659 * @return RecentChange
661 public static function notifyNew(
662 $timestamp, &$title, $minor, &$user, $comment, $bot,
663 $ip = '', $size = 0, $newId = 0, $patrol = 0, $tags = []
665 $rc = new RecentChange
;
666 $rc->mTitle
= $title;
667 $rc->mPerformer
= $user;
669 'rc_timestamp' => $timestamp,
670 'rc_namespace' => $title->getNamespace(),
671 'rc_title' => $title->getDBkey(),
673 'rc_source' => self
::SRC_NEW
,
674 'rc_minor' => $minor ?
1 : 0,
675 'rc_cur_id' => $title->getArticleID(),
676 'rc_user' => $user->getId(),
677 'rc_user_text' => $user->getName(),
678 'rc_comment' => &$comment,
679 'rc_comment_text' => &$comment,
680 'rc_comment_data' => null,
681 'rc_this_oldid' => $newId,
682 'rc_last_oldid' => 0,
683 'rc_bot' => $bot ?
1 : 0,
684 'rc_ip' => self
::checkIPAddress( $ip ),
685 'rc_patrolled' => intval( $patrol ),
686 'rc_new' => 1, # obsolete
688 'rc_new_len' => $size,
691 'rc_log_type' => null,
692 'rc_log_action' => '',
697 'prefixedDBkey' => $title->getPrefixedDBkey(),
698 'lastTimestamp' => 0,
701 'pageStatus' => 'created'
704 DeferredUpdates
::addCallableUpdate(
705 function () use ( $rc, $tags ) {
706 $rc->addTags( $tags );
708 if ( $rc->mAttribs
['rc_patrolled'] ) {
709 PatrolLog
::record( $rc, true, $rc->getPerformer() );
712 DeferredUpdates
::POSTSEND
,
720 * @param string $timestamp
721 * @param Title &$title
723 * @param string $actionComment
725 * @param string $type
726 * @param string $action
727 * @param Title $target
728 * @param string $logComment
729 * @param string $params
731 * @param string $actionCommentIRC
734 public static function notifyLog( $timestamp, &$title, &$user, $actionComment, $ip, $type,
735 $action, $target, $logComment, $params, $newId = 0, $actionCommentIRC = ''
737 global $wgLogRestrictions;
739 # Don't add private logs to RC!
740 if ( isset( $wgLogRestrictions[$type] ) && $wgLogRestrictions[$type] != '*' ) {
743 $rc = self
::newLogEntry( $timestamp, $title, $user, $actionComment, $ip, $type, $action,
744 $target, $logComment, $params, $newId, $actionCommentIRC );
751 * @param string $timestamp
752 * @param Title &$title
754 * @param string $actionComment
756 * @param string $type
757 * @param string $action
758 * @param Title $target
759 * @param string $logComment
760 * @param string $params
762 * @param string $actionCommentIRC
763 * @param int $revId Id of associated revision, if any
764 * @param bool $isPatrollable Whether this log entry is patrollable
765 * @return RecentChange
767 public static function newLogEntry( $timestamp, &$title, &$user, $actionComment, $ip,
768 $type, $action, $target, $logComment, $params, $newId = 0, $actionCommentIRC = '',
769 $revId = 0, $isPatrollable = false ) {
772 # # Get pageStatus for email notification
773 switch ( $type . '-' . $action ) {
774 case 'delete-delete':
775 case 'delete-delete_redir':
776 $pageStatus = 'deleted';
779 case 'move-move_redir':
780 $pageStatus = 'moved';
782 case 'delete-restore':
783 $pageStatus = 'restored';
785 case 'upload-upload':
786 $pageStatus = 'created';
788 case 'upload-overwrite':
790 $pageStatus = 'changed';
794 // Allow unpatrolled status for patrollable log entries
795 $markPatrolled = $isPatrollable ?
$user->isAllowed( 'autopatrol' ) : true;
797 $rc = new RecentChange
;
798 $rc->mTitle
= $target;
799 $rc->mPerformer
= $user;
801 'rc_timestamp' => $timestamp,
802 'rc_namespace' => $target->getNamespace(),
803 'rc_title' => $target->getDBkey(),
805 'rc_source' => self
::SRC_LOG
,
807 'rc_cur_id' => $target->getArticleID(),
808 'rc_user' => $user->getId(),
809 'rc_user_text' => $user->getName(),
810 'rc_comment' => &$logComment,
811 'rc_comment_text' => &$logComment,
812 'rc_comment_data' => null,
813 'rc_this_oldid' => $revId,
814 'rc_last_oldid' => 0,
815 'rc_bot' => $user->isAllowed( 'bot' ) ?
(int)$wgRequest->getBool( 'bot', true ) : 0,
816 'rc_ip' => self
::checkIPAddress( $ip ),
817 'rc_patrolled' => $markPatrolled ?
1 : 0,
818 'rc_new' => 0, # obsolete
819 'rc_old_len' => null,
820 'rc_new_len' => null,
822 'rc_logid' => $newId,
823 'rc_log_type' => $type,
824 'rc_log_action' => $action,
825 'rc_params' => $params
829 'prefixedDBkey' => $title->getPrefixedDBkey(),
830 'lastTimestamp' => 0,
831 'actionComment' => $actionComment, // the comment appended to the action, passed from LogPage
832 'pageStatus' => $pageStatus,
833 'actionCommentIRC' => $actionCommentIRC
840 * Constructs a RecentChange object for the given categorization
841 * This does not call save() on the object and thus does not write to the db
845 * @param string $timestamp Timestamp of the recent change to occur
846 * @param Title $categoryTitle Title of the category a page is being added to or removed from
847 * @param User $user User object of the user that made the change
848 * @param string $comment Change summary
849 * @param Title $pageTitle Title of the page that is being added or removed
850 * @param int $oldRevId Parent revision ID of this change
851 * @param int $newRevId Revision ID of this change
852 * @param string $lastTimestamp Parent revision timestamp of this change
853 * @param bool $bot true, if the change was made by a bot
854 * @param string $ip IP address of the user, if the change was made anonymously
855 * @param int $deleted Indicates whether the change has been deleted
857 * @return RecentChange
859 public static function newForCategorization(
861 Title
$categoryTitle,
872 $rc = new RecentChange
;
873 $rc->mTitle
= $categoryTitle;
874 $rc->mPerformer
= $user;
876 'rc_timestamp' => $timestamp,
877 'rc_namespace' => $categoryTitle->getNamespace(),
878 'rc_title' => $categoryTitle->getDBkey(),
879 'rc_type' => RC_CATEGORIZE
,
880 'rc_source' => self
::SRC_CATEGORIZE
,
882 'rc_cur_id' => $pageTitle->getArticleID(),
883 'rc_user' => $user ?
$user->getId() : 0,
884 'rc_user_text' => $user ?
$user->getName() : '',
885 'rc_comment' => &$comment,
886 'rc_comment_text' => &$comment,
887 'rc_comment_data' => null,
888 'rc_this_oldid' => $newRevId,
889 'rc_last_oldid' => $oldRevId,
890 'rc_bot' => $bot ?
1 : 0,
891 'rc_ip' => self
::checkIPAddress( $ip ),
892 'rc_patrolled' => 1, // Always patrolled, just like log entries
893 'rc_new' => 0, # obsolete
894 'rc_old_len' => null,
895 'rc_new_len' => null,
896 'rc_deleted' => $deleted,
898 'rc_log_type' => null,
899 'rc_log_action' => '',
900 'rc_params' => serialize( [
901 'hidden-cat' => WikiCategoryPage
::factory( $categoryTitle )->isHidden()
906 'prefixedDBkey' => $categoryTitle->getPrefixedDBkey(),
907 'lastTimestamp' => $lastTimestamp,
910 'pageStatus' => 'changed'
917 * Get a parameter value
921 * @param string $name parameter name
924 public function getParam( $name ) {
925 $params = $this->parseParams();
926 return isset( $params[$name] ) ?
$params[$name] : null;
930 * Initialises the members of this object from a mysql row object
934 public function loadFromRow( $row ) {
935 $this->mAttribs
= get_object_vars( $row );
936 $this->mAttribs
['rc_timestamp'] = wfTimestamp( TS_MW
, $this->mAttribs
['rc_timestamp'] );
937 // rc_deleted MUST be set
938 $this->mAttribs
['rc_deleted'] = $row->rc_deleted
;
940 if ( isset( $this->mAttribs
['rc_ip'] ) ) {
941 // Clean up CIDRs for Postgres per T164898. ("127.0.0.1" casts to "127.0.0.1/32")
942 $n = strpos( $this->mAttribs
['rc_ip'], '/' );
943 if ( $n !== false ) {
944 $this->mAttribs
['rc_ip'] = substr( $this->mAttribs
['rc_ip'], 0, $n );
948 $comment = CommentStore
::newKey( 'rc_comment' )
949 // Legacy because $row probably came from self::selectFields()
950 ->getCommentLegacy( wfGetDB( DB_REPLICA
), $row, true )->text
;
951 $this->mAttribs
['rc_comment'] = &$comment;
952 $this->mAttribs
['rc_comment_text'] = &$comment;
953 $this->mAttribs
['rc_comment_data'] = null;
957 * Get an attribute value
959 * @param string $name Attribute name
962 public function getAttribute( $name ) {
963 if ( $name === 'rc_comment' ) {
964 return CommentStore
::newKey( 'rc_comment' )->getComment( $this->mAttribs
, true )->text
;
966 return isset( $this->mAttribs
[$name] ) ?
$this->mAttribs
[$name] : null;
972 public function getAttributes() {
973 return $this->mAttribs
;
977 * Gets the end part of the diff URL associated with this object
978 * Blank if no diff link should be displayed
979 * @param bool $forceCur
982 public function diffLinkTrail( $forceCur ) {
983 if ( $this->mAttribs
['rc_type'] == RC_EDIT
) {
984 $trail = "curid=" . (int)( $this->mAttribs
['rc_cur_id'] ) .
985 "&oldid=" . (int)( $this->mAttribs
['rc_last_oldid'] );
989 $trail .= '&diff=' . (int)( $this->mAttribs
['rc_this_oldid'] );
999 * Returns the change size (HTML).
1000 * The lengths can be given optionally.
1005 public function getCharacterDifference( $old = 0, $new = 0 ) {
1007 $old = $this->mAttribs
['rc_old_len'];
1010 $new = $this->mAttribs
['rc_new_len'];
1012 if ( $old === null ||
$new === null ) {
1016 return ChangesList
::showCharacterDifference( $old, $new );
1019 private static function checkIPAddress( $ip ) {
1022 if ( !IP
::isIPAddress( $ip ) ) {
1023 throw new MWException( "Attempt to write \"" . $ip .
1024 "\" as an IP address into recent changes" );
1027 $ip = $wgRequest->getIP();
1037 * Check whether the given timestamp is new enough to have a RC row with a given tolerance
1038 * as the recentchanges table might not be cleared out regularly (so older entries might exist)
1039 * or rows which will be deleted soon shouldn't be included.
1041 * @param mixed $timestamp MWTimestamp compatible timestamp
1042 * @param int $tolerance Tolerance in seconds
1045 public static function isInRCLifespan( $timestamp, $tolerance = 0 ) {
1048 return wfTimestamp( TS_UNIX
, $timestamp ) > time() - $tolerance - $wgRCMaxAge;
1052 * Parses and returns the rc_params attribute
1056 * @return mixed|bool false on failed unserialization
1058 public function parseParams() {
1059 $rcParams = $this->getAttribute( 'rc_params' );
1061 MediaWiki\
suppressWarnings();
1062 $unserializedParams = unserialize( $rcParams );
1063 MediaWiki\restoreWarnings
();
1065 return $unserializedParams;
1069 * Tags to append to the recent change,
1070 * and associated revision/log
1074 * @param string|array $tags
1076 public function addTags( $tags ) {
1077 if ( is_string( $tags ) ) {
1078 $this->tags
[] = $tags;
1080 $this->tags
= array_merge( $tags, $this->tags
);