API: Move ApiQueryBlocks::convertHexIP() to IP::hexToIP() per Werdna's comment on...
authorRoan Kattouw <catrope@users.mediawiki.org>
Sun, 2 Nov 2008 16:50:59 +0000 (16:50 +0000)
committerRoan Kattouw <catrope@users.mediawiki.org>
Sun, 2 Nov 2008 16:50:59 +0000 (16:50 +0000)
includes/IP.php
includes/api/ApiQueryBlocks.php

index 312aaca..b9dfb73 100644 (file)
@@ -168,6 +168,24 @@ class IP {
                $ip_oct = preg_replace( '/(^|:)0+' . RE_IPV6_WORD . '/', '$1$2', $ip_oct );
                return $ip_oct;
        }
+       
+       /**
+        * Converts a hexadecimal number to an IPv4 address in octet notation
+        * @param $ip string Hex IP
+        * @return string
+        */ 
+       public static function hexToIP($ip)
+       {
+               // Converts a hexadecimal IP to nnn.nnn.nnn.nnn format
+               $dec = wfBaseConvert($ip, 16, 10);
+               $parts[3] = $dec % 256;
+               $dec /= 256;
+               $parts[2] = $dec % 256;
+               $dec /= 256;
+               $parts[1] = $dec % 256;
+               $parts[0] = $dec / 256;
+               return implode('.', array_reverse($parts));
+       }
 
        /**
         * Convert a network specification in IPv6 CIDR notation to an integer network and a number of bits
index b888b66..c3b46a6 100644 (file)
@@ -148,8 +148,8 @@ class ApiQueryBlocks extends ApiQueryBase {
                                $block['reason'] = $row->ipb_reason;
                        if($fld_range)
                        {
-                               $block['rangestart'] = self::convertHexIP($row->ipb_range_start);
-                               $block['rangeend'] = self::convertHexIP($row->ipb_range_end);
+                               $block['rangestart'] = IP::hexToIP($row->ipb_range_start);
+                               $block['rangeend'] = IP::hexToIP($row->ipb_range_end);
                        }
                        if($fld_flags)
                        {
@@ -185,19 +185,6 @@ class ApiQueryBlocks extends ApiQueryBase {
                $this->usernames[] = $name;
        }
 
-       protected static function convertHexIP($ip)
-       {
-               // Converts a hexadecimal IP to nnn.nnn.nnn.nnn format
-               $dec = wfBaseConvert($ip, 16, 10);
-               $parts[3] = $dec % 256;
-               $dec /= 256;
-               $parts[2] = $dec % 256;
-               $dec /= 256;
-               $parts[1] = $dec % 256;
-               $parts[0] = $dec / 256;
-               return implode('.', array_reverse($parts));
-       }
-
        public function getAllowedParams() {
                return array (
                        'start' => array(