r110955: also truncate rc_comment for log entries. This adds the code in save() to...
[lhc/web/wiklou.git] / includes / RecentChange.php
1 <?php
2
3 /**
4 * Utility class for creating new RC entries
5 *
6 * mAttribs:
7 * rc_id id of the row in the recentchanges table
8 * rc_timestamp time the entry was made
9 * rc_cur_time timestamp on the cur row
10 * rc_namespace namespace #
11 * rc_title non-prefixed db key
12 * rc_type is new entry, used to determine whether updating is necessary
13 * rc_minor is minor
14 * rc_cur_id page_id of associated page entry
15 * rc_user user id who made the entry
16 * rc_user_text user name who made the entry
17 * rc_comment edit summary
18 * rc_this_oldid rev_id associated with this entry (or zero)
19 * rc_last_oldid rev_id associated with the entry before this one (or zero)
20 * rc_bot is bot, hidden
21 * rc_ip IP address of the user in dotted quad notation
22 * rc_new obsolete, use rc_type==RC_NEW
23 * rc_patrolled boolean whether or not someone has marked this edit as patrolled
24 * rc_old_len integer byte length of the text before the edit
25 * rc_new_len the same after the edit
26 * rc_deleted partial deletion
27 * rc_logid the log_id value for this log entry (or zero)
28 * rc_log_type the log type (or null)
29 * rc_log_action the log action (or null)
30 * rc_params log params
31 *
32 * mExtra:
33 * prefixedDBkey prefixed db key, used by external app via msg queue
34 * lastTimestamp timestamp of previous entry, used in WHERE clause during update
35 * lang the interwiki prefix, automatically set in save()
36 * oldSize text size before the change
37 * newSize text size after the change
38 *
39 * temporary: not stored in the database
40 * notificationtimestamp
41 * numberofWatchingusers
42 *
43 * @todo document functions and variables
44 */
45 class RecentChange {
46 var $mAttribs = array(), $mExtra = array();
47
48 /**
49 * @var Title
50 */
51 var $mTitle = false;
52
53 /**
54 * @var Title
55 */
56 var $mMovedToTitle = false;
57 var $numberofWatchingusers = 0 ; # Dummy to prevent error message in SpecialRecentchangeslinked
58 var $notificationtimestamp;
59
60 # Factory methods
61
62 /**
63 * @param $row
64 * @return RecentChange
65 */
66 public static function newFromRow( $row ) {
67 $rc = new RecentChange;
68 $rc->loadFromRow( $row );
69 return $rc;
70 }
71
72 /**
73 * @param $row
74 * @return RecentChange
75 */
76 public static function newFromCurRow( $row ) {
77 $rc = new RecentChange;
78 $rc->loadFromCurRow( $row );
79 $rc->notificationtimestamp = false;
80 $rc->numberofWatchingusers = false;
81 return $rc;
82 }
83
84 /**
85 * Obtain the recent change with a given rc_id value
86 *
87 * @param $rcid Int rc_id value to retrieve
88 * @return RecentChange
89 */
90 public static function newFromId( $rcid ) {
91 $dbr = wfGetDB( DB_SLAVE );
92 $res = $dbr->select( 'recentchanges', '*', array( 'rc_id' => $rcid ), __METHOD__ );
93 if( $res && $dbr->numRows( $res ) > 0 ) {
94 $row = $dbr->fetchObject( $res );
95 return self::newFromRow( $row );
96 } else {
97 return null;
98 }
99 }
100
101 /**
102 * Find the first recent change matching some specific conditions
103 *
104 * @param $conds Array of conditions
105 * @param $fname Mixed: override the method name in profiling/logs
106 * @return RecentChange
107 */
108 public static function newFromConds( $conds, $fname = __METHOD__ ) {
109 $dbr = wfGetDB( DB_SLAVE );
110 $res = $dbr->select(
111 'recentchanges',
112 '*',
113 $conds,
114 $fname
115 );
116 if( $res instanceof ResultWrapper && $res->numRows() > 0 ) {
117 $row = $res->fetchObject();
118 $res->free();
119 return self::newFromRow( $row );
120 }
121 return null;
122 }
123
124 # Accessors
125
126 /**
127 * @param $attribs array
128 */
129 public function setAttribs( $attribs ) {
130 $this->mAttribs = $attribs;
131 }
132
133 /**
134 * @param $extra array
135 */
136 public function setExtra( $extra ) {
137 $this->mExtra = $extra;
138 }
139
140 /**
141 *
142 * @return Title
143 */
144 public function &getTitle() {
145 if( $this->mTitle === false ) {
146 $this->mTitle = Title::makeTitle( $this->mAttribs['rc_namespace'], $this->mAttribs['rc_title'] );
147 # Make sure the correct page ID is process cached
148 $this->mTitle->resetArticleID( $this->mAttribs['rc_cur_id'] );
149 }
150 return $this->mTitle;
151 }
152
153 /**
154 * @return bool|\Title
155 */
156 public function getMovedToTitle() {
157 if( $this->mMovedToTitle === false ) {
158 $this->mMovedToTitle = Title::makeTitle( $this->mAttribs['rc_moved_to_ns'],
159 $this->mAttribs['rc_moved_to_title'] );
160 }
161 return $this->mMovedToTitle;
162 }
163
164 /**
165 * Writes the data in this object to the database
166 * @param $noudp bool
167 */
168 public function save( $noudp = false ) {
169 global $wgLocalInterwiki, $wgPutIPinRC, $wgContLang;
170
171 $dbw = wfGetDB( DB_MASTER );
172 if( !is_array($this->mExtra) ) {
173 $this->mExtra = array();
174 }
175 $this->mExtra['lang'] = $wgLocalInterwiki;
176
177 if( !$wgPutIPinRC ) {
178 $this->mAttribs['rc_ip'] = '';
179 }
180
181 # If our database is strict about IP addresses, use NULL instead of an empty string
182 if( $dbw->strictIPs() and $this->mAttribs['rc_ip'] == '' ) {
183 unset( $this->mAttribs['rc_ip'] );
184 }
185
186 # Make sure summary is truncated (whole multibyte characters)
187 $this->mAttribs['rc_comment'] = $wgContLang->truncate( $this->mAttribs['rc_comment'], 255 );
188
189 # Fixup database timestamps
190 $this->mAttribs['rc_timestamp'] = $dbw->timestamp($this->mAttribs['rc_timestamp']);
191 $this->mAttribs['rc_cur_time'] = $dbw->timestamp($this->mAttribs['rc_cur_time']);
192 $this->mAttribs['rc_id'] = $dbw->nextSequenceValue( 'recentchanges_rc_id_seq' );
193
194 ## If we are using foreign keys, an entry of 0 for the page_id will fail, so use NULL
195 if( $dbw->cascadingDeletes() and $this->mAttribs['rc_cur_id']==0 ) {
196 unset( $this->mAttribs['rc_cur_id'] );
197 }
198
199 # Insert new row
200 $dbw->insert( 'recentchanges', $this->mAttribs, __METHOD__ );
201
202 # Set the ID
203 $this->mAttribs['rc_id'] = $dbw->insertId();
204
205 # Notify extensions
206 wfRunHooks( 'RecentChange_save', array( &$this ) );
207
208 # Notify external application via UDP
209 if ( !$noudp ) {
210 $this->notifyRC2UDP();
211 }
212
213 # E-mail notifications
214 global $wgUseEnotif, $wgShowUpdatedMarker, $wgUser;
215 if( $wgUseEnotif || $wgShowUpdatedMarker ) {
216 // Users
217 if( $this->mAttribs['rc_user'] ) {
218 $editor = ($wgUser->getId() == $this->mAttribs['rc_user']) ?
219 $wgUser : User::newFromID( $this->mAttribs['rc_user'] );
220 // Anons
221 } else {
222 $editor = ($wgUser->getName() == $this->mAttribs['rc_user_text']) ?
223 $wgUser : User::newFromName( $this->mAttribs['rc_user_text'], false );
224 }
225 $title = Title::makeTitle( $this->mAttribs['rc_namespace'], $this->mAttribs['rc_title'] );
226
227 # @todo FIXME: This would be better as an extension hook
228 $enotif = new EmailNotification();
229 $status = $enotif->notifyOnPageChange( $editor, $title,
230 $this->mAttribs['rc_timestamp'],
231 $this->mAttribs['rc_comment'],
232 $this->mAttribs['rc_minor'],
233 $this->mAttribs['rc_last_oldid'] );
234 }
235 }
236
237 public function notifyRC2UDP() {
238 global $wgRC2UDPAddress, $wgRC2UDPOmitBots;
239 # Notify external application via UDP
240 if( $wgRC2UDPAddress && ( !$this->mAttribs['rc_bot'] || !$wgRC2UDPOmitBots ) ) {
241 self::sendToUDP( $this->getIRCLine() );
242 }
243 }
244
245 /**
246 * Send some text to UDP.
247 * @see RecentChange::cleanupForIRC
248 * @param $line String: text to send
249 * @param $address String: defaults to $wgRC2UDPAddress.
250 * @param $prefix String: defaults to $wgRC2UDPPrefix.
251 * @param $port Int: defaults to $wgRC2UDPPort. (Since 1.17)
252 * @return Boolean: success
253 */
254 public static function sendToUDP( $line, $address = '', $prefix = '', $port = '' ) {
255 global $wgRC2UDPAddress, $wgRC2UDPPrefix, $wgRC2UDPPort;
256 # Assume default for standard RC case
257 $address = $address ? $address : $wgRC2UDPAddress;
258 $prefix = $prefix ? $prefix : $wgRC2UDPPrefix;
259 $port = $port ? $port : $wgRC2UDPPort;
260 # Notify external application via UDP
261 if( $address ) {
262 $conn = socket_create( AF_INET, SOCK_DGRAM, SOL_UDP );
263 if( $conn ) {
264 $line = $prefix . $line;
265 wfDebug( __METHOD__ . ": sending UDP line: $line\n" );
266 socket_sendto( $conn, $line, strlen($line), 0, $address, $port );
267 socket_close( $conn );
268 return true;
269 } else {
270 wfDebug( __METHOD__ . ": failed to create UDP socket\n" );
271 }
272 }
273 return false;
274 }
275
276 /**
277 * Remove newlines, carriage returns and decode html entites
278 * @param $text String
279 * @return String
280 */
281 public static function cleanupForIRC( $text ) {
282 return Sanitizer::decodeCharReferences( str_replace( array( "\n", "\r" ), array( "", "" ), $text ) );
283 }
284
285 /**
286 * Mark a given change as patrolled
287 *
288 * @param $change Mixed: RecentChange or corresponding rc_id
289 * @param $auto Boolean: for automatic patrol
290 * @return Array See doMarkPatrolled(), or null if $change is not an existing rc_id
291 */
292 public static function markPatrolled( $change, $auto = false ) {
293 global $wgUser;
294
295 $change = $change instanceof RecentChange
296 ? $change
297 : RecentChange::newFromId($change);
298
299 if( !$change instanceof RecentChange ) {
300 return null;
301 }
302 return $change->doMarkPatrolled( $wgUser, $auto );
303 }
304
305 /**
306 * Mark this RecentChange as patrolled
307 *
308 * NOTE: Can also return 'rcpatroldisabled', 'hookaborted' and 'markedaspatrollederror-noautopatrol' as errors
309 * @param $user User object doing the action
310 * @param $auto Boolean: for automatic patrol
311 * @return array of permissions errors, see Title::getUserPermissionsErrors()
312 */
313 public function doMarkPatrolled( User $user, $auto = false ) {
314 global $wgUseRCPatrol, $wgUseNPPatrol;
315 $errors = array();
316 // If recentchanges patrol is disabled, only new pages
317 // can be patrolled
318 if( !$wgUseRCPatrol && ( !$wgUseNPPatrol || $this->getAttribute('rc_type') != RC_NEW ) ) {
319 $errors[] = array('rcpatroldisabled');
320 }
321 // Automatic patrol needs "autopatrol", ordinary patrol needs "patrol"
322 $right = $auto ? 'autopatrol' : 'patrol';
323 $errors = array_merge( $errors, $this->getTitle()->getUserPermissionsErrors( $right, $user ) );
324 if( !wfRunHooks('MarkPatrolled', array($this->getAttribute('rc_id'), &$user, false)) ) {
325 $errors[] = array('hookaborted');
326 }
327 // Users without the 'autopatrol' right can't patrol their
328 // own revisions
329 if( $user->getName() == $this->getAttribute('rc_user_text') && !$user->isAllowed('autopatrol') ) {
330 $errors[] = array('markedaspatrollederror-noautopatrol');
331 }
332 if( $errors ) {
333 return $errors;
334 }
335 // If the change was patrolled already, do nothing
336 if( $this->getAttribute('rc_patrolled') ) {
337 return array();
338 }
339 // Actually set the 'patrolled' flag in RC
340 $this->reallyMarkPatrolled();
341 // Log this patrol event
342 PatrolLog::record( $this, $auto, $user );
343 wfRunHooks( 'MarkPatrolledComplete', array($this->getAttribute('rc_id'), &$user, false) );
344 return array();
345 }
346
347 /**
348 * Mark this RecentChange patrolled, without error checking
349 * @return Integer: number of affected rows
350 */
351 public function reallyMarkPatrolled() {
352 $dbw = wfGetDB( DB_MASTER );
353 $dbw->update(
354 'recentchanges',
355 array(
356 'rc_patrolled' => 1
357 ),
358 array(
359 'rc_id' => $this->getAttribute('rc_id')
360 ),
361 __METHOD__
362 );
363 return $dbw->affectedRows();
364 }
365
366 /**
367 * Makes an entry in the database corresponding to an edit
368 *
369 * @param $timestamp
370 * @param $title Title
371 * @param $minor
372 * @param $user User
373 * @param $comment
374 * @param $oldId
375 * @param $lastTimestamp
376 * @param $bot
377 * @param $ip string
378 * @param $oldSize int
379 * @param $newSize int
380 * @param $newId int
381 * @param $patrol int
382 * @return RecentChange
383 */
384 public static function notifyEdit( $timestamp, &$title, $minor, &$user, $comment, $oldId,
385 $lastTimestamp, $bot, $ip='', $oldSize=0, $newSize=0, $newId=0, $patrol=0 ) {
386 global $wgRequest;
387 if( !$ip ) {
388 $ip = $wgRequest->getIP();
389 if( !$ip ) $ip = '';
390 }
391
392 $rc = new RecentChange;
393 $rc->mAttribs = array(
394 'rc_timestamp' => $timestamp,
395 'rc_cur_time' => $timestamp,
396 'rc_namespace' => $title->getNamespace(),
397 'rc_title' => $title->getDBkey(),
398 'rc_type' => RC_EDIT,
399 'rc_minor' => $minor ? 1 : 0,
400 'rc_cur_id' => $title->getArticleID(),
401 'rc_user' => $user->getId(),
402 'rc_user_text' => $user->getName(),
403 'rc_comment' => $comment,
404 'rc_this_oldid' => $newId,
405 'rc_last_oldid' => $oldId,
406 'rc_bot' => $bot ? 1 : 0,
407 'rc_moved_to_ns' => 0,
408 'rc_moved_to_title' => '',
409 'rc_ip' => $ip,
410 'rc_patrolled' => intval($patrol),
411 'rc_new' => 0, # obsolete
412 'rc_old_len' => $oldSize,
413 'rc_new_len' => $newSize,
414 'rc_deleted' => 0,
415 'rc_logid' => 0,
416 'rc_log_type' => null,
417 'rc_log_action' => '',
418 'rc_params' => ''
419 );
420
421 $rc->mExtra = array(
422 'prefixedDBkey' => $title->getPrefixedDBkey(),
423 'lastTimestamp' => $lastTimestamp,
424 'oldSize' => $oldSize,
425 'newSize' => $newSize,
426 );
427 $rc->save();
428 return $rc;
429 }
430
431 /**
432 * Makes an entry in the database corresponding to page creation
433 * Note: the title object must be loaded with the new id using resetArticleID()
434 * @todo Document parameters and return
435 *
436 * @param $timestamp
437 * @param $title Title
438 * @param $minor
439 * @param $user User
440 * @param $comment
441 * @param $bot
442 * @param $ip string
443 * @param $size int
444 * @param $newId int
445 * @param $patrol int
446 * @return RecentChange
447 */
448 public static function notifyNew( $timestamp, &$title, $minor, &$user, $comment, $bot,
449 $ip='', $size=0, $newId=0, $patrol=0 ) {
450 global $wgRequest;
451 if( !$ip ) {
452 $ip = $wgRequest->getIP();
453 if( !$ip ) {
454 $ip = '';
455 }
456 }
457
458 $rc = new RecentChange;
459 $rc->mAttribs = array(
460 'rc_timestamp' => $timestamp,
461 'rc_cur_time' => $timestamp,
462 'rc_namespace' => $title->getNamespace(),
463 'rc_title' => $title->getDBkey(),
464 'rc_type' => RC_NEW,
465 'rc_minor' => $minor ? 1 : 0,
466 'rc_cur_id' => $title->getArticleID(),
467 'rc_user' => $user->getId(),
468 'rc_user_text' => $user->getName(),
469 'rc_comment' => $comment,
470 'rc_this_oldid' => $newId,
471 'rc_last_oldid' => 0,
472 'rc_bot' => $bot ? 1 : 0,
473 'rc_moved_to_ns' => 0,
474 'rc_moved_to_title' => '',
475 'rc_ip' => $ip,
476 'rc_patrolled' => intval($patrol),
477 'rc_new' => 1, # obsolete
478 'rc_old_len' => 0,
479 'rc_new_len' => $size,
480 'rc_deleted' => 0,
481 'rc_logid' => 0,
482 'rc_log_type' => null,
483 'rc_log_action' => '',
484 'rc_params' => ''
485 );
486
487 $rc->mExtra = array(
488 'prefixedDBkey' => $title->getPrefixedDBkey(),
489 'lastTimestamp' => 0,
490 'oldSize' => 0,
491 'newSize' => $size
492 );
493 $rc->save();
494 return $rc;
495 }
496
497 /**
498 * @param $timestamp
499 * @param $title
500 * @param $user
501 * @param $actionComment
502 * @param $ip string
503 * @param $type
504 * @param $action
505 * @param $target
506 * @param $logComment
507 * @param $params
508 * @param $newId int
509 * @param $actionCommentIRC string
510 * @return bool
511 */
512 public static function notifyLog( $timestamp, &$title, &$user, $actionComment, $ip, $type,
513 $action, $target, $logComment, $params, $newId=0, $actionCommentIRC='' )
514 {
515 global $wgLogRestrictions;
516 # Don't add private logs to RC!
517 if( isset($wgLogRestrictions[$type]) && $wgLogRestrictions[$type] != '*' ) {
518 return false;
519 }
520 $rc = self::newLogEntry( $timestamp, $title, $user, $actionComment, $ip, $type, $action,
521 $target, $logComment, $params, $newId, $actionCommentIRC );
522 $rc->save();
523 return true;
524 }
525
526 /**
527 * @param $timestamp
528 * @param $title Title
529 * @param $user User
530 * @param $actionComment
531 * @param $ip string
532 * @param $type
533 * @param $action
534 * @param $target Title
535 * @param $logComment
536 * @param $params
537 * @param $newId int
538 * @param $actionCommentIRC string
539 * @return RecentChange
540 */
541 public static function newLogEntry( $timestamp, &$title, &$user, $actionComment, $ip,
542 $type, $action, $target, $logComment, $params, $newId=0, $actionCommentIRC='' ) {
543 global $wgRequest;
544 if( !$ip ) {
545 $ip = $wgRequest->getIP();
546 if( !$ip ) {
547 $ip = '';
548 }
549 }
550
551 $rc = new RecentChange;
552 $rc->mAttribs = array(
553 'rc_timestamp' => $timestamp,
554 'rc_cur_time' => $timestamp,
555 'rc_namespace' => $target->getNamespace(),
556 'rc_title' => $target->getDBkey(),
557 'rc_type' => RC_LOG,
558 'rc_minor' => 0,
559 'rc_cur_id' => $target->getArticleID(),
560 'rc_user' => $user->getId(),
561 'rc_user_text' => $user->getName(),
562 'rc_comment' => $logComment,
563 'rc_this_oldid' => 0,
564 'rc_last_oldid' => 0,
565 'rc_bot' => $user->isAllowed( 'bot' ) ? $wgRequest->getBool( 'bot', true ) : 0,
566 'rc_moved_to_ns' => 0,
567 'rc_moved_to_title' => '',
568 'rc_ip' => $ip,
569 'rc_patrolled' => 1,
570 'rc_new' => 0, # obsolete
571 'rc_old_len' => null,
572 'rc_new_len' => null,
573 'rc_deleted' => 0,
574 'rc_logid' => $newId,
575 'rc_log_type' => $type,
576 'rc_log_action' => $action,
577 'rc_params' => $params
578 );
579 $rc->mExtra = array(
580 'prefixedDBkey' => $title->getPrefixedDBkey(),
581 'lastTimestamp' => 0,
582 'actionComment' => $actionComment, // the comment appended to the action, passed from LogPage
583 'actionCommentIRC' => $actionCommentIRC
584 );
585 return $rc;
586 }
587
588 /**
589 * Initialises the members of this object from a mysql row object
590 *
591 * @param $row
592 */
593 public function loadFromRow( $row ) {
594 $this->mAttribs = get_object_vars( $row );
595 $this->mAttribs['rc_timestamp'] = wfTimestamp(TS_MW, $this->mAttribs['rc_timestamp']);
596 $this->mAttribs['rc_deleted'] = $row->rc_deleted; // MUST be set
597 }
598
599 /**
600 * Makes a pseudo-RC entry from a cur row
601 *
602 * @param $row
603 */
604 public function loadFromCurRow( $row ) {
605 $this->mAttribs = array(
606 'rc_timestamp' => wfTimestamp(TS_MW, $row->rev_timestamp),
607 'rc_cur_time' => $row->rev_timestamp,
608 'rc_user' => $row->rev_user,
609 'rc_user_text' => $row->rev_user_text,
610 'rc_namespace' => $row->page_namespace,
611 'rc_title' => $row->page_title,
612 'rc_comment' => $row->rev_comment,
613 'rc_minor' => $row->rev_minor_edit ? 1 : 0,
614 'rc_type' => $row->page_is_new ? RC_NEW : RC_EDIT,
615 'rc_cur_id' => $row->page_id,
616 'rc_this_oldid' => $row->rev_id,
617 'rc_last_oldid' => isset($row->rc_last_oldid) ? $row->rc_last_oldid : 0,
618 'rc_bot' => 0,
619 'rc_moved_to_ns' => 0,
620 'rc_moved_to_title' => '',
621 'rc_ip' => '',
622 'rc_id' => $row->rc_id,
623 'rc_patrolled' => $row->rc_patrolled,
624 'rc_new' => $row->page_is_new, # obsolete
625 'rc_old_len' => $row->rc_old_len,
626 'rc_new_len' => $row->rc_new_len,
627 'rc_params' => isset($row->rc_params) ? $row->rc_params : '',
628 'rc_log_type' => isset($row->rc_log_type) ? $row->rc_log_type : null,
629 'rc_log_action' => isset($row->rc_log_action) ? $row->rc_log_action : null,
630 'rc_log_id' => isset($row->rc_log_id) ? $row->rc_log_id: 0,
631 'rc_deleted' => $row->rc_deleted // MUST be set
632 );
633 }
634
635 /**
636 * Get an attribute value
637 *
638 * @param $name String Attribute name
639 * @return mixed
640 */
641 public function getAttribute( $name ) {
642 return isset( $this->mAttribs[$name] ) ? $this->mAttribs[$name] : null;
643 }
644
645 /**
646 * @return array
647 */
648 public function getAttributes() {
649 return $this->mAttribs;
650 }
651
652 /**
653 * Gets the end part of the diff URL associated with this object
654 * Blank if no diff link should be displayed
655 * @param $forceCur
656 * @return string
657 */
658 public function diffLinkTrail( $forceCur ) {
659 if( $this->mAttribs['rc_type'] == RC_EDIT ) {
660 $trail = "curid=" . (int)($this->mAttribs['rc_cur_id']) .
661 "&oldid=" . (int)($this->mAttribs['rc_last_oldid']);
662 if( $forceCur ) {
663 $trail .= '&diff=0' ;
664 } else {
665 $trail .= '&diff=' . (int)($this->mAttribs['rc_this_oldid']);
666 }
667 } else {
668 $trail = '';
669 }
670 return $trail;
671 }
672
673 /**
674 * @return string
675 */
676 public function getIRCLine() {
677 global $wgUseRCPatrol, $wgUseNPPatrol, $wgRC2UDPInterwikiPrefix, $wgLocalInterwiki,
678 $wgCanonicalServer, $wgScript;
679
680 if( $this->mAttribs['rc_type'] == RC_LOG ) {
681 $titleObj = SpecialPage::getTitleFor( 'Log', $this->mAttribs['rc_log_type'] );
682 } else {
683 $titleObj =& $this->getTitle();
684 }
685 $title = $titleObj->getPrefixedText();
686 $title = self::cleanupForIRC( $title );
687
688 if( $this->mAttribs['rc_type'] == RC_LOG ) {
689 $url = '';
690 } else {
691 $url = $wgCanonicalServer . $wgScript;
692 if( $this->mAttribs['rc_type'] == RC_NEW ) {
693 $query = '?oldid=' . $this->mAttribs['rc_this_oldid'];
694 } else {
695 $query = '?diff=' . $this->mAttribs['rc_this_oldid'] . '&oldid=' . $this->mAttribs['rc_last_oldid'];
696 }
697 if ( $wgUseRCPatrol || ( $this->mAttribs['rc_type'] == RC_NEW && $wgUseNPPatrol ) ) {
698 $query .= '&rcid=' . $this->mAttribs['rc_id'];
699 }
700 // HACK: We need this hook for WMF's secure server setup
701 wfRunHooks( 'IRCLineURL', array( &$url, &$query ) );
702 $url .= $query;
703 }
704
705 if( $this->mAttribs['rc_old_len'] !== null && $this->mAttribs['rc_new_len'] !== null ) {
706 $szdiff = $this->mAttribs['rc_new_len'] - $this->mAttribs['rc_old_len'];
707 if($szdiff < -500) {
708 $szdiff = "\002$szdiff\002";
709 } elseif($szdiff >= 0) {
710 $szdiff = '+' . $szdiff ;
711 }
712 // @todo i18n with parentheses in content language?
713 $szdiff = '(' . $szdiff . ')' ;
714 } else {
715 $szdiff = '';
716 }
717
718 $user = self::cleanupForIRC( $this->mAttribs['rc_user_text'] );
719
720 if ( $this->mAttribs['rc_type'] == RC_LOG ) {
721 $targetText = $this->getTitle()->getPrefixedText();
722 $comment = self::cleanupForIRC( str_replace( "[[$targetText]]", "[[\00302$targetText\00310]]", $this->mExtra['actionCommentIRC'] ) );
723 $flag = $this->mAttribs['rc_log_action'];
724 } else {
725 $comment = self::cleanupForIRC( $this->mAttribs['rc_comment'] );
726 $flag = '';
727 if ( !$this->mAttribs['rc_patrolled'] && ( $wgUseRCPatrol || $this->mAttribs['rc_new'] && $wgUseNPPatrol ) ) {
728 $flag .= '!';
729 }
730 $flag .= ( $this->mAttribs['rc_new'] ? "N" : "" ) . ( $this->mAttribs['rc_minor'] ? "M" : "" ) . ( $this->mAttribs['rc_bot'] ? "B" : "" );
731 }
732
733 if ( $wgRC2UDPInterwikiPrefix === true && $wgLocalInterwiki !== false ) {
734 $prefix = $wgLocalInterwiki;
735 } elseif ( $wgRC2UDPInterwikiPrefix ) {
736 $prefix = $wgRC2UDPInterwikiPrefix;
737 } else {
738 $prefix = false;
739 }
740 if ( $prefix !== false ) {
741 $titleString = "\00314[[\00303$prefix:\00307$title\00314]]";
742 } else {
743 $titleString = "\00314[[\00307$title\00314]]";
744 }
745
746 # see http://www.irssi.org/documentation/formats for some colour codes. prefix is \003,
747 # no colour (\003) switches back to the term default
748 $fullString = "$titleString\0034 $flag\00310 " .
749 "\00302$url\003 \0035*\003 \00303$user\003 \0035*\003 $szdiff \00310$comment\003\n";
750
751 return $fullString;
752 }
753
754 /**
755 * Returns the change size (HTML).
756 * The lengths can be given optionally.
757 * @param $old int
758 * @param $new int
759 * @return string
760 */
761 public function getCharacterDifference( $old = 0, $new = 0 ) {
762 if( $old === 0 ) {
763 $old = $this->mAttribs['rc_old_len'];
764 }
765 if( $new === 0 ) {
766 $new = $this->mAttribs['rc_new_len'];
767 }
768 if( $old === null || $new === null ) {
769 return '';
770 }
771 return ChangesList::showCharacterDifference( $old, $new );
772 }
773 }