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 ) {
159 case RC_MOVE_OVER_REDIRECT
:
160 $type = 'move over redirect';
170 * No uses left in Gerrit on 2013-11-19.
171 * @deprecated since 1.22
173 * @return RecentChange
175 public static function newFromCurRow( $row ) {
176 wfDeprecated( __METHOD__
, '1.22' );
177 $rc = new RecentChange
;
178 $rc->loadFromCurRow( $row );
179 $rc->notificationtimestamp
= false;
180 $rc->numberofWatchingusers
= false;
186 * Obtain the recent change with a given rc_id value
188 * @param int $rcid rc_id value to retrieve
189 * @return RecentChange
191 public static function newFromId( $rcid ) {
192 return self
::newFromConds( array( 'rc_id' => $rcid ), __METHOD__
);
196 * Find the first recent change matching some specific conditions
198 * @param array $conds Array of conditions
199 * @param mixed $fname Override the method name in profiling/logs
200 * @param array $options Query options
201 * @return RecentChange
203 public static function newFromConds( $conds, $fname = __METHOD__
, $options = array() ) {
204 $dbr = wfGetDB( DB_SLAVE
);
205 $row = $dbr->selectRow( 'recentchanges', self
::selectFields(), $conds, $fname, $options );
206 if ( $row !== false ) {
207 return self
::newFromRow( $row );
214 * Return the list of recentchanges fields that should be selected to create
215 * a new recentchanges object.
218 public static function selectFields() {
250 * @param array $attribs
252 public function setAttribs( $attribs ) {
253 $this->mAttribs
= $attribs;
257 * @param array $extra
259 public function setExtra( $extra ) {
260 $this->mExtra
= $extra;
266 public function &getTitle() {
267 if ( $this->mTitle
=== false ) {
268 $this->mTitle
= Title
::makeTitle( $this->mAttribs
['rc_namespace'], $this->mAttribs
['rc_title'] );
271 return $this->mTitle
;
275 * Get the User object of the person who performed this change.
279 public function getPerformer() {
280 if ( $this->mPerformer
=== false ) {
281 if ( $this->mAttribs
['rc_user'] ) {
282 $this->mPerformer
= User
::newFromID( $this->mAttribs
['rc_user'] );
284 $this->mPerformer
= User
::newFromName( $this->mAttribs
['rc_user_text'], false );
288 return $this->mPerformer
;
292 * Writes the data in this object to the database
295 public function save( $noudp = false ) {
296 global $wgPutIPinRC, $wgUseEnotif, $wgShowUpdatedMarker, $wgContLang;
298 $dbw = wfGetDB( DB_MASTER
);
299 if ( !is_array( $this->mExtra
) ) {
300 $this->mExtra
= array();
303 if ( !$wgPutIPinRC ) {
304 $this->mAttribs
['rc_ip'] = '';
307 # If our database is strict about IP addresses, use NULL instead of an empty string
308 if ( $dbw->strictIPs() and $this->mAttribs
['rc_ip'] == '' ) {
309 unset( $this->mAttribs
['rc_ip'] );
312 # Trim spaces on user supplied text
313 $this->mAttribs
['rc_comment'] = trim( $this->mAttribs
['rc_comment'] );
315 # Make sure summary is truncated (whole multibyte characters)
316 $this->mAttribs
['rc_comment'] = $wgContLang->truncate( $this->mAttribs
['rc_comment'], 255 );
318 # Fixup database timestamps
319 $this->mAttribs
['rc_timestamp'] = $dbw->timestamp( $this->mAttribs
['rc_timestamp'] );
320 $this->mAttribs
['rc_id'] = $dbw->nextSequenceValue( 'recentchanges_rc_id_seq' );
322 ## If we are using foreign keys, an entry of 0 for the page_id will fail, so use NULL
323 if ( $dbw->cascadingDeletes() and $this->mAttribs
['rc_cur_id'] == 0 ) {
324 unset( $this->mAttribs
['rc_cur_id'] );
328 $dbw->insert( 'recentchanges', $this->mAttribs
, __METHOD__
);
331 $this->mAttribs
['rc_id'] = $dbw->insertId();
334 wfRunHooks( 'RecentChange_save', array( &$this ) );
336 # Notify external application via UDP
338 $this->notifyRCFeeds();
341 # E-mail notifications
342 if ( $wgUseEnotif ||
$wgShowUpdatedMarker ) {
343 $editor = $this->getPerformer();
344 $title = $this->getTitle();
346 if ( wfRunHooks( 'AbortEmailNotification', array( $editor, $title, $this ) ) ) {
347 # @todo FIXME: This would be better as an extension hook
348 $enotif = new EmailNotification();
349 $enotif->notifyOnPageChange( $editor, $title,
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 * @deprecated since 1.22, use notifyRCFeeds instead.
362 public function notifyRC2UDP() {
363 wfDeprecated( __METHOD__
, '1.22' );
364 $this->notifyRCFeeds();
368 * Send some text to UDP.
369 * @deprecated since 1.22
371 public static function sendToUDP( $line, $address = '', $prefix = '', $port = '' ) {
372 global $wgRC2UDPAddress, $wgRC2UDPInterwikiPrefix, $wgRC2UDPPort, $wgRC2UDPPrefix;
374 wfDeprecated( __METHOD__
, '1.22' );
376 # Assume default for standard RC case
377 $address = $address ?
$address : $wgRC2UDPAddress;
378 $prefix = $prefix ?
$prefix : $wgRC2UDPPrefix;
379 $port = $port ?
$port : $wgRC2UDPPort;
381 $engine = new UDPRCFeedEngine();
383 'uri' => "udp://$address:$port/$prefix",
384 'formatter' => 'IRCColourfulRCFeedFormatter',
385 'add_interwiki_prefix' => $wgRC2UDPInterwikiPrefix,
388 $engine->send( $feed, $line );
392 * Notify all the feeds about the change.
393 * @param array $feeds Optional feeds to send to, defaults to $wgRCFeeds
395 public function notifyRCFeeds( array $feeds = null ) {
397 if ( $feeds === null ) {
401 $performer = $this->getPerformer();
403 foreach ( $feeds as $feed ) {
405 'omit_bots' => false,
406 'omit_anon' => false,
407 'omit_user' => false,
408 'omit_minor' => false,
409 'omit_patrolled' => false,
413 ( $feed['omit_bots'] && $this->mAttribs
['rc_bot'] ) ||
414 ( $feed['omit_anon'] && $performer->isAnon() ) ||
415 ( $feed['omit_user'] && !$performer->isAnon() ) ||
416 ( $feed['omit_minor'] && $this->mAttribs
['rc_minor'] ) ||
417 ( $feed['omit_patrolled'] && $this->mAttribs
['rc_patrolled'] ) ||
418 $this->mAttribs
['rc_type'] == RC_EXTERNAL
423 $engine = self
::getEngine( $feed['uri'] );
425 if ( isset( $this->mExtra
['actionCommentIRC'] ) ) {
426 $actionComment = $this->mExtra
['actionCommentIRC'];
428 $actionComment = null;
431 /** @var $formatter RCFeedFormatter */
432 $formatter = is_object( $feed['formatter'] ) ?
$feed['formatter'] : new $feed['formatter']();
433 $line = $formatter->getLine( $feed, $this, $actionComment );
435 $engine->send( $feed, $line );
440 * Gets the stream engine object for a given URI from $wgRCEngines
442 * @param string $uri URI to get the engine object for
443 * @throws MWException
444 * @return RCFeedEngine The engine object
446 public static function getEngine( $uri ) {
449 $scheme = parse_url( $uri, PHP_URL_SCHEME
);
451 throw new MWException( __FUNCTION__
. ": Invalid stream logger URI: '$uri'" );
454 if ( !isset( $wgRCEngines[$scheme] ) ) {
455 throw new MWException( __FUNCTION__
. ": Unknown stream logger URI scheme: $scheme" );
458 return new $wgRCEngines[$scheme];
462 * @deprecated since 1.22, moved to IRCColourfulRCFeedFormatter
464 public static function cleanupForIRC( $text ) {
465 wfDeprecated( __METHOD__
, '1.22' );
467 return IRCColourfulRCFeedFormatter
::cleanupForIRC( $text );
471 * Mark a given change as patrolled
473 * @param RecentChange|int $change RecentChange or corresponding rc_id
474 * @param bool $auto For automatic patrol
475 * @return array See doMarkPatrolled(), or null if $change is not an existing rc_id
477 public static function markPatrolled( $change, $auto = false ) {
480 $change = $change instanceof RecentChange
482 : RecentChange
::newFromId( $change );
484 if ( !$change instanceof RecentChange
) {
488 return $change->doMarkPatrolled( $wgUser, $auto );
492 * Mark this RecentChange as patrolled
494 * NOTE: Can also return 'rcpatroldisabled', 'hookaborted' and
495 * 'markedaspatrollederror-noautopatrol' as errors
496 * @param User $user User object doing the action
497 * @param bool $auto For automatic patrol
498 * @return array Array of permissions errors, see Title::getUserPermissionsErrors()
500 public function doMarkPatrolled( User
$user, $auto = false ) {
501 global $wgUseRCPatrol, $wgUseNPPatrol;
503 // If recentchanges patrol is disabled, only new pages
505 if ( !$wgUseRCPatrol && ( !$wgUseNPPatrol ||
$this->getAttribute( 'rc_type' ) != RC_NEW
) ) {
506 $errors[] = array( '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 ( !wfRunHooks( 'MarkPatrolled', array( $this->getAttribute( 'rc_id' ), &$user, false ) ) ) {
512 $errors[] = array( 'hookaborted' );
514 // Users without the 'autopatrol' right can't patrol their
516 if ( $user->getName() == $this->getAttribute( 'rc_user_text' )
517 && !$user->isAllowed( 'autopatrol' )
519 $errors[] = array( 'markedaspatrollederror-noautopatrol' );
524 // If the change was patrolled already, do nothing
525 if ( $this->getAttribute( 'rc_patrolled' ) ) {
528 // Actually set the 'patrolled' flag in RC
529 $this->reallyMarkPatrolled();
530 // Log this patrol event
531 PatrolLog
::record( $this, $auto, $user );
532 wfRunHooks( 'MarkPatrolledComplete', array( $this->getAttribute( 'rc_id' ), &$user, false ) );
538 * Mark this RecentChange patrolled, without error checking
539 * @return int Number of affected rows
541 public function reallyMarkPatrolled() {
542 $dbw = wfGetDB( DB_MASTER
);
549 'rc_id' => $this->getAttribute( 'rc_id' )
553 // Invalidate the page cache after the page has been patrolled
554 // to make sure that the Patrol link isn't visible any longer!
555 $this->getTitle()->invalidateCache();
557 return $dbw->affectedRows();
561 * Makes an entry in the database corresponding to an edit
563 * @param string $timestamp
564 * @param Title $title
567 * @param string $comment
569 * @param string $lastTimestamp
572 * @param int $oldSize
573 * @param int $newSize
576 * @return RecentChange
578 public static function notifyEdit( $timestamp, &$title, $minor, &$user, $comment, $oldId,
579 $lastTimestamp, $bot, $ip = '', $oldSize = 0, $newSize = 0, $newId = 0, $patrol = 0 ) {
580 $rc = new RecentChange
;
581 $rc->mTitle
= $title;
582 $rc->mPerformer
= $user;
583 $rc->mAttribs
= array(
584 'rc_timestamp' => $timestamp,
585 'rc_namespace' => $title->getNamespace(),
586 'rc_title' => $title->getDBkey(),
587 'rc_type' => RC_EDIT
,
588 'rc_source' => self
::SRC_EDIT
,
589 'rc_minor' => $minor ?
1 : 0,
590 'rc_cur_id' => $title->getArticleID(),
591 'rc_user' => $user->getId(),
592 'rc_user_text' => $user->getName(),
593 'rc_comment' => $comment,
594 'rc_this_oldid' => $newId,
595 'rc_last_oldid' => $oldId,
596 'rc_bot' => $bot ?
1 : 0,
597 'rc_ip' => self
::checkIPAddress( $ip ),
598 'rc_patrolled' => intval( $patrol ),
599 'rc_new' => 0, # obsolete
600 'rc_old_len' => $oldSize,
601 'rc_new_len' => $newSize,
604 'rc_log_type' => null,
605 'rc_log_action' => '',
610 'prefixedDBkey' => $title->getPrefixedDBkey(),
611 'lastTimestamp' => $lastTimestamp,
612 'oldSize' => $oldSize,
613 'newSize' => $newSize,
614 'pageStatus' => 'changed'
622 * Makes an entry in the database corresponding to page creation
623 * Note: the title object must be loaded with the new id using resetArticleID()
625 * @param string $timestamp
626 * @param Title $title
629 * @param string $comment
635 * @return RecentChange
637 public static function notifyNew( $timestamp, &$title, $minor, &$user, $comment, $bot,
638 $ip = '', $size = 0, $newId = 0, $patrol = 0 ) {
639 $rc = new RecentChange
;
640 $rc->mTitle
= $title;
641 $rc->mPerformer
= $user;
642 $rc->mAttribs
= array(
643 'rc_timestamp' => $timestamp,
644 'rc_namespace' => $title->getNamespace(),
645 'rc_title' => $title->getDBkey(),
647 'rc_source' => self
::SRC_NEW
,
648 'rc_minor' => $minor ?
1 : 0,
649 'rc_cur_id' => $title->getArticleID(),
650 'rc_user' => $user->getId(),
651 'rc_user_text' => $user->getName(),
652 'rc_comment' => $comment,
653 'rc_this_oldid' => $newId,
654 'rc_last_oldid' => 0,
655 'rc_bot' => $bot ?
1 : 0,
656 'rc_ip' => self
::checkIPAddress( $ip ),
657 'rc_patrolled' => intval( $patrol ),
658 'rc_new' => 1, # obsolete
660 'rc_new_len' => $size,
663 'rc_log_type' => null,
664 'rc_log_action' => '',
669 'prefixedDBkey' => $title->getPrefixedDBkey(),
670 'lastTimestamp' => 0,
673 'pageStatus' => 'created'
681 * @param string $timestamp
682 * @param Title $title
684 * @param string $actionComment
686 * @param string $type
687 * @param string $action
688 * @param Title $target
689 * @param string $logComment
690 * @param string $params
692 * @param string $actionCommentIRC
695 public static function notifyLog( $timestamp, &$title, &$user, $actionComment, $ip, $type,
696 $action, $target, $logComment, $params, $newId = 0, $actionCommentIRC = ''
698 global $wgLogRestrictions;
700 # Don't add private logs to RC!
701 if ( isset( $wgLogRestrictions[$type] ) && $wgLogRestrictions[$type] != '*' ) {
704 $rc = self
::newLogEntry( $timestamp, $title, $user, $actionComment, $ip, $type, $action,
705 $target, $logComment, $params, $newId, $actionCommentIRC );
712 * @param string $timestamp
713 * @param Title $title
715 * @param string $actionComment
717 * @param string $type
718 * @param string $action
719 * @param Title $target
720 * @param string $logComment
721 * @param string $params
723 * @param string $actionCommentIRC
724 * @return RecentChange
726 public static function newLogEntry( $timestamp, &$title, &$user, $actionComment, $ip,
727 $type, $action, $target, $logComment, $params, $newId = 0, $actionCommentIRC = '' ) {
730 ## Get pageStatus for email notification
731 switch ( $type . '-' . $action ) {
732 case 'delete-delete':
733 $pageStatus = 'deleted';
736 case 'move-move_redir':
737 $pageStatus = 'moved';
739 case 'delete-restore':
740 $pageStatus = 'restored';
742 case 'upload-upload':
743 $pageStatus = 'created';
745 case 'upload-overwrite':
747 $pageStatus = 'changed';
751 $rc = new RecentChange
;
752 $rc->mTitle
= $target;
753 $rc->mPerformer
= $user;
754 $rc->mAttribs
= array(
755 'rc_timestamp' => $timestamp,
756 'rc_namespace' => $target->getNamespace(),
757 'rc_title' => $target->getDBkey(),
759 'rc_source' => self
::SRC_LOG
,
761 'rc_cur_id' => $target->getArticleID(),
762 'rc_user' => $user->getId(),
763 'rc_user_text' => $user->getName(),
764 'rc_comment' => $logComment,
765 'rc_this_oldid' => 0,
766 'rc_last_oldid' => 0,
767 'rc_bot' => $user->isAllowed( 'bot' ) ?
$wgRequest->getBool( 'bot', true ) : 0,
768 'rc_ip' => self
::checkIPAddress( $ip ),
770 'rc_new' => 0, # obsolete
771 'rc_old_len' => null,
772 'rc_new_len' => null,
774 'rc_logid' => $newId,
775 'rc_log_type' => $type,
776 'rc_log_action' => $action,
777 'rc_params' => $params
781 'prefixedDBkey' => $title->getPrefixedDBkey(),
782 'lastTimestamp' => 0,
783 'actionComment' => $actionComment, // the comment appended to the action, passed from LogPage
784 'pageStatus' => $pageStatus,
785 'actionCommentIRC' => $actionCommentIRC
792 * Initialises the members of this object from a mysql row object
796 public function loadFromRow( $row ) {
797 $this->mAttribs
= get_object_vars( $row );
798 $this->mAttribs
['rc_timestamp'] = wfTimestamp( TS_MW
, $this->mAttribs
['rc_timestamp'] );
799 $this->mAttribs
['rc_deleted'] = $row->rc_deleted
; // MUST be set
803 * Makes a pseudo-RC entry from a cur row
805 * @deprecated since 1.22
808 public function loadFromCurRow( $row ) {
809 wfDeprecated( __METHOD__
, '1.22' );
810 $this->mAttribs
= array(
811 'rc_timestamp' => wfTimestamp( TS_MW
, $row->rev_timestamp
),
812 'rc_user' => $row->rev_user
,
813 'rc_user_text' => $row->rev_user_text
,
814 'rc_namespace' => $row->page_namespace
,
815 'rc_title' => $row->page_title
,
816 'rc_comment' => $row->rev_comment
,
817 'rc_minor' => $row->rev_minor_edit ?
1 : 0,
818 'rc_type' => $row->page_is_new ? RC_NEW
: RC_EDIT
,
819 'rc_source' => $row->page_is_new ? self
::SRC_NEW
: self
::SRC_EDIT
,
820 'rc_cur_id' => $row->page_id
,
821 'rc_this_oldid' => $row->rev_id
,
822 'rc_last_oldid' => isset( $row->rc_last_oldid
) ?
$row->rc_last_oldid
: 0,
825 'rc_id' => $row->rc_id
,
826 'rc_patrolled' => $row->rc_patrolled
,
827 'rc_new' => $row->page_is_new
, # obsolete
828 'rc_old_len' => $row->rc_old_len
,
829 'rc_new_len' => $row->rc_new_len
,
830 'rc_params' => isset( $row->rc_params
) ?
$row->rc_params
: '',
831 'rc_log_type' => isset( $row->rc_log_type
) ?
$row->rc_log_type
: null,
832 'rc_log_action' => isset( $row->rc_log_action
) ?
$row->rc_log_action
: null,
833 'rc_logid' => isset( $row->rc_logid
) ?
$row->rc_logid
: 0,
834 'rc_deleted' => $row->rc_deleted
// MUST be set
839 * Get an attribute value
841 * @param string $name Attribute name
844 public function getAttribute( $name ) {
845 return isset( $this->mAttribs
[$name] ) ?
$this->mAttribs
[$name] : null;
851 public function getAttributes() {
852 return $this->mAttribs
;
856 * Gets the end part of the diff URL associated with this object
857 * Blank if no diff link should be displayed
858 * @param bool $forceCur
861 public function diffLinkTrail( $forceCur ) {
862 if ( $this->mAttribs
['rc_type'] == RC_EDIT
) {
863 $trail = "curid=" . (int)( $this->mAttribs
['rc_cur_id'] ) .
864 "&oldid=" . (int)( $this->mAttribs
['rc_last_oldid'] );
868 $trail .= '&diff=' . (int)( $this->mAttribs
['rc_this_oldid'] );
878 * Returns the change size (HTML).
879 * The lengths can be given optionally.
884 public function getCharacterDifference( $old = 0, $new = 0 ) {
886 $old = $this->mAttribs
['rc_old_len'];
889 $new = $this->mAttribs
['rc_new_len'];
891 if ( $old === null ||
$new === null ) {
895 return ChangesList
::showCharacterDifference( $old, $new );
899 * Purge expired changes from the recentchanges table
902 public static function purgeExpiredChanges() {
903 if ( wfReadOnly() ) {
907 $method = __METHOD__
;
908 $dbw = wfGetDB( DB_MASTER
);
909 $dbw->onTransactionIdle( function () use ( $dbw, $method ) {
912 $cutoff = $dbw->timestamp( time() - $wgRCMaxAge );
915 array( 'rc_timestamp < ' . $dbw->addQuotes( $cutoff ) ),
921 private static function checkIPAddress( $ip ) {
924 if ( !IP
::isIPAddress( $ip ) ) {
925 throw new MWException( "Attempt to write \"" . $ip .
926 "\" as an IP address into recent changes" );
929 $ip = $wgRequest->getIP();
939 * Check whether the given timestamp is new enough to have a RC row with a given tolerance
940 * as the recentchanges table might not be cleared out regularly (so older entries might exist)
941 * or rows which will be deleted soon shouldn't be included.
943 * @param mixed $timestamp MWTimestamp compatible timestamp
944 * @param int $tolerance Tolerance in seconds
947 public static function isInRCLifespan( $timestamp, $tolerance = 0 ) {
950 return wfTimestamp( TS_UNIX
, $timestamp ) > time() - $tolerance - $wgRCMaxAge;