+ 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 );
+ }
+ }
+
+ /**
+ * Get the type of target for this particular block
+ * @return Block::TYPE_ constant, will never be TYPE_ID
+ */
+ public function getType() {
+ return $this->mAuto
+ ? self::TYPE_AUTO
+ : $this->type;
+ }
+
+ /**
+ * Get the target and target type for this particular Block. Note that for autoblocks,
+ * this returns the unredacted name; frontend functions need to call $block->getRedactedName()
+ * in this situation.
+ * @return array( User|String, Block::TYPE_ constant )
+ * @todo FIXME: This should be an integral part of the Block member variables
+ */
+ public function getTargetAndType() {
+ return array( $this->getTarget(), $this->getType() );
+ }
+
+ /**
+ * Get the target for this particular Block. Note that for autoblocks,
+ * this returns the unredacted name; frontend functions need to call $block->getRedactedName()
+ * in this situation.
+ * @return User|String
+ */
+ public function getTarget() {
+ return $this->target;
+ }
+
+ /**
+ * Set the target for this block, and update $this->type accordingly
+ * @param $target Mixed
+ */
+ public function setTarget( $target ){
+ list( $this->target, $this->type ) = self::parseTarget( $target );
+ }
+
+ /**
+ * Get the user who implemented this block
+ * @return User
+ */
+ public function getBlocker(){
+ return $this->blocker;
+ }
+
+ /**
+ * Set the user who implemented (or will implement) this block
+ * @param $user User
+ */
+ public function setBlocker( User $user ){
+ $this->blocker = $user;