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
64 // Constants for the rc_source field. Extensions may also have
65 // their own source constants.
66 const SRC_EDIT
= 'mw.edit';
67 const SRC_NEW
= 'mw.new';
68 const SRC_LOG
= 'mw.log';
69 const SRC_EXTERNAL
= 'mw.external'; // obsolete
70 const SRC_CATEGORIZE
= 'mw.categorize';
72 public $mAttribs = [];
78 public $mTitle = false;
83 private $mPerformer = false;
85 public $numberofWatchingusers = 0; # Dummy to prevent error message in SpecialRecentChangesLinked
86 public $notificationtimestamp;
89 * @var int Line number of recent change. Default -1.
94 * @var array List of tags to apply
99 * @var array Array of change types
101 private static $changeTypes = [
105 'external' => RC_EXTERNAL
,
106 'categorize' => RC_CATEGORIZE
,
113 * @return RecentChange
115 public static function newFromRow( $row ) {
116 $rc = new RecentChange
;
117 $rc->loadFromRow( $row );
123 * Parsing text to RC_* constants
125 * @param string|array $type
126 * @throws MWException
127 * @return int|array RC_TYPE
129 public static function parseToRCType( $type ) {
130 if ( is_array( $type ) ) {
132 foreach ( $type as $t ) {
133 $retval[] = RecentChange
::parseToRCType( $t );
139 if ( !array_key_exists( $type, self
::$changeTypes ) ) {
140 throw new MWException( "Unknown type '$type'" );
142 return self
::$changeTypes[$type];
146 * Parsing RC_* constants to human-readable test
149 * @return string $type
151 public static function parseFromRCType( $rcType ) {
152 return array_search( $rcType, self
::$changeTypes, true ) ?
: "$rcType";
156 * Get an array of all change types
162 public static function getChangeTypes() {
163 return array_keys( self
::$changeTypes );
167 * Obtain the recent change with a given rc_id value
169 * @param int $rcid The rc_id value to retrieve
170 * @return RecentChange|null
172 public static function newFromId( $rcid ) {
173 return self
::newFromConds( [ 'rc_id' => $rcid ], __METHOD__
);
177 * Find the first recent change matching some specific conditions
179 * @param array $conds Array of conditions
180 * @param mixed $fname Override the method name in profiling/logs
181 * @param int $dbType DB_* constant
183 * @return RecentChange|null
185 public static function newFromConds(
190 $db = wfGetDB( $dbType );
191 $row = $db->selectRow( 'recentchanges', self
::selectFields(), $conds, $fname );
192 if ( $row !== false ) {
193 return self
::newFromRow( $row );
200 * Return the list of recentchanges fields that should be selected to create
201 * a new recentchanges object.
204 public static function selectFields() {
236 * @param array $attribs
238 public function setAttribs( $attribs ) {
239 $this->mAttribs
= $attribs;
243 * @param array $extra
245 public function setExtra( $extra ) {
246 $this->mExtra
= $extra;
252 public function &getTitle() {
253 if ( $this->mTitle
=== false ) {
254 $this->mTitle
= Title
::makeTitle( $this->mAttribs
['rc_namespace'], $this->mAttribs
['rc_title'] );
257 return $this->mTitle
;
261 * Get the User object of the person who performed this change.
265 public function getPerformer() {
266 if ( $this->mPerformer
=== false ) {
267 if ( $this->mAttribs
['rc_user'] ) {
268 $this->mPerformer
= User
::newFromId( $this->mAttribs
['rc_user'] );
270 $this->mPerformer
= User
::newFromName( $this->mAttribs
['rc_user_text'], false );
274 return $this->mPerformer
;
278 * Writes the data in this object to the database
281 public function save( $noudp = false ) {
282 global $wgPutIPinRC, $wgUseEnotif, $wgShowUpdatedMarker, $wgContLang;
284 $dbw = wfGetDB( DB_MASTER
);
285 if ( !is_array( $this->mExtra
) ) {
289 if ( !$wgPutIPinRC ) {
290 $this->mAttribs
['rc_ip'] = '';
293 # Strict mode fixups (not-NULL fields)
294 foreach ( [ 'minor', 'bot', 'new', 'patrolled', 'deleted' ] as $field ) {
295 $this->mAttribs
["rc_$field"] = (int)$this->mAttribs
["rc_$field"];
297 # ...more fixups (NULL fields)
298 foreach ( [ 'old_len', 'new_len' ] as $field ) {
299 $this->mAttribs
["rc_$field"] = isset( $this->mAttribs
["rc_$field"] )
300 ?
(int)$this->mAttribs
["rc_$field"]
304 # If our database is strict about IP addresses, use NULL instead of an empty string
305 $strictIPs = in_array( $dbw->getType(), [ 'oracle', 'postgres' ] ); // legacy
306 if ( $strictIPs && $this->mAttribs
['rc_ip'] == '' ) {
307 unset( $this->mAttribs
['rc_ip'] );
310 # Trim spaces on user supplied text
311 $this->mAttribs
['rc_comment'] = trim( $this->mAttribs
['rc_comment'] );
313 # Make sure summary is truncated (whole multibyte characters)
314 $this->mAttribs
['rc_comment'] = $wgContLang->truncate( $this->mAttribs
['rc_comment'], 255 );
316 # Fixup database timestamps
317 $this->mAttribs
['rc_timestamp'] = $dbw->timestamp( $this->mAttribs
['rc_timestamp'] );
318 $this->mAttribs
['rc_id'] = $dbw->nextSequenceValue( 'recentchanges_rc_id_seq' );
320 # # If we are using foreign keys, an entry of 0 for the page_id will fail, so use NULL
321 if ( $this->mAttribs
['rc_cur_id'] == 0 ) {
322 unset( $this->mAttribs
['rc_cur_id'] );
326 $dbw->insert( 'recentchanges', $this->mAttribs
, __METHOD__
);
329 $this->mAttribs
['rc_id'] = $dbw->insertId();
332 Hooks
::run( 'RecentChange_save', [ &$this ] );
334 if ( count( $this->tags
) ) {
335 ChangeTags
::addTags( $this->tags
, $this->mAttribs
['rc_id'],
336 $this->mAttribs
['rc_this_oldid'], $this->mAttribs
['rc_logid'], null, $this );
339 # Notify external application via UDP
341 $this->notifyRCFeeds();
344 # E-mail notifications
345 if ( $wgUseEnotif ||
$wgShowUpdatedMarker ) {
346 $editor = $this->getPerformer();
347 $title = $this->getTitle();
349 // Never send an RC notification email about categorization changes
351 $this->mAttribs
['rc_type'] != RC_CATEGORIZE
&&
352 Hooks
::run( 'AbortEmailNotification', [ $editor, $title, $this ] )
354 // @FIXME: This would be better as an extension hook
355 // Send emails or email jobs once this row is safely committed
356 $dbw->onTransactionIdle(
357 function () use ( $editor, $title ) {
358 $enotif = new EmailNotification();
359 $enotif->notifyOnPageChange(
362 $this->mAttribs
['rc_timestamp'],
363 $this->mAttribs
['rc_comment'],
364 $this->mAttribs
['rc_minor'],
365 $this->mAttribs
['rc_last_oldid'],
366 $this->mExtra
['pageStatus']
374 // Update the cached list of active users
375 if ( $this->mAttribs
['rc_user'] > 0 ) {
376 JobQueueGroup
::singleton()->lazyPush( RecentChangesUpdateJob
::newCacheUpdateJob() );
381 * Notify all the feeds about the change.
382 * @param array $feeds Optional feeds to send to, defaults to $wgRCFeeds
384 public function notifyRCFeeds( array $feeds = null ) {
386 if ( $feeds === null ) {
390 $performer = $this->getPerformer();
392 foreach ( $feeds as $params ) {
394 'omit_bots' => false,
395 'omit_anon' => false,
396 'omit_user' => false,
397 'omit_minor' => false,
398 'omit_patrolled' => false,
402 ( $params['omit_bots'] && $this->mAttribs
['rc_bot'] ) ||
403 ( $params['omit_anon'] && $performer->isAnon() ) ||
404 ( $params['omit_user'] && !$performer->isAnon() ) ||
405 ( $params['omit_minor'] && $this->mAttribs
['rc_minor'] ) ||
406 ( $params['omit_patrolled'] && $this->mAttribs
['rc_patrolled'] ) ||
407 $this->mAttribs
['rc_type'] == RC_EXTERNAL
412 if ( isset( $this->mExtra
['actionCommentIRC'] ) ) {
413 $actionComment = $this->mExtra
['actionCommentIRC'];
415 $actionComment = null;
418 $feed = RCFeed
::factory( $params );
419 $feed->notify( $this, $actionComment );
425 * @deprecated since 1.29 Use RCFeed::factory() instead
426 * @param string $uri URI to get the engine object for
427 * @return RCFeedEngine The engine object
428 * @throws MWException
430 public static function getEngine( $uri ) {
431 // TODO: Merge into RCFeed::factory().
433 $scheme = parse_url( $uri, PHP_URL_SCHEME
);
435 throw new MWException( "Invalid RCFeed uri: '$uri'" );
437 if ( !isset( $wgRCEngines[$scheme] ) ) {
438 throw new MWException( "Unknown RCFeedEngine scheme: '$scheme'" );
440 if ( defined( 'MW_PHPUNIT_TEST' ) && is_object( $wgRCEngines[$scheme] ) ) {
441 return $wgRCEngines[$scheme];
443 return new $wgRCEngines[$scheme];
447 * Mark a given change as patrolled
449 * @param RecentChange|int $change RecentChange or corresponding rc_id
450 * @param bool $auto For automatic patrol
451 * @param string|string[] $tags Change tags to add to the patrol log entry
452 * ($user should be able to add the specified tags before this is called)
453 * @return array See doMarkPatrolled(), or null if $change is not an existing rc_id
455 public static function markPatrolled( $change, $auto = false, $tags = null ) {
458 $change = $change instanceof RecentChange
460 : RecentChange
::newFromId( $change );
462 if ( !$change instanceof RecentChange
) {
466 return $change->doMarkPatrolled( $wgUser, $auto, $tags );
470 * Mark this RecentChange as patrolled
472 * NOTE: Can also return 'rcpatroldisabled', 'hookaborted' and
473 * 'markedaspatrollederror-noautopatrol' as errors
474 * @param User $user User object doing the action
475 * @param bool $auto For automatic patrol
476 * @param string|string[] $tags Change tags to add to the patrol log entry
477 * ($user should be able to add the specified tags before this is called)
478 * @return array Array of permissions errors, see Title::getUserPermissionsErrors()
480 public function doMarkPatrolled( User
$user, $auto = false, $tags = null ) {
481 global $wgUseRCPatrol, $wgUseNPPatrol, $wgUseFilePatrol;
484 // If recentchanges patrol is disabled, only new pages or new file versions
485 // can be patrolled, provided the appropriate config variable is set
486 if ( !$wgUseRCPatrol && ( !$wgUseNPPatrol ||
$this->getAttribute( 'rc_type' ) != RC_NEW
) &&
487 ( !$wgUseFilePatrol ||
!( $this->getAttribute( 'rc_type' ) == RC_LOG
&&
488 $this->getAttribute( 'rc_log_type' ) == 'upload' ) ) ) {
489 $errors[] = [ 'rcpatroldisabled' ];
491 // Automatic patrol needs "autopatrol", ordinary patrol needs "patrol"
492 $right = $auto ?
'autopatrol' : 'patrol';
493 $errors = array_merge( $errors, $this->getTitle()->getUserPermissionsErrors( $right, $user ) );
494 if ( !Hooks
::run( 'MarkPatrolled',
495 [ $this->getAttribute( 'rc_id' ), &$user, false, $auto ] )
497 $errors[] = [ 'hookaborted' ];
499 // Users without the 'autopatrol' right can't patrol their
501 if ( $user->getName() === $this->getAttribute( 'rc_user_text' )
502 && !$user->isAllowed( 'autopatrol' )
504 $errors[] = [ 'markedaspatrollederror-noautopatrol' ];
509 // If the change was patrolled already, do nothing
510 if ( $this->getAttribute( 'rc_patrolled' ) ) {
513 // Actually set the 'patrolled' flag in RC
514 $this->reallyMarkPatrolled();
515 // Log this patrol event
516 PatrolLog
::record( $this, $auto, $user, $tags );
519 'MarkPatrolledComplete',
520 [ $this->getAttribute( 'rc_id' ), &$user, false, $auto ]
527 * Mark this RecentChange patrolled, without error checking
528 * @return int Number of affected rows
530 public function reallyMarkPatrolled() {
531 $dbw = wfGetDB( DB_MASTER
);
538 'rc_id' => $this->getAttribute( 'rc_id' )
542 // Invalidate the page cache after the page has been patrolled
543 // to make sure that the Patrol link isn't visible any longer!
544 $this->getTitle()->invalidateCache();
546 return $dbw->affectedRows();
550 * Makes an entry in the database corresponding to an edit
552 * @param string $timestamp
553 * @param Title $title
556 * @param string $comment
558 * @param string $lastTimestamp
561 * @param int $oldSize
562 * @param int $newSize
566 * @return RecentChange
568 public static function notifyEdit(
569 $timestamp, &$title, $minor, &$user, $comment, $oldId, $lastTimestamp,
570 $bot, $ip = '', $oldSize = 0, $newSize = 0, $newId = 0, $patrol = 0,
573 $rc = new RecentChange
;
574 $rc->mTitle
= $title;
575 $rc->mPerformer
= $user;
577 'rc_timestamp' => $timestamp,
578 'rc_namespace' => $title->getNamespace(),
579 'rc_title' => $title->getDBkey(),
580 'rc_type' => RC_EDIT
,
581 'rc_source' => self
::SRC_EDIT
,
582 'rc_minor' => $minor ?
1 : 0,
583 'rc_cur_id' => $title->getArticleID(),
584 'rc_user' => $user->getId(),
585 'rc_user_text' => $user->getName(),
586 'rc_comment' => $comment,
587 'rc_this_oldid' => $newId,
588 'rc_last_oldid' => $oldId,
589 'rc_bot' => $bot ?
1 : 0,
590 'rc_ip' => self
::checkIPAddress( $ip ),
591 'rc_patrolled' => intval( $patrol ),
592 'rc_new' => 0, # obsolete
593 'rc_old_len' => $oldSize,
594 'rc_new_len' => $newSize,
597 'rc_log_type' => null,
598 'rc_log_action' => '',
603 'prefixedDBkey' => $title->getPrefixedDBkey(),
604 'lastTimestamp' => $lastTimestamp,
605 'oldSize' => $oldSize,
606 'newSize' => $newSize,
607 'pageStatus' => 'changed'
610 DeferredUpdates
::addCallableUpdate(
611 function () use ( $rc, $tags ) {
612 $rc->addTags( $tags );
614 if ( $rc->mAttribs
['rc_patrolled'] ) {
615 PatrolLog
::record( $rc, true, $rc->getPerformer() );
618 DeferredUpdates
::POSTSEND
,
626 * Makes an entry in the database corresponding to page creation
627 * Note: the title object must be loaded with the new id using resetArticleID()
629 * @param string $timestamp
630 * @param Title $title
633 * @param string $comment
640 * @return RecentChange
642 public static function notifyNew(
643 $timestamp, &$title, $minor, &$user, $comment, $bot,
644 $ip = '', $size = 0, $newId = 0, $patrol = 0, $tags = []
646 $rc = new RecentChange
;
647 $rc->mTitle
= $title;
648 $rc->mPerformer
= $user;
650 'rc_timestamp' => $timestamp,
651 'rc_namespace' => $title->getNamespace(),
652 'rc_title' => $title->getDBkey(),
654 'rc_source' => self
::SRC_NEW
,
655 'rc_minor' => $minor ?
1 : 0,
656 'rc_cur_id' => $title->getArticleID(),
657 'rc_user' => $user->getId(),
658 'rc_user_text' => $user->getName(),
659 'rc_comment' => $comment,
660 'rc_this_oldid' => $newId,
661 'rc_last_oldid' => 0,
662 'rc_bot' => $bot ?
1 : 0,
663 'rc_ip' => self
::checkIPAddress( $ip ),
664 'rc_patrolled' => intval( $patrol ),
665 'rc_new' => 1, # obsolete
667 'rc_new_len' => $size,
670 'rc_log_type' => null,
671 'rc_log_action' => '',
676 'prefixedDBkey' => $title->getPrefixedDBkey(),
677 'lastTimestamp' => 0,
680 'pageStatus' => 'created'
683 DeferredUpdates
::addCallableUpdate(
684 function () use ( $rc, $tags ) {
685 $rc->addTags( $tags );
687 if ( $rc->mAttribs
['rc_patrolled'] ) {
688 PatrolLog
::record( $rc, true, $rc->getPerformer() );
691 DeferredUpdates
::POSTSEND
,
699 * @param string $timestamp
700 * @param Title $title
702 * @param string $actionComment
704 * @param string $type
705 * @param string $action
706 * @param Title $target
707 * @param string $logComment
708 * @param string $params
710 * @param string $actionCommentIRC
713 public static function notifyLog( $timestamp, &$title, &$user, $actionComment, $ip, $type,
714 $action, $target, $logComment, $params, $newId = 0, $actionCommentIRC = ''
716 global $wgLogRestrictions;
718 # Don't add private logs to RC!
719 if ( isset( $wgLogRestrictions[$type] ) && $wgLogRestrictions[$type] != '*' ) {
722 $rc = self
::newLogEntry( $timestamp, $title, $user, $actionComment, $ip, $type, $action,
723 $target, $logComment, $params, $newId, $actionCommentIRC );
730 * @param string $timestamp
731 * @param Title $title
733 * @param string $actionComment
735 * @param string $type
736 * @param string $action
737 * @param Title $target
738 * @param string $logComment
739 * @param string $params
741 * @param string $actionCommentIRC
742 * @param int $revId Id of associated revision, if any
743 * @param bool $isPatrollable Whether this log entry is patrollable
744 * @return RecentChange
746 public static function newLogEntry( $timestamp, &$title, &$user, $actionComment, $ip,
747 $type, $action, $target, $logComment, $params, $newId = 0, $actionCommentIRC = '',
748 $revId = 0, $isPatrollable = false ) {
751 # # Get pageStatus for email notification
752 switch ( $type . '-' . $action ) {
753 case 'delete-delete':
754 case 'delete-delete_redir':
755 $pageStatus = 'deleted';
758 case 'move-move_redir':
759 $pageStatus = 'moved';
761 case 'delete-restore':
762 $pageStatus = 'restored';
764 case 'upload-upload':
765 $pageStatus = 'created';
767 case 'upload-overwrite':
769 $pageStatus = 'changed';
773 // Allow unpatrolled status for patrollable log entries
774 $markPatrolled = $isPatrollable ?
$user->isAllowed( 'autopatrol' ) : true;
776 $rc = new RecentChange
;
777 $rc->mTitle
= $target;
778 $rc->mPerformer
= $user;
780 'rc_timestamp' => $timestamp,
781 'rc_namespace' => $target->getNamespace(),
782 'rc_title' => $target->getDBkey(),
784 'rc_source' => self
::SRC_LOG
,
786 'rc_cur_id' => $target->getArticleID(),
787 'rc_user' => $user->getId(),
788 'rc_user_text' => $user->getName(),
789 'rc_comment' => $logComment,
790 'rc_this_oldid' => $revId,
791 'rc_last_oldid' => 0,
792 'rc_bot' => $user->isAllowed( 'bot' ) ?
(int)$wgRequest->getBool( 'bot', true ) : 0,
793 'rc_ip' => self
::checkIPAddress( $ip ),
794 'rc_patrolled' => $markPatrolled ?
1 : 0,
795 'rc_new' => 0, # obsolete
796 'rc_old_len' => null,
797 'rc_new_len' => null,
799 'rc_logid' => $newId,
800 'rc_log_type' => $type,
801 'rc_log_action' => $action,
802 'rc_params' => $params
806 'prefixedDBkey' => $title->getPrefixedDBkey(),
807 'lastTimestamp' => 0,
808 'actionComment' => $actionComment, // the comment appended to the action, passed from LogPage
809 'pageStatus' => $pageStatus,
810 'actionCommentIRC' => $actionCommentIRC
817 * Constructs a RecentChange object for the given categorization
818 * This does not call save() on the object and thus does not write to the db
822 * @param string $timestamp Timestamp of the recent change to occur
823 * @param Title $categoryTitle Title of the category a page is being added to or removed from
824 * @param User $user User object of the user that made the change
825 * @param string $comment Change summary
826 * @param Title $pageTitle Title of the page that is being added or removed
827 * @param int $oldRevId Parent revision ID of this change
828 * @param int $newRevId Revision ID of this change
829 * @param string $lastTimestamp Parent revision timestamp of this change
830 * @param bool $bot true, if the change was made by a bot
831 * @param string $ip IP address of the user, if the change was made anonymously
832 * @param int $deleted Indicates whether the change has been deleted
834 * @return RecentChange
836 public static function newForCategorization(
838 Title
$categoryTitle,
849 $rc = new RecentChange
;
850 $rc->mTitle
= $categoryTitle;
851 $rc->mPerformer
= $user;
853 'rc_timestamp' => $timestamp,
854 'rc_namespace' => $categoryTitle->getNamespace(),
855 'rc_title' => $categoryTitle->getDBkey(),
856 'rc_type' => RC_CATEGORIZE
,
857 'rc_source' => self
::SRC_CATEGORIZE
,
859 'rc_cur_id' => $pageTitle->getArticleID(),
860 'rc_user' => $user ?
$user->getId() : 0,
861 'rc_user_text' => $user ?
$user->getName() : '',
862 'rc_comment' => $comment,
863 'rc_this_oldid' => $newRevId,
864 'rc_last_oldid' => $oldRevId,
865 'rc_bot' => $bot ?
1 : 0,
866 'rc_ip' => self
::checkIPAddress( $ip ),
867 'rc_patrolled' => 1, // Always patrolled, just like log entries
868 'rc_new' => 0, # obsolete
869 'rc_old_len' => null,
870 'rc_new_len' => null,
871 'rc_deleted' => $deleted,
873 'rc_log_type' => null,
874 'rc_log_action' => '',
875 'rc_params' => serialize( [
876 'hidden-cat' => WikiCategoryPage
::factory( $categoryTitle )->isHidden()
881 'prefixedDBkey' => $categoryTitle->getPrefixedDBkey(),
882 'lastTimestamp' => $lastTimestamp,
885 'pageStatus' => 'changed'
892 * Get a parameter value
896 * @param string $name parameter name
899 public function getParam( $name ) {
900 $params = $this->parseParams();
901 return isset( $params[$name] ) ?
$params[$name] : null;
905 * Initialises the members of this object from a mysql row object
909 public function loadFromRow( $row ) {
910 $this->mAttribs
= get_object_vars( $row );
911 $this->mAttribs
['rc_timestamp'] = wfTimestamp( TS_MW
, $this->mAttribs
['rc_timestamp'] );
912 $this->mAttribs
['rc_deleted'] = $row->rc_deleted
; // MUST be set
916 * Get an attribute value
918 * @param string $name Attribute name
921 public function getAttribute( $name ) {
922 return isset( $this->mAttribs
[$name] ) ?
$this->mAttribs
[$name] : null;
928 public function getAttributes() {
929 return $this->mAttribs
;
933 * Gets the end part of the diff URL associated with this object
934 * Blank if no diff link should be displayed
935 * @param bool $forceCur
938 public function diffLinkTrail( $forceCur ) {
939 if ( $this->mAttribs
['rc_type'] == RC_EDIT
) {
940 $trail = "curid=" . (int)( $this->mAttribs
['rc_cur_id'] ) .
941 "&oldid=" . (int)( $this->mAttribs
['rc_last_oldid'] );
945 $trail .= '&diff=' . (int)( $this->mAttribs
['rc_this_oldid'] );
955 * Returns the change size (HTML).
956 * The lengths can be given optionally.
961 public function getCharacterDifference( $old = 0, $new = 0 ) {
963 $old = $this->mAttribs
['rc_old_len'];
966 $new = $this->mAttribs
['rc_new_len'];
968 if ( $old === null ||
$new === null ) {
972 return ChangesList
::showCharacterDifference( $old, $new );
975 private static function checkIPAddress( $ip ) {
978 if ( !IP
::isIPAddress( $ip ) ) {
979 throw new MWException( "Attempt to write \"" . $ip .
980 "\" as an IP address into recent changes" );
983 $ip = $wgRequest->getIP();
993 * Check whether the given timestamp is new enough to have a RC row with a given tolerance
994 * as the recentchanges table might not be cleared out regularly (so older entries might exist)
995 * or rows which will be deleted soon shouldn't be included.
997 * @param mixed $timestamp MWTimestamp compatible timestamp
998 * @param int $tolerance Tolerance in seconds
1001 public static function isInRCLifespan( $timestamp, $tolerance = 0 ) {
1004 return wfTimestamp( TS_UNIX
, $timestamp ) > time() - $tolerance - $wgRCMaxAge;
1008 * Parses and returns the rc_params attribute
1012 * @return mixed|bool false on failed unserialization
1014 public function parseParams() {
1015 $rcParams = $this->getAttribute( 'rc_params' );
1017 MediaWiki\
suppressWarnings();
1018 $unserializedParams = unserialize( $rcParams );
1019 MediaWiki\restoreWarnings
();
1021 return $unserializedParams;
1025 * Tags to append to the recent change,
1026 * and associated revision/log
1030 * @param string|array $tags
1032 public function addTags( $tags ) {
1033 if ( is_string( $tags ) ) {
1034 $this->tags
[] = $tags;
1036 $this->tags
= array_merge( $tags, $this->tags
);