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
71 public $mAttribs = array();
72 public $mExtra = array();
77 public $mTitle = false;
82 private $mPerformer = false;
84 public $numberofWatchingusers = 0; # Dummy to prevent error message in SpecialRecentChangesLinked
85 public $notificationtimestamp;
88 * @var int Line number of recent change. Default -1.
96 * @return RecentChange
98 public static function newFromRow( $row ) {
99 $rc = new RecentChange
;
100 $rc->loadFromRow( $row );
106 * Parsing text to RC_* constants
108 * @param string|array $type
109 * @throws MWException
110 * @return int|array RC_TYPE
112 public static function parseToRCType( $type ) {
113 if ( is_array( $type ) ) {
115 foreach ( $type as $t ) {
116 $retval[] = RecentChange
::parseToRCType( $t );
132 throw new MWException( "Unknown type '$type'" );
137 * Parsing RC_* constants to human-readable test
139 * @param int $rc_type
140 * @return string $type
142 public static function parseFromRCType( $rcType ) {
164 * No uses left in Gerrit on 2013-11-19.
165 * @deprecated since 1.22
167 * @return RecentChange
169 public static function newFromCurRow( $row ) {
170 wfDeprecated( __METHOD__
, '1.22' );
171 $rc = new RecentChange
;
172 $rc->loadFromCurRow( $row );
173 $rc->notificationtimestamp
= false;
174 $rc->numberofWatchingusers
= false;
180 * Obtain the recent change with a given rc_id value
182 * @param int $rcid rc_id value to retrieve
183 * @return RecentChange
185 public static function newFromId( $rcid ) {
186 return self
::newFromConds( array( 'rc_id' => $rcid ), __METHOD__
);
190 * Find the first recent change matching some specific conditions
192 * @param array $conds Array of conditions
193 * @param mixed $fname Override the method name in profiling/logs
194 * @param array $options Query options
195 * @return RecentChange
197 public static function newFromConds( $conds, $fname = __METHOD__
, $options = array() ) {
198 $dbr = wfGetDB( DB_SLAVE
);
199 $row = $dbr->selectRow( 'recentchanges', self
::selectFields(), $conds, $fname, $options );
200 if ( $row !== false ) {
201 return self
::newFromRow( $row );
208 * Return the list of recentchanges fields that should be selected to create
209 * a new recentchanges object.
212 public static function selectFields() {
244 * @param array $attribs
246 public function setAttribs( $attribs ) {
247 $this->mAttribs
= $attribs;
251 * @param array $extra
253 public function setExtra( $extra ) {
254 $this->mExtra
= $extra;
260 public function &getTitle() {
261 if ( $this->mTitle
=== false ) {
262 $this->mTitle
= Title
::makeTitle( $this->mAttribs
['rc_namespace'], $this->mAttribs
['rc_title'] );
265 return $this->mTitle
;
269 * Get the User object of the person who performed this change.
273 public function getPerformer() {
274 if ( $this->mPerformer
=== false ) {
275 if ( $this->mAttribs
['rc_user'] ) {
276 $this->mPerformer
= User
::newFromID( $this->mAttribs
['rc_user'] );
278 $this->mPerformer
= User
::newFromName( $this->mAttribs
['rc_user_text'], false );
282 return $this->mPerformer
;
286 * Writes the data in this object to the database
289 public function save( $noudp = false ) {
290 global $wgPutIPinRC, $wgUseEnotif, $wgShowUpdatedMarker, $wgContLang;
292 $dbw = wfGetDB( DB_MASTER
);
293 if ( !is_array( $this->mExtra
) ) {
294 $this->mExtra
= array();
297 if ( !$wgPutIPinRC ) {
298 $this->mAttribs
['rc_ip'] = '';
301 # If our database is strict about IP addresses, use NULL instead of an empty string
302 if ( $dbw->strictIPs() and $this->mAttribs
['rc_ip'] == '' ) {
303 unset( $this->mAttribs
['rc_ip'] );
306 # Trim spaces on user supplied text
307 $this->mAttribs
['rc_comment'] = trim( $this->mAttribs
['rc_comment'] );
309 # Make sure summary is truncated (whole multibyte characters)
310 $this->mAttribs
['rc_comment'] = $wgContLang->truncate( $this->mAttribs
['rc_comment'], 255 );
312 # Fixup database timestamps
313 $this->mAttribs
['rc_timestamp'] = $dbw->timestamp( $this->mAttribs
['rc_timestamp'] );
314 $this->mAttribs
['rc_id'] = $dbw->nextSequenceValue( 'recentchanges_rc_id_seq' );
316 ## If we are using foreign keys, an entry of 0 for the page_id will fail, so use NULL
317 if ( $dbw->cascadingDeletes() and $this->mAttribs
['rc_cur_id'] == 0 ) {
318 unset( $this->mAttribs
['rc_cur_id'] );
322 $dbw->insert( 'recentchanges', $this->mAttribs
, __METHOD__
);
325 $this->mAttribs
['rc_id'] = $dbw->insertId();
328 wfRunHooks( 'RecentChange_save', array( &$this ) );
330 # Notify external application via UDP
332 $this->notifyRCFeeds();
335 # E-mail notifications
336 if ( $wgUseEnotif ||
$wgShowUpdatedMarker ) {
337 $editor = $this->getPerformer();
338 $title = $this->getTitle();
340 if ( wfRunHooks( 'AbortEmailNotification', array( $editor, $title, $this ) ) ) {
341 # @todo FIXME: This would be better as an extension hook
342 $enotif = new EmailNotification();
343 $enotif->notifyOnPageChange( $editor, $title,
344 $this->mAttribs
['rc_timestamp'],
345 $this->mAttribs
['rc_comment'],
346 $this->mAttribs
['rc_minor'],
347 $this->mAttribs
['rc_last_oldid'],
348 $this->mExtra
['pageStatus'] );
354 * @deprecated since 1.22, use notifyRCFeeds instead.
356 public function notifyRC2UDP() {
357 wfDeprecated( __METHOD__
, '1.22' );
358 $this->notifyRCFeeds();
362 * Send some text to UDP.
363 * @deprecated since 1.22
365 public static function sendToUDP( $line, $address = '', $prefix = '', $port = '' ) {
366 global $wgRC2UDPAddress, $wgRC2UDPInterwikiPrefix, $wgRC2UDPPort, $wgRC2UDPPrefix;
368 wfDeprecated( __METHOD__
, '1.22' );
370 # Assume default for standard RC case
371 $address = $address ?
$address : $wgRC2UDPAddress;
372 $prefix = $prefix ?
$prefix : $wgRC2UDPPrefix;
373 $port = $port ?
$port : $wgRC2UDPPort;
375 $engine = new UDPRCFeedEngine();
377 'uri' => "udp://$address:$port/$prefix",
378 'formatter' => 'IRCColourfulRCFeedFormatter',
379 'add_interwiki_prefix' => $wgRC2UDPInterwikiPrefix,
382 $engine->send( $feed, $line );
386 * Notify all the feeds about the change.
387 * @param array $feeds Optional feeds to send to, defaults to $wgRCFeeds
389 public function notifyRCFeeds( array $feeds = null ) {
391 if ( $feeds === null ) {
395 $performer = $this->getPerformer();
397 foreach ( $feeds as $feed ) {
399 'omit_bots' => false,
400 'omit_anon' => false,
401 'omit_user' => false,
402 'omit_minor' => false,
403 'omit_patrolled' => false,
407 ( $feed['omit_bots'] && $this->mAttribs
['rc_bot'] ) ||
408 ( $feed['omit_anon'] && $performer->isAnon() ) ||
409 ( $feed['omit_user'] && !$performer->isAnon() ) ||
410 ( $feed['omit_minor'] && $this->mAttribs
['rc_minor'] ) ||
411 ( $feed['omit_patrolled'] && $this->mAttribs
['rc_patrolled'] ) ||
412 $this->mAttribs
['rc_type'] == RC_EXTERNAL
417 $engine = self
::getEngine( $feed['uri'] );
419 if ( isset( $this->mExtra
['actionCommentIRC'] ) ) {
420 $actionComment = $this->mExtra
['actionCommentIRC'];
422 $actionComment = null;
425 /** @var $formatter RCFeedFormatter */
426 $formatter = is_object( $feed['formatter'] ) ?
$feed['formatter'] : new $feed['formatter']();
427 $line = $formatter->getLine( $feed, $this, $actionComment );
429 $engine->send( $feed, $line );
434 * Gets the stream engine object for a given URI from $wgRCEngines
436 * @param string $uri URI to get the engine object for
437 * @throws MWException
438 * @return RCFeedEngine The engine object
440 public static function getEngine( $uri ) {
443 $scheme = parse_url( $uri, PHP_URL_SCHEME
);
445 throw new MWException( __FUNCTION__
. ": Invalid stream logger URI: '$uri'" );
448 if ( !isset( $wgRCEngines[$scheme] ) ) {
449 throw new MWException( __FUNCTION__
. ": Unknown stream logger URI scheme: $scheme" );
452 return new $wgRCEngines[$scheme];
456 * @deprecated since 1.22, moved to IRCColourfulRCFeedFormatter
458 public static function cleanupForIRC( $text ) {
459 wfDeprecated( __METHOD__
, '1.22' );
461 return IRCColourfulRCFeedFormatter
::cleanupForIRC( $text );
465 * Mark a given change as patrolled
467 * @param RecentChange|int $change RecentChange or corresponding rc_id
468 * @param bool $auto For automatic patrol
469 * @return array See doMarkPatrolled(), or null if $change is not an existing rc_id
471 public static function markPatrolled( $change, $auto = false ) {
474 $change = $change instanceof RecentChange
476 : RecentChange
::newFromId( $change );
478 if ( !$change instanceof RecentChange
) {
482 return $change->doMarkPatrolled( $wgUser, $auto );
486 * Mark this RecentChange as patrolled
488 * NOTE: Can also return 'rcpatroldisabled', 'hookaborted' and
489 * 'markedaspatrollederror-noautopatrol' as errors
490 * @param User $user User object doing the action
491 * @param bool $auto For automatic patrol
492 * @return array Array of permissions errors, see Title::getUserPermissionsErrors()
494 public function doMarkPatrolled( User
$user, $auto = false ) {
495 global $wgUseRCPatrol, $wgUseNPPatrol;
497 // If recentchanges patrol is disabled, only new pages
499 if ( !$wgUseRCPatrol && ( !$wgUseNPPatrol ||
$this->getAttribute( 'rc_type' ) != RC_NEW
) ) {
500 $errors[] = array( 'rcpatroldisabled' );
502 // Automatic patrol needs "autopatrol", ordinary patrol needs "patrol"
503 $right = $auto ?
'autopatrol' : 'patrol';
504 $errors = array_merge( $errors, $this->getTitle()->getUserPermissionsErrors( $right, $user ) );
505 if ( !wfRunHooks( 'MarkPatrolled', array( $this->getAttribute( 'rc_id' ), &$user, false ) ) ) {
506 $errors[] = array( 'hookaborted' );
508 // Users without the 'autopatrol' right can't patrol their
510 if ( $user->getName() == $this->getAttribute( 'rc_user_text' )
511 && !$user->isAllowed( 'autopatrol' )
513 $errors[] = array( 'markedaspatrollederror-noautopatrol' );
518 // If the change was patrolled already, do nothing
519 if ( $this->getAttribute( 'rc_patrolled' ) ) {
522 // Actually set the 'patrolled' flag in RC
523 $this->reallyMarkPatrolled();
524 // Log this patrol event
525 PatrolLog
::record( $this, $auto, $user );
526 wfRunHooks( 'MarkPatrolledComplete', array( $this->getAttribute( 'rc_id' ), &$user, false ) );
532 * Mark this RecentChange patrolled, without error checking
533 * @return int Number of affected rows
535 public function reallyMarkPatrolled() {
536 $dbw = wfGetDB( DB_MASTER
);
543 'rc_id' => $this->getAttribute( 'rc_id' )
547 // Invalidate the page cache after the page has been patrolled
548 // to make sure that the Patrol link isn't visible any longer!
549 $this->getTitle()->invalidateCache();
551 return $dbw->affectedRows();
555 * Makes an entry in the database corresponding to an edit
557 * @param string $timestamp
558 * @param Title $title
561 * @param string $comment
563 * @param string $lastTimestamp
566 * @param int $oldSize
567 * @param int $newSize
570 * @return RecentChange
572 public static function notifyEdit( $timestamp, &$title, $minor, &$user, $comment, $oldId,
573 $lastTimestamp, $bot, $ip = '', $oldSize = 0, $newSize = 0, $newId = 0, $patrol = 0 ) {
574 $rc = new RecentChange
;
575 $rc->mTitle
= $title;
576 $rc->mPerformer
= $user;
577 $rc->mAttribs
= array(
578 'rc_timestamp' => $timestamp,
579 'rc_namespace' => $title->getNamespace(),
580 'rc_title' => $title->getDBkey(),
581 'rc_type' => RC_EDIT
,
582 'rc_source' => self
::SRC_EDIT
,
583 'rc_minor' => $minor ?
1 : 0,
584 'rc_cur_id' => $title->getArticleID(),
585 'rc_user' => $user->getId(),
586 'rc_user_text' => $user->getName(),
587 'rc_comment' => $comment,
588 'rc_this_oldid' => $newId,
589 'rc_last_oldid' => $oldId,
590 'rc_bot' => $bot ?
1 : 0,
591 'rc_ip' => self
::checkIPAddress( $ip ),
592 'rc_patrolled' => intval( $patrol ),
593 'rc_new' => 0, # obsolete
594 'rc_old_len' => $oldSize,
595 'rc_new_len' => $newSize,
598 'rc_log_type' => null,
599 'rc_log_action' => '',
604 'prefixedDBkey' => $title->getPrefixedDBkey(),
605 'lastTimestamp' => $lastTimestamp,
606 'oldSize' => $oldSize,
607 'newSize' => $newSize,
608 'pageStatus' => 'changed'
616 * Makes an entry in the database corresponding to page creation
617 * Note: the title object must be loaded with the new id using resetArticleID()
619 * @param string $timestamp
620 * @param Title $title
623 * @param string $comment
629 * @return RecentChange
631 public static function notifyNew( $timestamp, &$title, $minor, &$user, $comment, $bot,
632 $ip = '', $size = 0, $newId = 0, $patrol = 0 ) {
633 $rc = new RecentChange
;
634 $rc->mTitle
= $title;
635 $rc->mPerformer
= $user;
636 $rc->mAttribs
= array(
637 'rc_timestamp' => $timestamp,
638 'rc_namespace' => $title->getNamespace(),
639 'rc_title' => $title->getDBkey(),
641 'rc_source' => self
::SRC_NEW
,
642 'rc_minor' => $minor ?
1 : 0,
643 'rc_cur_id' => $title->getArticleID(),
644 'rc_user' => $user->getId(),
645 'rc_user_text' => $user->getName(),
646 'rc_comment' => $comment,
647 'rc_this_oldid' => $newId,
648 'rc_last_oldid' => 0,
649 'rc_bot' => $bot ?
1 : 0,
650 'rc_ip' => self
::checkIPAddress( $ip ),
651 'rc_patrolled' => intval( $patrol ),
652 'rc_new' => 1, # obsolete
654 'rc_new_len' => $size,
657 'rc_log_type' => null,
658 'rc_log_action' => '',
663 'prefixedDBkey' => $title->getPrefixedDBkey(),
664 'lastTimestamp' => 0,
667 'pageStatus' => 'created'
675 * @param string $timestamp
676 * @param Title $title
678 * @param string $actionComment
680 * @param string $type
681 * @param string $action
682 * @param Title $target
683 * @param string $logComment
684 * @param string $params
686 * @param string $actionCommentIRC
689 public static function notifyLog( $timestamp, &$title, &$user, $actionComment, $ip, $type,
690 $action, $target, $logComment, $params, $newId = 0, $actionCommentIRC = ''
692 global $wgLogRestrictions;
694 # Don't add private logs to RC!
695 if ( isset( $wgLogRestrictions[$type] ) && $wgLogRestrictions[$type] != '*' ) {
698 $rc = self
::newLogEntry( $timestamp, $title, $user, $actionComment, $ip, $type, $action,
699 $target, $logComment, $params, $newId, $actionCommentIRC );
706 * @param string $timestamp
707 * @param Title $title
709 * @param string $actionComment
711 * @param string $type
712 * @param string $action
713 * @param Title $target
714 * @param string $logComment
715 * @param string $params
717 * @param string $actionCommentIRC
718 * @return RecentChange
720 public static function newLogEntry( $timestamp, &$title, &$user, $actionComment, $ip,
721 $type, $action, $target, $logComment, $params, $newId = 0, $actionCommentIRC = '' ) {
724 ## Get pageStatus for email notification
725 switch ( $type . '-' . $action ) {
726 case 'delete-delete':
727 $pageStatus = 'deleted';
730 case 'move-move_redir':
731 $pageStatus = 'moved';
733 case 'delete-restore':
734 $pageStatus = 'restored';
736 case 'upload-upload':
737 $pageStatus = 'created';
739 case 'upload-overwrite':
741 $pageStatus = 'changed';
745 $rc = new RecentChange
;
746 $rc->mTitle
= $target;
747 $rc->mPerformer
= $user;
748 $rc->mAttribs
= array(
749 'rc_timestamp' => $timestamp,
750 'rc_namespace' => $target->getNamespace(),
751 'rc_title' => $target->getDBkey(),
753 'rc_source' => self
::SRC_LOG
,
755 'rc_cur_id' => $target->getArticleID(),
756 'rc_user' => $user->getId(),
757 'rc_user_text' => $user->getName(),
758 'rc_comment' => $logComment,
759 'rc_this_oldid' => 0,
760 'rc_last_oldid' => 0,
761 'rc_bot' => $user->isAllowed( 'bot' ) ?
$wgRequest->getBool( 'bot', true ) : 0,
762 'rc_ip' => self
::checkIPAddress( $ip ),
764 'rc_new' => 0, # obsolete
765 'rc_old_len' => null,
766 'rc_new_len' => null,
768 'rc_logid' => $newId,
769 'rc_log_type' => $type,
770 'rc_log_action' => $action,
771 'rc_params' => $params
775 'prefixedDBkey' => $title->getPrefixedDBkey(),
776 'lastTimestamp' => 0,
777 'actionComment' => $actionComment, // the comment appended to the action, passed from LogPage
778 'pageStatus' => $pageStatus,
779 'actionCommentIRC' => $actionCommentIRC
786 * Initialises the members of this object from a mysql row object
790 public function loadFromRow( $row ) {
791 $this->mAttribs
= get_object_vars( $row );
792 $this->mAttribs
['rc_timestamp'] = wfTimestamp( TS_MW
, $this->mAttribs
['rc_timestamp'] );
793 $this->mAttribs
['rc_deleted'] = $row->rc_deleted
; // MUST be set
797 * Makes a pseudo-RC entry from a cur row
799 * @deprecated since 1.22
802 public function loadFromCurRow( $row ) {
803 wfDeprecated( __METHOD__
, '1.22' );
804 $this->mAttribs
= array(
805 'rc_timestamp' => wfTimestamp( TS_MW
, $row->rev_timestamp
),
806 'rc_user' => $row->rev_user
,
807 'rc_user_text' => $row->rev_user_text
,
808 'rc_namespace' => $row->page_namespace
,
809 'rc_title' => $row->page_title
,
810 'rc_comment' => $row->rev_comment
,
811 'rc_minor' => $row->rev_minor_edit ?
1 : 0,
812 'rc_type' => $row->page_is_new ? RC_NEW
: RC_EDIT
,
813 'rc_source' => $row->page_is_new ? self
::SRC_NEW
: self
::SRC_EDIT
,
814 'rc_cur_id' => $row->page_id
,
815 'rc_this_oldid' => $row->rev_id
,
816 'rc_last_oldid' => isset( $row->rc_last_oldid
) ?
$row->rc_last_oldid
: 0,
819 'rc_id' => $row->rc_id
,
820 'rc_patrolled' => $row->rc_patrolled
,
821 'rc_new' => $row->page_is_new
, # obsolete
822 'rc_old_len' => $row->rc_old_len
,
823 'rc_new_len' => $row->rc_new_len
,
824 'rc_params' => isset( $row->rc_params
) ?
$row->rc_params
: '',
825 'rc_log_type' => isset( $row->rc_log_type
) ?
$row->rc_log_type
: null,
826 'rc_log_action' => isset( $row->rc_log_action
) ?
$row->rc_log_action
: null,
827 'rc_logid' => isset( $row->rc_logid
) ?
$row->rc_logid
: 0,
828 'rc_deleted' => $row->rc_deleted
// MUST be set
833 * Get an attribute value
835 * @param string $name Attribute name
838 public function getAttribute( $name ) {
839 return isset( $this->mAttribs
[$name] ) ?
$this->mAttribs
[$name] : null;
845 public function getAttributes() {
846 return $this->mAttribs
;
850 * Gets the end part of the diff URL associated with this object
851 * Blank if no diff link should be displayed
852 * @param bool $forceCur
855 public function diffLinkTrail( $forceCur ) {
856 if ( $this->mAttribs
['rc_type'] == RC_EDIT
) {
857 $trail = "curid=" . (int)( $this->mAttribs
['rc_cur_id'] ) .
858 "&oldid=" . (int)( $this->mAttribs
['rc_last_oldid'] );
862 $trail .= '&diff=' . (int)( $this->mAttribs
['rc_this_oldid'] );
872 * Returns the change size (HTML).
873 * The lengths can be given optionally.
878 public function getCharacterDifference( $old = 0, $new = 0 ) {
880 $old = $this->mAttribs
['rc_old_len'];
883 $new = $this->mAttribs
['rc_new_len'];
885 if ( $old === null ||
$new === null ) {
889 return ChangesList
::showCharacterDifference( $old, $new );
893 * Purge expired changes from the recentchanges table
896 public static function purgeExpiredChanges() {
897 if ( wfReadOnly() ) {
901 $method = __METHOD__
;
902 $dbw = wfGetDB( DB_MASTER
);
903 $dbw->onTransactionIdle( function () use ( $dbw, $method ) {
906 $cutoff = $dbw->timestamp( time() - $wgRCMaxAge );
909 array( 'rc_timestamp < ' . $dbw->addQuotes( $cutoff ) ),
915 private static function checkIPAddress( $ip ) {
918 if ( !IP
::isIPAddress( $ip ) ) {
919 throw new MWException( "Attempt to write \"" . $ip .
920 "\" as an IP address into recent changes" );
923 $ip = $wgRequest->getIP();
933 * Check whether the given timestamp is new enough to have a RC row with a given tolerance
934 * as the recentchanges table might not be cleared out regularly (so older entries might exist)
935 * or rows which will be deleted soon shouldn't be included.
937 * @param mixed $timestamp MWTimestamp compatible timestamp
938 * @param int $tolerance Tolerance in seconds
941 public static function isInRCLifespan( $timestamp, $tolerance = 0 ) {
944 return wfTimestamp( TS_UNIX
, $timestamp ) > time() - $tolerance - $wgRCMaxAge;