Let's do this again, without all the breakages... (bug 15925) Properly bold rc bytes...
[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, $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( $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 ## FIXME: Why is this treating log entries as changes to the page?
196 ## This causes problems when pages are deleted.
197 $enotif = new EmailNotification();
198 $title = Title::makeTitle( $this->mAttribs['rc_namespace'], $this->mAttribs['rc_title'] );
199 $enotif->notifyOnPageChange( $editor, $title,
200 $this->mAttribs['rc_timestamp'],
201 $this->mAttribs['rc_comment'],
202 $this->mAttribs['rc_minor'],
203 $this->mAttribs['rc_last_oldid'] );
204 }
205
206 # Notify extensions
207 wfRunHooks( 'RecentChange_save', array( &$this ) );
208 }
209
210 /**
211 * Send some text to UDP
212 * @param string $line
213 * @param string $prefix
214 * @param string $address
215 * @return bool success
216 */
217 public static function sendToUDP( $line, $address = '', $prefix = '' ) {
218 global $wgRC2UDPAddress, $wgRC2UDPPrefix, $wgRC2UDPPort;
219 # Assume default for standard RC case
220 $address = $address ? $address : $wgRC2UDPAddress;
221 $prefix = $prefix ? $prefix : $wgRC2UDPPrefix;
222 # Notify external application via UDP
223 if( $address ) {
224 $conn = socket_create( AF_INET, SOCK_DGRAM, SOL_UDP );
225 if( $conn ) {
226 $line = $prefix . $line;
227 socket_sendto( $conn, $line, strlen($line), 0, $address, $wgRC2UDPPort );
228 socket_close( $conn );
229 return true;
230 }
231 }
232 return false;
233 }
234
235 /**
236 * Remove newlines and carriage returns
237 * @param string $line
238 * @return string
239 */
240 public static function cleanupForIRC( $text ) {
241 return str_replace(array("\n", "\r"), array("", ""), $text);
242 }
243
244 /**
245 * Mark a given change as patrolled
246 *
247 * @param mixed $change RecentChange or corresponding rc_id
248 * @param bool $auto for automatic patrol
249 * @return See doMarkPatrolled(), or null if $change is not an existing rc_id
250 */
251 public static function markPatrolled( $change, $auto = false ) {
252 $change = $change instanceof RecentChange
253 ? $change
254 : RecentChange::newFromId($change);
255 if( !$change instanceof RecentChange ) {
256 return null;
257 }
258 return $change->doMarkPatrolled( $auto );
259 }
260
261 /**
262 * Mark this RecentChange as patrolled
263 *
264 * NOTE: Can also return 'rcpatroldisabled', 'hookaborted' and 'markedaspatrollederror-noautopatrol' as errors
265 * @param bool $auto for automatic patrol
266 * @return array of permissions errors, see Title::getUserPermissionsErrors()
267 */
268 public function doMarkPatrolled( $auto = false ) {
269 global $wgUser, $wgUseRCPatrol, $wgUseNPPatrol;
270 $errors = array();
271 // If recentchanges patrol is disabled, only new pages
272 // can be patrolled
273 if ( !$wgUseRCPatrol
274 && ( !$wgUseNPPatrol || $this->getAttribute( 'rc_type' ) != RC_NEW ) )
275 {
276 $errors[] = array('rcpatroldisabled');
277 }
278
279 // Automatic patrol needs "autopatrol", ordinary patrol needs "patrol"
280 $right = $auto ? 'autopatrol' : 'patrol';
281 $errors = array_merge( $errors, $this->getTitle()->getUserPermissionsErrors( $right, $wgUser ) );
282 if( !wfRunHooks('MarkPatrolled', array($this->getAttribute('rc_id'), &$wgUser, false)) )
283 $errors[] = array('hookaborted');
284
285 // Users without the 'autopatrol' right can't patrol their
286 // own revisions
287 if( $wgUser->getName() == $this->getAttribute('rc_user_text') && !$wgUser->isAllowed('autopatrol') )
288 $errors[] = array('markedaspatrollederror-noautopatrol');
289
290 if( $errors ) {
291 return $errors;
292 }
293
294 // If the change was patrolled already, do nothing
295 if( $this->getAttribute('rc_patrolled') )
296 return array();
297
298 // Actually set the 'patrolled' flag in RC
299 $this->reallyMarkPatrolled();
300
301 // Log this patrol event
302 PatrolLog::record( $this, $auto );
303 wfRunHooks( 'MarkPatrolledComplete', array($this->getAttribute('rc_id'), &$wgUser, false) );
304 return array();
305 }
306
307 /**
308 * Mark this RecentChange patrolled, without error checking
309 * @return int Number of affected rows
310 */
311 public function reallyMarkPatrolled() {
312 $dbw = wfGetDB( DB_MASTER );
313 $dbw->update(
314 'recentchanges',
315 array(
316 'rc_patrolled' => 1
317 ),
318 array(
319 'rc_id' => $this->getAttribute('rc_id')
320 ),
321 __METHOD__
322 );
323 return $dbw->affectedRows();
324 }
325
326 # Makes an entry in the database corresponding to an edit
327 public static function notifyEdit( $timestamp, &$title, $minor, &$user, $comment,
328 $oldId, $lastTimestamp, $bot, $ip = '', $oldSize = 0, $newSize = 0, $newId = 0)
329 {
330 if ( !$ip ) {
331 $ip = wfGetIP();
332 if ( !$ip ) {
333 $ip = '';
334 }
335 }
336
337 $rc = new RecentChange;
338 $rc->mAttribs = array(
339 'rc_timestamp' => $timestamp,
340 'rc_cur_time' => $timestamp,
341 'rc_namespace' => $title->getNamespace(),
342 'rc_title' => $title->getDBkey(),
343 'rc_type' => RC_EDIT,
344 'rc_minor' => $minor ? 1 : 0,
345 'rc_cur_id' => $title->getArticleID(),
346 'rc_user' => $user->getId(),
347 'rc_user_text' => $user->getName(),
348 'rc_comment' => $comment,
349 'rc_this_oldid' => $newId,
350 'rc_last_oldid' => $oldId,
351 'rc_bot' => $bot ? 1 : 0,
352 'rc_moved_to_ns' => 0,
353 'rc_moved_to_title' => '',
354 'rc_ip' => $ip,
355 'rc_patrolled' => 0,
356 'rc_new' => 0, # obsolete
357 'rc_old_len' => $oldSize,
358 'rc_new_len' => $newSize,
359 'rc_deleted' => 0,
360 'rc_logid' => 0,
361 'rc_log_type' => null,
362 'rc_log_action' => '',
363 'rc_params' => ''
364 );
365
366 $rc->mExtra = array(
367 'prefixedDBkey' => $title->getPrefixedDBkey(),
368 'lastTimestamp' => $lastTimestamp,
369 'oldSize' => $oldSize,
370 'newSize' => $newSize,
371 );
372 $rc->save();
373 return $rc;
374 }
375
376 /**
377 * Makes an entry in the database corresponding to page creation
378 * Note: the title object must be loaded with the new id using resetArticleID()
379 * @todo Document parameters and return
380 */
381 public static function notifyNew( $timestamp, &$title, $minor, &$user, $comment, $bot,
382 $ip='', $size = 0, $newId = 0 )
383 {
384 if ( !$ip ) {
385 $ip = wfGetIP();
386 if ( !$ip ) {
387 $ip = '';
388 }
389 }
390
391 $rc = new RecentChange;
392 $rc->mAttribs = array(
393 'rc_timestamp' => $timestamp,
394 'rc_cur_time' => $timestamp,
395 'rc_namespace' => $title->getNamespace(),
396 'rc_title' => $title->getDBkey(),
397 'rc_type' => RC_NEW,
398 'rc_minor' => $minor ? 1 : 0,
399 'rc_cur_id' => $title->getArticleID(),
400 'rc_user' => $user->getId(),
401 'rc_user_text' => $user->getName(),
402 'rc_comment' => $comment,
403 'rc_this_oldid' => $newId,
404 'rc_last_oldid' => 0,
405 'rc_bot' => $bot ? 1 : 0,
406 'rc_moved_to_ns' => 0,
407 'rc_moved_to_title' => '',
408 'rc_ip' => $ip,
409 'rc_patrolled' => 0,
410 'rc_new' => 1, # obsolete
411 'rc_old_len' => 0,
412 'rc_new_len' => $size,
413 'rc_deleted' => 0,
414 'rc_logid' => 0,
415 'rc_log_type' => null,
416 'rc_log_action' => '',
417 'rc_params' => ''
418 );
419
420 $rc->mExtra = array(
421 'prefixedDBkey' => $title->getPrefixedDBkey(),
422 'lastTimestamp' => 0,
423 'oldSize' => 0,
424 'newSize' => $size
425 );
426 $rc->save();
427 return $rc;
428 }
429
430 # Makes an entry in the database corresponding to a rename
431 public static function notifyMove( $timestamp, &$oldTitle, &$newTitle, &$user, $comment, $ip='', $overRedir = false )
432 {
433 global $wgRequest;
434
435 if ( !$ip ) {
436 $ip = wfGetIP();
437 if ( !$ip ) {
438 $ip = '';
439 }
440 }
441
442 $rc = new RecentChange;
443 $rc->mAttribs = array(
444 'rc_timestamp' => $timestamp,
445 'rc_cur_time' => $timestamp,
446 'rc_namespace' => $oldTitle->getNamespace(),
447 'rc_title' => $oldTitle->getDBkey(),
448 'rc_type' => $overRedir ? RC_MOVE_OVER_REDIRECT : RC_MOVE,
449 'rc_minor' => 0,
450 'rc_cur_id' => $oldTitle->getArticleID(),
451 'rc_user' => $user->getId(),
452 'rc_user_text' => $user->getName(),
453 'rc_comment' => $comment,
454 'rc_this_oldid' => 0,
455 'rc_last_oldid' => 0,
456 'rc_bot' => $user->isAllowed( 'bot' ) ? $wgRequest->getBool( 'bot' , true ) : 0,
457 'rc_moved_to_ns' => $newTitle->getNamespace(),
458 'rc_moved_to_title' => $newTitle->getDBkey(),
459 'rc_ip' => $ip,
460 'rc_new' => 0, # obsolete
461 'rc_patrolled' => 1,
462 'rc_old_len' => NULL,
463 'rc_new_len' => NULL,
464 'rc_deleted' => 0,
465 'rc_logid' => 0, # notifyMove not used anymore
466 'rc_log_type' => null,
467 'rc_log_action' => '',
468 'rc_params' => ''
469 );
470
471 $rc->mExtra = array(
472 'prefixedDBkey' => $oldTitle->getPrefixedDBkey(),
473 'lastTimestamp' => 0,
474 'prefixedMoveTo' => $newTitle->getPrefixedDBkey()
475 );
476 $rc->save();
477 }
478
479 public static function notifyMoveToNew( $timestamp, &$oldTitle, &$newTitle, &$user, $comment, $ip='' ) {
480 RecentChange::notifyMove( $timestamp, $oldTitle, $newTitle, $user, $comment, $ip, false );
481 }
482
483 public static function notifyMoveOverRedirect( $timestamp, &$oldTitle, &$newTitle, &$user, $comment, $ip='' ) {
484 RecentChange::notifyMove( $timestamp, $oldTitle, $newTitle, $user, $comment, $ip, true );
485 }
486
487 public static function notifyLog( $timestamp, &$title, &$user, $actionComment, $ip='',
488 $type, $action, $target, $logComment, $params, $newId=0 )
489 {
490 global $wgRequest;
491
492 if ( !$ip ) {
493 $ip = wfGetIP();
494 if ( !$ip ) {
495 $ip = '';
496 }
497 }
498
499 $rc = new RecentChange;
500 $rc->mAttribs = array(
501 'rc_timestamp' => $timestamp,
502 'rc_cur_time' => $timestamp,
503 'rc_namespace' => $target->getNamespace(),
504 'rc_title' => $target->getDBkey(),
505 'rc_type' => RC_LOG,
506 'rc_minor' => 0,
507 'rc_cur_id' => $target->getArticleID(),
508 'rc_user' => $user->getId(),
509 'rc_user_text' => $user->getName(),
510 'rc_comment' => $logComment,
511 'rc_this_oldid' => 0,
512 'rc_last_oldid' => 0,
513 'rc_bot' => $user->isAllowed( 'bot' ) ? $wgRequest->getBool( 'bot', true ) : 0,
514 'rc_moved_to_ns' => 0,
515 'rc_moved_to_title' => '',
516 'rc_ip' => $ip,
517 'rc_patrolled' => 1,
518 'rc_new' => 0, # obsolete
519 'rc_old_len' => NULL,
520 'rc_new_len' => NULL,
521 'rc_deleted' => 0,
522 'rc_logid' => $newId,
523 'rc_log_type' => $type,
524 'rc_log_action' => $action,
525 'rc_params' => $params
526 );
527 $rc->mExtra = array(
528 'prefixedDBkey' => $title->getPrefixedDBkey(),
529 'lastTimestamp' => 0,
530 'actionComment' => $actionComment, // the comment appended to the action, passed from LogPage
531 );
532 $rc->save();
533 }
534
535 # Initialises the members of this object from a mysql row object
536 function loadFromRow( $row )
537 {
538 $this->mAttribs = get_object_vars( $row );
539 $this->mAttribs["rc_timestamp"] = wfTimestamp(TS_MW, $this->mAttribs["rc_timestamp"]);
540 $this->mExtra = array();
541 }
542
543 # Makes a pseudo-RC entry from a cur row
544 function loadFromCurRow( $row )
545 {
546 $this->mAttribs = array(
547 'rc_timestamp' => wfTimestamp(TS_MW, $row->rev_timestamp),
548 'rc_cur_time' => $row->rev_timestamp,
549 'rc_user' => $row->rev_user,
550 'rc_user_text' => $row->rev_user_text,
551 'rc_namespace' => $row->page_namespace,
552 'rc_title' => $row->page_title,
553 'rc_comment' => $row->rev_comment,
554 'rc_minor' => $row->rev_minor_edit ? 1 : 0,
555 'rc_type' => $row->page_is_new ? RC_NEW : RC_EDIT,
556 'rc_cur_id' => $row->page_id,
557 'rc_this_oldid' => $row->rev_id,
558 'rc_last_oldid' => isset($row->rc_last_oldid) ? $row->rc_last_oldid : 0,
559 'rc_bot' => 0,
560 'rc_moved_to_ns' => 0,
561 'rc_moved_to_title' => '',
562 'rc_ip' => '',
563 'rc_id' => $row->rc_id,
564 'rc_patrolled' => $row->rc_patrolled,
565 'rc_new' => $row->page_is_new, # obsolete
566 'rc_old_len' => $row->rc_old_len,
567 'rc_new_len' => $row->rc_new_len,
568 'rc_params' => isset($row->rc_params) ? $row->rc_params : '',
569 'rc_log_type' => isset($row->rc_log_type) ? $row->rc_log_type : null,
570 'rc_log_action' => isset($row->rc_log_action) ? $row->rc_log_action : null,
571 'rc_log_id' => isset($row->rc_log_id) ? $row->rc_log_id: 0,
572 // this one REALLY should be set...
573 'rc_deleted' => isset($row->rc_deleted) ? $row->rc_deleted: 0,
574 );
575
576 $this->mExtra = array();
577 }
578
579 /**
580 * Get an attribute value
581 *
582 * @param $name Attribute name
583 * @return mixed
584 */
585 public function getAttribute( $name ) {
586 return isset( $this->mAttribs[$name] ) ? $this->mAttribs[$name] : NULL;
587 }
588
589 /**
590 * Gets the end part of the diff URL associated with this object
591 * Blank if no diff link should be displayed
592 */
593 function diffLinkTrail( $forceCur )
594 {
595 if ( $this->mAttribs['rc_type'] == RC_EDIT ) {
596 $trail = "curid=" . (int)($this->mAttribs['rc_cur_id']) .
597 "&oldid=" . (int)($this->mAttribs['rc_last_oldid']);
598 if ( $forceCur ) {
599 $trail .= '&diff=0' ;
600 } else {
601 $trail .= '&diff=' . (int)($this->mAttribs['rc_this_oldid']);
602 }
603 } else {
604 $trail = '';
605 }
606 return $trail;
607 }
608
609 function getIRCLine() {
610 global $wgUseRCPatrol;
611
612 // FIXME: Would be good to replace these 2 extract() calls with something more explicit
613 // e.g. list ($rc_type, $rc_id) = array_values ($this->mAttribs); [or something like that]
614 extract($this->mAttribs);
615 extract($this->mExtra);
616
617 if ( $rc_type == RC_LOG ) {
618 $titleObj = Title::newFromText( "Log/$rc_log_type", NS_SPECIAL );
619 } else {
620 $titleObj =& $this->getTitle();
621 }
622 $title = $titleObj->getPrefixedText();
623 $title = self::cleanupForIRC( $title );
624
625 // FIXME: *HACK* these should be getFullURL(), hacked for SSL madness --brion 2005-12-26
626 if ( $rc_type == RC_LOG ) {
627 $url = '';
628 } elseif ( $rc_new && $wgUseRCPatrol ) {
629 $url = $titleObj->getInternalURL("rcid=$rc_id");
630 } else if ( $rc_new ) {
631 $url = $titleObj->getInternalURL();
632 } else if ( $wgUseRCPatrol ) {
633 $url = $titleObj->getInternalURL("diff=$rc_this_oldid&oldid=$rc_last_oldid&rcid=$rc_id");
634 } else {
635 $url = $titleObj->getInternalURL("diff=$rc_this_oldid&oldid=$rc_last_oldid");
636 }
637
638 if ( isset( $oldSize ) && isset( $newSize ) ) {
639 $szdiff = $newSize - $oldSize;
640 if ($szdiff < -500) {
641 $szdiff = "\002$szdiff\002";
642 } elseif ($szdiff >= 0) {
643 $szdiff = '+' . $szdiff ;
644 }
645 $szdiff = '(' . $szdiff . ')' ;
646 } else {
647 $szdiff = '';
648 }
649
650 $user = self::cleanupForIRC( $rc_user_text );
651
652 if ( $rc_type == RC_LOG ) {
653 $targetText = $this->getTitle()->getPrefixedText();
654 $comment = self::cleanupForIRC( str_replace("[[$targetText]]","[[\00302$targetText\00310]]",$actionComment) );
655 $flag = $rc_log_action;
656 } else {
657 $comment = self::cleanupForIRC( $rc_comment );
658 $flag = ($rc_new ? "N" : "") . ($rc_minor ? "M" : "") . ($rc_bot ? "B" : "");
659 }
660 # see http://www.irssi.org/documentation/formats for some colour codes. prefix is \003,
661 # no colour (\003) switches back to the term default
662 $fullString = "\00314[[\00307$title\00314]]\0034 $flag\00310 " .
663 "\00302$url\003 \0035*\003 \00303$user\003 \0035*\003 $szdiff \00310$comment\003\n";
664 return $fullString;
665 }
666
667 /**
668 * Returns the change size (HTML).
669 * The lengths can be given optionally.
670 */
671 function getCharacterDifference( $old = 0, $new = 0 ) {
672 global $wgRCChangedSizeThreshold, $wgLang;
673
674 if( $old === 0 ) {
675 $old = $this->mAttribs['rc_old_len'];
676 }
677 if( $new === 0 ) {
678 $new = $this->mAttribs['rc_new_len'];
679 }
680
681 if( $old === NULL || $new === NULL ) {
682 return '';
683 }
684
685 $szdiff = $new - $old;
686 $formatedSize = wfMsgExt( 'rc-change-size', array( 'parsemag', 'escape'),
687 $wgLang->formatNum($szdiff) );
688
689
690 if( abs( $szdiff ) > abs( $wgRCChangedSizeThreshold ) ) {
691 $tag = 'strong';
692 }
693 else{
694 $tag = 'span';
695 }
696
697 if( $szdiff === 0 ) {
698 return "<$tag class='mw-plusminus-null'>($formatedSize)</$tag>";
699 } elseif( $szdiff > 0 ) {
700 return "<$tag class='mw-plusminus-pos'>(+$formatedSize)</$tag>";
701 } else {
702 return "<$tag class='mw-plusminus-neg'>($formatedSize)</$tag>";
703 }
704 }
705 }