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