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