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