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