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