Changed sequence names to a standard <table>_<field>_seq form.
[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( 'recentchanges_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 }
201 }
202
203 public function notifyRC2UDP() {
204 global $wgRC2UDPAddress, $wgRC2UDPOmitBots;
205 # Notify external application via UDP
206 if( $wgRC2UDPAddress && ( !$this->mAttribs['rc_bot'] || !$wgRC2UDPOmitBots ) ) {
207 self::sendToUDP( $this->getIRCLine() );
208 }
209 }
210
211 /**
212 * Send some text to UDP
213 * @param string $line
214 * @param string $prefix
215 * @param string $address
216 * @return bool success
217 */
218 public static function sendToUDP( $line, $address = '', $prefix = '' ) {
219 global $wgRC2UDPAddress, $wgRC2UDPPrefix, $wgRC2UDPPort;
220 # Assume default for standard RC case
221 $address = $address ? $address : $wgRC2UDPAddress;
222 $prefix = $prefix ? $prefix : $wgRC2UDPPrefix;
223 # Notify external application via UDP
224 if( $address ) {
225 $conn = socket_create( AF_INET, SOCK_DGRAM, SOL_UDP );
226 if( $conn ) {
227 $line = $prefix . $line;
228 wfDebug( __METHOD__ . ": sending UDP line: $line\n" );
229 socket_sendto( $conn, $line, strlen($line), 0, $address, $wgRC2UDPPort );
230 socket_close( $conn );
231 return true;
232 } else {
233 wfDebug( __METHOD__ . ": failed to create UDP socket\n" );
234 }
235 }
236 return false;
237 }
238
239 /**
240 * Remove newlines, carriage returns and decode html entites
241 * @param string $line
242 * @return string
243 */
244 public static function cleanupForIRC( $text ) {
245 return Sanitizer::decodeCharReferences( str_replace( array( "\n", "\r" ), array( "", "" ), $text ) );
246 }
247
248 /**
249 * Mark a given change as patrolled
250 *
251 * @param mixed $change RecentChange or corresponding rc_id
252 * @param bool $auto for automatic patrol
253 * @return See doMarkPatrolled(), or null if $change is not an existing rc_id
254 */
255 public static function markPatrolled( $change, $auto = false ) {
256 $change = $change instanceof RecentChange
257 ? $change
258 : RecentChange::newFromId($change);
259 if( !$change instanceof RecentChange ) {
260 return null;
261 }
262 return $change->doMarkPatrolled( $auto );
263 }
264
265 /**
266 * Mark this RecentChange as patrolled
267 *
268 * NOTE: Can also return 'rcpatroldisabled', 'hookaborted' and 'markedaspatrollederror-noautopatrol' as errors
269 * @param bool $auto for automatic patrol
270 * @return array of permissions errors, see Title::getUserPermissionsErrors()
271 */
272 public function doMarkPatrolled( $auto = false ) {
273 global $wgUser, $wgUseRCPatrol, $wgUseNPPatrol;
274 $errors = array();
275 // If recentchanges patrol is disabled, only new pages
276 // can be patrolled
277 if( !$wgUseRCPatrol && ( !$wgUseNPPatrol || $this->getAttribute('rc_type') != RC_NEW ) ) {
278 $errors[] = array('rcpatroldisabled');
279 }
280 // Automatic patrol needs "autopatrol", ordinary patrol needs "patrol"
281 $right = $auto ? 'autopatrol' : 'patrol';
282 $errors = array_merge( $errors, $this->getTitle()->getUserPermissionsErrors( $right, $wgUser ) );
283 if( !wfRunHooks('MarkPatrolled', array($this->getAttribute('rc_id'), &$wgUser, false)) ) {
284 $errors[] = array('hookaborted');
285 }
286 // Users without the 'autopatrol' right can't patrol their
287 // own revisions
288 if( $wgUser->getName() == $this->getAttribute('rc_user_text') && !$wgUser->isAllowed('autopatrol') ) {
289 $errors[] = array('markedaspatrollederror-noautopatrol');
290 }
291 if( $errors ) {
292 return $errors;
293 }
294 // If the change was patrolled already, do nothing
295 if( $this->getAttribute('rc_patrolled') ) {
296 return array();
297 }
298 // Actually set the 'patrolled' flag in RC
299 $this->reallyMarkPatrolled();
300 // Log this patrol event
301 PatrolLog::record( $this, $auto );
302 wfRunHooks( 'MarkPatrolledComplete', array($this->getAttribute('rc_id'), &$wgUser, false) );
303 return array();
304 }
305
306 /**
307 * Mark this RecentChange patrolled, without error checking
308 * @return int Number of affected rows
309 */
310 public function reallyMarkPatrolled() {
311 $dbw = wfGetDB( DB_MASTER );
312 $dbw->update(
313 'recentchanges',
314 array(
315 'rc_patrolled' => 1
316 ),
317 array(
318 'rc_id' => $this->getAttribute('rc_id')
319 ),
320 __METHOD__
321 );
322 return $dbw->affectedRows();
323 }
324
325 # Makes an entry in the database corresponding to an edit
326 public static function notifyEdit( $timestamp, &$title, $minor, &$user, $comment, $oldId,
327 $lastTimestamp, $bot, $ip='', $oldSize=0, $newSize=0, $newId=0, $patrol=0 )
328 {
329 if( !$ip ) {
330 $ip = wfGetIP();
331 if( !$ip ) $ip = '';
332 }
333
334 $rc = new RecentChange;
335 $rc->mAttribs = array(
336 'rc_timestamp' => $timestamp,
337 'rc_cur_time' => $timestamp,
338 'rc_namespace' => $title->getNamespace(),
339 'rc_title' => $title->getDBkey(),
340 'rc_type' => RC_EDIT,
341 'rc_minor' => $minor ? 1 : 0,
342 'rc_cur_id' => $title->getArticleID(),
343 'rc_user' => $user->getId(),
344 'rc_user_text' => $user->getName(),
345 'rc_comment' => $comment,
346 'rc_this_oldid' => $newId,
347 'rc_last_oldid' => $oldId,
348 'rc_bot' => $bot ? 1 : 0,
349 'rc_moved_to_ns' => 0,
350 'rc_moved_to_title' => '',
351 'rc_ip' => $ip,
352 'rc_patrolled' => intval($patrol),
353 'rc_new' => 0, # obsolete
354 'rc_old_len' => $oldSize,
355 'rc_new_len' => $newSize,
356 'rc_deleted' => 0,
357 'rc_logid' => 0,
358 'rc_log_type' => null,
359 'rc_log_action' => '',
360 'rc_params' => ''
361 );
362
363 $rc->mExtra = array(
364 'prefixedDBkey' => $title->getPrefixedDBkey(),
365 'lastTimestamp' => $lastTimestamp,
366 'oldSize' => $oldSize,
367 'newSize' => $newSize,
368 );
369 $rc->save();
370 return $rc;
371 }
372
373 /**
374 * Makes an entry in the database corresponding to page creation
375 * Note: the title object must be loaded with the new id using resetArticleID()
376 * @todo Document parameters and return
377 */
378 public static function notifyNew( $timestamp, &$title, $minor, &$user, $comment, $bot,
379 $ip='', $size=0, $newId=0, $patrol=0 )
380 {
381 if( !$ip ) {
382 $ip = wfGetIP();
383 if( !$ip ) $ip = '';
384 }
385
386 $rc = new RecentChange;
387 $rc->mAttribs = array(
388 'rc_timestamp' => $timestamp,
389 'rc_cur_time' => $timestamp,
390 'rc_namespace' => $title->getNamespace(),
391 'rc_title' => $title->getDBkey(),
392 'rc_type' => RC_NEW,
393 'rc_minor' => $minor ? 1 : 0,
394 'rc_cur_id' => $title->getArticleID(),
395 'rc_user' => $user->getId(),
396 'rc_user_text' => $user->getName(),
397 'rc_comment' => $comment,
398 'rc_this_oldid' => $newId,
399 'rc_last_oldid' => 0,
400 'rc_bot' => $bot ? 1 : 0,
401 'rc_moved_to_ns' => 0,
402 'rc_moved_to_title' => '',
403 'rc_ip' => $ip,
404 'rc_patrolled' => intval($patrol),
405 'rc_new' => 1, # obsolete
406 'rc_old_len' => 0,
407 'rc_new_len' => $size,
408 'rc_deleted' => 0,
409 'rc_logid' => 0,
410 'rc_log_type' => null,
411 'rc_log_action' => '',
412 'rc_params' => ''
413 );
414
415 $rc->mExtra = array(
416 'prefixedDBkey' => $title->getPrefixedDBkey(),
417 'lastTimestamp' => 0,
418 'oldSize' => 0,
419 'newSize' => $size
420 );
421 $rc->save();
422 return $rc;
423 }
424
425 # Makes an entry in the database corresponding to a rename
426 public static function notifyMove( $timestamp, &$oldTitle, &$newTitle, &$user, $comment, $ip='', $overRedir = false )
427 {
428 global $wgRequest;
429 if( !$ip ) {
430 $ip = wfGetIP();
431 if( !$ip ) $ip = '';
432 }
433
434 $rc = new RecentChange;
435 $rc->mAttribs = array(
436 'rc_timestamp' => $timestamp,
437 'rc_cur_time' => $timestamp,
438 'rc_namespace' => $oldTitle->getNamespace(),
439 'rc_title' => $oldTitle->getDBkey(),
440 'rc_type' => $overRedir ? RC_MOVE_OVER_REDIRECT : RC_MOVE,
441 'rc_minor' => 0,
442 'rc_cur_id' => $oldTitle->getArticleID(),
443 'rc_user' => $user->getId(),
444 'rc_user_text' => $user->getName(),
445 'rc_comment' => $comment,
446 'rc_this_oldid' => 0,
447 'rc_last_oldid' => 0,
448 'rc_bot' => $user->isAllowed( 'bot' ) ? $wgRequest->getBool( 'bot' , true ) : 0,
449 'rc_moved_to_ns' => $newTitle->getNamespace(),
450 'rc_moved_to_title' => $newTitle->getDBkey(),
451 'rc_ip' => $ip,
452 'rc_new' => 0, # obsolete
453 'rc_patrolled' => 1,
454 'rc_old_len' => NULL,
455 'rc_new_len' => NULL,
456 'rc_deleted' => 0,
457 'rc_logid' => 0, # notifyMove not used anymore
458 'rc_log_type' => null,
459 'rc_log_action' => '',
460 'rc_params' => ''
461 );
462
463 $rc->mExtra = array(
464 'prefixedDBkey' => $oldTitle->getPrefixedDBkey(),
465 'lastTimestamp' => 0,
466 'prefixedMoveTo' => $newTitle->getPrefixedDBkey()
467 );
468 $rc->save();
469 }
470
471 public static function notifyMoveToNew( $timestamp, &$oldTitle, &$newTitle, &$user, $comment, $ip='' ) {
472 RecentChange::notifyMove( $timestamp, $oldTitle, $newTitle, $user, $comment, $ip, false );
473 }
474
475 public static function notifyMoveOverRedirect( $timestamp, &$oldTitle, &$newTitle, &$user, $comment, $ip='' ) {
476 RecentChange::notifyMove( $timestamp, $oldTitle, $newTitle, $user, $comment, $ip, true );
477 }
478
479 public static function notifyLog( $timestamp, &$title, &$user, $actionComment, $ip='', $type,
480 $action, $target, $logComment, $params, $newId=0 )
481 {
482 global $wgLogRestrictions;
483 # Don't add private logs to RC!
484 if( isset($wgLogRestrictions[$type]) && $wgLogRestrictions[$type] != '*' ) {
485 return false;
486 }
487 $rc = self::newLogEntry( $timestamp, $title, $user, $actionComment, $ip, $type, $action,
488 $target, $logComment, $params, $newId );
489 $rc->save();
490 return true;
491 }
492
493 public static function newLogEntry( $timestamp, &$title, &$user, $actionComment, $ip='',
494 $type, $action, $target, $logComment, $params, $newId=0 )
495 {
496 global $wgRequest;
497 if( !$ip ) {
498 $ip = wfGetIP();
499 if( !$ip ) $ip = '';
500 }
501
502 $rc = new RecentChange;
503 $rc->mAttribs = array(
504 'rc_timestamp' => $timestamp,
505 'rc_cur_time' => $timestamp,
506 'rc_namespace' => $target->getNamespace(),
507 'rc_title' => $target->getDBkey(),
508 'rc_type' => RC_LOG,
509 'rc_minor' => 0,
510 'rc_cur_id' => $target->getArticleID(),
511 'rc_user' => $user->getId(),
512 'rc_user_text' => $user->getName(),
513 'rc_comment' => $logComment,
514 'rc_this_oldid' => 0,
515 'rc_last_oldid' => 0,
516 'rc_bot' => $user->isAllowed( 'bot' ) ? $wgRequest->getBool( 'bot', true ) : 0,
517 'rc_moved_to_ns' => 0,
518 'rc_moved_to_title' => '',
519 'rc_ip' => $ip,
520 'rc_patrolled' => 1,
521 'rc_new' => 0, # obsolete
522 'rc_old_len' => NULL,
523 'rc_new_len' => NULL,
524 'rc_deleted' => 0,
525 'rc_logid' => $newId,
526 'rc_log_type' => $type,
527 'rc_log_action' => $action,
528 'rc_params' => $params
529 );
530 $rc->mExtra = array(
531 'prefixedDBkey' => $title->getPrefixedDBkey(),
532 'lastTimestamp' => 0,
533 'actionComment' => $actionComment, // the comment appended to the action, passed from LogPage
534 );
535 return $rc;
536 }
537
538 # Initialises the members of this object from a mysql row object
539 public function loadFromRow( $row ) {
540 $this->mAttribs = get_object_vars( $row );
541 $this->mAttribs['rc_timestamp'] = wfTimestamp(TS_MW, $this->mAttribs['rc_timestamp']);
542 $this->mAttribs['rc_deleted'] = $row->rc_deleted; // MUST be set
543 }
544
545 # Makes a pseudo-RC entry from a cur row
546 public function loadFromCurRow( $row ) {
547 $this->mAttribs = array(
548 'rc_timestamp' => wfTimestamp(TS_MW, $row->rev_timestamp),
549 'rc_cur_time' => $row->rev_timestamp,
550 'rc_user' => $row->rev_user,
551 'rc_user_text' => $row->rev_user_text,
552 'rc_namespace' => $row->page_namespace,
553 'rc_title' => $row->page_title,
554 'rc_comment' => $row->rev_comment,
555 'rc_minor' => $row->rev_minor_edit ? 1 : 0,
556 'rc_type' => $row->page_is_new ? RC_NEW : RC_EDIT,
557 'rc_cur_id' => $row->page_id,
558 'rc_this_oldid' => $row->rev_id,
559 'rc_last_oldid' => isset($row->rc_last_oldid) ? $row->rc_last_oldid : 0,
560 'rc_bot' => 0,
561 'rc_moved_to_ns' => 0,
562 'rc_moved_to_title' => '',
563 'rc_ip' => '',
564 'rc_id' => $row->rc_id,
565 'rc_patrolled' => $row->rc_patrolled,
566 'rc_new' => $row->page_is_new, # obsolete
567 'rc_old_len' => $row->rc_old_len,
568 'rc_new_len' => $row->rc_new_len,
569 'rc_params' => isset($row->rc_params) ? $row->rc_params : '',
570 'rc_log_type' => isset($row->rc_log_type) ? $row->rc_log_type : null,
571 'rc_log_action' => isset($row->rc_log_action) ? $row->rc_log_action : null,
572 'rc_log_id' => isset($row->rc_log_id) ? $row->rc_log_id: 0,
573 'rc_deleted' => $row->rc_deleted // MUST be set
574 );
575 }
576
577 /**
578 * Get an attribute value
579 *
580 * @param $name Attribute name
581 * @return mixed
582 */
583 public function getAttribute( $name ) {
584 return isset( $this->mAttribs[$name] ) ? $this->mAttribs[$name] : NULL;
585 }
586
587 public function getAttributes() {
588 return $this->mAttribs;
589 }
590
591 /**
592 * Gets the end part of the diff URL associated with this object
593 * Blank if no diff link should be displayed
594 */
595 public function diffLinkTrail( $forceCur ) {
596 if( $this->mAttribs['rc_type'] == RC_EDIT ) {
597 $trail = "curid=" . (int)($this->mAttribs['rc_cur_id']) .
598 "&oldid=" . (int)($this->mAttribs['rc_last_oldid']);
599 if( $forceCur ) {
600 $trail .= '&diff=0' ;
601 } else {
602 $trail .= '&diff=' . (int)($this->mAttribs['rc_this_oldid']);
603 }
604 } else {
605 $trail = '';
606 }
607 return $trail;
608 }
609
610 public function getIRCLine() {
611 global $wgUseRCPatrol, $wgUseNPPatrol, $wgRC2UDPInterwikiPrefix, $wgLocalInterwiki;
612
613 // FIXME: Would be good to replace these 2 extract() calls with something more explicit
614 // e.g. list ($rc_type, $rc_id) = array_values ($this->mAttribs); [or something like that]
615 extract($this->mAttribs);
616 extract($this->mExtra);
617
618 if( $rc_type == RC_LOG ) {
619 $titleObj = Title::newFromText( "Log/$rc_log_type", NS_SPECIAL );
620 } else {
621 $titleObj =& $this->getTitle();
622 }
623 $title = $titleObj->getPrefixedText();
624 $title = self::cleanupForIRC( $title );
625
626 if( $rc_type == RC_LOG ) {
627 $url = '';
628 } else {
629 if( $rc_type == RC_NEW ) {
630 $url = "oldid=$rc_this_oldid";
631 } else {
632 $url = "diff=$rc_this_oldid&oldid=$rc_last_oldid";
633 }
634 if( $wgUseRCPatrol || ($rc_type == RC_NEW && $wgUseNPPatrol) ) {
635 $url .= "&rcid=$rc_id";
636 }
637 // XXX: *HACK* this should use getFullURL(), hacked for SSL madness --brion 2005-12-26
638 // XXX: *HACK^2* the preg_replace() undoes much of what getInternalURL() does, but we
639 // XXX: need to call it so that URL paths on the Wikimedia secure server can be fixed
640 // XXX: by a custom GetInternalURL hook --vyznev 2008-12-10
641 $url = preg_replace( '/title=[^&]*&/', '', $titleObj->getInternalURL( $url ) );
642 }
643
644 if( isset( $oldSize ) && isset( $newSize ) ) {
645 $szdiff = $newSize - $oldSize;
646 if($szdiff < -500) {
647 $szdiff = "\002$szdiff\002";
648 } elseif($szdiff >= 0) {
649 $szdiff = '+' . $szdiff ;
650 }
651 $szdiff = '(' . $szdiff . ')' ;
652 } else {
653 $szdiff = '';
654 }
655
656 $user = self::cleanupForIRC( $rc_user_text );
657
658 if( $rc_type == RC_LOG ) {
659 $targetText = $this->getTitle()->getPrefixedText();
660 $comment = self::cleanupForIRC( str_replace("[[$targetText]]","[[\00302$targetText\00310]]",$actionComment) );
661 $flag = $rc_log_action;
662 } else {
663 $comment = self::cleanupForIRC( $rc_comment );
664 $flag = '';
665 if( !$rc_patrolled && ($wgUseRCPatrol || $rc_new && $wgUseNPPatrol) ) {
666 $flag .= '!';
667 }
668 $flag .= ($rc_new ? "N" : "") . ($rc_minor ? "M" : "") . ($rc_bot ? "B" : "");
669 }
670
671 if ( $wgRC2UDPInterwikiPrefix === true ) {
672 $prefix = $wgLocalInterwiki;
673 } elseif ( $wgRC2UDPInterwikiPrefix ) {
674 $prefix = $wgRC2UDPInterwikiPrefix;
675 } else {
676 $prefix = false;
677 }
678 if ( $prefix !== false ) {
679 $titleString = "\00314[[\00303$prefix:\00307$title\00314]]";
680 } else {
681 $titleString = "\00314[[\00307$title\00314]]";
682 }
683
684 # see http://www.irssi.org/documentation/formats for some colour codes. prefix is \003,
685 # no colour (\003) switches back to the term default
686 $fullString = "$titleString\0034 $flag\00310 " .
687 "\00302$url\003 \0035*\003 \00303$user\003 \0035*\003 $szdiff \00310$comment\003\n";
688
689 return $fullString;
690 }
691
692 /**
693 * Returns the change size (HTML).
694 * The lengths can be given optionally.
695 */
696 public function getCharacterDifference( $old = 0, $new = 0 ) {
697 if( $old === 0 ) {
698 $old = $this->mAttribs['rc_old_len'];
699 }
700 if( $new === 0 ) {
701 $new = $this->mAttribs['rc_new_len'];
702 }
703 if( $old === NULL || $new === NULL ) {
704 return '';
705 }
706 return ChangesList::showCharacterDifference( $old, $new );
707 }
708 }