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