+ public static function parseExpiryInput( $expiry ) {
+ wfDeprecated( __METHOD__ );
+ return SpecialBlock::parseExpiryInput( $expiry );
+ }
+
+ /**
+ * Given a target and the target's type, get an existing Block object if possible.
+ * @param $specificTarget String|User|Int a block target, which may be one of several types:
+ * * A user to block, in which case $target will be a User
+ * * An IP to block, in which case $target will be a User generated by using
+ * User::newFromName( $ip, false ) to turn off name validation
+ * * An IP range, in which case $target will be a String "123.123.123.123/18" etc
+ * * The ID of an existing block, in the format "#12345" (since pure numbers are valid
+ * usernames
+ * Calling this with a user, IP address or range will not select autoblocks, and will
+ * only select a block where the targets match exactly (so looking for blocks on
+ * 1.2.3.4 will not select 1.2.0.0/16 or even 1.2.3.4/32)
+ * @param $vagueTarget String|User|Int as above, but we will search for *any* block which
+ * affects that target (so for an IP address, get ranges containing that IP; and also
+ * get any relevant autoblocks)
+ * @param $fromMaster Bool whether to use the DB_MASTER database
+ * @return Block|null (null if no relevant block could be found). The target and type
+ * of the returned Block will refer to the actual block which was found, which might
+ * not be the same as the target you gave if you used $vagueTarget!
+ */
+ public static function newFromTarget( $specificTarget, $vagueTarget = null, $fromMaster = false ) {
+ # (bug 29116) passing $vagueTarget = '' is not unreasonable here, but int(0)
+ # is a valid username, so we can't just use weak comparisons.
+ if( $vagueTarget === '' ){
+ $vagueTarget = null;
+ }
+
+ list( $target, $type ) = self::parseTarget( $specificTarget );
+ if( $type == Block::TYPE_ID || $type == Block::TYPE_AUTO ){
+ return Block::newFromID( $target );
+
+ } elseif( $target === null && $vagueTarget === null ){
+ # We're not going to find anything useful here
+ return null;
+
+ } elseif( in_array( $type, array( Block::TYPE_USER, Block::TYPE_IP, Block::TYPE_RANGE, null ) ) ) {
+ $block = new Block();
+ $block->fromMaster( $fromMaster );
+
+ if( $type !== null ){
+ $block->setTarget( $target );
+ }
+
+ if( $block->newLoad( $vagueTarget ) ){
+ return $block;
+ } else {
+ return null;
+ }