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