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