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