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