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