r36429 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r36428‎ | r36429 | r36430 >
Date:18:10, 18 June 2008
Author:aaron
Status:old
Tags:
Comment:
Remove ugly IP code duplication
Modified paths:
  • /trunk/phase3/includes/User.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/User.php
@@ -431,7 +431,7 @@
432432 * @return bool
433433 */
434434 static function isIP( $name ) {
435 - return preg_match('/^\d{1,3}\.\d{1,3}\.\d{1,3}\.(?:xxx|\d{1,3})$/',$name) || User::isIPv6($name);
 435+ return IP::isIPAddress($name);
436436 /*return preg_match("/^
437437 (?:[01]?\d{1,2}|2(:?[0-4]\d|5[0-5]))\.
438438 (?:[01]?\d{1,2}|2(:?[0-4]\d|5[0-5]))\.
@@ -441,27 +441,6 @@
442442 }
443443
444444 /**
445 - * Check if $name is an IPv6 IP.
446 - */
447 - static function isIPv6($name) {
448 - /*
449 - * if it has any non-valid characters, it can't be a valid IPv6
450 - * address.
451 - */
452 - if (preg_match("/[^:a-fA-F0-9]/", $name))
453 - return false;
454 -
455 - $parts = explode(":", $name);
456 - if (count($parts) < 3)
457 - return false;
458 - foreach ($parts as $part) {
459 - if (!preg_match("/^[0-9a-fA-F]{0,4}$/", $part))
460 - return false;
461 - }
462 - return true;
463 - }
464 -
465 - /**
466445 * Is the input a valid username?
467446 *
468447 * Checks if the input is a valid username, we don't want an empty string,

Status & tagging log