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