aboutsummaryrefslogtreecommitdiffstats
path: root/includes/IP.php
diff options
context:
space:
mode:
authorTim Starling <tstarling@users.mediawiki.org>2006-07-14 17:38:47 +0000
committerTim Starling <tstarling@users.mediawiki.org>2006-07-14 17:38:47 +0000
commitb3352f6b68a18fe4a620d329027bdcffc278b68f (patch)
treeac88a68cca6b4638e21073656d09063dcc01fad6 /includes/IP.php
parent588b6a80cd088fc83823d42b34f00974609ad4f7 (diff)
downloadmediawikicore-b3352f6b68a18fe4a620d329027bdcffc278b68f.tar.gz
mediawikicore-b3352f6b68a18fe4a620d329027bdcffc278b68f.zip
That doesn't work... oh well, as long as no other module tries to use these constants then the original scheme will be OK.
Notes
Notes: http://mediawiki.org/wiki/Special:Code/MediaWiki/15617
Diffstat (limited to 'includes/IP.php')
-rw-r--r--includes/IP.php21
1 files changed, 11 insertions, 10 deletions
diff --git a/includes/IP.php b/includes/IP.php
index 371945c90040..2691a15be988 100644
--- a/includes/IP.php
+++ b/includes/IP.php
@@ -7,22 +7,23 @@
* @License GPL v2 or later
*/
-class IP {
- // Some regex definition to "play" with IP address and IP address blocks
+// Some regex definition to "play" with IP address and IP address blocks
+
+// An IP is made of 4 bytes from x00 to xFF which is d0 to d255
+define( 'RE_IP_BYTE', '(25[0-5]|2[0-4]\d|1?\d{1,2})');
+define( 'RE_IP_ADD' , RE_IP_BYTE . '\.' . RE_IP_BYTE . '\.' . RE_IP_BYTE . '\.' . RE_IP_BYTE );
+// An IP block is an IP address and a prefix (d1 to d32)
+define( 'RE_IP_PREFIX' , '(3[0-2]|[12]?\d)');
+define( 'RE_IP_BLOCK', RE_IP_ADD . '\/' . RE_IP_PREFIX);
- // An IP is made of 4 bytes from x00 to xFF which is d0 to d255
- const RE_BYTE = '(25[0-5]|2[0-4]\d|1?\d{1,2})';
- const RE_ADD = self::RE_BYTE . '\.' . self::RE_BYTE . '\.' . self::RE_BYTE . '\.' . self::RE_BYTE;
- // An IP block is an IP address and a prefix (d1 to d32)
- const RE_PREFIX = '(3[0-2]|[12]?\d)';
- const RE_BLOCK = self::RE_ADD . '\/' . self::RE_PREFIX;
+class IP {
/**
* Validate an IP address.
* @return boolean True if it is valid.
*/
public static function isValid( $ip ) {
- return preg_match( '/^' . self::RE_ADD . '$/', $ip, $matches) ;
+ return preg_match( '/^' . RE_IP_ADD . '$/', $ip, $matches) ;
}
/**
@@ -79,7 +80,7 @@ class IP {
* @return array
*/
public static function toArray( $ipblock ) {
- if(! preg_match( '/^' . self::RE_ADD . '(?:\/(?:'.self::RE_PREFIX.'))?' . '$/', $ipblock, $matches ) ) {
+ if(! preg_match( '/^' . RE_IP_ADD . '(?:\/(?:'.RE_IP_PREFIX.'))?' . '$/', $ipblock, $matches ) ) {
return false;
} else {
return $matches;