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