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 Array of change types
96 private static $changeTypes = [
100 'external' => RC_EXTERNAL
,
101 'categorize' => RC_CATEGORIZE
,
108 * @return RecentChange
110 public static function newFromRow( $row ) {
111 $rc = new RecentChange
;
112 $rc->loadFromRow( $row );
118 * Parsing text to RC_* constants
120 * @param string|array $type
121 * @throws MWException
122 * @return int|array RC_TYPE
124 public static function parseToRCType( $type ) {
125 if ( is_array( $type ) ) {
127 foreach ( $type as $t ) {
128 $retval[] = RecentChange
::parseToRCType( $t );
134 if ( !array_key_exists( $type, self
::$changeTypes ) ) {
135 throw new MWException( "Unknown type '$type'" );
137 return self
::$changeTypes[$type];
141 * Parsing RC_* constants to human-readable test
144 * @return string $type
146 public static function parseFromRCType( $rcType ) {
147 return array_search( $rcType, self
::$changeTypes, true ) ?
: "$rcType";
151 * Get an array of all change types
157 public static function getChangeTypes() {
158 return array_keys( self
::$changeTypes );
162 * Obtain the recent change with a given rc_id value
164 * @param int $rcid The rc_id value to retrieve
165 * @return RecentChange|null
167 public static function newFromId( $rcid ) {
168 return self
::newFromConds( [ 'rc_id' => $rcid ], __METHOD__
);
172 * Find the first recent change matching some specific conditions
174 * @param array $conds Array of conditions
175 * @param mixed $fname Override the method name in profiling/logs
176 * @param int $dbType DB_* constant
178 * @return RecentChange|null
180 public static function newFromConds(
185 $db = wfGetDB( $dbType );
186 $row = $db->selectRow( 'recentchanges', self
::selectFields(), $conds, $fname );
187 if ( $row !== false ) {
188 return self
::newFromRow( $row );
195 * Return the list of recentchanges fields that should be selected to create
196 * a new recentchanges object.
199 public static function selectFields() {
231 * @param array $attribs
233 public function setAttribs( $attribs ) {
234 $this->mAttribs
= $attribs;
238 * @param array $extra
240 public function setExtra( $extra ) {
241 $this->mExtra
= $extra;
247 public function &getTitle() {
248 if ( $this->mTitle
=== false ) {
249 $this->mTitle
= Title
::makeTitle( $this->mAttribs
['rc_namespace'], $this->mAttribs
['rc_title'] );
252 return $this->mTitle
;
256 * Get the User object of the person who performed this change.
260 public function getPerformer() {
261 if ( $this->mPerformer
=== false ) {
262 if ( $this->mAttribs
['rc_user'] ) {
263 $this->mPerformer
= User
::newFromId( $this->mAttribs
['rc_user'] );
265 $this->mPerformer
= User
::newFromName( $this->mAttribs
['rc_user_text'], false );
269 return $this->mPerformer
;
273 * Writes the data in this object to the database
276 public function save( $noudp = false ) {
277 global $wgPutIPinRC, $wgUseEnotif, $wgShowUpdatedMarker, $wgContLang;
279 $dbw = wfGetDB( DB_MASTER
);
280 if ( !is_array( $this->mExtra
) ) {
284 if ( !$wgPutIPinRC ) {
285 $this->mAttribs
['rc_ip'] = '';
288 # Strict mode fixups (not-NULL fields)
289 foreach ( [ 'minor', 'bot', 'new', 'patrolled', 'deleted' ] as $field ) {
290 $this->mAttribs
["rc_$field"] = (int)$this->mAttribs
["rc_$field"];
292 # ...more fixups (NULL fields)
293 foreach ( [ 'old_len', 'new_len' ] as $field ) {
294 $this->mAttribs
["rc_$field"] = isset( $this->mAttribs
["rc_$field"] )
295 ?
(int)$this->mAttribs
["rc_$field"]
299 # If our database is strict about IP addresses, use NULL instead of an empty string
300 if ( $dbw->strictIPs() && $this->mAttribs
['rc_ip'] == '' ) {
301 unset( $this->mAttribs
['rc_ip'] );
304 # Trim spaces on user supplied text
305 $this->mAttribs
['rc_comment'] = trim( $this->mAttribs
['rc_comment'] );
307 # Make sure summary is truncated (whole multibyte characters)
308 $this->mAttribs
['rc_comment'] = $wgContLang->truncate( $this->mAttribs
['rc_comment'], 255 );
310 # Fixup database timestamps
311 $this->mAttribs
['rc_timestamp'] = $dbw->timestamp( $this->mAttribs
['rc_timestamp'] );
312 $this->mAttribs
['rc_id'] = $dbw->nextSequenceValue( 'recentchanges_rc_id_seq' );
314 # # If we are using foreign keys, an entry of 0 for the page_id will fail, so use NULL
315 if ( $dbw->cascadingDeletes() && $this->mAttribs
['rc_cur_id'] == 0 ) {
316 unset( $this->mAttribs
['rc_cur_id'] );
320 $dbw->insert( 'recentchanges', $this->mAttribs
, __METHOD__
);
323 $this->mAttribs
['rc_id'] = $dbw->insertId();
326 Hooks
::run( 'RecentChange_save', [ &$this ] );
328 # Notify external application via UDP
330 $this->notifyRCFeeds();
333 # E-mail notifications
334 if ( $wgUseEnotif ||
$wgShowUpdatedMarker ) {
335 $editor = $this->getPerformer();
336 $title = $this->getTitle();
338 // Never send an RC notification email about categorization changes
340 $this->mAttribs
['rc_type'] != RC_CATEGORIZE
&&
341 Hooks
::run( 'AbortEmailNotification', [ $editor, $title, $this ] )
343 // @FIXME: This would be better as an extension hook
344 // Send emails or email jobs once this row is safely committed
345 $dbw->onTransactionIdle( function () use ( $editor, $title ) {
346 $enotif = new EmailNotification();
347 $enotif->notifyOnPageChange(
350 $this->mAttribs
['rc_timestamp'],
351 $this->mAttribs
['rc_comment'],
352 $this->mAttribs
['rc_minor'],
353 $this->mAttribs
['rc_last_oldid'],
354 $this->mExtra
['pageStatus']
360 // Update the cached list of active users
361 if ( $this->mAttribs
['rc_user'] > 0 ) {
362 JobQueueGroup
::singleton()->lazyPush( RecentChangesUpdateJob
::newCacheUpdateJob() );
367 * Notify all the feeds about the change.
368 * @param array $feeds Optional feeds to send to, defaults to $wgRCFeeds
370 public function notifyRCFeeds( array $feeds = null ) {
372 if ( $feeds === null ) {
376 $performer = $this->getPerformer();
378 foreach ( $feeds as $feed ) {
380 'omit_bots' => false,
381 'omit_anon' => false,
382 'omit_user' => false,
383 'omit_minor' => false,
384 'omit_patrolled' => false,
388 ( $feed['omit_bots'] && $this->mAttribs
['rc_bot'] ) ||
389 ( $feed['omit_anon'] && $performer->isAnon() ) ||
390 ( $feed['omit_user'] && !$performer->isAnon() ) ||
391 ( $feed['omit_minor'] && $this->mAttribs
['rc_minor'] ) ||
392 ( $feed['omit_patrolled'] && $this->mAttribs
['rc_patrolled'] ) ||
393 $this->mAttribs
['rc_type'] == RC_EXTERNAL
398 $engine = self
::getEngine( $feed['uri'] );
400 if ( isset( $this->mExtra
['actionCommentIRC'] ) ) {
401 $actionComment = $this->mExtra
['actionCommentIRC'];
403 $actionComment = null;
406 /** @var $formatter RCFeedFormatter */
407 $formatter = is_object( $feed['formatter'] ) ?
$feed['formatter'] : new $feed['formatter']();
408 $line = $formatter->getLine( $feed, $this, $actionComment );
411 // If a feed formatter returns null, this will otherwise cause an
412 // error in at least RedisPubSubFeedEngine.
413 // Not sure where/how this should best be handled.
417 $engine->send( $feed, $line );
422 * Gets the stream engine object for a given URI from $wgRCEngines
424 * @param string $uri URI to get the engine object for
425 * @throws MWException
426 * @return RCFeedEngine The engine object
428 public static function getEngine( $uri ) {
431 $scheme = parse_url( $uri, PHP_URL_SCHEME
);
433 throw new MWException( __FUNCTION__
. ": Invalid stream logger URI: '$uri'" );
436 if ( !isset( $wgRCEngines[$scheme] ) ) {
437 throw new MWException( __FUNCTION__
. ": Unknown stream logger URI scheme: $scheme" );
440 return new $wgRCEngines[$scheme];
444 * Mark a given change as patrolled
446 * @param RecentChange|int $change RecentChange or corresponding rc_id
447 * @param bool $auto For automatic patrol
448 * @param string|string[] $tags Change tags to add to the patrol log entry
449 * ($user should be able to add the specified tags before this is called)
450 * @return array See doMarkPatrolled(), or null if $change is not an existing rc_id
452 public static function markPatrolled( $change, $auto = false, $tags = null ) {
455 $change = $change instanceof RecentChange
457 : RecentChange
::newFromId( $change );
459 if ( !$change instanceof RecentChange
) {
463 return $change->doMarkPatrolled( $wgUser, $auto, $tags );
467 * Mark this RecentChange as patrolled
469 * NOTE: Can also return 'rcpatroldisabled', 'hookaborted' and
470 * 'markedaspatrollederror-noautopatrol' as errors
471 * @param User $user User object doing the action
472 * @param bool $auto For automatic patrol
473 * @param string|string[] $tags Change tags to add to the patrol log entry
474 * ($user should be able to add the specified tags before this is called)
475 * @return array Array of permissions errors, see Title::getUserPermissionsErrors()
477 public function doMarkPatrolled( User
$user, $auto = false, $tags = null ) {
478 global $wgUseRCPatrol, $wgUseNPPatrol, $wgUseFilePatrol;
481 // If recentchanges patrol is disabled, only new pages or new file versions
482 // can be patrolled, provided the appropriate config variable is set
483 if ( !$wgUseRCPatrol && ( !$wgUseNPPatrol ||
$this->getAttribute( 'rc_type' ) != RC_NEW
) &&
484 ( !$wgUseFilePatrol ||
!( $this->getAttribute( 'rc_type' ) == RC_LOG
&&
485 $this->getAttribute( 'rc_log_type' ) == 'upload' ) ) ) {
486 $errors[] = [ 'rcpatroldisabled' ];
488 // Automatic patrol needs "autopatrol", ordinary patrol needs "patrol"
489 $right = $auto ?
'autopatrol' : 'patrol';
490 $errors = array_merge( $errors, $this->getTitle()->getUserPermissionsErrors( $right, $user ) );
491 if ( !Hooks
::run( 'MarkPatrolled',
492 [ $this->getAttribute( 'rc_id' ), &$user, false, $auto ] )
494 $errors[] = [ 'hookaborted' ];
496 // Users without the 'autopatrol' right can't patrol their
498 if ( $user->getName() === $this->getAttribute( 'rc_user_text' )
499 && !$user->isAllowed( 'autopatrol' )
501 $errors[] = [ 'markedaspatrollederror-noautopatrol' ];
506 // If the change was patrolled already, do nothing
507 if ( $this->getAttribute( 'rc_patrolled' ) ) {
510 // Actually set the 'patrolled' flag in RC
511 $this->reallyMarkPatrolled();
512 // Log this patrol event
513 PatrolLog
::record( $this, $auto, $user, $tags );
516 'MarkPatrolledComplete',
517 [ $this->getAttribute( 'rc_id' ), &$user, false, $auto ]
524 * Mark this RecentChange patrolled, without error checking
525 * @return int Number of affected rows
527 public function reallyMarkPatrolled() {
528 $dbw = wfGetDB( DB_MASTER
);
535 'rc_id' => $this->getAttribute( 'rc_id' )
539 // Invalidate the page cache after the page has been patrolled
540 // to make sure that the Patrol link isn't visible any longer!
541 $this->getTitle()->invalidateCache();
543 return $dbw->affectedRows();
547 * Makes an entry in the database corresponding to an edit
549 * @param string $timestamp
550 * @param Title $title
553 * @param string $comment
555 * @param string $lastTimestamp
558 * @param int $oldSize
559 * @param int $newSize
563 * @return RecentChange
565 public static function notifyEdit(
566 $timestamp, &$title, $minor, &$user, $comment, $oldId, $lastTimestamp,
567 $bot, $ip = '', $oldSize = 0, $newSize = 0, $newId = 0, $patrol = 0,
570 $rc = new RecentChange
;
571 $rc->mTitle
= $title;
572 $rc->mPerformer
= $user;
574 'rc_timestamp' => $timestamp,
575 'rc_namespace' => $title->getNamespace(),
576 'rc_title' => $title->getDBkey(),
577 'rc_type' => RC_EDIT
,
578 'rc_source' => self
::SRC_EDIT
,
579 'rc_minor' => $minor ?
1 : 0,
580 'rc_cur_id' => $title->getArticleID(),
581 'rc_user' => $user->getId(),
582 'rc_user_text' => $user->getName(),
583 'rc_comment' => $comment,
584 'rc_this_oldid' => $newId,
585 'rc_last_oldid' => $oldId,
586 'rc_bot' => $bot ?
1 : 0,
587 'rc_ip' => self
::checkIPAddress( $ip ),
588 'rc_patrolled' => intval( $patrol ),
589 'rc_new' => 0, # obsolete
590 'rc_old_len' => $oldSize,
591 'rc_new_len' => $newSize,
594 'rc_log_type' => null,
595 'rc_log_action' => '',
600 'prefixedDBkey' => $title->getPrefixedDBkey(),
601 'lastTimestamp' => $lastTimestamp,
602 'oldSize' => $oldSize,
603 'newSize' => $newSize,
604 'pageStatus' => 'changed'
607 DeferredUpdates
::addCallableUpdate(
608 function () use ( $rc, $tags ) {
610 if ( $rc->mAttribs
['rc_patrolled'] ) {
611 PatrolLog
::record( $rc, true, $rc->getPerformer() );
613 if ( count( $tags ) ) {
614 ChangeTags
::addTags( $tags, $rc->mAttribs
['rc_id'],
615 $rc->mAttribs
['rc_this_oldid'], null, null );
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 ) {
686 if ( $rc->mAttribs
['rc_patrolled'] ) {
687 PatrolLog
::record( $rc, true, $rc->getPerformer() );
689 if ( count( $tags ) ) {
690 ChangeTags
::addTags( $tags, $rc->mAttribs
['rc_id'],
691 $rc->mAttribs
['rc_this_oldid'], null, null );
694 DeferredUpdates
::POSTSEND
,
702 * @param string $timestamp
703 * @param Title $title
705 * @param string $actionComment
707 * @param string $type
708 * @param string $action
709 * @param Title $target
710 * @param string $logComment
711 * @param string $params
713 * @param string $actionCommentIRC
716 public static function notifyLog( $timestamp, &$title, &$user, $actionComment, $ip, $type,
717 $action, $target, $logComment, $params, $newId = 0, $actionCommentIRC = ''
719 global $wgLogRestrictions;
721 # Don't add private logs to RC!
722 if ( isset( $wgLogRestrictions[$type] ) && $wgLogRestrictions[$type] != '*' ) {
725 $rc = self
::newLogEntry( $timestamp, $title, $user, $actionComment, $ip, $type, $action,
726 $target, $logComment, $params, $newId, $actionCommentIRC );
733 * @param string $timestamp
734 * @param Title $title
736 * @param string $actionComment
738 * @param string $type
739 * @param string $action
740 * @param Title $target
741 * @param string $logComment
742 * @param string $params
744 * @param string $actionCommentIRC
745 * @param int $revId Id of associated revision, if any
746 * @param bool $isPatrollable Whether this log entry is patrollable
747 * @return RecentChange
749 public static function newLogEntry( $timestamp, &$title, &$user, $actionComment, $ip,
750 $type, $action, $target, $logComment, $params, $newId = 0, $actionCommentIRC = '',
751 $revId = 0, $isPatrollable = false ) {
754 # # Get pageStatus for email notification
755 switch ( $type . '-' . $action ) {
756 case 'delete-delete':
757 $pageStatus = 'deleted';
760 case 'move-move_redir':
761 $pageStatus = 'moved';
763 case 'delete-restore':
764 $pageStatus = 'restored';
766 case 'upload-upload':
767 $pageStatus = 'created';
769 case 'upload-overwrite':
771 $pageStatus = 'changed';
775 // Allow unpatrolled status for patrollable log entries
776 $markPatrolled = $isPatrollable ?
$user->isAllowed( 'autopatrol' ) : true;
778 $rc = new RecentChange
;
779 $rc->mTitle
= $target;
780 $rc->mPerformer
= $user;
782 'rc_timestamp' => $timestamp,
783 'rc_namespace' => $target->getNamespace(),
784 'rc_title' => $target->getDBkey(),
786 'rc_source' => self
::SRC_LOG
,
788 'rc_cur_id' => $target->getArticleID(),
789 'rc_user' => $user->getId(),
790 'rc_user_text' => $user->getName(),
791 'rc_comment' => $logComment,
792 'rc_this_oldid' => $revId,
793 'rc_last_oldid' => 0,
794 'rc_bot' => $user->isAllowed( 'bot' ) ?
(int)$wgRequest->getBool( 'bot', true ) : 0,
795 'rc_ip' => self
::checkIPAddress( $ip ),
796 'rc_patrolled' => $markPatrolled ?
1 : 0,
797 'rc_new' => 0, # obsolete
798 'rc_old_len' => null,
799 'rc_new_len' => null,
801 'rc_logid' => $newId,
802 'rc_log_type' => $type,
803 'rc_log_action' => $action,
804 'rc_params' => $params
808 'prefixedDBkey' => $title->getPrefixedDBkey(),
809 'lastTimestamp' => 0,
810 'actionComment' => $actionComment, // the comment appended to the action, passed from LogPage
811 'pageStatus' => $pageStatus,
812 'actionCommentIRC' => $actionCommentIRC
819 * Constructs a RecentChange object for the given categorization
820 * This does not call save() on the object and thus does not write to the db
824 * @param string $timestamp Timestamp of the recent change to occur
825 * @param Title $categoryTitle Title of the category a page is being added to or removed from
826 * @param User $user User object of the user that made the change
827 * @param string $comment Change summary
828 * @param Title $pageTitle Title of the page that is being added or removed
829 * @param int $oldRevId Parent revision ID of this change
830 * @param int $newRevId Revision ID of this change
831 * @param string $lastTimestamp Parent revision timestamp of this change
832 * @param bool $bot true, if the change was made by a bot
833 * @param string $ip IP address of the user, if the change was made anonymously
834 * @param int $deleted Indicates whether the change has been deleted
836 * @return RecentChange
838 public static function newForCategorization(
840 Title
$categoryTitle,
851 $rc = new RecentChange
;
852 $rc->mTitle
= $categoryTitle;
853 $rc->mPerformer
= $user;
855 'rc_timestamp' => $timestamp,
856 'rc_namespace' => $categoryTitle->getNamespace(),
857 'rc_title' => $categoryTitle->getDBkey(),
858 'rc_type' => RC_CATEGORIZE
,
859 'rc_source' => self
::SRC_CATEGORIZE
,
861 'rc_cur_id' => $pageTitle->getArticleID(),
862 'rc_user' => $user ?
$user->getId() : 0,
863 'rc_user_text' => $user ?
$user->getName() : '',
864 'rc_comment' => $comment,
865 'rc_this_oldid' => $newRevId,
866 'rc_last_oldid' => $oldRevId,
867 'rc_bot' => $bot ?
1 : 0,
868 'rc_ip' => self
::checkIPAddress( $ip ),
869 'rc_patrolled' => 1, // Always patrolled, just like log entries
870 'rc_new' => 0, # obsolete
871 'rc_old_len' => null,
872 'rc_new_len' => null,
873 'rc_deleted' => $deleted,
875 'rc_log_type' => null,
876 'rc_log_action' => '',
877 'rc_params' => serialize( [
878 'hidden-cat' => WikiCategoryPage
::factory( $categoryTitle )->isHidden()
883 'prefixedDBkey' => $categoryTitle->getPrefixedDBkey(),
884 'lastTimestamp' => $lastTimestamp,
887 'pageStatus' => 'changed'
894 * Get a parameter value
898 * @param string $name parameter name
901 public function getParam( $name ) {
902 $params = $this->parseParams();
903 return isset( $params[$name] ) ?
$params[$name] : null;
907 * Initialises the members of this object from a mysql row object
911 public function loadFromRow( $row ) {
912 $this->mAttribs
= get_object_vars( $row );
913 $this->mAttribs
['rc_timestamp'] = wfTimestamp( TS_MW
, $this->mAttribs
['rc_timestamp'] );
914 $this->mAttribs
['rc_deleted'] = $row->rc_deleted
; // MUST be set
918 * Get an attribute value
920 * @param string $name Attribute name
923 public function getAttribute( $name ) {
924 return isset( $this->mAttribs
[$name] ) ?
$this->mAttribs
[$name] : null;
930 public function getAttributes() {
931 return $this->mAttribs
;
935 * Gets the end part of the diff URL associated with this object
936 * Blank if no diff link should be displayed
937 * @param bool $forceCur
940 public function diffLinkTrail( $forceCur ) {
941 if ( $this->mAttribs
['rc_type'] == RC_EDIT
) {
942 $trail = "curid=" . (int)( $this->mAttribs
['rc_cur_id'] ) .
943 "&oldid=" . (int)( $this->mAttribs
['rc_last_oldid'] );
947 $trail .= '&diff=' . (int)( $this->mAttribs
['rc_this_oldid'] );
957 * Returns the change size (HTML).
958 * The lengths can be given optionally.
963 public function getCharacterDifference( $old = 0, $new = 0 ) {
965 $old = $this->mAttribs
['rc_old_len'];
968 $new = $this->mAttribs
['rc_new_len'];
970 if ( $old === null ||
$new === null ) {
974 return ChangesList
::showCharacterDifference( $old, $new );
977 private static function checkIPAddress( $ip ) {
980 if ( !IP
::isIPAddress( $ip ) ) {
981 throw new MWException( "Attempt to write \"" . $ip .
982 "\" as an IP address into recent changes" );
985 $ip = $wgRequest->getIP();
995 * Check whether the given timestamp is new enough to have a RC row with a given tolerance
996 * as the recentchanges table might not be cleared out regularly (so older entries might exist)
997 * or rows which will be deleted soon shouldn't be included.
999 * @param mixed $timestamp MWTimestamp compatible timestamp
1000 * @param int $tolerance Tolerance in seconds
1003 public static function isInRCLifespan( $timestamp, $tolerance = 0 ) {
1006 return wfTimestamp( TS_UNIX
, $timestamp ) > time() - $tolerance - $wgRCMaxAge;
1010 * Parses and returns the rc_params attribute
1014 * @return mixed|bool false on failed unserialization
1016 public function parseParams() {
1017 $rcParams = $this->getAttribute( 'rc_params' );
1019 MediaWiki\
suppressWarnings();
1020 $unserializedParams = unserialize( $rcParams );
1021 MediaWiki\restoreWarnings
();
1023 return $unserializedParams;