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