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