(bug 34702) More localised parentheses.
[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;
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 # Fixup database timestamps
187 $this->mAttribs['rc_timestamp'] = $dbw->timestamp($this->mAttribs['rc_timestamp']);
188 $this->mAttribs['rc_cur_time'] = $dbw->timestamp($this->mAttribs['rc_cur_time']);
189 $this->mAttribs['rc_id'] = $dbw->nextSequenceValue( 'recentchanges_rc_id_seq' );
190
191 ## If we are using foreign keys, an entry of 0 for the page_id will fail, so use NULL
192 if( $dbw->cascadingDeletes() and $this->mAttribs['rc_cur_id']==0 ) {
193 unset( $this->mAttribs['rc_cur_id'] );
194 }
195
196 # Insert new row
197 $dbw->insert( 'recentchanges', $this->mAttribs, __METHOD__ );
198
199 # Set the ID
200 $this->mAttribs['rc_id'] = $dbw->insertId();
201
202 # Notify extensions
203 wfRunHooks( 'RecentChange_save', array( &$this ) );
204
205 # Notify external application via UDP
206 if ( !$noudp ) {
207 $this->notifyRC2UDP();
208 }
209
210 # E-mail notifications
211 global $wgUseEnotif, $wgShowUpdatedMarker, $wgUser;
212 if( $wgUseEnotif || $wgShowUpdatedMarker ) {
213 // Users
214 if( $this->mAttribs['rc_user'] ) {
215 $editor = ($wgUser->getId() == $this->mAttribs['rc_user']) ?
216 $wgUser : User::newFromID( $this->mAttribs['rc_user'] );
217 // Anons
218 } else {
219 $editor = ($wgUser->getName() == $this->mAttribs['rc_user_text']) ?
220 $wgUser : User::newFromName( $this->mAttribs['rc_user_text'], false );
221 }
222 $title = Title::makeTitle( $this->mAttribs['rc_namespace'], $this->mAttribs['rc_title'] );
223
224 # @todo FIXME: This would be better as an extension hook
225 $enotif = new EmailNotification();
226 $status = $enotif->notifyOnPageChange( $editor, $title,
227 $this->mAttribs['rc_timestamp'],
228 $this->mAttribs['rc_comment'],
229 $this->mAttribs['rc_minor'],
230 $this->mAttribs['rc_last_oldid'] );
231 }
232 }
233
234 public function notifyRC2UDP() {
235 global $wgRC2UDPAddress, $wgRC2UDPOmitBots;
236 # Notify external application via UDP
237 if( $wgRC2UDPAddress && ( !$this->mAttribs['rc_bot'] || !$wgRC2UDPOmitBots ) ) {
238 self::sendToUDP( $this->getIRCLine() );
239 }
240 }
241
242 /**
243 * Send some text to UDP.
244 * @see RecentChange::cleanupForIRC
245 * @param $line String: text to send
246 * @param $address String: defaults to $wgRC2UDPAddress.
247 * @param $prefix String: defaults to $wgRC2UDPPrefix.
248 * @param $port Int: defaults to $wgRC2UDPPort. (Since 1.17)
249 * @return Boolean: success
250 */
251 public static function sendToUDP( $line, $address = '', $prefix = '', $port = '' ) {
252 global $wgRC2UDPAddress, $wgRC2UDPPrefix, $wgRC2UDPPort;
253 # Assume default for standard RC case
254 $address = $address ? $address : $wgRC2UDPAddress;
255 $prefix = $prefix ? $prefix : $wgRC2UDPPrefix;
256 $port = $port ? $port : $wgRC2UDPPort;
257 # Notify external application via UDP
258 if( $address ) {
259 $conn = socket_create( AF_INET, SOCK_DGRAM, SOL_UDP );
260 if( $conn ) {
261 $line = $prefix . $line;
262 wfDebug( __METHOD__ . ": sending UDP line: $line\n" );
263 socket_sendto( $conn, $line, strlen($line), 0, $address, $port );
264 socket_close( $conn );
265 return true;
266 } else {
267 wfDebug( __METHOD__ . ": failed to create UDP socket\n" );
268 }
269 }
270 return false;
271 }
272
273 /**
274 * Remove newlines, carriage returns and decode html entites
275 * @param $text String
276 * @return String
277 */
278 public static function cleanupForIRC( $text ) {
279 return Sanitizer::decodeCharReferences( str_replace( array( "\n", "\r" ), array( "", "" ), $text ) );
280 }
281
282 /**
283 * Mark a given change as patrolled
284 *
285 * @param $change Mixed: RecentChange or corresponding rc_id
286 * @param $auto Boolean: for automatic patrol
287 * @return Array See doMarkPatrolled(), or null if $change is not an existing rc_id
288 */
289 public static function markPatrolled( $change, $auto = false ) {
290 global $wgUser;
291
292 $change = $change instanceof RecentChange
293 ? $change
294 : RecentChange::newFromId($change);
295
296 if( !$change instanceof RecentChange ) {
297 return null;
298 }
299 return $change->doMarkPatrolled( $wgUser, $auto );
300 }
301
302 /**
303 * Mark this RecentChange as patrolled
304 *
305 * NOTE: Can also return 'rcpatroldisabled', 'hookaborted' and 'markedaspatrollederror-noautopatrol' as errors
306 * @param $user User object doing the action
307 * @param $auto Boolean: for automatic patrol
308 * @return array of permissions errors, see Title::getUserPermissionsErrors()
309 */
310 public function doMarkPatrolled( User $user, $auto = false ) {
311 global $wgUseRCPatrol, $wgUseNPPatrol;
312 $errors = array();
313 // If recentchanges patrol is disabled, only new pages
314 // can be patrolled
315 if( !$wgUseRCPatrol && ( !$wgUseNPPatrol || $this->getAttribute('rc_type') != RC_NEW ) ) {
316 $errors[] = array('rcpatroldisabled');
317 }
318 // Automatic patrol needs "autopatrol", ordinary patrol needs "patrol"
319 $right = $auto ? 'autopatrol' : 'patrol';
320 $errors = array_merge( $errors, $this->getTitle()->getUserPermissionsErrors( $right, $user ) );
321 if( !wfRunHooks('MarkPatrolled', array($this->getAttribute('rc_id'), &$user, false)) ) {
322 $errors[] = array('hookaborted');
323 }
324 // Users without the 'autopatrol' right can't patrol their
325 // own revisions
326 if( $user->getName() == $this->getAttribute('rc_user_text') && !$user->isAllowed('autopatrol') ) {
327 $errors[] = array('markedaspatrollederror-noautopatrol');
328 }
329 if( $errors ) {
330 return $errors;
331 }
332 // If the change was patrolled already, do nothing
333 if( $this->getAttribute('rc_patrolled') ) {
334 return array();
335 }
336 // Actually set the 'patrolled' flag in RC
337 $this->reallyMarkPatrolled();
338 // Log this patrol event
339 PatrolLog::record( $this, $auto, $user );
340 wfRunHooks( 'MarkPatrolledComplete', array($this->getAttribute('rc_id'), &$user, false) );
341 return array();
342 }
343
344 /**
345 * Mark this RecentChange patrolled, without error checking
346 * @return Integer: number of affected rows
347 */
348 public function reallyMarkPatrolled() {
349 $dbw = wfGetDB( DB_MASTER );
350 $dbw->update(
351 'recentchanges',
352 array(
353 'rc_patrolled' => 1
354 ),
355 array(
356 'rc_id' => $this->getAttribute('rc_id')
357 ),
358 __METHOD__
359 );
360 return $dbw->affectedRows();
361 }
362
363 /**
364 * Makes an entry in the database corresponding to an edit
365 *
366 * @param $timestamp
367 * @param $title Title
368 * @param $minor
369 * @param $user User
370 * @param $comment
371 * @param $oldId
372 * @param $lastTimestamp
373 * @param $bot
374 * @param $ip string
375 * @param $oldSize int
376 * @param $newSize int
377 * @param $newId int
378 * @param $patrol int
379 * @return RecentChange
380 */
381 public static function notifyEdit( $timestamp, &$title, $minor, &$user, $comment, $oldId,
382 $lastTimestamp, $bot, $ip='', $oldSize=0, $newSize=0, $newId=0, $patrol=0 ) {
383 global $wgRequest;
384 if( !$ip ) {
385 $ip = $wgRequest->getIP();
386 if( !$ip ) $ip = '';
387 }
388
389 $rc = new RecentChange;
390 $rc->mAttribs = array(
391 'rc_timestamp' => $timestamp,
392 'rc_cur_time' => $timestamp,
393 'rc_namespace' => $title->getNamespace(),
394 'rc_title' => $title->getDBkey(),
395 'rc_type' => RC_EDIT,
396 'rc_minor' => $minor ? 1 : 0,
397 'rc_cur_id' => $title->getArticleID(),
398 'rc_user' => $user->getId(),
399 'rc_user_text' => $user->getName(),
400 'rc_comment' => $comment,
401 'rc_this_oldid' => $newId,
402 'rc_last_oldid' => $oldId,
403 'rc_bot' => $bot ? 1 : 0,
404 'rc_moved_to_ns' => 0,
405 'rc_moved_to_title' => '',
406 'rc_ip' => $ip,
407 'rc_patrolled' => intval($patrol),
408 'rc_new' => 0, # obsolete
409 'rc_old_len' => $oldSize,
410 'rc_new_len' => $newSize,
411 'rc_deleted' => 0,
412 'rc_logid' => 0,
413 'rc_log_type' => null,
414 'rc_log_action' => '',
415 'rc_params' => ''
416 );
417
418 $rc->mExtra = array(
419 'prefixedDBkey' => $title->getPrefixedDBkey(),
420 'lastTimestamp' => $lastTimestamp,
421 'oldSize' => $oldSize,
422 'newSize' => $newSize,
423 );
424 $rc->save();
425 return $rc;
426 }
427
428 /**
429 * Makes an entry in the database corresponding to page creation
430 * Note: the title object must be loaded with the new id using resetArticleID()
431 * @todo Document parameters and return
432 *
433 * @param $timestamp
434 * @param $title Title
435 * @param $minor
436 * @param $user User
437 * @param $comment
438 * @param $bot
439 * @param $ip string
440 * @param $size int
441 * @param $newId int
442 * @param $patrol int
443 * @return RecentChange
444 */
445 public static function notifyNew( $timestamp, &$title, $minor, &$user, $comment, $bot,
446 $ip='', $size=0, $newId=0, $patrol=0 ) {
447 global $wgRequest;
448 if( !$ip ) {
449 $ip = $wgRequest->getIP();
450 if( !$ip ) {
451 $ip = '';
452 }
453 }
454
455 $rc = new RecentChange;
456 $rc->mAttribs = array(
457 'rc_timestamp' => $timestamp,
458 'rc_cur_time' => $timestamp,
459 'rc_namespace' => $title->getNamespace(),
460 'rc_title' => $title->getDBkey(),
461 'rc_type' => RC_NEW,
462 'rc_minor' => $minor ? 1 : 0,
463 'rc_cur_id' => $title->getArticleID(),
464 'rc_user' => $user->getId(),
465 'rc_user_text' => $user->getName(),
466 'rc_comment' => $comment,
467 'rc_this_oldid' => $newId,
468 'rc_last_oldid' => 0,
469 'rc_bot' => $bot ? 1 : 0,
470 'rc_moved_to_ns' => 0,
471 'rc_moved_to_title' => '',
472 'rc_ip' => $ip,
473 'rc_patrolled' => intval($patrol),
474 'rc_new' => 1, # obsolete
475 'rc_old_len' => 0,
476 'rc_new_len' => $size,
477 'rc_deleted' => 0,
478 'rc_logid' => 0,
479 'rc_log_type' => null,
480 'rc_log_action' => '',
481 'rc_params' => ''
482 );
483
484 $rc->mExtra = array(
485 'prefixedDBkey' => $title->getPrefixedDBkey(),
486 'lastTimestamp' => 0,
487 'oldSize' => 0,
488 'newSize' => $size
489 );
490 $rc->save();
491 return $rc;
492 }
493
494 /**
495 * @param $timestamp
496 * @param $title
497 * @param $user
498 * @param $actionComment
499 * @param $ip string
500 * @param $type
501 * @param $action
502 * @param $target
503 * @param $logComment
504 * @param $params
505 * @param $newId int
506 * @param $actionCommentIRC string
507 * @return bool
508 */
509 public static function notifyLog( $timestamp, &$title, &$user, $actionComment, $ip, $type,
510 $action, $target, $logComment, $params, $newId=0, $actionCommentIRC='' )
511 {
512 global $wgLogRestrictions;
513 # Don't add private logs to RC!
514 if( isset($wgLogRestrictions[$type]) && $wgLogRestrictions[$type] != '*' ) {
515 return false;
516 }
517 $rc = self::newLogEntry( $timestamp, $title, $user, $actionComment, $ip, $type, $action,
518 $target, $logComment, $params, $newId, $actionCommentIRC );
519 $rc->save();
520 return true;
521 }
522
523 /**
524 * @param $timestamp
525 * @param $title Title
526 * @param $user User
527 * @param $actionComment
528 * @param $ip string
529 * @param $type
530 * @param $action
531 * @param $target Title
532 * @param $logComment
533 * @param $params
534 * @param $newId int
535 * @param $actionCommentIRC string
536 * @return RecentChange
537 */
538 public static function newLogEntry( $timestamp, &$title, &$user, $actionComment, $ip,
539 $type, $action, $target, $logComment, $params, $newId=0, $actionCommentIRC='' ) {
540 global $wgRequest;
541 if( !$ip ) {
542 $ip = $wgRequest->getIP();
543 if( !$ip ) {
544 $ip = '';
545 }
546 }
547
548 $rc = new RecentChange;
549 $rc->mAttribs = array(
550 'rc_timestamp' => $timestamp,
551 'rc_cur_time' => $timestamp,
552 'rc_namespace' => $target->getNamespace(),
553 'rc_title' => $target->getDBkey(),
554 'rc_type' => RC_LOG,
555 'rc_minor' => 0,
556 'rc_cur_id' => $target->getArticleID(),
557 'rc_user' => $user->getId(),
558 'rc_user_text' => $user->getName(),
559 'rc_comment' => $logComment,
560 'rc_this_oldid' => 0,
561 'rc_last_oldid' => 0,
562 'rc_bot' => $user->isAllowed( 'bot' ) ? $wgRequest->getBool( 'bot', true ) : 0,
563 'rc_moved_to_ns' => 0,
564 'rc_moved_to_title' => '',
565 'rc_ip' => $ip,
566 'rc_patrolled' => 1,
567 'rc_new' => 0, # obsolete
568 'rc_old_len' => null,
569 'rc_new_len' => null,
570 'rc_deleted' => 0,
571 'rc_logid' => $newId,
572 'rc_log_type' => $type,
573 'rc_log_action' => $action,
574 'rc_params' => $params
575 );
576 $rc->mExtra = array(
577 'prefixedDBkey' => $title->getPrefixedDBkey(),
578 'lastTimestamp' => 0,
579 'actionComment' => $actionComment, // the comment appended to the action, passed from LogPage
580 'actionCommentIRC' => $actionCommentIRC
581 );
582 return $rc;
583 }
584
585 /**
586 * Initialises the members of this object from a mysql row object
587 *
588 * @param $row
589 */
590 public function loadFromRow( $row ) {
591 $this->mAttribs = get_object_vars( $row );
592 $this->mAttribs['rc_timestamp'] = wfTimestamp(TS_MW, $this->mAttribs['rc_timestamp']);
593 $this->mAttribs['rc_deleted'] = $row->rc_deleted; // MUST be set
594 }
595
596 /**
597 * Makes a pseudo-RC entry from a cur row
598 *
599 * @param $row
600 */
601 public function loadFromCurRow( $row ) {
602 $this->mAttribs = array(
603 'rc_timestamp' => wfTimestamp(TS_MW, $row->rev_timestamp),
604 'rc_cur_time' => $row->rev_timestamp,
605 'rc_user' => $row->rev_user,
606 'rc_user_text' => $row->rev_user_text,
607 'rc_namespace' => $row->page_namespace,
608 'rc_title' => $row->page_title,
609 'rc_comment' => $row->rev_comment,
610 'rc_minor' => $row->rev_minor_edit ? 1 : 0,
611 'rc_type' => $row->page_is_new ? RC_NEW : RC_EDIT,
612 'rc_cur_id' => $row->page_id,
613 'rc_this_oldid' => $row->rev_id,
614 'rc_last_oldid' => isset($row->rc_last_oldid) ? $row->rc_last_oldid : 0,
615 'rc_bot' => 0,
616 'rc_moved_to_ns' => 0,
617 'rc_moved_to_title' => '',
618 'rc_ip' => '',
619 'rc_id' => $row->rc_id,
620 'rc_patrolled' => $row->rc_patrolled,
621 'rc_new' => $row->page_is_new, # obsolete
622 'rc_old_len' => $row->rc_old_len,
623 'rc_new_len' => $row->rc_new_len,
624 'rc_params' => isset($row->rc_params) ? $row->rc_params : '',
625 'rc_log_type' => isset($row->rc_log_type) ? $row->rc_log_type : null,
626 'rc_log_action' => isset($row->rc_log_action) ? $row->rc_log_action : null,
627 'rc_log_id' => isset($row->rc_log_id) ? $row->rc_log_id: 0,
628 'rc_deleted' => $row->rc_deleted // MUST be set
629 );
630 }
631
632 /**
633 * Get an attribute value
634 *
635 * @param $name String Attribute name
636 * @return mixed
637 */
638 public function getAttribute( $name ) {
639 return isset( $this->mAttribs[$name] ) ? $this->mAttribs[$name] : null;
640 }
641
642 /**
643 * @return array
644 */
645 public function getAttributes() {
646 return $this->mAttribs;
647 }
648
649 /**
650 * Gets the end part of the diff URL associated with this object
651 * Blank if no diff link should be displayed
652 * @param $forceCur
653 * @return string
654 */
655 public function diffLinkTrail( $forceCur ) {
656 if( $this->mAttribs['rc_type'] == RC_EDIT ) {
657 $trail = "curid=" . (int)($this->mAttribs['rc_cur_id']) .
658 "&oldid=" . (int)($this->mAttribs['rc_last_oldid']);
659 if( $forceCur ) {
660 $trail .= '&diff=0' ;
661 } else {
662 $trail .= '&diff=' . (int)($this->mAttribs['rc_this_oldid']);
663 }
664 } else {
665 $trail = '';
666 }
667 return $trail;
668 }
669
670 /**
671 * @return string
672 */
673 public function getIRCLine() {
674 global $wgUseRCPatrol, $wgUseNPPatrol, $wgRC2UDPInterwikiPrefix, $wgLocalInterwiki,
675 $wgCanonicalServer, $wgScript;
676
677 if( $this->mAttribs['rc_type'] == RC_LOG ) {
678 $titleObj = SpecialPage::getTitleFor( 'Log', $this->mAttribs['rc_log_type'] );
679 } else {
680 $titleObj =& $this->getTitle();
681 }
682 $title = $titleObj->getPrefixedText();
683 $title = self::cleanupForIRC( $title );
684
685 if( $this->mAttribs['rc_type'] == RC_LOG ) {
686 $url = '';
687 } else {
688 $url = $wgCanonicalServer . $wgScript;
689 if( $this->mAttribs['rc_type'] == RC_NEW ) {
690 $query = '?oldid=' . $this->mAttribs['rc_this_oldid'];
691 } else {
692 $query = '?diff=' . $this->mAttribs['rc_this_oldid'] . '&oldid=' . $this->mAttribs['rc_last_oldid'];
693 }
694 if ( $wgUseRCPatrol || ( $this->mAttribs['rc_type'] == RC_NEW && $wgUseNPPatrol ) ) {
695 $query .= '&rcid=' . $this->mAttribs['rc_id'];
696 }
697 // HACK: We need this hook for WMF's secure server setup
698 wfRunHooks( 'IRCLineURL', array( &$url, &$query ) );
699 $url .= $query;
700 }
701
702 if( $this->mAttribs['rc_old_len'] !== null && $this->mAttribs['rc_new_len'] !== null ) {
703 $szdiff = $this->mAttribs['rc_new_len'] - $this->mAttribs['rc_old_len'];
704 if($szdiff < -500) {
705 $szdiff = "\002$szdiff\002";
706 } elseif($szdiff >= 0) {
707 $szdiff = '+' . $szdiff ;
708 }
709 // @todo i18n with parentheses in content language?
710 $szdiff = '(' . $szdiff . ')' ;
711 } else {
712 $szdiff = '';
713 }
714
715 $user = self::cleanupForIRC( $this->mAttribs['rc_user_text'] );
716
717 if ( $this->mAttribs['rc_type'] == RC_LOG ) {
718 $targetText = $this->getTitle()->getPrefixedText();
719 $comment = self::cleanupForIRC( str_replace( "[[$targetText]]", "[[\00302$targetText\00310]]", $this->mExtra['actionCommentIRC'] ) );
720 $flag = $this->mAttribs['rc_log_action'];
721 } else {
722 $comment = self::cleanupForIRC( $this->mAttribs['rc_comment'] );
723 $flag = '';
724 if ( !$this->mAttribs['rc_patrolled'] && ( $wgUseRCPatrol || $this->mAttribs['rc_new'] && $wgUseNPPatrol ) ) {
725 $flag .= '!';
726 }
727 $flag .= ( $this->mAttribs['rc_new'] ? "N" : "" ) . ( $this->mAttribs['rc_minor'] ? "M" : "" ) . ( $this->mAttribs['rc_bot'] ? "B" : "" );
728 }
729
730 if ( $wgRC2UDPInterwikiPrefix === true && $wgLocalInterwiki !== false ) {
731 $prefix = $wgLocalInterwiki;
732 } elseif ( $wgRC2UDPInterwikiPrefix ) {
733 $prefix = $wgRC2UDPInterwikiPrefix;
734 } else {
735 $prefix = false;
736 }
737 if ( $prefix !== false ) {
738 $titleString = "\00314[[\00303$prefix:\00307$title\00314]]";
739 } else {
740 $titleString = "\00314[[\00307$title\00314]]";
741 }
742
743 # see http://www.irssi.org/documentation/formats for some colour codes. prefix is \003,
744 # no colour (\003) switches back to the term default
745 $fullString = "$titleString\0034 $flag\00310 " .
746 "\00302$url\003 \0035*\003 \00303$user\003 \0035*\003 $szdiff \00310$comment\003\n";
747
748 return $fullString;
749 }
750
751 /**
752 * Returns the change size (HTML).
753 * The lengths can be given optionally.
754 * @param $old int
755 * @param $new int
756 * @return string
757 */
758 public function getCharacterDifference( $old = 0, $new = 0 ) {
759 if( $old === 0 ) {
760 $old = $this->mAttribs['rc_old_len'];
761 }
762 if( $new === 0 ) {
763 $new = $this->mAttribs['rc_new_len'];
764 }
765 if( $old === null || $new === null ) {
766 return '';
767 }
768 return ChangesList::showCharacterDifference( $old, $new );
769 }
770 }