MediaWiki  1.23.14
IP.php
Go to the documentation of this file.
1 <?php
24 // Some regex definition to "play" with IP address and IP address blocks
25 
26 // An IPv4 address is made of 4 bytes from x00 to xFF which is d0 to d255
27 define( 'RE_IP_BYTE', '(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|0?[0-9]?[0-9])' );
28 define( 'RE_IP_ADD', RE_IP_BYTE . '\.' . RE_IP_BYTE . '\.' . RE_IP_BYTE . '\.' . RE_IP_BYTE );
29 // An IPv4 block is an IP address and a prefix (d1 to d32)
30 define( 'RE_IP_PREFIX', '(3[0-2]|[12]?\d)' );
31 define( 'RE_IP_BLOCK', RE_IP_ADD . '\/' . RE_IP_PREFIX );
32 
33 // An IPv6 address is made up of 8 words (each x0000 to xFFFF).
34 // However, the "::" abbreviation can be used on consecutive x0000 words.
35 define( 'RE_IPV6_WORD', '([0-9A-Fa-f]{1,4})' );
36 define( 'RE_IPV6_PREFIX', '(12[0-8]|1[01][0-9]|[1-9]?\d)' );
37 define( 'RE_IPV6_ADD',
38  '(?:' . // starts with "::" (including "::")
39  ':(?::|(?::' . RE_IPV6_WORD . '){1,7})' .
40  '|' . // ends with "::" (except "::")
41  RE_IPV6_WORD . '(?::' . RE_IPV6_WORD . '){0,6}::' .
42  '|' . // contains one "::" in the middle (the ^ makes the test fail if none found)
43  RE_IPV6_WORD . '(?::((?(-1)|:))?' . RE_IPV6_WORD . '){1,6}(?(-2)|^)' .
44  '|' . // contains no "::"
45  RE_IPV6_WORD . '(?::' . RE_IPV6_WORD . '){7}' .
46  ')'
47 );
48 // An IPv6 block is an IP address and a prefix (d1 to d128)
49 define( 'RE_IPV6_BLOCK', RE_IPV6_ADD . '\/' . RE_IPV6_PREFIX );
50 // For IPv6 canonicalization (NOT for strict validation; these are quite lax!)
51 define( 'RE_IPV6_GAP', ':(?:0+:)*(?::(?:0+:)*)?' );
52 define( 'RE_IPV6_V4_PREFIX', '0*' . RE_IPV6_GAP . '(?:ffff:)?' );
53 
54 // This might be useful for regexps used elsewhere, matches any IPv6 or IPv6 address or network
55 define( 'IP_ADDRESS_STRING',
56  '(?:' .
57  RE_IP_ADD . '(?:\/' . RE_IP_PREFIX . ')?' . // IPv4
58  '|' .
59  RE_IPV6_ADD . '(?:\/' . RE_IPV6_PREFIX . ')?' . // IPv6
60  ')'
61 );
62 
67 class IP {
76  public static function isIPAddress( $ip ) {
77  return (bool)preg_match( '/^' . IP_ADDRESS_STRING . '$/', $ip );
78  }
79 
87  public static function isIPv6( $ip ) {
88  return (bool)preg_match( '/^' . RE_IPV6_ADD . '(?:\/' . RE_IPV6_PREFIX . ')?$/', $ip );
89  }
90 
98  public static function isIPv4( $ip ) {
99  return (bool)preg_match( '/^' . RE_IP_ADD . '(?:\/' . RE_IP_PREFIX . ')?$/', $ip );
100  }
101 
110  public static function isValid( $ip ) {
111  return ( preg_match( '/^' . RE_IP_ADD . '$/', $ip )
112  || preg_match( '/^' . RE_IPV6_ADD . '$/', $ip ) );
113  }
114 
123  public static function isValidBlock( $ipblock ) {
124  return ( preg_match( '/^' . RE_IPV6_BLOCK . '$/', $ipblock )
125  || preg_match( '/^' . RE_IP_BLOCK . '$/', $ipblock ) );
126  }
127 
137  public static function sanitizeIP( $ip ) {
138  $ip = trim( $ip );
139  if ( $ip === '' ) {
140  return null;
141  }
142  /* If not an IP, just return trimmed value, since sanitizeIP() is called
143  * in a number of contexts where usernames are supplied as input.
144  */
145  if ( !self::isIPAddress($ip) ) {
146  return $ip;
147  }
148  if ( self::isIPv4( $ip ) ) {
149  // Remove leading 0's from octet representation of IPv4 address
150  $ip = preg_replace( '/(?:^|(?<=\.))0+(?=[1-9]|0\.|0$)/', '', $ip );
151  return $ip;
152  }
153  // Remove any whitespaces, convert to upper case
154  $ip = strtoupper( $ip );
155  // Expand zero abbreviations
156  $abbrevPos = strpos( $ip, '::' );
157  if ( $abbrevPos !== false ) {
158  // We know this is valid IPv6. Find the last index of the
159  // address before any CIDR number (e.g. "a:b:c::/24").
160  $CIDRStart = strpos( $ip, "/" );
161  $addressEnd = ( $CIDRStart !== false )
162  ? $CIDRStart - 1
163  : strlen( $ip ) - 1;
164  // If the '::' is at the beginning...
165  if ( $abbrevPos == 0 ) {
166  $repeat = '0:';
167  $extra = ( $ip == '::' ) ? '0' : ''; // for the address '::'
168  $pad = 9; // 7+2 (due to '::')
169  // If the '::' is at the end...
170  } elseif ( $abbrevPos == ( $addressEnd - 1 ) ) {
171  $repeat = ':0';
172  $extra = '';
173  $pad = 9; // 7+2 (due to '::')
174  // If the '::' is in the middle...
175  } else {
176  $repeat = ':0';
177  $extra = ':';
178  $pad = 8; // 6+2 (due to '::')
179  }
180  $ip = str_replace( '::',
181  str_repeat( $repeat, $pad - substr_count( $ip, ':' ) ) . $extra,
182  $ip
183  );
184  }
185  // Remove leading zeros from each bloc as needed
186  $ip = preg_replace( '/(^|:)0+(' . RE_IPV6_WORD . ')/', '$1$2', $ip );
187 
188  return $ip;
189  }
190 
198  public static function prettifyIP( $ip ) {
199  $ip = self::sanitizeIP( $ip ); // normalize (removes '::')
200  if ( self::isIPv6( $ip ) ) {
201  // Split IP into an address and a CIDR
202  if ( strpos( $ip, '/' ) !== false ) {
203  list( $ip, $cidr ) = explode( '/', $ip, 2 );
204  } else {
205  list( $ip, $cidr ) = array( $ip, '' );
206  }
207  // Get the largest slice of words with multiple zeros
208  $offset = 0;
209  $longest = $longestPos = false;
210  while ( preg_match(
211  '!(?:^|:)0(?::0)+(?:$|:)!', $ip, $m, PREG_OFFSET_CAPTURE, $offset
212  ) ) {
213  list( $match, $pos ) = $m[0]; // full match
214  if ( strlen( $match ) > strlen( $longest ) ) {
215  $longest = $match;
216  $longestPos = $pos;
217  }
218  $offset = ( $pos + strlen( $match ) ); // advance
219  }
220  if ( $longest !== false ) {
221  // Replace this portion of the string with the '::' abbreviation
222  $ip = substr_replace( $ip, '::', $longestPos, strlen( $longest ) );
223  }
224  // Add any CIDR back on
225  if ( $cidr !== '' ) {
226  $ip = "{$ip}/{$cidr}";
227  }
228  // Convert to lower case to make it more readable
229  $ip = strtolower( $ip );
230  }
231 
232  return $ip;
233  }
234 
251  public static function splitHostAndPort( $both ) {
252  if ( substr( $both, 0, 1 ) === '[' ) {
253  if ( preg_match( '/^\[(' . RE_IPV6_ADD . ')\](?::(?P<port>\d+))?$/', $both, $m ) ) {
254  if ( isset( $m['port'] ) ) {
255  return array( $m[1], intval( $m['port'] ) );
256  } else {
257  return array( $m[1], false );
258  }
259  } else {
260  // Square bracket found but no IPv6
261  return false;
262  }
263  }
264  $numColons = substr_count( $both, ':' );
265  if ( $numColons >= 2 ) {
266  // Is it a bare IPv6 address?
267  if ( preg_match( '/^' . RE_IPV6_ADD . '$/', $both ) ) {
268  return array( $both, false );
269  } else {
270  // Not valid IPv6, but too many colons for anything else
271  return false;
272  }
273  }
274  if ( $numColons >= 1 ) {
275  // Host:port?
276  $bits = explode( ':', $both );
277  if ( preg_match( '/^\d+/', $bits[1] ) ) {
278  return array( $bits[0], intval( $bits[1] ) );
279  } else {
280  // Not a valid port
281  return false;
282  }
283  }
284 
285  // Plain hostname
286  return array( $both, false );
287  }
288 
300  public static function combineHostAndPort( $host, $port, $defaultPort = false ) {
301  if ( strpos( $host, ':' ) !== false ) {
302  $host = "[$host]";
303  }
304  if ( $defaultPort !== false && $port == $defaultPort ) {
305  return $host;
306  } else {
307  return "$host:$port";
308  }
309  }
310 
317  public static function toOctet( $ip_int ) {
318  return self::hexToOctet( wfBaseConvert( $ip_int, 10, 16, 32, false ) );
319  }
320 
327  public static function formatHex( $hex ) {
328  if ( substr( $hex, 0, 3 ) == 'v6-' ) { // IPv6
329  return self::hexToOctet( substr( $hex, 3 ) );
330  } else { // IPv4
331  return self::hexToQuad( $hex );
332  }
333  }
334 
341  public static function hexToOctet( $ip_hex ) {
342  // Pad hex to 32 chars (128 bits)
343  $ip_hex = str_pad( strtoupper( $ip_hex ), 32, '0', STR_PAD_LEFT );
344  // Separate into 8 words
345  $ip_oct = substr( $ip_hex, 0, 4 );
346  for ( $n = 1; $n < 8; $n++ ) {
347  $ip_oct .= ':' . substr( $ip_hex, 4 * $n, 4 );
348  }
349  // NO leading zeroes
350  $ip_oct = preg_replace( '/(^|:)0+(' . RE_IPV6_WORD . ')/', '$1$2', $ip_oct );
351 
352  return $ip_oct;
353  }
354 
361  public static function hexToQuad( $ip_hex ) {
362  // Pad hex to 8 chars (32 bits)
363  $ip_hex = str_pad( strtoupper( $ip_hex ), 8, '0', STR_PAD_LEFT );
364  // Separate into four quads
365  $s = '';
366  for ( $i = 0; $i < 4; $i++ ) {
367  if ( $s !== '' ) {
368  $s .= '.';
369  }
370  $s .= base_convert( substr( $ip_hex, $i * 2, 2 ), 16, 10 );
371  }
372 
373  return $s;
374  }
375 
383  public static function isPublic( $ip ) {
384  if ( self::isIPv6( $ip ) ) {
385  return self::isPublic6( $ip );
386  }
387  $n = self::toUnsigned( $ip );
388  if ( !$n ) {
389  return false;
390  }
391 
392  // ip2long accepts incomplete addresses, as well as some addresses
393  // followed by garbage characters. Check that it's really valid.
394  if ( $ip != long2ip( $n ) ) {
395  return false;
396  }
397 
398  static $privateRanges = false;
399  if ( !$privateRanges ) {
400  $privateRanges = array(
401  array( '10.0.0.0', '10.255.255.255' ), # RFC 1918 (private)
402  array( '172.16.0.0', '172.31.255.255' ), # RFC 1918 (private)
403  array( '192.168.0.0', '192.168.255.255' ), # RFC 1918 (private)
404  array( '0.0.0.0', '0.255.255.255' ), # this network
405  array( '127.0.0.0', '127.255.255.255' ), # loopback
406  );
407  }
408 
409  foreach ( $privateRanges as $r ) {
410  $start = self::toUnsigned( $r[0] );
411  $end = self::toUnsigned( $r[1] );
412  if ( $n >= $start && $n <= $end ) {
413  return false;
414  }
415  }
416 
417  return true;
418  }
419 
427  private static function isPublic6( $ip ) {
428  static $privateRanges = false;
429  if ( !$privateRanges ) {
430  $privateRanges = array(
431  array( 'fc00::', 'fdff:ffff:ffff:ffff:ffff:ffff:ffff:ffff' ), # RFC 4193 (local)
432  array( '0:0:0:0:0:0:0:1', '0:0:0:0:0:0:0:1' ), # loopback
433  );
434  }
435  $n = self::toHex( $ip );
436  foreach ( $privateRanges as $r ) {
437  $start = self::toHex( $r[0] );
438  $end = self::toHex( $r[1] );
439  if ( $n >= $start && $n <= $end ) {
440  return false;
441  }
442  }
443 
444  return true;
445  }
446 
458  public static function toHex( $ip ) {
459  if ( self::isIPv6( $ip ) ) {
460  $n = 'v6-' . self::IPv6ToRawHex( $ip );
461  } else {
462  $n = self::toUnsigned( $ip );
463  if ( $n !== false ) {
464  $n = wfBaseConvert( $n, 10, 16, 8, false );
465  }
466  }
467 
468  return $n;
469  }
470 
477  private static function IPv6ToRawHex( $ip ) {
478  $ip = self::sanitizeIP( $ip );
479  if ( !$ip ) {
480  return null;
481  }
482  $r_ip = '';
483  foreach ( explode( ':', $ip ) as $v ) {
484  $r_ip .= str_pad( $v, 4, 0, STR_PAD_LEFT );
485  }
486 
487  return $r_ip;
488  }
489 
497  public static function toUnsigned( $ip ) {
498  if ( self::isIPv6( $ip ) ) {
499  $n = self::toUnsigned6( $ip );
500  } else {
501  // T62035/T97897: An IP with leading 0's fails in ip2long sometimes (e.g. *.08),
502  // also double/triple 0 needs to be changed to just a single 0 for ip2long.
503  $ip = self::sanitizeIP( $ip );
504  $n = ip2long( $ip );
505  if ( $n < 0 ) {
506  $n += pow( 2, 32 );
507  # On 32-bit platforms (and on Windows), 2^32 does not fit into an int,
508  # so $n becomes a float. We convert it to string instead.
509  if ( is_float( $n ) ) {
510  $n = (string)$n;
511  }
512  }
513  }
514 
515  return $n;
516  }
517 
522  private static function toUnsigned6( $ip ) {
523  return wfBaseConvert( self::IPv6ToRawHex( $ip ), 16, 10 );
524  }
525 
533  public static function parseCIDR( $range ) {
534  if ( self::isIPv6( $range ) ) {
535  return self::parseCIDR6( $range );
536  }
537  $parts = explode( '/', $range, 2 );
538  if ( count( $parts ) != 2 ) {
539  return array( false, false );
540  }
541  list( $network, $bits ) = $parts;
542  $network = ip2long( $network );
543  if ( $network !== false && is_numeric( $bits ) && $bits >= 0 && $bits <= 32 ) {
544  if ( $bits == 0 ) {
545  $network = 0;
546  } else {
547  $network &= ~( ( 1 << ( 32 - $bits ) ) - 1 );
548  }
549  # Convert to unsigned
550  if ( $network < 0 ) {
551  $network += pow( 2, 32 );
552  }
553  } else {
554  $network = false;
555  $bits = false;
556  }
557 
558  return array( $network, $bits );
559  }
560 
576  public static function parseRange( $range ) {
577  // CIDR notation
578  if ( strpos( $range, '/' ) !== false ) {
579  if ( self::isIPv6( $range ) ) {
580  return self::parseRange6( $range );
581  }
582  list( $network, $bits ) = self::parseCIDR( $range );
583  if ( $network === false ) {
584  $start = $end = false;
585  } else {
586  $start = sprintf( '%08X', $network );
587  $end = sprintf( '%08X', $network + pow( 2, ( 32 - $bits ) ) - 1 );
588  }
589  // Explicit range
590  } elseif ( strpos( $range, '-' ) !== false ) {
591  list( $start, $end ) = array_map( 'trim', explode( '-', $range, 2 ) );
592  if ( self::isIPv6( $start ) && self::isIPv6( $end ) ) {
593  return self::parseRange6( $range );
594  }
595  if ( self::isIPv4( $start ) && self::isIPv4( $end ) ) {
596  $start = self::toUnsigned( $start );
597  $end = self::toUnsigned( $end );
598  if ( $start > $end ) {
599  $start = $end = false;
600  } else {
601  $start = sprintf( '%08X', $start );
602  $end = sprintf( '%08X', $end );
603  }
604  } else {
605  $start = $end = false;
606  }
607  } else {
608  # Single IP
609  $start = $end = self::toHex( $range );
610  }
611  if ( $start === false || $end === false ) {
612  return array( false, false );
613  } else {
614  return array( $start, $end );
615  }
616  }
617 
626  private static function parseCIDR6( $range ) {
627  # Explode into <expanded IP,range>
628  $parts = explode( '/', IP::sanitizeIP( $range ), 2 );
629  if ( count( $parts ) != 2 ) {
630  return array( false, false );
631  }
632  list( $network, $bits ) = $parts;
633  $network = self::IPv6ToRawHex( $network );
634  if ( $network !== false && is_numeric( $bits ) && $bits >= 0 && $bits <= 128 ) {
635  if ( $bits == 0 ) {
636  $network = "0";
637  } else {
638  # Native 32 bit functions WONT work here!!!
639  # Convert to a padded binary number
640  $network = wfBaseConvert( $network, 16, 2, 128 );
641  # Truncate the last (128-$bits) bits and replace them with zeros
642  $network = str_pad( substr( $network, 0, $bits ), 128, 0, STR_PAD_RIGHT );
643  # Convert back to an integer
644  $network = wfBaseConvert( $network, 2, 10 );
645  }
646  } else {
647  $network = false;
648  $bits = false;
649  }
650 
651  return array( $network, (int)$bits );
652  }
653 
667  private static function parseRange6( $range ) {
668  # Expand any IPv6 IP
669  $range = IP::sanitizeIP( $range );
670  // CIDR notation...
671  if ( strpos( $range, '/' ) !== false ) {
672  list( $network, $bits ) = self::parseCIDR6( $range );
673  if ( $network === false ) {
674  $start = $end = false;
675  } else {
676  $start = wfBaseConvert( $network, 10, 16, 32, false );
677  # Turn network to binary (again)
678  $end = wfBaseConvert( $network, 10, 2, 128 );
679  # Truncate the last (128-$bits) bits and replace them with ones
680  $end = str_pad( substr( $end, 0, $bits ), 128, 1, STR_PAD_RIGHT );
681  # Convert to hex
682  $end = wfBaseConvert( $end, 2, 16, 32, false );
683  # see toHex() comment
684  $start = "v6-$start";
685  $end = "v6-$end";
686  }
687  // Explicit range notation...
688  } elseif ( strpos( $range, '-' ) !== false ) {
689  list( $start, $end ) = array_map( 'trim', explode( '-', $range, 2 ) );
690  $start = self::toUnsigned6( $start );
691  $end = self::toUnsigned6( $end );
692  if ( $start > $end ) {
693  $start = $end = false;
694  } else {
695  $start = wfBaseConvert( $start, 10, 16, 32, false );
696  $end = wfBaseConvert( $end, 10, 16, 32, false );
697  }
698  # see toHex() comment
699  $start = "v6-$start";
700  $end = "v6-$end";
701  } else {
702  # Single IP
703  $start = $end = self::toHex( $range );
704  }
705  if ( $start === false || $end === false ) {
706  return array( false, false );
707  } else {
708  return array( $start, $end );
709  }
710  }
711 
719  public static function isInRange( $addr, $range ) {
720  $hexIP = self::toHex( $addr );
721  list( $start, $end ) = self::parseRange( $range );
722 
723  return ( strcmp( $hexIP, $start ) >= 0 &&
724  strcmp( $hexIP, $end ) <= 0 );
725  }
726 
737  public static function canonicalize( $addr ) {
738  // remove zone info (bug 35738)
739  $addr = preg_replace( '/\%.*/', '', $addr );
740 
741  if ( self::isValid( $addr ) ) {
742  return $addr;
743  }
744  // Turn mapped addresses from ::ce:ffff:1.2.3.4 to 1.2.3.4
745  if ( strpos( $addr, ':' ) !== false && strpos( $addr, '.' ) !== false ) {
746  $addr = substr( $addr, strrpos( $addr, ':' ) + 1 );
747  if ( self::isIPv4( $addr ) ) {
748  return $addr;
749  }
750  }
751  // IPv6 loopback address
752  $m = array();
753  if ( preg_match( '/^0*' . RE_IPV6_GAP . '1$/', $addr, $m ) ) {
754  return '127.0.0.1';
755  }
756  // IPv4-mapped and IPv4-compatible IPv6 addresses
757  if ( preg_match( '/^' . RE_IPV6_V4_PREFIX . '(' . RE_IP_ADD . ')$/i', $addr, $m ) ) {
758  return $m[1];
759  }
760  if ( preg_match( '/^' . RE_IPV6_V4_PREFIX . RE_IPV6_WORD .
761  ':' . RE_IPV6_WORD . '$/i', $addr, $m )
762  ) {
763  return long2ip( ( hexdec( $m[1] ) << 16 ) + hexdec( $m[2] ) );
764  }
765 
766  return null; // give up
767  }
768 
775  public static function sanitizeRange( $range ) {
776  list( /*...*/, $bits ) = self::parseCIDR( $range );
777  list( $start, /*...*/ ) = self::parseRange( $range );
778  $start = self::formatHex( $start );
779  if ( $bits === false ) {
780  return $start; // wasn't actually a range
781  }
782 
783  return "$start/$bits";
784  }
785 }
RE_IPV6_V4_PREFIX
const RE_IPV6_V4_PREFIX
Definition: IP.php:51
RE_IP_BLOCK
const RE_IP_BLOCK
Definition: IP.php:31
IP\toHex
static toHex( $ip)
Return a zero-padded upper case hexadecimal representation of an IP address.
Definition: IP.php:456
IP\hexToOctet
static hexToOctet( $ip_hex)
Converts a hexadecimal number to an IPv6 address in octet notation.
Definition: IP.php:339
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
RE_IPV6_PREFIX
const RE_IPV6_PREFIX
Definition: IP.php:36
IP\toOctet
static toOctet( $ip_int)
Given an unsigned integer, returns an IPv6 address in octet notation.
Definition: IP.php:315
IP\combineHostAndPort
static combineHostAndPort( $host, $port, $defaultPort=false)
Given a host name and a port, combine them into host/port string like you might find in a URL.
Definition: IP.php:298
RE_IPV6_ADD
const RE_IPV6_ADD
Definition: IP.php:37
IP_ADDRESS_STRING
const IP_ADDRESS_STRING
Definition: IP.php:54
IP\canonicalize
static canonicalize( $addr)
Convert some unusual representations of IPv4 addresses to their canonical dotted quad representation.
Definition: IP.php:735
$n
$n
Definition: RandomTest.php:76
RE_IPV6_GAP
const RE_IPV6_GAP
Definition: IP.php:50
IP\parseRange6
static parseRange6( $range)
Given a string range in a number of formats, return the start and end of the range in hexadecimal.
Definition: IP.php:665
RE_IPV6_BLOCK
const RE_IPV6_BLOCK
Definition: IP.php:48
IP
A collection of public static functions to play with IP address and IP blocks.
Definition: IP.php:65
IP\isIPv6
static isIPv6( $ip)
Given a string, determine if it as valid IP in IPv6 only.
Definition: IP.php:85
$s
$s
Definition: mergeMessageFileList.php:156
IP\toUnsigned6
static toUnsigned6( $ip)
Definition: IP.php:520
IP\parseCIDR6
static parseCIDR6( $range)
Convert a network specification in IPv6 CIDR notation to an integer network and a number of bits.
Definition: IP.php:624
RE_IP_PREFIX
const RE_IP_PREFIX
Definition: IP.php:30
RE_IPV6_WORD
const RE_IPV6_WORD
Definition: IP.php:35
IP\isPublic6
static isPublic6( $ip)
Determine if an IPv6 address really is an IP address, and if it is public, i.e.
Definition: IP.php:425
IP\hexToQuad
static hexToQuad( $ip_hex)
Converts a hexadecimal number to an IPv4 address in quad-dotted notation.
Definition: IP.php:359
IP\IPv6ToRawHex
static IPv6ToRawHex( $ip)
Given an IPv6 address in octet notation, returns a pure hex string.
Definition: IP.php:475
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
IP\isInRange
static isInRange( $addr, $range)
Determine if a given IPv4/IPv6 address is in a given CIDR network.
Definition: IP.php:717
IP\isPublic
static isPublic( $ip)
Determine if an IP address really is an IP address, and if it is public, i.e.
Definition: IP.php:381
list
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these but it might have such a feature in the future We handle these by creating a deferred update object and putting those objects on a global list
Definition: deferred.txt:11
false
processing should stop and the error should be shown to the user * false
Definition: hooks.txt:188
IP\prettifyIP
static prettifyIP( $ip)
Prettify an IP for display to end users.
Definition: IP.php:196
IP\toUnsigned
static toUnsigned( $ip)
Given an IP address in dotted-quad/octet notation, returns an unsigned integer.
Definition: IP.php:495
RE_IP_BYTE
const RE_IP_BYTE
Definition: IP.php:27
IP\splitHostAndPort
static splitHostAndPort( $both)
Given a host/port string, like one might find in the host part of a URL per RFC 2732,...
Definition: IP.php:249
IP\parseRange
static parseRange( $range)
Given a string range in a number of formats, return the start and end of the range in hexadecimal.
Definition: IP.php:574
IP\isValid
static isValid( $ip)
Validate an IP address.
Definition: IP.php:108
IP\isIPv4
static isIPv4( $ip)
Given a string, determine if it as valid IP in IPv4 only.
Definition: IP.php:96
IP\parseCIDR
static parseCIDR( $range)
Convert a network specification in CIDR notation to an integer network and a number of bits.
Definition: IP.php:531
network
MediaWiki has optional support for a high distributed memory object caching system For general information on but for a larger site with heavy like it should help lighten the load on the database servers by caching data and objects in Ubuntu and probably other Linux distributions If you there s no package available for your you can compile it from epoll rt patch for Linux is current Memcached and libevent are under BSD style licenses The server should run on Linux and other Unix like systems you can run multiple servers on one machine or on multiple machines on a network
Definition: memcached.txt:16
IP\sanitizeIP
static sanitizeIP( $ip)
Convert an IP into a verbose, uppercase, normalized form.
Definition: IP.php:135
wfBaseConvert
wfBaseConvert( $input, $sourceBase, $destBase, $pad=1, $lowercase=true, $engine='auto')
Convert an arbitrarily-long digit string from one numeric base to another, optionally zero-padding to...
Definition: GlobalFunctions.php:3432
as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
RE_IP_ADD
const RE_IP_ADD
Definition: IP.php:28
IP\isValidBlock
static isValidBlock( $ipblock)
Validate an IP Block (valid address WITH a valid prefix).
Definition: IP.php:121
IP\sanitizeRange
static sanitizeRange( $range)
Gets rid of unneeded numbers in quad-dotted/octet IP strings For example, 127.111....
Definition: IP.php:773
IP\isIPAddress
static isIPAddress( $ip)
Determine if a string is as valid IP address or network (CIDR prefix).
Definition: IP.php:74
IP\formatHex
static formatHex( $hex)
Convert an IPv4 or IPv6 hexadecimal representation back to readable format.
Definition: IP.php:325