Quick ugly fix to avoid duplicate log entries in rc feed.
[lhc/web/wiklou.git] / includes / RecentChange.php
1 <?php
2
3 /**
4 * Utility class for creating new RC entries
5 *
6 * mAttribs:
7 * rc_id id of the row in the recentchanges table
8 * rc_timestamp time the entry was made
9 * rc_cur_time timestamp on the cur row
10 * rc_namespace namespace #
11 * rc_title non-prefixed db key
12 * rc_type is new entry, used to determine whether updating is necessary
13 * rc_minor is minor
14 * rc_cur_id page_id of associated page entry
15 * rc_user user id who made the entry
16 * rc_user_text user name who made the entry
17 * rc_comment edit summary
18 * rc_this_oldid rev_id associated with this entry (or zero)
19 * rc_last_oldid rev_id associated with the entry before this one (or zero)
20 * rc_bot is bot, hidden
21 * rc_ip IP address of the user in dotted quad notation
22 * rc_new obsolete, use rc_type==RC_NEW
23 * rc_patrolled boolean whether or not someone has marked this edit as patrolled
24 * rc_old_len integer byte length of the text before the edit
25 * rc_new_len the same after the edit
26 * rc_deleted partial deletion
27 * rc_logid the log_id value for this log entry (or zero)
28 * rc_log_type the log type (or null)
29 * rc_log_action the log action (or null)
30 * rc_params log params
31 *
32 * mExtra:
33 * prefixedDBkey prefixed db key, used by external app via msg queue
34 * lastTimestamp timestamp of previous entry, used in WHERE clause during update
35 * lang the interwiki prefix, automatically set in save()
36 * oldSize text size before the change
37 * newSize text size after the change
38 *
39 * temporary: not stored in the database
40 * notificationtimestamp
41 * numberofWatchingusers
42 *
43 * @todo document functions and variables
44 */
45 class RecentChange {
46 var $mAttribs = array(), $mExtra = array();
47
48 /**
49 * @var Title
50 */
51 var $mTitle = false;
52
53 /**
54 * @var Title
55 */
56 var $mMovedToTitle = false;
57 var $numberofWatchingusers = 0 ; # Dummy to prevent error message in SpecialRecentchangeslinked
58
59 # Factory methods
60
61 /**
62 * @param $row
63 * @return RecentChange
64 */
65 public static function newFromRow( $row ) {
66 $rc = new RecentChange;
67 $rc->loadFromRow( $row );
68 return $rc;
69 }
70
71 /**
72 * @staticw
73 * @return RecentChange
74 */
75 public static function newFromCurRow( $row ) {
76 $rc = new RecentChange;
77 $rc->loadFromCurRow( $row );
78 $rc->notificationtimestamp = false;
79 $rc->numberofWatchingusers = false;
80 return $rc;
81 }
82
83 /**
84 * Obtain the recent change with a given rc_id value
85 *
86 * @param $rcid Int rc_id value to retrieve
87 * @return RecentChange
88 */
89 public static function newFromId( $rcid ) {
90 $dbr = wfGetDB( DB_SLAVE );
91 $res = $dbr->select( 'recentchanges', '*', array( 'rc_id' => $rcid ), __METHOD__ );
92 if( $res && $dbr->numRows( $res ) > 0 ) {
93 $row = $dbr->fetchObject( $res );
94 return self::newFromRow( $row );
95 } else {
96 return null;
97 }
98 }
99
100 /**
101 * Find the first recent change matching some specific conditions
102 *
103 * @param $conds Array of conditions
104 * @param $fname Mixed: override the method name in profiling/logs
105 * @return RecentChange
106 */
107 public static function newFromConds( $conds, $fname = false ) {
108 if( $fname === false )
109 $fname = __METHOD__;
110 $dbr = wfGetDB( DB_SLAVE );
111 $res = $dbr->select(
112 'recentchanges',
113 '*',
114 $conds,
115 $fname
116 );
117 if( $res instanceof ResultWrapper && $res->numRows() > 0 ) {
118 $row = $res->fetchObject();
119 $res->free();
120 return self::newFromRow( $row );
121 }
122 return null;
123 }
124
125 # Accessors
126
127 public function setAttribs( $attribs ) {
128 $this->mAttribs = $attribs;
129 }
130
131 public function setExtra( $extra ) {
132 $this->mExtra = $extra;
133 }
134
135 /**
136 *
137 * @return Title
138 */
139 public function &getTitle() {
140 if( $this->mTitle === false ) {
141 $this->mTitle = Title::makeTitle( $this->mAttribs['rc_namespace'], $this->mAttribs['rc_title'] );
142 # Make sure the correct page ID is process cached
143 $this->mTitle->resetArticleID( $this->mAttribs['rc_cur_id'] );
144 }
145 return $this->mTitle;
146 }
147
148 /**
149 * @return bool|\Title
150 */
151 public function getMovedToTitle() {
152 if( $this->mMovedToTitle === false ) {
153 $this->mMovedToTitle = Title::makeTitle( $this->mAttribs['rc_moved_to_ns'],
154 $this->mAttribs['rc_moved_to_title'] );
155 }
156 return $this->mMovedToTitle;
157 }
158
159 /**
160 * Writes the data in this object to the database
161 * @param $noudp bool
162 */
163 public function save( $noudp = false ) {
164 global $wgLocalInterwiki, $wgPutIPinRC;
165
166 $dbw = wfGetDB( DB_MASTER );
167 if( !is_array($this->mExtra) ) {
168 $this->mExtra = array();
169 }
170 $this->mExtra['lang'] = $wgLocalInterwiki;
171
172 if( !$wgPutIPinRC ) {
173 $this->mAttribs['rc_ip'] = '';
174 }
175
176 # If our database is strict about IP addresses, use NULL instead of an empty string
177 if( $dbw->strictIPs() and $this->mAttribs['rc_ip'] == '' ) {
178 unset( $this->mAttribs['rc_ip'] );
179 }
180
181 # Fixup database timestamps
182 $this->mAttribs['rc_timestamp'] = $dbw->timestamp($this->mAttribs['rc_timestamp']);
183 $this->mAttribs['rc_cur_time'] = $dbw->timestamp($this->mAttribs['rc_cur_time']);
184 $this->mAttribs['rc_id'] = $dbw->nextSequenceValue( 'recentchanges_rc_id_seq' );
185
186 ## If we are using foreign keys, an entry of 0 for the page_id will fail, so use NULL
187 if( $dbw->cascadingDeletes() and $this->mAttribs['rc_cur_id']==0 ) {
188 unset( $this->mAttribs['rc_cur_id'] );
189 }
190
191 # Insert new row
192 $dbw->insert( 'recentchanges', $this->mAttribs, __METHOD__ );
193
194 # Set the ID
195 $this->mAttribs['rc_id'] = $dbw->insertId();
196
197 # Notify extensions
198 wfRunHooks( 'RecentChange_save', array( &$this ) );
199
200 # Notify external application via UDP
201 if ( !$noudp ) {
202 $this->notifyRC2UDP()
203 }
204
205 # E-mail notifications
206 global $wgUseEnotif, $wgShowUpdatedMarker, $wgUser;
207 if( $wgUseEnotif || $wgShowUpdatedMarker ) {
208 // Users
209 if( $this->mAttribs['rc_user'] ) {
210 $editor = ($wgUser->getId() == $this->mAttribs['rc_user']) ?
211 $wgUser : User::newFromID( $this->mAttribs['rc_user'] );
212 // Anons
213 } else {
214 $editor = ($wgUser->getName() == $this->mAttribs['rc_user_text']) ?
215 $wgUser : User::newFromName( $this->mAttribs['rc_user_text'], false );
216 }
217 # @todo FIXME: This would be better as an extension hook
218 $enotif = new EmailNotification();
219 $title = Title::makeTitle( $this->mAttribs['rc_namespace'], $this->mAttribs['rc_title'] );
220 $enotif->notifyOnPageChange( $editor, $title,
221 $this->mAttribs['rc_timestamp'],
222 $this->mAttribs['rc_comment'],
223 $this->mAttribs['rc_minor'],
224 $this->mAttribs['rc_last_oldid'] );
225 }
226 }
227
228 public function notifyRC2UDP() {
229 global $wgRC2UDPAddress, $wgRC2UDPOmitBots;
230 # Notify external application via UDP
231 if( $wgRC2UDPAddress && ( !$this->mAttribs['rc_bot'] || !$wgRC2UDPOmitBots ) ) {
232 self::sendToUDP( $this->getIRCLine() );
233 }
234 }
235
236 /**
237 * Send some text to UDP.
238 * @see RecentChange::cleanupForIRC
239 * @param $line String: text to send
240 * @param $address String: defaults to $wgRC2UDPAddress.
241 * @param $prefix String: defaults to $wgRC2UDPPrefix.
242 * @param $port Int: defaults to $wgRC2UDPPort. (Since 1.17)
243 * @return Boolean: success
244 */
245 public static function sendToUDP( $line, $address = '', $prefix = '', $port = '' ) {
246 global $wgRC2UDPAddress, $wgRC2UDPPrefix, $wgRC2UDPPort;
247 # Assume default for standard RC case
248 $address = $address ? $address : $wgRC2UDPAddress;
249 $prefix = $prefix ? $prefix : $wgRC2UDPPrefix;
250 $port = $port ? $port : $wgRC2UDPPort;
251 # Notify external application via UDP
252 if( $address ) {
253 $conn = socket_create( AF_INET, SOCK_DGRAM, SOL_UDP );
254 if( $conn ) {
255 $line = $prefix . $line;
256 wfDebug( __METHOD__ . ": sending UDP line: $line\n" );
257 socket_sendto( $conn, $line, strlen($line), 0, $address, $port );
258 socket_close( $conn );
259 return true;
260 } else {
261 wfDebug( __METHOD__ . ": failed to create UDP socket\n" );
262 }
263 }
264 return false;
265 }
266
267 /**
268 * Remove newlines, carriage returns and decode html entites
269 * @param $text String
270 * @return String
271 */
272 public static function cleanupForIRC( $text ) {
273 return Sanitizer::decodeCharReferences( str_replace( array( "\n", "\r" ), array( "", "" ), $text ) );
274 }
275
276 /**
277 * Mark a given change as patrolled
278 *
279 * @param $change Mixed: RecentChange or corresponding rc_id
280 * @param $auto Boolean: for automatic patrol
281 * @return Array See doMarkPatrolled(), or null if $change is not an existing rc_id
282 */
283 public static function markPatrolled( $change, $auto = false ) {
284 global $wgUser;
285
286 $change = $change instanceof RecentChange
287 ? $change
288 : RecentChange::newFromId($change);
289
290 if( !$change instanceof RecentChange ) {
291 return null;
292 }
293 return $change->doMarkPatrolled( $wgUser, $auto );
294 }
295
296 /**
297 * Mark this RecentChange as patrolled
298 *
299 * NOTE: Can also return 'rcpatroldisabled', 'hookaborted' and 'markedaspatrollederror-noautopatrol' as errors
300 * @param $user User object doing the action
301 * @param $auto Boolean: for automatic patrol
302 * @return array of permissions errors, see Title::getUserPermissionsErrors()
303 */
304 public function doMarkPatrolled( User $user, $auto = false ) {
305 global $wgUseRCPatrol, $wgUseNPPatrol;
306 $errors = array();
307 // If recentchanges patrol is disabled, only new pages
308 // can be patrolled
309 if( !$wgUseRCPatrol && ( !$wgUseNPPatrol || $this->getAttribute('rc_type') != RC_NEW ) ) {
310 $errors[] = array('rcpatroldisabled');
311 }
312 // Automatic patrol needs "autopatrol", ordinary patrol needs "patrol"
313 $right = $auto ? 'autopatrol' : 'patrol';
314 $errors = array_merge( $errors, $this->getTitle()->getUserPermissionsErrors( $right, $user ) );
315 if( !wfRunHooks('MarkPatrolled', array($this->getAttribute('rc_id'), &$user, false)) ) {
316 $errors[] = array('hookaborted');
317 }
318 // Users without the 'autopatrol' right can't patrol their
319 // own revisions
320 if( $user->getName() == $this->getAttribute('rc_user_text') && !$user->isAllowed('autopatrol') ) {
321 $errors[] = array('markedaspatrollederror-noautopatrol');
322 }
323 if( $errors ) {
324 return $errors;
325 }
326 // If the change was patrolled already, do nothing
327 if( $this->getAttribute('rc_patrolled') ) {
328 return array();
329 }
330 // Actually set the 'patrolled' flag in RC
331 $this->reallyMarkPatrolled();
332 // Log this patrol event
333 PatrolLog::record( $this, $auto );
334 wfRunHooks( 'MarkPatrolledComplete', array($this->getAttribute('rc_id'), &$user, false) );
335 return array();
336 }
337
338 /**
339 * Mark this RecentChange patrolled, without error checking
340 * @return Integer: number of affected rows
341 */
342 public function reallyMarkPatrolled() {
343 $dbw = wfGetDB( DB_MASTER );
344 $dbw->update(
345 'recentchanges',
346 array(
347 'rc_patrolled' => 1
348 ),
349 array(
350 'rc_id' => $this->getAttribute('rc_id')
351 ),
352 __METHOD__
353 );
354 return $dbw->affectedRows();
355 }
356
357 /**
358 * Makes an entry in the database corresponding to an edit
359 *
360 * @param $timestamp
361 * @param $title Title
362 * @param $minor
363 * @param $user User
364 * @param $comment
365 * @param $oldId
366 * @param $lastTimestamp
367 * @param $bot
368 * @param $ip string
369 * @param $oldSize int
370 * @param $newSize int
371 * @param $newId int
372 * @param $patrol int
373 * @return RecentChange
374 */
375 public static function notifyEdit( $timestamp, &$title, $minor, &$user, $comment, $oldId,
376 $lastTimestamp, $bot, $ip='', $oldSize=0, $newSize=0, $newId=0, $patrol=0 ) {
377 global $wgRequest;
378 if( !$ip ) {
379 $ip = $wgRequest->getIP();
380 if( !$ip ) $ip = '';
381 }
382
383 $rc = new RecentChange;
384 $rc->mAttribs = array(
385 'rc_timestamp' => $timestamp,
386 'rc_cur_time' => $timestamp,
387 'rc_namespace' => $title->getNamespace(),
388 'rc_title' => $title->getDBkey(),
389 'rc_type' => RC_EDIT,
390 'rc_minor' => $minor ? 1 : 0,
391 'rc_cur_id' => $title->getArticleID(),
392 'rc_user' => $user->getId(),
393 'rc_user_text' => $user->getName(),
394 'rc_comment' => $comment,
395 'rc_this_oldid' => $newId,
396 'rc_last_oldid' => $oldId,
397 'rc_bot' => $bot ? 1 : 0,
398 'rc_moved_to_ns' => 0,
399 'rc_moved_to_title' => '',
400 'rc_ip' => $ip,
401 'rc_patrolled' => intval($patrol),
402 'rc_new' => 0, # obsolete
403 'rc_old_len' => $oldSize,
404 'rc_new_len' => $newSize,
405 'rc_deleted' => 0,
406 'rc_logid' => 0,
407 'rc_log_type' => null,
408 'rc_log_action' => '',
409 'rc_params' => ''
410 );
411
412 $rc->mExtra = array(
413 'prefixedDBkey' => $title->getPrefixedDBkey(),
414 'lastTimestamp' => $lastTimestamp,
415 'oldSize' => $oldSize,
416 'newSize' => $newSize,
417 );
418 $rc->save();
419 return $rc;
420 }
421
422 /**
423 * Makes an entry in the database corresponding to page creation
424 * Note: the title object must be loaded with the new id using resetArticleID()
425 * @todo Document parameters and return
426 *
427 * @param $timestamp
428 * @param $title Title
429 * @param $minor
430 * @param $user User
431 * @param $comment
432 * @param $bot
433 * @param $ip string
434 * @param $size int
435 * @param $newId int
436 * @param $patrol int
437 * @return RecentChange
438 */
439 public static function notifyNew( $timestamp, &$title, $minor, &$user, $comment, $bot,
440 $ip='', $size=0, $newId=0, $patrol=0 ) {
441 global $wgRequest;
442 if( !$ip ) {
443 $ip = $wgRequest->getIP();
444 if( !$ip ) $ip = '';
445 }
446
447 $rc = new RecentChange;
448 $rc->mAttribs = array(
449 'rc_timestamp' => $timestamp,
450 'rc_cur_time' => $timestamp,
451 'rc_namespace' => $title->getNamespace(),
452 'rc_title' => $title->getDBkey(),
453 'rc_type' => RC_NEW,
454 'rc_minor' => $minor ? 1 : 0,
455 'rc_cur_id' => $title->getArticleID(),
456 'rc_user' => $user->getId(),
457 'rc_user_text' => $user->getName(),
458 'rc_comment' => $comment,
459 'rc_this_oldid' => $newId,
460 'rc_last_oldid' => 0,
461 'rc_bot' => $bot ? 1 : 0,
462 'rc_moved_to_ns' => 0,
463 'rc_moved_to_title' => '',
464 'rc_ip' => $ip,
465 'rc_patrolled' => intval($patrol),
466 'rc_new' => 1, # obsolete
467 'rc_old_len' => 0,
468 'rc_new_len' => $size,
469 'rc_deleted' => 0,
470 'rc_logid' => 0,
471 'rc_log_type' => null,
472 'rc_log_action' => '',
473 'rc_params' => ''
474 );
475
476 $rc->mExtra = array(
477 'prefixedDBkey' => $title->getPrefixedDBkey(),
478 'lastTimestamp' => 0,
479 'oldSize' => 0,
480 'newSize' => $size
481 );
482 $rc->save();
483 return $rc;
484 }
485
486 /**
487 * @param $timestamp
488 * @param $title
489 * @param $user
490 * @param $actionComment
491 * @param $ip string
492 * @param $type
493 * @param $action
494 * @param $target
495 * @param $logComment
496 * @param $params
497 * @param $newId int
498 * @return bool
499 */
500 public static function notifyLog( $timestamp, &$title, &$user, $actionComment, $ip='', $type,
501 $action, $target, $logComment, $params, $newId=0 )
502 {
503 global $wgLogRestrictions;
504 # Don't add private logs to RC!
505 if( isset($wgLogRestrictions[$type]) && $wgLogRestrictions[$type] != '*' ) {
506 return false;
507 }
508 $rc = self::newLogEntry( $timestamp, $title, $user, $actionComment, $ip, $type, $action,
509 $target, $logComment, $params, $newId );
510 $rc->save();
511 return true;
512 }
513
514 /**
515 * @param $timestamp
516 * @param $title Title
517 * @param $user User
518 * @param $actionComment
519 * @param $ip string
520 * @param $type
521 * @param $action
522 * @param $target Title
523 * @param $logComment
524 * @param $params
525 * @param $newId int
526 * @return RecentChange
527 */
528 public static function newLogEntry( $timestamp, &$title, &$user, $actionComment, $ip='',
529 $type, $action, $target, $logComment, $params, $newId=0 ) {
530 global $wgRequest;
531 if( !$ip ) {
532 $ip = $wgRequest->getIP();
533 if( !$ip ) {
534 $ip = '';
535 }
536 }
537
538 $rc = new RecentChange;
539 $rc->mAttribs = array(
540 'rc_timestamp' => $timestamp,
541 'rc_cur_time' => $timestamp,
542 'rc_namespace' => $target->getNamespace(),
543 'rc_title' => $target->getDBkey(),
544 'rc_type' => RC_LOG,
545 'rc_minor' => 0,
546 'rc_cur_id' => $target->getArticleID(),
547 'rc_user' => $user->getId(),
548 'rc_user_text' => $user->getName(),
549 'rc_comment' => $logComment,
550 'rc_this_oldid' => 0,
551 'rc_last_oldid' => 0,
552 'rc_bot' => $user->isAllowed( 'bot' ) ? $wgRequest->getBool( 'bot', true ) : 0,
553 'rc_moved_to_ns' => 0,
554 'rc_moved_to_title' => '',
555 'rc_ip' => $ip,
556 'rc_patrolled' => 1,
557 'rc_new' => 0, # obsolete
558 'rc_old_len' => null,
559 'rc_new_len' => null,
560 'rc_deleted' => 0,
561 'rc_logid' => $newId,
562 'rc_log_type' => $type,
563 'rc_log_action' => $action,
564 'rc_params' => $params
565 );
566 $rc->mExtra = array(
567 'prefixedDBkey' => $title->getPrefixedDBkey(),
568 'lastTimestamp' => 0,
569 'actionComment' => $actionComment, // the comment appended to the action, passed from LogPage
570 );
571 return $rc;
572 }
573
574 /**
575 * Initialises the members of this object from a mysql row object
576 *
577 * @param $row
578 */
579 public function loadFromRow( $row ) {
580 $this->mAttribs = get_object_vars( $row );
581 $this->mAttribs['rc_timestamp'] = wfTimestamp(TS_MW, $this->mAttribs['rc_timestamp']);
582 $this->mAttribs['rc_deleted'] = $row->rc_deleted; // MUST be set
583 }
584
585 /**
586 * Makes a pseudo-RC entry from a cur row
587 *
588 * @param $row
589 */
590 public function loadFromCurRow( $row ) {
591 $this->mAttribs = array(
592 'rc_timestamp' => wfTimestamp(TS_MW, $row->rev_timestamp),
593 'rc_cur_time' => $row->rev_timestamp,
594 'rc_user' => $row->rev_user,
595 'rc_user_text' => $row->rev_user_text,
596 'rc_namespace' => $row->page_namespace,
597 'rc_title' => $row->page_title,
598 'rc_comment' => $row->rev_comment,
599 'rc_minor' => $row->rev_minor_edit ? 1 : 0,
600 'rc_type' => $row->page_is_new ? RC_NEW : RC_EDIT,
601 'rc_cur_id' => $row->page_id,
602 'rc_this_oldid' => $row->rev_id,
603 'rc_last_oldid' => isset($row->rc_last_oldid) ? $row->rc_last_oldid : 0,
604 'rc_bot' => 0,
605 'rc_moved_to_ns' => 0,
606 'rc_moved_to_title' => '',
607 'rc_ip' => '',
608 'rc_id' => $row->rc_id,
609 'rc_patrolled' => $row->rc_patrolled,
610 'rc_new' => $row->page_is_new, # obsolete
611 'rc_old_len' => $row->rc_old_len,
612 'rc_new_len' => $row->rc_new_len,
613 'rc_params' => isset($row->rc_params) ? $row->rc_params : '',
614 'rc_log_type' => isset($row->rc_log_type) ? $row->rc_log_type : null,
615 'rc_log_action' => isset($row->rc_log_action) ? $row->rc_log_action : null,
616 'rc_log_id' => isset($row->rc_log_id) ? $row->rc_log_id: 0,
617 'rc_deleted' => $row->rc_deleted // MUST be set
618 );
619 }
620
621 /**
622 * Get an attribute value
623 *
624 * @param $name String Attribute name
625 * @return mixed
626 */
627 public function getAttribute( $name ) {
628 return isset( $this->mAttribs[$name] ) ? $this->mAttribs[$name] : null;
629 }
630
631 /**
632 * @return array
633 */
634 public function getAttributes() {
635 return $this->mAttribs;
636 }
637
638 /**
639 * Gets the end part of the diff URL associated with this object
640 * Blank if no diff link should be displayed
641 * @param $forceCur
642 * @return string
643 */
644 public function diffLinkTrail( $forceCur ) {
645 if( $this->mAttribs['rc_type'] == RC_EDIT ) {
646 $trail = "curid=" . (int)($this->mAttribs['rc_cur_id']) .
647 "&oldid=" . (int)($this->mAttribs['rc_last_oldid']);
648 if( $forceCur ) {
649 $trail .= '&diff=0' ;
650 } else {
651 $trail .= '&diff=' . (int)($this->mAttribs['rc_this_oldid']);
652 }
653 } else {
654 $trail = '';
655 }
656 return $trail;
657 }
658
659 /**
660 * @return string
661 */
662 public function getIRCLine() {
663 global $wgUseRCPatrol, $wgUseNPPatrol, $wgRC2UDPInterwikiPrefix, $wgLocalInterwiki,
664 $wgCanonicalServer, $wgScript;
665
666 if( $this->mAttribs['rc_type'] == RC_LOG ) {
667 $titleObj = SpecialPage::getTitleFor( 'Log', $this->mAttribs['rc_log_type'] );
668 } else {
669 $titleObj =& $this->getTitle();
670 }
671 $title = $titleObj->getPrefixedText();
672 $title = self::cleanupForIRC( $title );
673
674 if( $this->mAttribs['rc_type'] == RC_LOG ) {
675 $url = '';
676 } else {
677 $url = $wgCanonicalServer . $wgScript;
678 if( $this->mAttribs['rc_type'] == RC_NEW ) {
679 $query = '?oldid=' . $this->mAttribs['rc_this_oldid'];
680 } else {
681 $query = '?diff=' . $this->mAttribs['rc_this_oldid'] . '&oldid=' . $this->mAttribs['rc_last_oldid'];
682 }
683 if ( $wgUseRCPatrol || ( $this->mAttribs['rc_type'] == RC_NEW && $wgUseNPPatrol ) ) {
684 $query .= '&rcid=' . $this->mAttribs['rc_id'];
685 }
686 // HACK: We need this hook for WMF's secure server setup
687 wfRunHooks( 'IRCLineURL', array( &$url, &$query ) );
688 $url .= $query;
689 }
690
691 if( $this->mAttribs['rc_old_len'] !== null && $this->mAttribs['rc_new_len'] !== null ) {
692 $szdiff = $this->mAttribs['rc_new_len'] - $this->mAttribs['rc_old_len'];
693 if($szdiff < -500) {
694 $szdiff = "\002$szdiff\002";
695 } elseif($szdiff >= 0) {
696 $szdiff = '+' . $szdiff ;
697 }
698 $szdiff = '(' . $szdiff . ')' ;
699 } else {
700 $szdiff = '';
701 }
702
703 $user = self::cleanupForIRC( $this->mAttribs['rc_user_text'] );
704
705 if ( $this->mAttribs['rc_type'] == RC_LOG ) {
706 $targetText = $this->getTitle()->getPrefixedText();
707 $comment = self::cleanupForIRC( str_replace( "[[$targetText]]", "[[\00302$targetText\00310]]", $this->mExtra['actionComment'] ) );
708 $flag = $this->mAttribs['rc_log_action'];
709 } else {
710 $comment = self::cleanupForIRC( $this->mAttribs['rc_comment'] );
711 $flag = '';
712 if ( !$this->mAttribs['rc_patrolled'] && ( $wgUseRCPatrol || $this->mAttribs['rc_new'] && $wgUseNPPatrol ) ) {
713 $flag .= '!';
714 }
715 $flag .= ( $this->mAttribs['rc_new'] ? "N" : "" ) . ( $this->mAttribs['rc_minor'] ? "M" : "" ) . ( $this->mAttribs['rc_bot'] ? "B" : "" );
716 }
717
718 if ( $wgRC2UDPInterwikiPrefix === true && $wgLocalInterwiki !== false ) {
719 $prefix = $wgLocalInterwiki;
720 } elseif ( $wgRC2UDPInterwikiPrefix ) {
721 $prefix = $wgRC2UDPInterwikiPrefix;
722 } else {
723 $prefix = false;
724 }
725 if ( $prefix !== false ) {
726 $titleString = "\00314[[\00303$prefix:\00307$title\00314]]";
727 } else {
728 $titleString = "\00314[[\00307$title\00314]]";
729 }
730
731 # see http://www.irssi.org/documentation/formats for some colour codes. prefix is \003,
732 # no colour (\003) switches back to the term default
733 $fullString = "$titleString\0034 $flag\00310 " .
734 "\00302$url\003 \0035*\003 \00303$user\003 \0035*\003 $szdiff \00310$comment\003\n";
735
736 return $fullString;
737 }
738
739 /**
740 * Returns the change size (HTML).
741 * The lengths can be given optionally.
742 * @param $old int
743 * @param $new int
744 * @return string
745 */
746 public function getCharacterDifference( $old = 0, $new = 0 ) {
747 if( $old === 0 ) {
748 $old = $this->mAttribs['rc_old_len'];
749 }
750 if( $new === 0 ) {
751 $new = $this->mAttribs['rc_new_len'];
752 }
753 if( $old === null || $new === null ) {
754 return '';
755 }
756 return ChangesList::showCharacterDifference( $old, $new );
757 }
758 }