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