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