Localisation updates from http://translatewiki.net.
[mediawiki.git] / includes / RecentChange.php
blobb5d4a1c531c1f1d73a5436bebbe03232a9633be7
1 <?php
2 /**
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
20 * @file
23 /**
24 * Utility class for creating new RC entries
26 * mAttribs:
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
33 * rc_minor is minor
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
52 * mExtra:
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
66 class RecentChange {
67 var $mAttribs = array(), $mExtra = array();
69 /**
70 * @var Title
72 var $mTitle = false;
74 /**
75 * @var User
77 private $mPerformer = false;
79 /**
80 * @var Title
82 var $mMovedToTitle = false;
83 var $numberofWatchingusers = 0; # Dummy to prevent error message in SpecialRecentchangeslinked
84 var $notificationtimestamp;
86 # Factory methods
88 /**
89 * @param $row
90 * @return RecentChange
92 public static function newFromRow( $row ) {
93 $rc = new RecentChange;
94 $rc->loadFromRow( $row );
95 return $rc;
98 /**
99 * @param $row
100 * @return RecentChange
102 public static function newFromCurRow( $row ) {
103 $rc = new RecentChange;
104 $rc->loadFromCurRow( $row );
105 $rc->notificationtimestamp = false;
106 $rc->numberofWatchingusers = false;
107 return $rc;
111 * Obtain the recent change with a given rc_id value
113 * @param int $rcid rc_id value to retrieve
114 * @return RecentChange
116 public static function newFromId( $rcid ) {
117 return self::newFromConds( array( 'rc_id' => $rcid ), __METHOD__ );
121 * Find the first recent change matching some specific conditions
123 * @param array $conds of conditions
124 * @param $fname Mixed: override the method name in profiling/logs
125 * @return RecentChange
127 public static function newFromConds( $conds, $fname = __METHOD__ ) {
128 $dbr = wfGetDB( DB_SLAVE );
129 $row = $dbr->selectRow( 'recentchanges', self::selectFields(), $conds, $fname );
130 if ( $row !== false ) {
131 return self::newFromRow( $row );
132 } else {
133 return null;
138 * Return the list of recentchanges fields that should be selected to create
139 * a new recentchanges object.
140 * @return array
142 public static function selectFields() {
143 return array(
144 'rc_id',
145 'rc_timestamp',
146 'rc_cur_time',
147 'rc_user',
148 'rc_user_text',
149 'rc_namespace',
150 'rc_title',
151 'rc_comment',
152 'rc_minor',
153 'rc_bot',
154 'rc_new',
155 'rc_cur_id',
156 'rc_this_oldid',
157 'rc_last_oldid',
158 'rc_type',
159 'rc_patrolled',
160 'rc_ip',
161 'rc_old_len',
162 'rc_new_len',
163 'rc_deleted',
164 'rc_logid',
165 'rc_log_type',
166 'rc_log_action',
167 'rc_params',
171 # Accessors
174 * @param $attribs array
176 public function setAttribs( $attribs ) {
177 $this->mAttribs = $attribs;
181 * @param $extra array
183 public function setExtra( $extra ) {
184 $this->mExtra = $extra;
189 * @return Title
191 public function &getTitle() {
192 if ( $this->mTitle === false ) {
193 $this->mTitle = Title::makeTitle( $this->mAttribs['rc_namespace'], $this->mAttribs['rc_title'] );
195 return $this->mTitle;
199 * Get the User object of the person who performed this change.
201 * @return User
203 public function getPerformer() {
204 if ( $this->mPerformer === false ) {
205 if ( $this->mAttribs['rc_user'] ) {
206 $this->mPerformer = User::newFromID( $this->mAttribs['rc_user'] );
207 } else {
208 $this->mPerformer = User::newFromName( $this->mAttribs['rc_user_text'], false );
211 return $this->mPerformer;
215 * Writes the data in this object to the database
216 * @param $noudp bool
218 public function save( $noudp = false ) {
219 global $wgLocalInterwiki, $wgPutIPinRC, $wgUseEnotif, $wgShowUpdatedMarker, $wgContLang;
221 $dbw = wfGetDB( DB_MASTER );
222 if ( !is_array( $this->mExtra ) ) {
223 $this->mExtra = array();
225 $this->mExtra['lang'] = $wgLocalInterwiki;
227 if ( !$wgPutIPinRC ) {
228 $this->mAttribs['rc_ip'] = '';
231 # If our database is strict about IP addresses, use NULL instead of an empty string
232 if ( $dbw->strictIPs() and $this->mAttribs['rc_ip'] == '' ) {
233 unset( $this->mAttribs['rc_ip'] );
236 # Trim spaces on user supplied text
237 $this->mAttribs['rc_comment'] = trim( $this->mAttribs['rc_comment'] );
239 # Make sure summary is truncated (whole multibyte characters)
240 $this->mAttribs['rc_comment'] = $wgContLang->truncate( $this->mAttribs['rc_comment'], 255 );
242 # Fixup database timestamps
243 $this->mAttribs['rc_timestamp'] = $dbw->timestamp( $this->mAttribs['rc_timestamp'] );
244 $this->mAttribs['rc_cur_time'] = $dbw->timestamp( $this->mAttribs['rc_cur_time'] );
245 $this->mAttribs['rc_id'] = $dbw->nextSequenceValue( 'recentchanges_rc_id_seq' );
247 ## If we are using foreign keys, an entry of 0 for the page_id will fail, so use NULL
248 if ( $dbw->cascadingDeletes() and $this->mAttribs['rc_cur_id'] == 0 ) {
249 unset( $this->mAttribs['rc_cur_id'] );
252 # Insert new row
253 $dbw->insert( 'recentchanges', $this->mAttribs, __METHOD__ );
255 # Set the ID
256 $this->mAttribs['rc_id'] = $dbw->insertId();
258 # Notify extensions
259 wfRunHooks( 'RecentChange_save', array( &$this ) );
261 # Notify external application via UDP
262 if ( !$noudp ) {
263 $this->notifyRC2UDP();
266 # E-mail notifications
267 if ( $wgUseEnotif || $wgShowUpdatedMarker ) {
268 $editor = $this->getPerformer();
269 $title = $this->getTitle();
271 if ( wfRunHooks( 'AbortEmailNotification', array( $editor, $title ) ) ) {
272 # @todo FIXME: This would be better as an extension hook
273 $enotif = new EmailNotification();
274 $enotif->notifyOnPageChange( $editor, $title,
275 $this->mAttribs['rc_timestamp'],
276 $this->mAttribs['rc_comment'],
277 $this->mAttribs['rc_minor'],
278 $this->mAttribs['rc_last_oldid'],
279 $this->mExtra['pageStatus'] );
284 public function notifyRC2UDP() {
285 global $wgRC2UDPAddress, $wgRC2UDPOmitBots;
286 # Notify external application via UDP
287 # Omit RC_EXTERNAL changes: bots and tools can get these edits from the feed of the external wiki
288 if ( $wgRC2UDPAddress && $this->mAttribs['rc_type'] != RC_EXTERNAL &&
289 ( !$this->mAttribs['rc_bot'] || !$wgRC2UDPOmitBots ) ) {
290 self::sendToUDP( $this->getIRCLine() );
295 * Send some text to UDP.
296 * @see RecentChange::cleanupForIRC
297 * @param string $line text to send
298 * @param string $address defaults to $wgRC2UDPAddress.
299 * @param string $prefix defaults to $wgRC2UDPPrefix.
300 * @param int $port defaults to $wgRC2UDPPort. (Since 1.17)
301 * @return Boolean: success
303 public static function sendToUDP( $line, $address = '', $prefix = '', $port = '' ) {
304 global $wgRC2UDPAddress, $wgRC2UDPPrefix, $wgRC2UDPPort;
305 # Assume default for standard RC case
306 $address = $address ? $address : $wgRC2UDPAddress;
307 $prefix = $prefix ? $prefix : $wgRC2UDPPrefix;
308 $port = $port ? $port : $wgRC2UDPPort;
309 # Notify external application via UDP
310 if ( $address ) {
311 $conn = socket_create( AF_INET, SOCK_DGRAM, SOL_UDP );
312 if ( $conn ) {
313 $line = $prefix . $line;
314 wfDebug( __METHOD__ . ": sending UDP line: $line\n" );
315 socket_sendto( $conn, $line, strlen( $line ), 0, $address, $port );
316 socket_close( $conn );
317 return true;
318 } else {
319 wfDebug( __METHOD__ . ": failed to create UDP socket\n" );
322 return false;
326 * Remove newlines, carriage returns and decode html entities
327 * @param $text String
328 * @return String
330 public static function cleanupForIRC( $text ) {
331 return Sanitizer::decodeCharReferences( str_replace( array( "\n", "\r" ), array( "", "" ), $text ) );
335 * Mark a given change as patrolled
337 * @param $change Mixed: RecentChange or corresponding rc_id
338 * @param $auto Boolean: for automatic patrol
339 * @return Array See doMarkPatrolled(), or null if $change is not an existing rc_id
341 public static function markPatrolled( $change, $auto = false ) {
342 global $wgUser;
344 $change = $change instanceof RecentChange
345 ? $change
346 : RecentChange::newFromId( $change );
348 if ( !$change instanceof RecentChange ) {
349 return null;
351 return $change->doMarkPatrolled( $wgUser, $auto );
355 * Mark this RecentChange as patrolled
357 * NOTE: Can also return 'rcpatroldisabled', 'hookaborted' and 'markedaspatrollederror-noautopatrol' as errors
358 * @param $user User object doing the action
359 * @param $auto Boolean: for automatic patrol
360 * @return array of permissions errors, see Title::getUserPermissionsErrors()
362 public function doMarkPatrolled( User $user, $auto = false ) {
363 global $wgUseRCPatrol, $wgUseNPPatrol;
364 $errors = array();
365 // If recentchanges patrol is disabled, only new pages
366 // can be patrolled
367 if ( !$wgUseRCPatrol && ( !$wgUseNPPatrol || $this->getAttribute( 'rc_type' ) != RC_NEW ) ) {
368 $errors[] = array( 'rcpatroldisabled' );
370 // Automatic patrol needs "autopatrol", ordinary patrol needs "patrol"
371 $right = $auto ? 'autopatrol' : 'patrol';
372 $errors = array_merge( $errors, $this->getTitle()->getUserPermissionsErrors( $right, $user ) );
373 if ( !wfRunHooks( 'MarkPatrolled', array( $this->getAttribute( 'rc_id' ), &$user, false ) ) ) {
374 $errors[] = array( 'hookaborted' );
376 // Users without the 'autopatrol' right can't patrol their
377 // own revisions
378 if ( $user->getName() == $this->getAttribute( 'rc_user_text' ) && !$user->isAllowed( 'autopatrol' ) ) {
379 $errors[] = array( 'markedaspatrollederror-noautopatrol' );
381 if ( $errors ) {
382 return $errors;
384 // If the change was patrolled already, do nothing
385 if ( $this->getAttribute( 'rc_patrolled' ) ) {
386 return array();
388 // Actually set the 'patrolled' flag in RC
389 $this->reallyMarkPatrolled();
390 // Log this patrol event
391 PatrolLog::record( $this, $auto, $user );
392 wfRunHooks( 'MarkPatrolledComplete', array( $this->getAttribute( 'rc_id' ), &$user, false ) );
393 return array();
397 * Mark this RecentChange patrolled, without error checking
398 * @return Integer: number of affected rows
400 public function reallyMarkPatrolled() {
401 $dbw = wfGetDB( DB_MASTER );
402 $dbw->update(
403 'recentchanges',
404 array(
405 'rc_patrolled' => 1
407 array(
408 'rc_id' => $this->getAttribute( 'rc_id' )
410 __METHOD__
412 return $dbw->affectedRows();
416 * Makes an entry in the database corresponding to an edit
418 * @param $timestamp
419 * @param $title Title
420 * @param $minor
421 * @param $user User
422 * @param $comment
423 * @param $oldId
424 * @param $lastTimestamp
425 * @param $bot
426 * @param $ip string
427 * @param $oldSize int
428 * @param $newSize int
429 * @param $newId int
430 * @param $patrol int
431 * @return RecentChange
433 public static function notifyEdit( $timestamp, &$title, $minor, &$user, $comment, $oldId,
434 $lastTimestamp, $bot, $ip = '', $oldSize = 0, $newSize = 0, $newId = 0, $patrol = 0 ) {
435 $rc = new RecentChange;
436 $rc->mTitle = $title;
437 $rc->mPerformer = $user;
438 $rc->mAttribs = array(
439 'rc_timestamp' => $timestamp,
440 'rc_cur_time' => $timestamp,
441 'rc_namespace' => $title->getNamespace(),
442 'rc_title' => $title->getDBkey(),
443 'rc_type' => RC_EDIT,
444 'rc_minor' => $minor ? 1 : 0,
445 'rc_cur_id' => $title->getArticleID(),
446 'rc_user' => $user->getId(),
447 'rc_user_text' => $user->getName(),
448 'rc_comment' => $comment,
449 'rc_this_oldid' => $newId,
450 'rc_last_oldid' => $oldId,
451 'rc_bot' => $bot ? 1 : 0,
452 'rc_ip' => self::checkIPAddress( $ip ),
453 'rc_patrolled' => intval( $patrol ),
454 'rc_new' => 0, # obsolete
455 'rc_old_len' => $oldSize,
456 'rc_new_len' => $newSize,
457 'rc_deleted' => 0,
458 'rc_logid' => 0,
459 'rc_log_type' => null,
460 'rc_log_action' => '',
461 'rc_params' => ''
464 $rc->mExtra = array(
465 'prefixedDBkey' => $title->getPrefixedDBkey(),
466 'lastTimestamp' => $lastTimestamp,
467 'oldSize' => $oldSize,
468 'newSize' => $newSize,
469 'pageStatus' => 'changed'
471 $rc->save();
472 return $rc;
476 * Makes an entry in the database corresponding to page creation
477 * Note: the title object must be loaded with the new id using resetArticleID()
478 * @todo Document parameters and return
480 * @param $timestamp
481 * @param $title Title
482 * @param $minor
483 * @param $user User
484 * @param $comment
485 * @param $bot
486 * @param $ip string
487 * @param $size int
488 * @param $newId int
489 * @param $patrol int
490 * @return RecentChange
492 public static function notifyNew( $timestamp, &$title, $minor, &$user, $comment, $bot,
493 $ip = '', $size = 0, $newId = 0, $patrol = 0 ) {
494 $rc = new RecentChange;
495 $rc->mTitle = $title;
496 $rc->mPerformer = $user;
497 $rc->mAttribs = array(
498 'rc_timestamp' => $timestamp,
499 'rc_cur_time' => $timestamp,
500 'rc_namespace' => $title->getNamespace(),
501 'rc_title' => $title->getDBkey(),
502 'rc_type' => RC_NEW,
503 'rc_minor' => $minor ? 1 : 0,
504 'rc_cur_id' => $title->getArticleID(),
505 'rc_user' => $user->getId(),
506 'rc_user_text' => $user->getName(),
507 'rc_comment' => $comment,
508 'rc_this_oldid' => $newId,
509 'rc_last_oldid' => 0,
510 'rc_bot' => $bot ? 1 : 0,
511 'rc_ip' => self::checkIPAddress( $ip ),
512 'rc_patrolled' => intval( $patrol ),
513 'rc_new' => 1, # obsolete
514 'rc_old_len' => 0,
515 'rc_new_len' => $size,
516 'rc_deleted' => 0,
517 'rc_logid' => 0,
518 'rc_log_type' => null,
519 'rc_log_action' => '',
520 'rc_params' => ''
523 $rc->mExtra = array(
524 'prefixedDBkey' => $title->getPrefixedDBkey(),
525 'lastTimestamp' => 0,
526 'oldSize' => 0,
527 'newSize' => $size,
528 'pageStatus' => 'created'
530 $rc->save();
531 return $rc;
535 * @param $timestamp
536 * @param $title
537 * @param $user
538 * @param $actionComment
539 * @param $ip string
540 * @param $type
541 * @param $action
542 * @param $target
543 * @param $logComment
544 * @param $params
545 * @param $newId int
546 * @param $actionCommentIRC string
547 * @return bool
549 public static function notifyLog( $timestamp, &$title, &$user, $actionComment, $ip, $type,
550 $action, $target, $logComment, $params, $newId = 0, $actionCommentIRC = '' )
552 global $wgLogRestrictions;
553 # Don't add private logs to RC!
554 if ( isset( $wgLogRestrictions[$type] ) && $wgLogRestrictions[$type] != '*' ) {
555 return false;
557 $rc = self::newLogEntry( $timestamp, $title, $user, $actionComment, $ip, $type, $action,
558 $target, $logComment, $params, $newId, $actionCommentIRC );
559 $rc->save();
560 return true;
564 * @param $timestamp
565 * @param $title Title
566 * @param $user User
567 * @param $actionComment
568 * @param $ip string
569 * @param $type
570 * @param $action
571 * @param $target Title
572 * @param $logComment
573 * @param $params
574 * @param $newId int
575 * @param $actionCommentIRC string
576 * @return RecentChange
578 public static function newLogEntry( $timestamp, &$title, &$user, $actionComment, $ip,
579 $type, $action, $target, $logComment, $params, $newId = 0, $actionCommentIRC = '' ) {
580 global $wgRequest;
582 ## Get pageStatus for email notification
583 switch ( $type . '-' . $action ) {
584 case 'delete-delete':
585 $pageStatus = 'deleted';
586 break;
587 case 'move-move':
588 case 'move-move_redir':
589 $pageStatus = 'moved';
590 break;
591 case 'delete-restore':
592 $pageStatus = 'restored';
593 break;
594 case 'upload-upload':
595 $pageStatus = 'created';
596 break;
597 case 'upload-overwrite':
598 default:
599 $pageStatus = 'changed';
600 break;
603 $rc = new RecentChange;
604 $rc->mTitle = $target;
605 $rc->mPerformer = $user;
606 $rc->mAttribs = array(
607 'rc_timestamp' => $timestamp,
608 'rc_cur_time' => $timestamp,
609 'rc_namespace' => $target->getNamespace(),
610 'rc_title' => $target->getDBkey(),
611 'rc_type' => RC_LOG,
612 'rc_minor' => 0,
613 'rc_cur_id' => $target->getArticleID(),
614 'rc_user' => $user->getId(),
615 'rc_user_text' => $user->getName(),
616 'rc_comment' => $logComment,
617 'rc_this_oldid' => 0,
618 'rc_last_oldid' => 0,
619 'rc_bot' => $user->isAllowed( 'bot' ) ? $wgRequest->getBool( 'bot', true ) : 0,
620 'rc_ip' => self::checkIPAddress( $ip ),
621 'rc_patrolled' => 1,
622 'rc_new' => 0, # obsolete
623 'rc_old_len' => null,
624 'rc_new_len' => null,
625 'rc_deleted' => 0,
626 'rc_logid' => $newId,
627 'rc_log_type' => $type,
628 'rc_log_action' => $action,
629 'rc_params' => $params
632 $rc->mExtra = array(
633 'prefixedDBkey' => $title->getPrefixedDBkey(),
634 'lastTimestamp' => 0,
635 'actionComment' => $actionComment, // the comment appended to the action, passed from LogPage
636 'pageStatus' => $pageStatus,
637 'actionCommentIRC' => $actionCommentIRC
639 return $rc;
643 * Initialises the members of this object from a mysql row object
645 * @param $row
647 public function loadFromRow( $row ) {
648 $this->mAttribs = get_object_vars( $row );
649 $this->mAttribs['rc_timestamp'] = wfTimestamp( TS_MW, $this->mAttribs['rc_timestamp'] );
650 $this->mAttribs['rc_deleted'] = $row->rc_deleted; // MUST be set
654 * Makes a pseudo-RC entry from a cur row
656 * @param $row
658 public function loadFromCurRow( $row ) {
659 $this->mAttribs = array(
660 'rc_timestamp' => wfTimestamp( TS_MW, $row->rev_timestamp ),
661 'rc_cur_time' => $row->rev_timestamp,
662 'rc_user' => $row->rev_user,
663 'rc_user_text' => $row->rev_user_text,
664 'rc_namespace' => $row->page_namespace,
665 'rc_title' => $row->page_title,
666 'rc_comment' => $row->rev_comment,
667 'rc_minor' => $row->rev_minor_edit ? 1 : 0,
668 'rc_type' => $row->page_is_new ? RC_NEW : RC_EDIT,
669 'rc_cur_id' => $row->page_id,
670 'rc_this_oldid' => $row->rev_id,
671 'rc_last_oldid' => isset( $row->rc_last_oldid ) ? $row->rc_last_oldid : 0,
672 'rc_bot' => 0,
673 'rc_ip' => '',
674 'rc_id' => $row->rc_id,
675 'rc_patrolled' => $row->rc_patrolled,
676 'rc_new' => $row->page_is_new, # obsolete
677 'rc_old_len' => $row->rc_old_len,
678 'rc_new_len' => $row->rc_new_len,
679 'rc_params' => isset( $row->rc_params ) ? $row->rc_params : '',
680 'rc_log_type' => isset( $row->rc_log_type ) ? $row->rc_log_type : null,
681 'rc_log_action' => isset( $row->rc_log_action ) ? $row->rc_log_action : null,
682 'rc_logid' => isset( $row->rc_logid ) ? $row->rc_logid : 0,
683 'rc_deleted' => $row->rc_deleted // MUST be set
688 * Get an attribute value
690 * @param string $name Attribute name
691 * @return mixed
693 public function getAttribute( $name ) {
694 return isset( $this->mAttribs[$name] ) ? $this->mAttribs[$name] : null;
698 * @return array
700 public function getAttributes() {
701 return $this->mAttribs;
705 * Gets the end part of the diff URL associated with this object
706 * Blank if no diff link should be displayed
707 * @param $forceCur
708 * @return string
710 public function diffLinkTrail( $forceCur ) {
711 if ( $this->mAttribs['rc_type'] == RC_EDIT ) {
712 $trail = "curid=" . (int)( $this->mAttribs['rc_cur_id'] ) .
713 "&oldid=" . (int)( $this->mAttribs['rc_last_oldid'] );
714 if ( $forceCur ) {
715 $trail .= '&diff=0';
716 } else {
717 $trail .= '&diff=' . (int)( $this->mAttribs['rc_this_oldid'] );
719 } else {
720 $trail = '';
722 return $trail;
726 * @return string
728 public function getIRCLine() {
729 global $wgUseRCPatrol, $wgUseNPPatrol, $wgRC2UDPInterwikiPrefix, $wgLocalInterwiki,
730 $wgCanonicalServer, $wgScript;
732 if ( $this->mAttribs['rc_type'] == RC_LOG ) {
733 // Don't use SpecialPage::getTitleFor, backwards compatibility with
734 // IRC API which expects "Log".
735 $titleObj = Title::newFromText( 'Log/' . $this->mAttribs['rc_log_type'], NS_SPECIAL );
736 } else {
737 $titleObj =& $this->getTitle();
739 $title = $titleObj->getPrefixedText();
740 $title = self::cleanupForIRC( $title );
742 if ( $this->mAttribs['rc_type'] == RC_LOG ) {
743 $url = '';
744 } else {
745 $url = $wgCanonicalServer . $wgScript;
746 if ( $this->mAttribs['rc_type'] == RC_NEW ) {
747 $query = '?oldid=' . $this->mAttribs['rc_this_oldid'];
748 } else {
749 $query = '?diff=' . $this->mAttribs['rc_this_oldid'] . '&oldid=' . $this->mAttribs['rc_last_oldid'];
751 if ( $wgUseRCPatrol || ( $this->mAttribs['rc_type'] == RC_NEW && $wgUseNPPatrol ) ) {
752 $query .= '&rcid=' . $this->mAttribs['rc_id'];
754 // HACK: We need this hook for WMF's secure server setup
755 wfRunHooks( 'IRCLineURL', array( &$url, &$query ) );
756 $url .= $query;
759 if ( $this->mAttribs['rc_old_len'] !== null && $this->mAttribs['rc_new_len'] !== null ) {
760 $szdiff = $this->mAttribs['rc_new_len'] - $this->mAttribs['rc_old_len'];
761 if ( $szdiff < -500 ) {
762 $szdiff = "\002$szdiff\002";
763 } elseif ( $szdiff >= 0 ) {
764 $szdiff = '+' . $szdiff;
766 // @todo i18n with parentheses in content language?
767 $szdiff = '(' . $szdiff . ')';
768 } else {
769 $szdiff = '';
772 $user = self::cleanupForIRC( $this->mAttribs['rc_user_text'] );
774 if ( $this->mAttribs['rc_type'] == RC_LOG ) {
775 $targetText = $this->getTitle()->getPrefixedText();
776 $comment = self::cleanupForIRC( str_replace( "[[$targetText]]", "[[\00302$targetText\00310]]", $this->mExtra['actionCommentIRC'] ) );
777 $flag = $this->mAttribs['rc_log_action'];
778 } else {
779 $comment = self::cleanupForIRC( $this->mAttribs['rc_comment'] );
780 $flag = '';
781 if ( !$this->mAttribs['rc_patrolled'] && ( $wgUseRCPatrol || $this->mAttribs['rc_type'] == RC_NEW && $wgUseNPPatrol ) ) {
782 $flag .= '!';
784 $flag .= ( $this->mAttribs['rc_type'] == RC_NEW ? "N" : "" ) . ( $this->mAttribs['rc_minor'] ? "M" : "" ) . ( $this->mAttribs['rc_bot'] ? "B" : "" );
787 if ( $wgRC2UDPInterwikiPrefix === true && $wgLocalInterwiki !== false ) {
788 $prefix = $wgLocalInterwiki;
789 } elseif ( $wgRC2UDPInterwikiPrefix ) {
790 $prefix = $wgRC2UDPInterwikiPrefix;
791 } else {
792 $prefix = false;
794 if ( $prefix !== false ) {
795 $titleString = "\00314[[\00303$prefix:\00307$title\00314]]";
796 } else {
797 $titleString = "\00314[[\00307$title\00314]]";
800 # see http://www.irssi.org/documentation/formats for some colour codes. prefix is \003,
801 # no colour (\003) switches back to the term default
802 $fullString = "$titleString\0034 $flag\00310 " .
803 "\00302$url\003 \0035*\003 \00303$user\003 \0035*\003 $szdiff \00310$comment\003\n";
805 return $fullString;
809 * Returns the change size (HTML).
810 * The lengths can be given optionally.
811 * @param $old int
812 * @param $new int
813 * @return string
815 public function getCharacterDifference( $old = 0, $new = 0 ) {
816 if ( $old === 0 ) {
817 $old = $this->mAttribs['rc_old_len'];
819 if ( $new === 0 ) {
820 $new = $this->mAttribs['rc_new_len'];
822 if ( $old === null || $new === null ) {
823 return '';
825 return ChangesList::showCharacterDifference( $old, $new );
829 * Purge expired changes from the recentchanges table
830 * @since 1.22
832 public static function purgeExpiredChanges() {
833 if ( wfReadOnly() ) {
834 return;
837 $method = __METHOD__;
838 $dbw = wfGetDB( DB_MASTER );
839 $dbw->onTransactionIdle( function() use ( $dbw, $method ) {
840 global $wgRCMaxAge;
842 $cutoff = $dbw->timestamp( time() - $wgRCMaxAge );
843 $dbw->delete(
844 'recentchanges',
845 array( 'rc_timestamp < ' . $dbw->addQuotes( $cutoff ) ),
846 $method
848 } );
851 private static function checkIPAddress( $ip ) {
852 global $wgRequest;
853 if ( $ip ) {
854 if ( !IP::isIPAddress( $ip ) ) {
855 throw new MWException( "Attempt to write \"" . $ip . "\" as an IP address into recent changes" );
857 } else {
858 $ip = $wgRequest->getIP();
859 if ( !$ip ) {
860 $ip = '';
863 return $ip;