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