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