Index: trunk/phase3/includes/IP.php |
— | — | @@ -69,8 +69,9 @@ |
70 | 70 | * Determine if a string is as valid IP address or network (CIDR prefix). |
71 | 71 | * SIIT IPv4-translated addresses are rejected. |
72 | 72 | * Note: canonicalize() tries to convert translated addresses to IPv4. |
73 | | - * @param string $ip possible IP address |
74 | | - * @return bool |
| 73 | + * |
| 74 | + * @param $ip String: possible IP address |
| 75 | + * @return Boolean |
75 | 76 | */ |
76 | 77 | public static function isIPAddress( $ip ) { |
77 | 78 | return (bool)preg_match( '/^' . IP_ADDRESS_STRING . '$/', $ip ); |
— | — | @@ -79,8 +80,9 @@ |
80 | 81 | /** |
81 | 82 | * Given a string, determine if it as valid IP in IPv6 only. |
82 | 83 | * Note: Unlike isValid(), this looks for networks too. |
83 | | - * @param string $ip possible IP address |
84 | | - * @return bool |
| 84 | + * |
| 85 | + * @param $ip String: possible IP address |
| 86 | + * @return Boolean |
85 | 87 | */ |
86 | 88 | public static function isIPv6( $ip ) { |
87 | 89 | return (bool)preg_match( '/^' . RE_IPV6_ADD . '(\/' . RE_IPV6_PREFIX . '|)$/', $ip ); |
— | — | @@ -89,8 +91,9 @@ |
90 | 92 | /** |
91 | 93 | * Given a string, determine if it as valid IP in IPv4 only. |
92 | 94 | * Note: Unlike isValid(), this looks for networks too. |
93 | | - * @param string $ip possible IP address |
94 | | - * @return bool |
| 95 | + * |
| 96 | + * @param $ip String: possible IP address |
| 97 | + * @return Boolean |
95 | 98 | */ |
96 | 99 | public static function isIPv4( $ip ) { |
97 | 100 | return (bool)preg_match( '/^' . RE_IP_ADD . '(\/' . RE_IP_PREFIX . '|)$/', $ip ); |
— | — | @@ -100,8 +103,9 @@ |
101 | 104 | * Validate an IP address. Ranges are NOT considered valid. |
102 | 105 | * SIIT IPv4-translated addresses are rejected. |
103 | 106 | * Note: canonicalize() tries to convert translated addresses to IPv4. |
104 | | - * @param string $ip |
105 | | - * @return boolean True if it is valid. |
| 107 | + * |
| 108 | + * @param $ip String |
| 109 | + * @return Boolean: True if it is valid. |
106 | 110 | */ |
107 | 111 | public static function isValid( $ip ) { |
108 | 112 | return ( preg_match( '/^' . RE_IP_ADD . '$/', $ip ) |
— | — | @@ -112,8 +116,9 @@ |
113 | 117 | * Validate an IP Block (valid address WITH a valid prefix). |
114 | 118 | * SIIT IPv4-translated addresses are rejected. |
115 | 119 | * Note: canonicalize() tries to convert translated addresses to IPv4. |
116 | | - * @param string $ipblock |
117 | | - * @return boolean True if it is valid. |
| 120 | + * |
| 121 | + * @param $ipblock String |
| 122 | + * @return Boolean: True if it is valid. |
118 | 123 | */ |
119 | 124 | public static function isValidBlock( $ipblock ) { |
120 | 125 | return ( preg_match( '/^' . RE_IPV6_BLOCK . '$/', $ipblock ) |
— | — | @@ -124,8 +129,9 @@ |
125 | 130 | * Convert an IP into a nice standard form. |
126 | 131 | * IPv6 addresses in octet notation are expanded to 8 words. |
127 | 132 | * IPv4 addresses are just trimmed. |
128 | | - * @param string $ip IP address in quad or octet form (CIDR or not). |
129 | | - * @return string |
| 133 | + * |
| 134 | + * @param $ip String: IP address in quad or octet form (CIDR or not). |
| 135 | + * @return String |
130 | 136 | */ |
131 | 137 | public static function sanitizeIP( $ip ) { |
132 | 138 | $ip = trim( $ip ); |
— | — | @@ -174,8 +180,9 @@ |
175 | 181 | |
176 | 182 | /** |
177 | 183 | * Given an unsigned integer, returns an IPv6 address in octet notation |
178 | | - * @param string $ip_int IP address. |
179 | | - * @return string |
| 184 | + * |
| 185 | + * @param $ip_int String: IP address. |
| 186 | + * @return String |
180 | 187 | */ |
181 | 188 | public static function toOctet( $ip_int ) { |
182 | 189 | return self::hexToOctet( wfBaseConvert( $ip_int, 10, 16, 32, false ) ); |
— | — | @@ -183,8 +190,9 @@ |
184 | 191 | |
185 | 192 | /** |
186 | 193 | * Convert an IPv4 or IPv6 hexadecimal representation back to readable format |
187 | | - * @param string $hex number, with "v6-" prefix if it is IPv6 |
188 | | - * @return string quad-dotted (IPv4) or octet notation (IPv6) |
| 194 | + * |
| 195 | + * @param $hex String: number, with "v6-" prefix if it is IPv6 |
| 196 | + * @return String: quad-dotted (IPv4) or octet notation (IPv6) |
189 | 197 | */ |
190 | 198 | public static function formatHex( $hex ) { |
191 | 199 | if ( substr( $hex, 0, 3 ) == 'v6-' ) { // IPv6 |
— | — | @@ -196,8 +204,9 @@ |
197 | 205 | |
198 | 206 | /** |
199 | 207 | * Converts a hexadecimal number to an IPv6 address in octet notation |
200 | | - * @param string $ip_hex pure hex (no v6- prefix) |
201 | | - * @return string (of format a:b:c:d:e:f:g:h) |
| 208 | + * |
| 209 | + * @param $ip_hex String: pure hex (no v6- prefix) |
| 210 | + * @return String (of format a:b:c:d:e:f:g:h) |
202 | 211 | */ |
203 | 212 | public static function hexToOctet( $ip_hex ) { |
204 | 213 | // Pad hex to 32 chars (128 bits) |
— | — | @@ -214,8 +223,9 @@ |
215 | 224 | |
216 | 225 | /** |
217 | 226 | * Converts a hexadecimal number to an IPv4 address in quad-dotted notation |
218 | | - * @param string $ip_hex pure hex |
219 | | - * @return string (of format a.b.c.d) |
| 227 | + * |
| 228 | + * @param $ip_hex String: pure hex |
| 229 | + * @return String (of format a.b.c.d) |
220 | 230 | */ |
221 | 231 | public static function hexToQuad( $ip_hex ) { |
222 | 232 | // Pad hex to 8 chars (32 bits) |
— | — | @@ -235,8 +245,9 @@ |
236 | 246 | * Determine if an IP address really is an IP address, and if it is public, |
237 | 247 | * i.e. not RFC 1918 or similar |
238 | 248 | * Comes from ProxyTools.php |
239 | | - * @param string $ip |
240 | | - * @return bool |
| 249 | + * |
| 250 | + * @param $ip String |
| 251 | + * @return Boolean |
241 | 252 | */ |
242 | 253 | public static function isPublic( $ip ) { |
243 | 254 | if ( self::isIPv6( $ip ) ) { |
— | — | @@ -277,8 +288,9 @@ |
278 | 289 | /** |
279 | 290 | * Determine if an IPv6 address really is an IP address, and if it is public, |
280 | 291 | * i.e. not RFC 4193 or similar |
281 | | - * @param string $ip |
282 | | - * @return bool |
| 292 | + * |
| 293 | + * @param $ip String |
| 294 | + * @return Boolean |
283 | 295 | */ |
284 | 296 | private static function isPublic6( $ip ) { |
285 | 297 | static $privateRanges = false; |
— | — | @@ -307,8 +319,8 @@ |
308 | 320 | * function for an IPv6 address will be prefixed with "v6-", a non- |
309 | 321 | * hexadecimal string which sorts after the IPv4 addresses. |
310 | 322 | * |
311 | | - * @param string $ip Quad dotted/octet IP address. |
312 | | - * @return string |
| 323 | + * @param $ip String: quad dotted/octet IP address. |
| 324 | + * @return String |
313 | 325 | */ |
314 | 326 | public static function toHex( $ip ) { |
315 | 327 | if ( self::isIPv6( $ip ) ) { |
— | — | @@ -324,8 +336,9 @@ |
325 | 337 | |
326 | 338 | /** |
327 | 339 | * Given an IPv6 address in octet notation, returns a pure hex string. |
328 | | - * @param string $ip octet ipv6 IP address. |
329 | | - * @return string pure hex (uppercase) |
| 340 | + * |
| 341 | + * @param $ip String: octet ipv6 IP address. |
| 342 | + * @return String: pure hex (uppercase) |
330 | 343 | */ |
331 | 344 | private static function IPv6ToRawHex( $ip ) { |
332 | 345 | $ip = self::sanitizeIP( $ip ); |
— | — | @@ -343,8 +356,9 @@ |
344 | 357 | * Given an IP address in dotted-quad/octet notation, returns an unsigned integer. |
345 | 358 | * Like ip2long() except that it actually works and has a consistent error return value. |
346 | 359 | * Comes from ProxyTools.php |
347 | | - * @param string $ip Quad dotted IP address. |
348 | | - * @return mixed (string/int/false) |
| 360 | + * |
| 361 | + * @param $ip String: quad dotted IP address. |
| 362 | + * @return Mixed: string/int/false |
349 | 363 | */ |
350 | 364 | public static function toUnsigned( $ip ) { |
351 | 365 | if ( self::isIPv6( $ip ) ) { |
— | — | @@ -365,7 +379,8 @@ |
366 | 380 | /** |
367 | 381 | * Convert a network specification in CIDR notation |
368 | 382 | * to an integer network and a number of bits |
369 | | - * @param string $range IP with CIDR prefix |
| 383 | + * |
| 384 | + * @param $range String: IP with CIDR prefix |
370 | 385 | * @return array(int or string, int) |
371 | 386 | */ |
372 | 387 | public static function parseCIDR( $range ) { |
— | — | @@ -407,7 +422,7 @@ |
408 | 423 | * 2001:0db8:85a3::7344/96 CIDR |
409 | 424 | * 2001:0db8:85a3::7344 - 2001:0db8:85a3::7344 Explicit range |
410 | 425 | * 2001:0db8:85a3::7344 Single IP |
411 | | - * @param string $range IP range |
| 426 | + * @param $range String: IP range |
412 | 427 | * @return array(string, string) |
413 | 428 | */ |
414 | 429 | public static function parseRange( $range ) { |
— | — | @@ -455,6 +470,7 @@ |
456 | 471 | /** |
457 | 472 | * Convert a network specification in IPv6 CIDR notation to an |
458 | 473 | * integer network and a number of bits |
| 474 | + * |
459 | 475 | * @return array(string, int) |
460 | 476 | */ |
461 | 477 | private static function parseCIDR6( $range ) { |
— | — | @@ -541,9 +557,10 @@ |
542 | 558 | |
543 | 559 | /** |
544 | 560 | * Determine if a given IPv4/IPv6 address is in a given CIDR network |
545 | | - * @param $addr The address to check against the given range. |
546 | | - * @param $range The range to check the given address against. |
547 | | - * @return bool Whether or not the given address is in the given range. |
| 561 | + * |
| 562 | + * @param $addr String: the address to check against the given range. |
| 563 | + * @param $range String: the range to check the given address against. |
| 564 | + * @return Boolean: whether or not the given address is in the given range. |
548 | 565 | */ |
549 | 566 | public static function isInRange( $addr, $range ) { |
550 | 567 | $hexIP = self::toHex( $addr ); |
— | — | @@ -559,8 +576,8 @@ |
560 | 577 | * This currently only checks a few IPV4-to-IPv6 related cases. More |
561 | 578 | * unusual representations may be added later. |
562 | 579 | * |
563 | | - * @param $addr something that might be an IP address |
564 | | - * @return valid dotted quad IPv4 address or null |
| 580 | + * @param $addr String: something that might be an IP address |
| 581 | + * @return String: valid dotted quad IPv4 address or null |
565 | 582 | */ |
566 | 583 | public static function canonicalize( $addr ) { |
567 | 584 | if ( self::isValid( $addr ) ) { |