+ } elseif( $target === null ){
+ return array( null, null );
+ }
+
+ if ( IP::isValid( $target ) ) {
+ # We can still create a User if it's an IP address, but we need to turn
+ # off validation checking (which would exclude IP addresses)
+ return array(
+ User::newFromName( IP::sanitizeIP( $target ), false ),
+ Block::TYPE_IP
+ );
+
+ } elseif ( IP::isValidBlock( $target ) ) {
+ # Can't create a User from an IP range
+ return array( IP::sanitizeRange( $target ), Block::TYPE_RANGE );
+ }
+
+ # Consider the possibility that this is not a username at all
+ # but actually an old subpage (bug #29797)
+ if( strpos( $target, '/' ) !== false ){
+ # An old subpage, drill down to the user behind it
+ $parts = explode( '/', $target );
+ $target = $parts[0];
+ }
+
+ $userObj = User::newFromName( $target );
+ if ( $userObj instanceof User ) {
+ # Note that since numbers are valid usernames, a $target of "12345" will be
+ # considered a User. If you want to pass a block ID, prepend a hash "#12345",
+ # since hash characters are not valid in usernames or titles generally.
+ return array( $userObj, Block::TYPE_USER );
+
+ } elseif ( preg_match( '/^#\d+$/', $target ) ) {
+ # Autoblock reference in the form "#12345"
+ return array( substr( $target, 1 ), Block::TYPE_AUTO );
+
+ } else {
+ # WTF?
+ return array( null, null );