Refactor getCharacterDifference()
authorAaron Schulz <aaron@users.mediawiki.org>
Sun, 16 Nov 2008 23:18:43 +0000 (23:18 +0000)
committerAaron Schulz <aaron@users.mediawiki.org>
Sun, 16 Nov 2008 23:18:43 +0000 (23:18 +0000)
includes/ChangesList.php
includes/RecentChange.php

index 469b067..7cdd2d0 100644 (file)
@@ -99,6 +99,30 @@ class ChangesList {
                $this->rclistOpen = false;
                return '';
        }
+       
+       /**
+        * Show formatted char difference
+        * @param int $old bytes
+        * @param int $new bytes
+        * @returns string
+        */
+       public static function showCharacterDifference( $old, $new ) {
+               global $wgRCChangedSizeThreshold, $wgLang;
+               $szdiff = $new - $old;
+               $formatedSize = wfMsgExt( 'rc-change-size', array( 'parsemag', 'escape'), $wgLang->formatNum($szdiff) );
+               if( abs( $szdiff ) > abs( $wgRCChangedSizeThreshold ) ) {
+                       $tag = 'strong';
+               } else {
+                   $tag = 'span';
+               }
+               if( $szdiff === 0 ) {
+                       return "<$tag class='mw-plusminus-null'>($formatedSize)</$tag>";
+               } elseif( $szdiff > 0 ) {
+                       return "<$tag class='mw-plusminus-pos'>(+$formatedSize)</$tag>";
+           } else {
+                       return "<$tag class='mw-plusminus-neg'>($formatedSize)</$tag>";
+               }
+       }
 
        /**
         * Returns text for the end of RC
index d071466..f628fdc 100644 (file)
@@ -668,37 +668,15 @@ class RecentChange
         * The lengths can be given optionally.
         */
        public function getCharacterDifference( $old = 0, $new = 0 ) {
-               global $wgRCChangedSizeThreshold, $wgLang;
-
                if( $old === 0 ) {
                        $old = $this->mAttribs['rc_old_len'];
                }
                if( $new === 0 ) {
                        $new = $this->mAttribs['rc_new_len'];
                }
-
                if( $old === NULL || $new === NULL ) {
                        return '';
                }
-
-               $szdiff = $new - $old;
-               $formatedSize = wfMsgExt( 'rc-change-size', array( 'parsemag', 'escape'),
-                       $wgLang->formatNum($szdiff) );
-
-               
-               if( abs( $szdiff ) > abs( $wgRCChangedSizeThreshold ) ) {
-                       $tag = 'strong';
-               } 
-               else{
-                   $tag = 'span';
-               }
-
-               if( $szdiff === 0 ) {
-                       return "<$tag class='mw-plusminus-null'>($formatedSize)</$tag>";
-               } elseif( $szdiff > 0 ) {
-                       return "<$tag class='mw-plusminus-pos'>(+$formatedSize)</$tag>";
-           } else {
-                       return "<$tag class='mw-plusminus-neg'>($formatedSize)</$tag>";
-               }
+               return ChangesList::showCharacterDifference( $old, $new );
        }
 }