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_cur_time timestamp on the cur row
30 * rc_namespace namespace #
31 * rc_title non-prefixed db key
32 * rc_type is new entry, used to determine whether updating is necessary
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 * lang the interwiki prefix, automatically set in save()
56 * oldSize text size before the change
57 * newSize text size after the change
58 * pageStatus status of the page: created, deleted, moved, restored, changed
60 * temporary: not stored in the database
61 * notificationtimestamp
62 * numberofWatchingusers
64 * @todo document functions and variables
67 var $mAttribs = array(), $mExtra = array();
77 private $mPerformer = false;
82 var $mMovedToTitle = false;
83 var $numberofWatchingusers = 0; # Dummy to prevent error message in SpecialRecentchangeslinked
84 var $notificationtimestamp;
90 * @return RecentChange
92 public static function newFromRow( $row ) {
93 $rc = new RecentChange
;
94 $rc->loadFromRow( $row );
101 * @return RecentChange
103 public static function newFromCurRow( $row ) {
104 wfDeprecated( __METHOD__
, '1.22' );
105 $rc = new RecentChange
;
106 $rc->loadFromCurRow( $row );
107 $rc->notificationtimestamp
= false;
108 $rc->numberofWatchingusers
= false;
113 * Obtain the recent change with a given rc_id value
115 * @param int $rcid rc_id value to retrieve
116 * @return RecentChange
118 public static function newFromId( $rcid ) {
119 return self
::newFromConds( array( 'rc_id' => $rcid ), __METHOD__
);
123 * Find the first recent change matching some specific conditions
125 * @param array $conds of conditions
126 * @param $fname Mixed: override the method name in profiling/logs
127 * @param $options Array Query options
128 * @return RecentChange
130 public static function newFromConds( $conds, $fname = __METHOD__
, $options = array() ) {
131 $dbr = wfGetDB( DB_SLAVE
);
132 $row = $dbr->selectRow( 'recentchanges', self
::selectFields(), $conds, $fname, $options );
133 if ( $row !== false ) {
134 return self
::newFromRow( $row );
141 * Return the list of recentchanges fields that should be selected to create
142 * a new recentchanges object.
145 public static function selectFields() {
177 * @param $attribs array
179 public function setAttribs( $attribs ) {
180 $this->mAttribs
= $attribs;
184 * @param $extra array
186 public function setExtra( $extra ) {
187 $this->mExtra
= $extra;
194 public function &getTitle() {
195 if ( $this->mTitle
=== false ) {
196 $this->mTitle
= Title
::makeTitle( $this->mAttribs
['rc_namespace'], $this->mAttribs
['rc_title'] );
198 return $this->mTitle
;
202 * Get the User object of the person who performed this change.
206 public function getPerformer() {
207 if ( $this->mPerformer
=== false ) {
208 if ( $this->mAttribs
['rc_user'] ) {
209 $this->mPerformer
= User
::newFromID( $this->mAttribs
['rc_user'] );
211 $this->mPerformer
= User
::newFromName( $this->mAttribs
['rc_user_text'], false );
214 return $this->mPerformer
;
218 * Writes the data in this object to the database
221 public function save( $noudp = false ) {
222 global $wgLocalInterwiki, $wgPutIPinRC, $wgUseEnotif, $wgShowUpdatedMarker, $wgContLang;
224 $dbw = wfGetDB( DB_MASTER
);
225 if ( !is_array( $this->mExtra
) ) {
226 $this->mExtra
= array();
228 $this->mExtra
['lang'] = $wgLocalInterwiki;
230 if ( !$wgPutIPinRC ) {
231 $this->mAttribs
['rc_ip'] = '';
234 # If our database is strict about IP addresses, use NULL instead of an empty string
235 if ( $dbw->strictIPs() and $this->mAttribs
['rc_ip'] == '' ) {
236 unset( $this->mAttribs
['rc_ip'] );
239 # Trim spaces on user supplied text
240 $this->mAttribs
['rc_comment'] = trim( $this->mAttribs
['rc_comment'] );
242 # Make sure summary is truncated (whole multibyte characters)
243 $this->mAttribs
['rc_comment'] = $wgContLang->truncate( $this->mAttribs
['rc_comment'], 255 );
245 # Fixup database timestamps
246 $this->mAttribs
['rc_timestamp'] = $dbw->timestamp( $this->mAttribs
['rc_timestamp'] );
247 $this->mAttribs
['rc_cur_time'] = $dbw->timestamp( $this->mAttribs
['rc_cur_time'] );
248 $this->mAttribs
['rc_id'] = $dbw->nextSequenceValue( 'recentchanges_rc_id_seq' );
250 ## If we are using foreign keys, an entry of 0 for the page_id will fail, so use NULL
251 if ( $dbw->cascadingDeletes() and $this->mAttribs
['rc_cur_id'] == 0 ) {
252 unset( $this->mAttribs
['rc_cur_id'] );
256 $dbw->insert( 'recentchanges', $this->mAttribs
, __METHOD__
);
259 $this->mAttribs
['rc_id'] = $dbw->insertId();
262 wfRunHooks( 'RecentChange_save', array( &$this ) );
264 # Notify external application via UDP
266 $this->notifyRC2UDP();
269 # E-mail notifications
270 if ( $wgUseEnotif ||
$wgShowUpdatedMarker ) {
271 $editor = $this->getPerformer();
272 $title = $this->getTitle();
274 if ( wfRunHooks( 'AbortEmailNotification', array( $editor, $title ) ) ) {
275 # @todo FIXME: This would be better as an extension hook
276 $enotif = new EmailNotification();
277 $enotif->notifyOnPageChange( $editor, $title,
278 $this->mAttribs
['rc_timestamp'],
279 $this->mAttribs
['rc_comment'],
280 $this->mAttribs
['rc_minor'],
281 $this->mAttribs
['rc_last_oldid'],
282 $this->mExtra
['pageStatus'] );
287 public function notifyRC2UDP() {
288 global $wgRC2UDPAddress, $wgRC2UDPOmitBots;
289 # Notify external application via UDP
290 # Omit RC_EXTERNAL changes: bots and tools can get these edits from the feed of the external wiki
291 if ( $wgRC2UDPAddress && $this->mAttribs
['rc_type'] != RC_EXTERNAL
&&
292 ( !$this->mAttribs
['rc_bot'] ||
!$wgRC2UDPOmitBots ) ) {
293 self
::sendToUDP( $this->getIRCLine() );
298 * Send some text to UDP.
299 * @see RecentChange::cleanupForIRC
300 * @param string $line text to send
301 * @param string $address defaults to $wgRC2UDPAddress.
302 * @param string $prefix defaults to $wgRC2UDPPrefix.
303 * @param int $port defaults to $wgRC2UDPPort. (Since 1.17)
304 * @return Boolean: success
306 public static function sendToUDP( $line, $address = '', $prefix = '', $port = '' ) {
307 global $wgRC2UDPAddress, $wgRC2UDPPrefix, $wgRC2UDPPort;
308 # Assume default for standard RC case
309 $address = $address ?
$address : $wgRC2UDPAddress;
310 $prefix = $prefix ?
$prefix : $wgRC2UDPPrefix;
311 $port = $port ?
$port : $wgRC2UDPPort;
312 # Notify external application via UDP
314 $conn = socket_create( AF_INET
, SOCK_DGRAM
, SOL_UDP
);
316 $line = $prefix . $line;
317 wfDebug( __METHOD__
. ": sending UDP line: $line\n" );
318 socket_sendto( $conn, $line, strlen( $line ), 0, $address, $port );
319 socket_close( $conn );
322 wfDebug( __METHOD__
. ": failed to create UDP socket\n" );
329 * Remove newlines, carriage returns and decode html entities
330 * @param $text String
333 public static function cleanupForIRC( $text ) {
334 return Sanitizer
::decodeCharReferences( str_replace( array( "\n", "\r" ), array( " ", "" ), $text ) );
338 * Mark a given change as patrolled
340 * @param $change Mixed: RecentChange or corresponding rc_id
341 * @param $auto Boolean: for automatic patrol
342 * @return Array See doMarkPatrolled(), or null if $change is not an existing rc_id
344 public static function markPatrolled( $change, $auto = false ) {
347 $change = $change instanceof RecentChange
349 : RecentChange
::newFromId( $change );
351 if ( !$change instanceof RecentChange
) {
354 return $change->doMarkPatrolled( $wgUser, $auto );
358 * Mark this RecentChange as patrolled
360 * NOTE: Can also return 'rcpatroldisabled', 'hookaborted' and 'markedaspatrollederror-noautopatrol' as errors
361 * @param $user User object doing the action
362 * @param $auto Boolean: for automatic patrol
363 * @return array of permissions errors, see Title::getUserPermissionsErrors()
365 public function doMarkPatrolled( User
$user, $auto = false ) {
366 global $wgUseRCPatrol, $wgUseNPPatrol;
368 // If recentchanges patrol is disabled, only new pages
370 if ( !$wgUseRCPatrol && ( !$wgUseNPPatrol ||
$this->getAttribute( 'rc_type' ) != RC_NEW
) ) {
371 $errors[] = array( 'rcpatroldisabled' );
373 // Automatic patrol needs "autopatrol", ordinary patrol needs "patrol"
374 $right = $auto ?
'autopatrol' : 'patrol';
375 $errors = array_merge( $errors, $this->getTitle()->getUserPermissionsErrors( $right, $user ) );
376 if ( !wfRunHooks( 'MarkPatrolled', array( $this->getAttribute( 'rc_id' ), &$user, false ) ) ) {
377 $errors[] = array( 'hookaborted' );
379 // Users without the 'autopatrol' right can't patrol their
381 if ( $user->getName() == $this->getAttribute( 'rc_user_text' ) && !$user->isAllowed( 'autopatrol' ) ) {
382 $errors[] = array( 'markedaspatrollederror-noautopatrol' );
387 // If the change was patrolled already, do nothing
388 if ( $this->getAttribute( 'rc_patrolled' ) ) {
391 // Actually set the 'patrolled' flag in RC
392 $this->reallyMarkPatrolled();
393 // Log this patrol event
394 PatrolLog
::record( $this, $auto, $user );
395 wfRunHooks( 'MarkPatrolledComplete', array( $this->getAttribute( 'rc_id' ), &$user, false ) );
400 * Mark this RecentChange patrolled, without error checking
401 * @return Integer: number of affected rows
403 public function reallyMarkPatrolled() {
404 $dbw = wfGetDB( DB_MASTER
);
411 'rc_id' => $this->getAttribute( 'rc_id' )
415 // Invalidate the page cache after the page has been patrolled
416 // to make sure that the Patrol link isn't visible any longer!
417 $this->getTitle()->invalidateCache();
418 return $dbw->affectedRows();
422 * Makes an entry in the database corresponding to an edit
425 * @param $title Title
430 * @param $lastTimestamp
433 * @param $oldSize int
434 * @param $newSize int
437 * @return RecentChange
439 public static function notifyEdit( $timestamp, &$title, $minor, &$user, $comment, $oldId,
440 $lastTimestamp, $bot, $ip = '', $oldSize = 0, $newSize = 0, $newId = 0, $patrol = 0 ) {
441 $rc = new RecentChange
;
442 $rc->mTitle
= $title;
443 $rc->mPerformer
= $user;
444 $rc->mAttribs
= array(
445 'rc_timestamp' => $timestamp,
446 'rc_cur_time' => $timestamp,
447 'rc_namespace' => $title->getNamespace(),
448 'rc_title' => $title->getDBkey(),
449 'rc_type' => RC_EDIT
,
450 'rc_minor' => $minor ?
1 : 0,
451 'rc_cur_id' => $title->getArticleID(),
452 'rc_user' => $user->getId(),
453 'rc_user_text' => $user->getName(),
454 'rc_comment' => $comment,
455 'rc_this_oldid' => $newId,
456 'rc_last_oldid' => $oldId,
457 'rc_bot' => $bot ?
1 : 0,
458 'rc_ip' => self
::checkIPAddress( $ip ),
459 'rc_patrolled' => intval( $patrol ),
460 'rc_new' => 0, # obsolete
461 'rc_old_len' => $oldSize,
462 'rc_new_len' => $newSize,
465 'rc_log_type' => null,
466 'rc_log_action' => '',
471 'prefixedDBkey' => $title->getPrefixedDBkey(),
472 'lastTimestamp' => $lastTimestamp,
473 'oldSize' => $oldSize,
474 'newSize' => $newSize,
475 'pageStatus' => 'changed'
482 * Makes an entry in the database corresponding to page creation
483 * Note: the title object must be loaded with the new id using resetArticleID()
484 * @todo Document parameters and return
487 * @param $title Title
496 * @return RecentChange
498 public static function notifyNew( $timestamp, &$title, $minor, &$user, $comment, $bot,
499 $ip = '', $size = 0, $newId = 0, $patrol = 0 ) {
500 $rc = new RecentChange
;
501 $rc->mTitle
= $title;
502 $rc->mPerformer
= $user;
503 $rc->mAttribs
= array(
504 'rc_timestamp' => $timestamp,
505 'rc_cur_time' => $timestamp,
506 'rc_namespace' => $title->getNamespace(),
507 'rc_title' => $title->getDBkey(),
509 'rc_minor' => $minor ?
1 : 0,
510 'rc_cur_id' => $title->getArticleID(),
511 'rc_user' => $user->getId(),
512 'rc_user_text' => $user->getName(),
513 'rc_comment' => $comment,
514 'rc_this_oldid' => $newId,
515 'rc_last_oldid' => 0,
516 'rc_bot' => $bot ?
1 : 0,
517 'rc_ip' => self
::checkIPAddress( $ip ),
518 'rc_patrolled' => intval( $patrol ),
519 'rc_new' => 1, # obsolete
521 'rc_new_len' => $size,
524 'rc_log_type' => null,
525 'rc_log_action' => '',
530 'prefixedDBkey' => $title->getPrefixedDBkey(),
531 'lastTimestamp' => 0,
534 'pageStatus' => 'created'
544 * @param $actionComment
552 * @param $actionCommentIRC string
555 public static function notifyLog( $timestamp, &$title, &$user, $actionComment, $ip, $type,
556 $action, $target, $logComment, $params, $newId = 0, $actionCommentIRC = '' )
558 global $wgLogRestrictions;
559 # Don't add private logs to RC!
560 if ( isset( $wgLogRestrictions[$type] ) && $wgLogRestrictions[$type] != '*' ) {
563 $rc = self
::newLogEntry( $timestamp, $title, $user, $actionComment, $ip, $type, $action,
564 $target, $logComment, $params, $newId, $actionCommentIRC );
571 * @param $title Title
573 * @param $actionComment
577 * @param $target Title
581 * @param $actionCommentIRC string
582 * @return RecentChange
584 public static function newLogEntry( $timestamp, &$title, &$user, $actionComment, $ip,
585 $type, $action, $target, $logComment, $params, $newId = 0, $actionCommentIRC = '' ) {
588 ## Get pageStatus for email notification
589 switch ( $type . '-' . $action ) {
590 case 'delete-delete':
591 $pageStatus = 'deleted';
594 case 'move-move_redir':
595 $pageStatus = 'moved';
597 case 'delete-restore':
598 $pageStatus = 'restored';
600 case 'upload-upload':
601 $pageStatus = 'created';
603 case 'upload-overwrite':
605 $pageStatus = 'changed';
609 $rc = new RecentChange
;
610 $rc->mTitle
= $target;
611 $rc->mPerformer
= $user;
612 $rc->mAttribs
= array(
613 'rc_timestamp' => $timestamp,
614 'rc_cur_time' => $timestamp,
615 'rc_namespace' => $target->getNamespace(),
616 'rc_title' => $target->getDBkey(),
619 'rc_cur_id' => $target->getArticleID(),
620 'rc_user' => $user->getId(),
621 'rc_user_text' => $user->getName(),
622 'rc_comment' => $logComment,
623 'rc_this_oldid' => 0,
624 'rc_last_oldid' => 0,
625 'rc_bot' => $user->isAllowed( 'bot' ) ?
$wgRequest->getBool( 'bot', true ) : 0,
626 'rc_ip' => self
::checkIPAddress( $ip ),
628 'rc_new' => 0, # obsolete
629 'rc_old_len' => null,
630 'rc_new_len' => null,
632 'rc_logid' => $newId,
633 'rc_log_type' => $type,
634 'rc_log_action' => $action,
635 'rc_params' => $params
639 'prefixedDBkey' => $title->getPrefixedDBkey(),
640 'lastTimestamp' => 0,
641 'actionComment' => $actionComment, // the comment appended to the action, passed from LogPage
642 'pageStatus' => $pageStatus,
643 'actionCommentIRC' => $actionCommentIRC
649 * Initialises the members of this object from a mysql row object
653 public function loadFromRow( $row ) {
654 $this->mAttribs
= get_object_vars( $row );
655 $this->mAttribs
['rc_timestamp'] = wfTimestamp( TS_MW
, $this->mAttribs
['rc_timestamp'] );
656 $this->mAttribs
['rc_deleted'] = $row->rc_deleted
; // MUST be set
660 * Makes a pseudo-RC entry from a cur row
665 public function loadFromCurRow( $row ) {
666 wfDeprecated( __METHOD__
, '1.22' );
667 $this->mAttribs
= array(
668 'rc_timestamp' => wfTimestamp( TS_MW
, $row->rev_timestamp
),
669 'rc_cur_time' => $row->rev_timestamp
,
670 'rc_user' => $row->rev_user
,
671 'rc_user_text' => $row->rev_user_text
,
672 'rc_namespace' => $row->page_namespace
,
673 'rc_title' => $row->page_title
,
674 'rc_comment' => $row->rev_comment
,
675 'rc_minor' => $row->rev_minor_edit ?
1 : 0,
676 'rc_type' => $row->page_is_new ? RC_NEW
: RC_EDIT
,
677 'rc_cur_id' => $row->page_id
,
678 'rc_this_oldid' => $row->rev_id
,
679 'rc_last_oldid' => isset( $row->rc_last_oldid
) ?
$row->rc_last_oldid
: 0,
682 'rc_id' => $row->rc_id
,
683 'rc_patrolled' => $row->rc_patrolled
,
684 'rc_new' => $row->page_is_new
, # obsolete
685 'rc_old_len' => $row->rc_old_len
,
686 'rc_new_len' => $row->rc_new_len
,
687 'rc_params' => isset( $row->rc_params
) ?
$row->rc_params
: '',
688 'rc_log_type' => isset( $row->rc_log_type
) ?
$row->rc_log_type
: null,
689 'rc_log_action' => isset( $row->rc_log_action
) ?
$row->rc_log_action
: null,
690 'rc_logid' => isset( $row->rc_logid
) ?
$row->rc_logid
: 0,
691 'rc_deleted' => $row->rc_deleted
// MUST be set
696 * Get an attribute value
698 * @param string $name Attribute name
701 public function getAttribute( $name ) {
702 return isset( $this->mAttribs
[$name] ) ?
$this->mAttribs
[$name] : null;
708 public function getAttributes() {
709 return $this->mAttribs
;
713 * Gets the end part of the diff URL associated with this object
714 * Blank if no diff link should be displayed
718 public function diffLinkTrail( $forceCur ) {
719 if ( $this->mAttribs
['rc_type'] == RC_EDIT
) {
720 $trail = "curid=" . (int)( $this->mAttribs
['rc_cur_id'] ) .
721 "&oldid=" . (int)( $this->mAttribs
['rc_last_oldid'] );
725 $trail .= '&diff=' . (int)( $this->mAttribs
['rc_this_oldid'] );
736 public function getIRCLine() {
737 global $wgUseRCPatrol, $wgUseNPPatrol, $wgRC2UDPInterwikiPrefix, $wgLocalInterwiki,
738 $wgCanonicalServer, $wgScript;
740 if ( $this->mAttribs
['rc_type'] == RC_LOG
) {
741 // Don't use SpecialPage::getTitleFor, backwards compatibility with
742 // IRC API which expects "Log".
743 $titleObj = Title
::newFromText( 'Log/' . $this->mAttribs
['rc_log_type'], NS_SPECIAL
);
745 $titleObj =& $this->getTitle();
747 $title = $titleObj->getPrefixedText();
748 $title = self
::cleanupForIRC( $title );
750 if ( $this->mAttribs
['rc_type'] == RC_LOG
) {
753 $url = $wgCanonicalServer . $wgScript;
754 if ( $this->mAttribs
['rc_type'] == RC_NEW
) {
755 $query = '?oldid=' . $this->mAttribs
['rc_this_oldid'];
757 $query = '?diff=' . $this->mAttribs
['rc_this_oldid'] . '&oldid=' . $this->mAttribs
['rc_last_oldid'];
759 if ( $wgUseRCPatrol ||
( $this->mAttribs
['rc_type'] == RC_NEW
&& $wgUseNPPatrol ) ) {
760 $query .= '&rcid=' . $this->mAttribs
['rc_id'];
762 // HACK: We need this hook for WMF's secure server setup
763 wfRunHooks( 'IRCLineURL', array( &$url, &$query ) );
767 if ( $this->mAttribs
['rc_old_len'] !== null && $this->mAttribs
['rc_new_len'] !== null ) {
768 $szdiff = $this->mAttribs
['rc_new_len'] - $this->mAttribs
['rc_old_len'];
769 if ( $szdiff < -500 ) {
770 $szdiff = "\002$szdiff\002";
771 } elseif ( $szdiff >= 0 ) {
772 $szdiff = '+' . $szdiff;
774 // @todo i18n with parentheses in content language?
775 $szdiff = '(' . $szdiff . ')';
780 $user = self
::cleanupForIRC( $this->mAttribs
['rc_user_text'] );
782 if ( $this->mAttribs
['rc_type'] == RC_LOG
) {
783 $targetText = $this->getTitle()->getPrefixedText();
784 $comment = self
::cleanupForIRC( str_replace( "[[$targetText]]", "[[\00302$targetText\00310]]", $this->mExtra
['actionCommentIRC'] ) );
785 $flag = $this->mAttribs
['rc_log_action'];
787 $comment = self
::cleanupForIRC( $this->mAttribs
['rc_comment'] );
789 if ( !$this->mAttribs
['rc_patrolled'] && ( $wgUseRCPatrol ||
$this->mAttribs
['rc_type'] == RC_NEW
&& $wgUseNPPatrol ) ) {
792 $flag .= ( $this->mAttribs
['rc_type'] == RC_NEW ?
"N" : "" ) . ( $this->mAttribs
['rc_minor'] ?
"M" : "" ) . ( $this->mAttribs
['rc_bot'] ?
"B" : "" );
795 if ( $wgRC2UDPInterwikiPrefix === true && $wgLocalInterwiki !== false ) {
796 $prefix = $wgLocalInterwiki;
797 } elseif ( $wgRC2UDPInterwikiPrefix ) {
798 $prefix = $wgRC2UDPInterwikiPrefix;
802 if ( $prefix !== false ) {
803 $titleString = "\00314[[\00303$prefix:\00307$title\00314]]";
805 $titleString = "\00314[[\00307$title\00314]]";
808 # see http://www.irssi.org/documentation/formats for some colour codes. prefix is \003,
809 # no colour (\003) switches back to the term default
810 $fullString = "$titleString\0034 $flag\00310 " .
811 "\00302$url\003 \0035*\003 \00303$user\003 \0035*\003 $szdiff \00310$comment\003\n";
817 * Returns the change size (HTML).
818 * The lengths can be given optionally.
823 public function getCharacterDifference( $old = 0, $new = 0 ) {
825 $old = $this->mAttribs
['rc_old_len'];
828 $new = $this->mAttribs
['rc_new_len'];
830 if ( $old === null ||
$new === null ) {
833 return ChangesList
::showCharacterDifference( $old, $new );
837 * Purge expired changes from the recentchanges table
840 public static function purgeExpiredChanges() {
841 if ( wfReadOnly() ) {
845 $method = __METHOD__
;
846 $dbw = wfGetDB( DB_MASTER
);
847 $dbw->onTransactionIdle( function() use ( $dbw, $method ) {
850 $cutoff = $dbw->timestamp( time() - $wgRCMaxAge );
853 array( 'rc_timestamp < ' . $dbw->addQuotes( $cutoff ) ),
859 private static function checkIPAddress( $ip ) {
862 if ( !IP
::isIPAddress( $ip ) ) {
863 throw new MWException( "Attempt to write \"" . $ip . "\" as an IP address into recent changes" );
866 $ip = $wgRequest->getIP();
875 * Check whether the given timestamp is new enough to have a RC row with a given tolerance
876 * as the recentchanges table might not be cleared out regularly (so older entries might exist)
877 * or rows which will be deleted soon shouldn't be included.
879 * @param $timestamp mixed MWTimestamp compatible timestamp
880 * @param $tolerance integer Tolerance in seconds
883 public static function isInRCLifespan( $timestamp, $tolerance = 0 ) {
885 return wfTimestamp( TS_UNIX
, $timestamp ) > time() - $tolerance - $wgRCMaxAge;