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