diff --git a/includes/AutoLoader.php b/includes/AutoLoader.php index 1e09d106e0e..16393bca587 100644 --- a/includes/AutoLoader.php +++ b/includes/AutoLoader.php @@ -674,6 +674,7 @@ $wgAutoloadLocalClasses = array( 'SpecialSpecialpages' => 'includes/specials/SpecialSpecialpages.php', 'SpecialStatistics' => 'includes/specials/SpecialStatistics.php', 'SpecialTags' => 'includes/specials/SpecialTags.php', + 'SpecialUnblock' => 'includes/specials/SpecialUnblock.php', 'SpecialUnlockdb' => 'includes/specials/SpecialUnlockdb.php', 'SpecialUpload' => 'includes/specials/SpecialUpload.php', 'SpecialUserlogout' => 'includes/specials/SpecialUserlogout.php', diff --git a/includes/Block.php b/includes/Block.php index d6fd3299151..b8a4f80eba2 100644 --- a/includes/Block.php +++ b/includes/Block.php @@ -920,7 +920,11 @@ class Block { # FIXME: everything above here is a mess, needs much cleaning up /** - * Given a target and the target's type, get a Block object if possible + * Given a target and the target's type, get an existing Block object if possible. + * Note that passing an IP address will get an applicable rangeblock if the IP is + * not individually blocked but falls within that range + * TODO: check that that fallback handles nested rangeblocks nicely (should return + * smallest one) * @param $target 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 @@ -942,7 +946,7 @@ class Block { } } elseif( $type == Block::TYPE_RANGE ){ - return Block::newFromDB( '', $target ); + return Block::newFromDB( $target, 0 ); } elseif( $type == Block::TYPE_ID || $type == Block::TYPE_AUTO ){ return Block::newFromID( $target ); @@ -1009,4 +1013,14 @@ class Block { return array( $target, $type ); } + + public function getType(){ + list( $target, $type ) = $this->getTargetAndType(); + return $type; + } + + public function getTarget(){ + list( $target, $type ) = $this->getTargetAndType(); + return $target; + } } diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index a7abbaa7a80..b7bcbe91cac 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -4948,6 +4948,7 @@ $wgSpecialPageGroups = array( 'Listbots' => 'users', 'Userrights' => 'users', 'Block' => 'users', + 'Unblock' => 'users', 'Preferences' => 'users', 'Resetpass' => 'users', 'DeletedContributions' => 'users', diff --git a/includes/LogEventsList.php b/includes/LogEventsList.php index 112bc17822f..9fd82848eb2 100644 --- a/includes/LogEventsList.php +++ b/includes/LogEventsList.php @@ -424,13 +424,10 @@ class LogEventsList { } else if( self::typeAction( $row, array( 'block', 'suppress' ), array( 'block', 'reblock' ), 'block' ) ) { $revert = '(' . $this->skin->link( - SpecialPage::getTitleFor( 'Ipblocklist' ), + SpecialPage::getTitleFor( 'Unblock', $row->log_title ), $this->message['unblocklink'], array(), - array( - 'action' => 'unblock', - 'ip' => $row->log_title - ), + array(), 'known' ) . $this->message['pipe-separator'] . diff --git a/includes/SpecialPage.php b/includes/SpecialPage.php index 043f72a08a7..5286adf1518 100644 --- a/includes/SpecialPage.php +++ b/includes/SpecialPage.php @@ -137,8 +137,8 @@ class SpecialPage { # Users and rights 'Block' => 'SpecialBlock', + 'Unblock' => 'SpecialUnblock', 'Ipblocklist' => 'IPUnblockForm', - 'Unblock' => array( 'SpecialRedirectToSpecial', 'Unblock', 'Ipblocklist', false, array( 'uselang', 'ip', 'id' ), array( 'action' => 'unblock' ) ), 'Resetpass' => 'SpecialResetpass', 'DeletedContributions' => 'DeletedContributionsPage', 'Preferences' => 'SpecialPreferences', diff --git a/includes/api/ApiUnblock.php b/includes/api/ApiUnblock.php index b0ce8038870..9a1bf336f4d 100644 --- a/includes/api/ApiUnblock.php +++ b/includes/api/ApiUnblock.php @@ -72,17 +72,19 @@ class ApiUnblock extends ApiBase { } } - $id = $params['id']; - $user = $params['user']; - $reason = ( is_null( $params['reason'] ) ? '' : $params['reason'] ); - $retval = IPUnblockForm::doUnblock( $id, $user, $reason, $range ); - if ( $retval ) { - $this->dieUsageMsg( $retval ); + $data = array( + 'Target' => is_null( $params['id'] ) ? $params['user'] : "#{$params['id']}", + 'Reason' => is_null( $params['reason'] ) ? '' : $params['reason'] + ); + $block = Block::newFromTarget( $data['Target'] ); + $retval = SpecialUnblock::processUnblock( $data ); + if ( $retval !== true ) { + $this->dieUsageMsg( $retval[0] ); } - $res['id'] = intval( $id ); - $res['user'] = $user; - $res['reason'] = $reason; + $res['id'] = $block->mId; + $res['user'] = $block->getType() == Block::TYPE_AUTO ? '' : $block->getTarget(); + $res['reason'] = $params['reason']; $this->getResult()->addValue( null, $this->getModuleName(), $res ); } diff --git a/includes/specials/SpecialBlock.php b/includes/specials/SpecialBlock.php index 22c8a0049ec..becb9f0a2bd 100644 --- a/includes/specials/SpecialBlock.php +++ b/includes/specials/SpecialBlock.php @@ -297,15 +297,14 @@ class SpecialBlock extends SpecialPage { } # Link to unblock the specified user, or to a blank unblock form - $list = SpecialPage::getTitleFor( 'Ipblocklist' ); - $query = array( 'action' => 'unblock' ); if( $this->target instanceof User ) { $message = wfMsgExt( 'ipb-unblock-addr', array( 'parseinline' ), $this->target->getName() ); - $query['ip'] = $this->target->getName(); + $list = SpecialPage::getTitleFor( 'Unblock', $this->target->getName() ); } else { $message = wfMsgExt( 'ipb-unblock', array( 'parseinline' ) ); + $list = SpecialPage::getTitleFor( 'Unblock' ); } - $links[] = $skin->linkKnown( $list, $message, array(), $query ); + $links[] = $skin->linkKnown( $list, $message, array() ); # Link to the block list $links[] = $skin->linkKnown( @@ -492,7 +491,7 @@ class SpecialBlock extends SpecialPage { $userId = 0; } else { # This should have been caught in the form field validation - return wfMessage( 'badipaddress' ); + return array( 'badipaddress' ); } if( ( strlen( $data['Expiry'] ) == 0) || ( strlen( $data['Expiry'] ) > 50 ) diff --git a/includes/specials/SpecialContributions.php b/includes/specials/SpecialContributions.php index fc2cfedc538..3119fe7db6c 100644 --- a/includes/specials/SpecialContributions.php +++ b/includes/specials/SpecialContributions.php @@ -256,13 +256,8 @@ class SpecialContributions extends SpecialPage { wfMsgHtml( 'change-blocklink' ) ); $tools[] = $sk->linkKnown( # Unblock link - SpecialPage::getTitleFor( 'Ipblocklist' ), - wfMsgHtml( 'unblocklink' ), - array(), - array( - 'action' => 'unblock', - 'ip' => $username - ) + SpecialPage::getTitleFor( 'Unblock', $username ), + wfMsgHtml( 'unblocklink' ) ); } else { # User is not blocked $tools[] = $sk->linkKnown( # Block link diff --git a/includes/specials/SpecialIpblocklist.php b/includes/specials/SpecialIpblocklist.php index 81c4643a069..4e6301a68e3 100644 --- a/includes/specials/SpecialIpblocklist.php +++ b/includes/specials/SpecialIpblocklist.php @@ -28,7 +28,7 @@ * @ingroup SpecialPage */ class IPUnblockForm extends SpecialPage { - var $ip, $reason, $id; + var $ip; var $hideuserblocks, $hidetempblocks, $hideaddressblocks; function __construct() { @@ -48,223 +48,23 @@ class IPUnblockForm extends SpecialPage { $ip = $wgRequest->getVal( 'ip', $ip ); $this->ip = trim( $wgRequest->getVal( 'wpUnblockAddress', $ip ) ); - $this->id = $wgRequest->getVal( 'id' ); - $this->reason = $wgRequest->getText( 'wpUnblockReason' ); $this->hideuserblocks = $wgRequest->getBool( 'hideuserblocks' ); $this->hidetempblocks = $wgRequest->getBool( 'hidetempblocks' ); $this->hideaddressblocks = $wgRequest->getBool( 'hideaddressblocks' ); $action = $wgRequest->getText( 'action' ); - $successip = $wgRequest->getVal( 'successip' ); if( $action == 'unblock' || $action == 'submit' && $wgRequest->wasPosted() ) { - # Check permissions - if( !$wgUser->isAllowed( 'block' ) ) { - $wgOut->permissionRequired( 'block' ); - return; - } - # Check for database lock - if( wfReadOnly() ) { - $wgOut->readOnlyPage(); - return; - } - - # bug 15810: blocked admins should have limited access here - if ( $wgUser->isBlocked() ) { - if ( $this->id ) { - # This doesn't pick up on autoblocks, but admins - # should have the ipblock-exempt permission anyway - $block = Block::newFromID( $this->id ); - $user = User::newFromName( $block->mAddress ); - } else { - $user = User::newFromName( $ip ); - } - $status = SpecialBlock::checkUnblockSelf( $user ); - if ( $status !== true ) { - throw new ErrorPageError( 'badaccess', $status ); - } - } - - if( $action == 'unblock' ){ - # Show unblock form - $this->showForm(); - } elseif( $action == 'submit' - && $wgRequest->wasPosted() - && $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) ) ) - { - # Remove blocks and redirect user to success page - $this->doSubmit(); - } - - } elseif( $action == 'success' ) { - # Inform the user of a successful unblock - # (No need to check permissions or locks here, - # if something was done, then it's too late!) - if ( substr( $successip, 0, 1) == '#' ) { - // A block ID was unblocked - $this->showList( $wgOut->parse( wfMsg( 'unblocked-id', $successip ) ) ); - } else { - // A username/IP was unblocked - $this->showList( $wgOut->parse( wfMsg( 'unblocked', $successip ) ) ); - } + # B/C @since 1.18: Unblock interface is now at Special:Unblock + $title = SpecialPage::getTitleFor( 'Unblock', $this->ip ); + $wgOut->redirect( $title->getFullUrl() ); + return; } else { # Just show the block list $this->showList( '' ); } } - /** - * Generates the unblock form - * - * @param $err String, Array or null: error message name or an array if - * there are parameters. Null indicates no error. - * @return $out string: HTML form - */ - function showForm( $err = null ) { - global $wgOut, $wgUser; - - $wgOut->addWikiMsg( 'unblockiptext' ); - - $action = $this->getTitle()->getLocalURL( 'action=submit' ); - - if ( $err !== null ) { - $wgOut->setSubtitle( wfMsg( 'formerror' ) ); - $wgOut->wrapWikiMsg( "$1\n", $err ); - } - - $addressPart = false; - if ( $this->id ) { - $block = Block::newFromID( $this->id ); - if ( $block ) { - $encName = htmlspecialchars( $block->getRedactedName() ); - $encId = $this->id; - $addressPart = $encName . Html::hidden( 'id', $encId ); - $ipa = wfMsgHtml( 'ipadressorusername' ); - } - } - if ( !$addressPart ) { - $addressPart = Xml::input( 'wpUnblockAddress', 40, $this->ip, array( 'type' => 'text', 'tabindex' => '1' ) ); - $ipa = Xml::label( wfMsg( 'ipadressorusername' ), 'wpUnblockAddress' ); - } - - $wgOut->addHTML( - Html::openElement( 'form', array( 'method' => 'post', 'action' => $action, 'id' => 'unblockip' ) ) . - Html::openElement( 'fieldset' ) . - Html::element( 'legend', null, wfMsg( 'ipb-unblock' ) ) . - Html::openElement( 'table', array( 'id' => 'mw-unblock-table' ) ). - "