/** * Blocks the user specified in the parameters for the given expiry, with the * given reason, and with all other settings provided in the params. If the block * succeeds, produces a result containing the details of the block and notice * of success. If it fails, the result will specify the nature of the error. */ public function execute() { global $wgContLang; $user = $this->getUser(); $params = $this->extractRequestParams(); if (!$user->isAllowed('block')) { $this->dieUsageMsg('cantblock'); } # bug 15810: blocked admins should have limited access here if ($user->isBlocked()) { $status = SpecialBlock::checkUnblockSelf($params['user'], $user); if ($status !== true) { $msg = $this->parseMsg($status); $this->dieUsage($msg['info'], $msg['code'], 0, ['blockinfo' => ApiQueryUserInfo::getBlockInfo($user->getBlock())]); } } $target = User::newFromName($params['user']); // Bug 38633 - if the target is a user (not an IP address), but it // doesn't exist or is unusable, error. if ($target instanceof User && ($target->isAnon() || !User::isUsableName($target->getName()))) { $this->dieUsageMsg(['nosuchuser', $params['user']]); } if ($params['hidename'] && !$user->isAllowed('hideuser')) { $this->dieUsageMsg('canthide'); } if ($params['noemail'] && !SpecialBlock::canBlockEmail($user)) { $this->dieUsageMsg('cantblock-email'); } $data = ['PreviousTarget' => $params['user'], 'Target' => $params['user'], 'Reason' => [$params['reason'], 'other', $params['reason']], 'Expiry' => $params['expiry'], 'HardBlock' => !$params['anononly'], 'CreateAccount' => $params['nocreate'], 'AutoBlock' => $params['autoblock'], 'DisableEmail' => $params['noemail'], 'HideUser' => $params['hidename'], 'DisableUTEdit' => !$params['allowusertalk'], 'Reblock' => $params['reblock'], 'Watch' => $params['watchuser'], 'Confirm' => true]; $retval = SpecialBlock::processForm($data, $this->getContext()); if ($retval !== true) { // We don't care about multiple errors, just report one of them $this->dieUsageMsg($retval); } list($target, ) = SpecialBlock::getTargetAndType($params['user']); $res['user'] = $params['user']; $res['userID'] = $target instanceof User ? $target->getId() : 0; $block = Block::newFromTarget($target, null, true); if ($block instanceof Block) { $res['expiry'] = $wgContLang->formatExpiry($block->mExpiry, TS_ISO_8601, 'infinite'); $res['id'] = $block->getId(); } else { # should be unreachable $res['expiry'] = ''; $res['id'] = ''; } $res['reason'] = $params['reason']; $res['anononly'] = $params['anononly']; $res['nocreate'] = $params['nocreate']; $res['autoblock'] = $params['autoblock']; $res['noemail'] = $params['noemail']; $res['hidename'] = $params['hidename']; $res['allowusertalk'] = $params['allowusertalk']; $res['watchuser'] = $params['watchuser']; $this->getResult()->addValue(null, $this->getModuleName(), $res); }
/** * Process the form * * @param $data Array * @param $context IContextSource * @throws ErrorPageError * @return Array( Array(message key, parameters) ) on failure, True on success */ public static function processUnblock(array $data, IContextSource $context) { $performer = $context->getUser(); $target = $data['Target']; $block = Block::newFromTarget($data['Target']); if (!$block instanceof Block) { return array(array('ipb_cant_unblock', $target)); } # bug 15810: blocked admins should have limited access here. This # won't allow sysops to remove autoblocks on themselves, but they # should have ipblock-exempt anyway $status = SpecialBlock::checkUnblockSelf($target, $performer); if ($status !== true) { throw new ErrorPageError('badaccess', $status); } # If the specified IP is a single address, and the block is a range block, don't # unblock the whole range. list($target, $type) = SpecialBlock::getTargetAndType($target); if ($block->getType() == Block::TYPE_RANGE && $type == Block::TYPE_IP) { $range = $block->getTarget(); return array(array('ipb_blocked_as_range', $target, $range)); } # If the name was hidden and the blocking user cannot hide # names, then don't allow any block removals... if (!$performer->isAllowed('hideuser') && $block->mHideName) { return array('unblock-hideuser'); } # Delete block if (!$block->delete()) { return array('ipb_cant_unblock', htmlspecialchars($block->getTarget())); } # Unset _deleted fields as needed if ($block->mHideName) { # Something is deeply FUBAR if this is not a User object, but who knows? $id = $block->getTarget() instanceof User ? $block->getTarget()->getID() : User::idFromName($block->getTarget()); RevisionDeleteUser::unsuppressUserName($block->getTarget(), $id); } # Redact the name (IP address) for autoblocks if ($block->getType() == Block::TYPE_AUTO) { $page = Title::makeTitle(NS_USER, '#' . $block->getId()); } else { $page = $block->getTarget() instanceof User ? $block->getTarget()->getUserpage() : Title::makeTitle(NS_USER, $block->getTarget()); } # Make log entry $log = new LogPage('block'); $log->addEntry('unblock', $page, $data['Reason'], array(), $performer); return true; }
/** * Process the form * @return Array( Array(message key, parameters) ) on failure, True on success */ public static function processUnblock(array $data) { global $wgUser; $target = $data['Target']; $block = Block::newFromTarget($data['Target']); if (!$block instanceof Block) { return array(array('ipb_cant_unblock', $target)); } # If the specified IP is a single address, and the block is a range block, don't # unblock the whole range. list($target, $type) = SpecialBlock::getTargetAndType($target); if ($block->getType() == Block::TYPE_RANGE && $type == Block::TYPE_IP) { $range = $block->getTarget(); return array(array('ipb_blocked_as_range', $target, $range)); } # If the name was hidden and the blocking user cannot hide # names, then don't allow any block removals... if (!$wgUser->isAllowed('hideuser') && $block->mHideName) { return array('unblock-hideuser'); } # Delete block if (!$block->delete()) { return array('ipb_cant_unblock', htmlspecialchars($block->getTarget())); } # Unset _deleted fields as needed if ($block->mHideName) { # Something is deeply FUBAR if this is not a User object, but who knows? $id = $block->getTarget() instanceof User ? $block->getTarget()->getID() : User::idFromName($block->getTarget()); RevisionDeleteUser::unsuppressUserName($block->getTarget(), $id); } # Redact the name (IP address) for autoblocks if ($block->getType() == Block::TYPE_AUTO) { $page = Title::makeTitle(NS_USER, '#' . $block->getId()); } else { $page = $block->getTarget() instanceof User ? $block->getTarget()->getUserpage() : Title::makeTitle(NS_USER, $block->getTarget()); } # Make log entry $log = new LogPage('block'); $log->addEntry('unblock', $page, $data['Reason']); return true; }
/** * Blocks the user specified in the parameters for the given expiry, with the * given reason, and with all other settings provided in the params. If the block * succeeds, produces a result containing the details of the block and notice * of success. If it fails, the result will specify the nature of the error. */ public function execute() { global $wgUser; $params = $this->extractRequestParams(); if ($params['gettoken']) { $res['blocktoken'] = $wgUser->editToken('', $this->getMain()->getRequest()); $this->getResult()->addValue(null, $this->getModuleName(), $res); return; } if (!$wgUser->isAllowed('block')) { $this->dieUsageMsg('cantblock'); } # bug 15810: blocked admins should have limited access here if ($wgUser->isBlocked()) { $status = SpecialBlock::checkUnblockSelf($params['user']); if ($status !== true) { $this->dieUsageMsg(array($status)); } } if ($params['hidename'] && !$wgUser->isAllowed('hideuser')) { $this->dieUsageMsg('canthide'); } if ($params['noemail'] && !SpecialBlock::canBlockEmail($wgUser)) { $this->dieUsageMsg('cantblock-email'); } $data = array('Target' => $params['user'], 'Reason' => array(is_null($params['reason']) ? '' : $params['reason'], 'other', is_null($params['reason']) ? '' : $params['reason']), 'Expiry' => $params['expiry'] == 'never' ? 'infinite' : $params['expiry'], 'HardBlock' => !$params['anononly'], 'CreateAccount' => $params['nocreate'], 'AutoBlock' => $params['autoblock'], 'DisableEmail' => $params['noemail'], 'HideUser' => $params['hidename'], 'DisableUTEdit' => $params['allowusertalk'], 'AlreadyBlocked' => $params['reblock'], 'Watch' => $params['watchuser'], 'Confirm' => true); $retval = SpecialBlock::processForm($data); if ($retval !== true) { // We don't care about multiple errors, just report one of them $this->dieUsageMsg($retval); } list($target, ) = SpecialBlock::getTargetAndType($params['user']); $res['user'] = $params['user']; $res['userID'] = $target instanceof User ? $target->getId() : 0; $block = Block::newFromTarget($target); if ($block instanceof Block) { $res['expiry'] = $block->mExpiry == wfGetDB(DB_SLAVE)->getInfinity() ? 'infinite' : wfTimestamp(TS_ISO_8601, $block->mExpiry); } else { # should be unreachable $res['expiry'] = ''; } $res['reason'] = $params['reason']; if ($params['anononly']) { $res['anononly'] = ''; } if ($params['nocreate']) { $res['nocreate'] = ''; } if ($params['autoblock']) { $res['autoblock'] = ''; } if ($params['noemail']) { $res['noemail'] = ''; } if ($params['hidename']) { $res['hidename'] = ''; } if ($params['allowusertalk']) { $res['allowusertalk'] = ''; } if ($params['watchuser']) { $res['watchuser'] = ''; } $this->getResult()->addValue(null, $this->getModuleName(), $res); }
/** * Blocks the user specified in the parameters for the given expiry, with the * given reason, and with all other settings provided in the params. If the block * succeeds, produces a result containing the details of the block and notice * of success. If it fails, the result will specify the nature of the error. */ public function execute() { $user = $this->getUser(); $params = $this->extractRequestParams(); if ( !$user->isAllowed( 'block' ) ) { $this->dieUsageMsg( 'cantblock' ); } # bug 15810: blocked admins should have limited access here if ( $user->isBlocked() ) { $status = SpecialBlock::checkUnblockSelf( $params['user'], $user ); if ( $status !== true ) { $this->dieUsageMsg( array( $status ) ); } } $target = User::newFromName( $params['user'] ); // Bug 38633 - if the target is a user (not an IP address), but it doesn't exist or is unusable, error. if ( $target instanceof User && ( $target->isAnon() /* doesn't exist */ || !User::isUsableName( $target->getName() ) ) ) { $this->dieUsageMsg( array( 'nosuchuser', $params['user'] ) ); } if ( $params['hidename'] && !$user->isAllowed( 'hideuser' ) ) { $this->dieUsageMsg( 'canthide' ); } if ( $params['noemail'] && !SpecialBlock::canBlockEmail( $user ) ) { $this->dieUsageMsg( 'cantblock-email' ); } $data = array( 'PreviousTarget' => $params['user'], 'Target' => $params['user'], 'Reason' => array( $params['reason'], 'other', $params['reason'] ), 'Expiry' => $params['expiry'] == 'never' ? 'infinite' : $params['expiry'], 'HardBlock' => !$params['anononly'], 'CreateAccount' => $params['nocreate'], 'AutoBlock' => $params['autoblock'], 'DisableEmail' => $params['noemail'], 'HideUser' => $params['hidename'], 'DisableUTEdit' => !$params['allowusertalk'], 'Reblock' => $params['reblock'], 'Watch' => $params['watchuser'], 'Confirm' => true, ); $retval = SpecialBlock::processForm( $data, $this->getContext() ); if ( $retval !== true ) { // We don't care about multiple errors, just report one of them $this->dieUsageMsg( $retval ); } list( $target, /*...*/ ) = SpecialBlock::getTargetAndType( $params['user'] ); $res['user'] = $params['user']; $res['userID'] = $target instanceof User ? $target->getId() : 0; $block = Block::newFromTarget( $target ); if ( $block instanceof Block ) { $res['expiry'] = $block->mExpiry == $this->getDB()->getInfinity() ? 'infinite' : wfTimestamp( TS_ISO_8601, $block->mExpiry ); $res['id'] = $block->getId(); } else { # should be unreachable $res['expiry'] = ''; $res['id'] = ''; } $res['reason'] = $params['reason']; if ( $params['anononly'] ) { $res['anononly'] = ''; } if ( $params['nocreate'] ) { $res['nocreate'] = ''; } if ( $params['autoblock'] ) { $res['autoblock'] = ''; } if ( $params['noemail'] ) { $res['noemail'] = ''; } if ( $params['hidename'] ) { $res['hidename'] = ''; } if ( $params['allowusertalk'] ) { $res['allowusertalk'] = ''; } if ( $params['watchuser'] ) { $res['watchuser'] = ''; } $this->getResult()->addValue( null, $this->getModuleName(), $res ); }