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