/** * Unblocks the specified user or provides the reason the unblock failed. */ public function execute() { $user = $this->getUser(); $params = $this->extractRequestParams(); if (is_null($params['id']) && is_null($params['user'])) { $this->dieUsageMsg('unblock-notarget'); } if (!is_null($params['id']) && !is_null($params['user'])) { $this->dieUsageMsg('unblock-idanduser'); } if (!$user->isAllowed('block')) { $this->dieUsageMsg('cantunblock'); } # bug 15810: blocked admins should have limited access here if ($user->isBlocked()) { $status = SpecialBlock::checkUnblockSelf($params['user'], $user); if ($status !== true) { $this->dieUsageMsg($status); } } $data = array('Target' => is_null($params['id']) ? $params['user'] : "******", 'Reason' => $params['reason']); $block = Block::newFromTarget($data['Target']); $retval = SpecialUnblock::processUnblock($data, $this->getContext()); if ($retval !== true) { $this->dieUsageMsg($retval[0]); } $res['id'] = $block->getId(); $target = $block->getType() == Block::TYPE_AUTO ? '' : $block->getTarget(); $res['user'] = $target instanceof User ? $target->getName() : $target; $res['userid'] = $target instanceof User ? $target->getId() : 0; $res['reason'] = $params['reason']; $this->getResult()->addValue(null, $this->getModuleName(), $res); }
/** * Block the target user account */ public function blockUser() { wfProfileIn(__METHOD__); if (!$this->wg->User->isAllowed('quicktools')) { $this->response->setVal('success', false); $this->response->setVal('error', wfMessage('quicktools-permissionerror')->plain()); wfProfileOut(__METHOD__); return true; } $target = $this->request->getVal('target'); $blockLength = $this->request->getVal('length'); $summary = $this->request->getVal('summary'); $data = array('Target' => $target, 'Reason' => array(is_null($summary) ? '' : $summary, 'other', is_null($summary) ? '' : $summary), 'Expiry' => $blockLength, 'HardBlock' => true, 'CreateAccount' => true, 'AutoBlock' => true, 'DisableEmail' => true, 'DisableUTEdit' => false, 'AlreadyBlocked' => true, 'Watch' => false, 'Confirm' => true); $retval = SpecialBlock::processForm($data, $this->getContext()); if ($retval !== true) { $this->response->setVal('success', false); $this->response->setVal('error', wfMessage($retval)->escaped()); wfProfileOut(__METHOD__); return true; } $this->response->setVal('success', true); $this->response->setVal('message', wfMessage('quicktools-success-block', $target)->escaped()); wfProfileOut(__METHOD__); 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 $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); }
/** * Unblocks the specified user or provides the reason the unblock failed. */ public function execute() { $user = $this->getUser(); $params = $this->extractRequestParams(); if (is_null($params['id']) && is_null($params['user'])) { $this->dieUsageMsg('unblock-notarget'); } if (!is_null($params['id']) && !is_null($params['user'])) { $this->dieUsageMsg('unblock-idanduser'); } if (!$user->isAllowed('block')) { $this->dieUsageMsg('cantunblock'); } # 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())]); } } // Check if user can add tags if (!is_null($params['tags'])) { $ableToTag = ChangeTags::canAddTagsAccompanyingChange($params['tags'], $user); if (!$ableToTag->isOK()) { $this->dieStatus($ableToTag); } } $data = ['Target' => is_null($params['id']) ? $params['user'] : "******", 'Reason' => $params['reason'], 'Tags' => $params['tags']]; $block = Block::newFromTarget($data['Target']); $retval = SpecialUnblock::processUnblock($data, $this->getContext()); if ($retval !== true) { $this->dieUsageMsg($retval[0]); } $res['id'] = $block->getId(); $target = $block->getType() == Block::TYPE_AUTO ? '' : $block->getTarget(); $res['user'] = $target instanceof User ? $target->getName() : $target; $res['userid'] = $target instanceof User ? $target->getId() : 0; $res['reason'] = $params['reason']; $this->getResult()->addValue(null, $this->getModuleName(), $res); }
/** * Unblocks the specified user or provides the reason the unblock failed. */ public function execute() { $user = $this->getUser(); $params = $this->extractRequestParams(); if ($params['gettoken']) { // If we're in JSON callback mode, no tokens can be obtained if (!is_null($this->getMain()->getRequest()->getVal('callback'))) { $this->dieUsage('Cannot get token when using a callback', 'aborted'); } $res['unblocktoken'] = $user->getEditToken('', $this->getMain()->getRequest()); $this->getResult()->addValue(null, $this->getModuleName(), $res); return; } if (is_null($params['id']) && is_null($params['user'])) { $this->dieUsageMsg('unblock-notarget'); } if (!is_null($params['id']) && !is_null($params['user'])) { $this->dieUsageMsg('unblock-idanduser'); } if (!$user->isAllowed('block')) { $this->dieUsageMsg('cantunblock'); } # bug 15810: blocked admins should have limited access here if ($user->isBlocked()) { $status = SpecialBlock::checkUnblockSelf($params['user'], $user); if ($status !== true) { $this->dieUsageMsg($status); } } $data = array('Target' => is_null($params['id']) ? $params['user'] : "******", 'Reason' => is_null($params['reason']) ? '' : $params['reason']); $block = Block::newFromTarget($data['Target']); $retval = SpecialUnblock::processUnblock($data, $this->getContext()); if ($retval !== true) { $this->dieUsageMsg($retval[0]); } $res['id'] = $block->getId(); $target = $block->getType() == Block::TYPE_AUTO ? '' : $block->getTarget(); $res['user'] = $target instanceof User ? $target->getName() : $target; $res['reason'] = $params['reason']; $this->getResult()->addValue(null, $this->getModuleName(), $res); }
/** * Unblocks the specified user or provides the reason the unblock failed. */ public function execute() { global $wgUser; $params = $this->extractRequestParams(); if ($params['gettoken']) { $res['unblocktoken'] = $wgUser->editToken('', $this->getMain()->getRequest()); $this->getResult()->addValue(null, $this->getModuleName(), $res); return; } if (is_null($params['id']) && is_null($params['user'])) { $this->dieUsageMsg('unblock-notarget'); } if (!is_null($params['id']) && !is_null($params['user'])) { $this->dieUsageMsg('unblock-idanduser'); } if (!$wgUser->isAllowed('block')) { $this->dieUsageMsg('cantunblock'); } # bug 15810: blocked admins should have limited access here if ($wgUser->isBlocked()) { $status = SpecialBlock::checkUnblockSelf($params['user']); if ($status !== true) { $this->dieUsageMsg($status); } } $data = array('Target' => is_null($params['id']) ? $params['user'] : "******", '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'] = $block->getId(); $res['user'] = $block->getType() == Block::TYPE_AUTO ? '' : $block->getTarget(); $res['reason'] = $params['reason']; $this->getResult()->addValue(null, $this->getModuleName(), $res); }
/** * @todo Maybe translate block durations. Note that this function is somewhat misnamed: it * deals with translating the *duration* ("1 week", "4 days", etc), not the expiry time * (which is an absolute timestamp). Please note: do NOT add this blindly, as it is used * on old expiry lengths recorded in log entries. You'd need to provide the start date to * match up with it. * * @param string $str The validated block duration in English * @return string Somehow translated block duration * @see LanguageFi.php for example implementation */ function translateBlockExpiry($str) { $duration = SpecialBlock::getSuggestedDurations($this); foreach ($duration as $show => $value) { if (strcmp($str, $value) == 0) { return htmlspecialchars(trim($show)); } } // Since usually only infinite or indefinite is only on list, so try // equivalents if still here. $indefs = array('infinite', 'infinity', 'indefinite'); if (in_array($str, $indefs)) { foreach ($indefs as $val) { $show = array_search($val, $duration, true); if ($show !== false) { return htmlspecialchars(trim($show)); } } } // If all else fails, return a standard duration or timestamp description. $time = strtotime($str, 0); if ($time === false) { // Unknown format. Return it as-is in case. return $str; } elseif ($time !== strtotime($str, 1)) { // It's a relative timestamp. // $time is relative to 0 so it's a duration length. return $this->formatDuration($time); } else { // It's an absolute timestamp. if ($time === 0) { // wfTimestamp() handles 0 as current time instead of epoch. return $this->timeanddate('19700101000000'); } else { return $this->timeanddate($time); } } }
/** * 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; }
/** * Block a list of selected users * * @param $users Array * @param $reason String * @param $tag String: replaces user pages * @param $talkTag String: replaces user talk pages * @return Array: list of html-safe usernames */ public static function doMassUserBlockInternal($users, $reason = '', $tag = '', $talkTag = '') { global $wgUser; $counter = $blockSize = 0; $safeUsers = array(); $log = new LogPage('block'); foreach ($users as $name) { # Enforce limits $counter++; $blockSize++; # Lets not go *too* fast if ($blockSize >= 20) { $blockSize = 0; wfWaitForSlaves(5); } $u = User::newFromName($name, false); // If user doesn't exist, it ought to be an IP then if (is_null($u) || !$u->getId() && !IP::isIPAddress($u->getName())) { continue; } $userTitle = $u->getUserPage(); $userTalkTitle = $u->getTalkPage(); $userpage = new Article($userTitle); $usertalk = new Article($userTalkTitle); $safeUsers[] = '[[' . $userTitle->getPrefixedText() . '|' . $userTitle->getText() . ']]'; $expirestr = $u->getId() ? 'indefinite' : '1 week'; $expiry = SpecialBlock::parseExpiryInput($expirestr); $anonOnly = IP::isIPAddress($u->getName()) ? 1 : 0; // Create the block $block = new Block(); $block->setTarget($u); $block->setBlocker($wgUser); $block->mReason = $reason; $block->mExpiry = $expiry; $block->isHardblock(!IP::isIPAddress($u->getName())); $block->isAutoblocking(true); $block->prevents('createaccount', true); $block->prevents('sendemail', false); $block->prevents('editownusertalk', false); $oldblock = Block::newFromTarget($u->getName()); if (!$oldblock) { $block->insert(); # Prepare log parameters $logParams = array(); $logParams[] = $expirestr; if ($anonOnly) { $logParams[] = 'anononly'; } $logParams[] = 'nocreate'; # Add log entry $log->addEntry('block', $userTitle, $reason, $logParams); } # Tag userpage! (check length to avoid mistakes) if (strlen($tag) > 2) { $userpage->doEdit($tag, $reason, EDIT_MINOR); } if (strlen($talkTag) > 2) { $usertalk->doEdit($talkTag, $reason, EDIT_MINOR); } } return $safeUsers; }
/** * @param ApiResult $result * @param array $vals * @param string $params * @param string $type * @param string $action * @param string $ts * @param bool $legacy * @return array */ public static function addLogParams($result, &$vals, $params, $type, $action, $ts, $legacy = false) { switch ($type) { case 'move': if ($legacy) { $targetKey = 0; $noredirKey = 1; } else { $targetKey = '4::target'; $noredirKey = '5::noredir'; } if (isset($params[$targetKey])) { $title = Title::newFromText($params[$targetKey]); if ($title) { $vals2 = array(); ApiQueryBase::addTitleInfo($vals2, $title, 'new_'); $vals[$type] = $vals2; } } if (isset($params[$noredirKey]) && $params[$noredirKey]) { $vals[$type]['suppressedredirect'] = ''; } $params = null; break; case 'patrol': if ($legacy) { $cur = 0; $prev = 1; $auto = 2; } else { $cur = '4::curid'; $prev = '5::previd'; $auto = '6::auto'; } $vals2 = array(); $vals2['cur'] = $params[$cur]; $vals2['prev'] = $params[$prev]; $vals2['auto'] = $params[$auto]; $vals[$type] = $vals2; $params = null; break; case 'rights': $vals2 = array(); if ($legacy) { list($vals2['old'], $vals2['new']) = $params; } else { $vals2['new'] = implode(', ', $params['5::newgroups']); $vals2['old'] = implode(', ', $params['4::oldgroups']); } $vals[$type] = $vals2; $params = null; break; case 'block': if ($action == 'unblock') { break; } $vals2 = array(); list($vals2['duration'], $vals2['flags']) = $params; // Indefinite blocks have no expiry time if (SpecialBlock::parseExpiryInput($params[0]) !== wfGetDB(DB_SLAVE)->getInfinity()) { $vals2['expiry'] = wfTimestamp(TS_ISO_8601, strtotime($params[0], wfTimestamp(TS_UNIX, $ts))); } $vals[$type] = $vals2; $params = null; break; case 'upload': if (isset($params['img_timestamp'])) { $params['img_timestamp'] = wfTimestamp(TS_ISO_8601, $params['img_timestamp']); } break; } if (!is_null($params)) { $logParams = array(); // Keys like "4::paramname" can't be used for output so we change them to "paramname" foreach ($params as $key => $value) { if (strpos($key, ':') === false) { $logParams[$key] = $value; continue; } $logParam = explode(':', $key, 3); $logParams[$logParam[2]] = $value; } $result->setIndexedTagName($logParams, 'param'); $result->setIndexedTagName_recursive($logParams, 'param'); $vals = array_merge($vals, $logParams); } return $vals; }
/** * 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; }
static function block($address, $reason, $expiry, $options = array()) { global $wgContLang; $expiry = SpecialBlock::parseExpiryInput($expiry); $errors = self::insertBlock($address, $reason, $expiry, $options); if (count($errors) > 0) { return $errors; } $anonOnly = in_array('anon-only', $options); $modify = in_array('modify', $options); // Log it. $logAction = $modify ? 'modify' : 'gblock2'; $flags = array(); if ($anonOnly) { $flags[] = wfMsgForContent('globalblocking-list-anononly'); } if ($expiry != 'infinity') { $displayExpiry = $wgContLang->timeanddate($expiry); $flags[] = wfMsgForContent('globalblocking-logentry-expiry', $displayExpiry); } else { $flags[] = wfMsgForContent('globalblocking-logentry-noexpiry'); } $info = implode(', ', $flags); $page = new LogPage('gblblock'); $page->addEntry($logAction, Title::makeTitleSafe(NS_USER, $address), $reason, array($info, $address)); return array(); }
/** * @todo Maybe translate block durations. Note that this function is somewhat misnamed: it * deals with translating the *duration* ("1 week", "4 days", etc), not the expiry time * (which is an absolute timestamp). Please note: do NOT add this blindly, as it is used * on old expiry lengths recorded in log entries. You'd need to provide the start date to * match up with it. * * @param string $str The validated block duration in English * @return string Somehow translated block duration * @see LanguageFi.php for example implementation */ function translateBlockExpiry($str) { $duration = SpecialBlock::getSuggestedDurations($this); foreach ($duration as $show => $value) { if (strcmp($str, $value) == 0) { return htmlspecialchars(trim($show)); } } if (wfIsInfinity($str)) { foreach ($duration as $show => $value) { if (wfIsInfinity($value)) { return htmlspecialchars(trim($show)); } } } // If all else fails, return a standard duration or timestamp description. $time = strtotime($str, 0); if ($time === false) { // Unknown format. Return it as-is in case. return $str; } elseif ($time !== strtotime($str, 1)) { // It's a relative timestamp. // $time is relative to 0 so it's a duration length. return $this->formatDuration($time); } else { // It's an absolute timestamp. if ($time === 0) { // wfTimestamp() handles 0 as current time instead of epoch. return $this->timeanddate('19700101000000'); } else { return $this->timeanddate($time); } } }
/** * @param $result ApiResult * @param $vals array * @param $params string * @param $type string * @param $action string * @param $ts * @return array */ public static function addLogParams($result, &$vals, $params, $type, $action, $ts) { $params = explode("\n", $params); switch ($type) { case 'move': if (isset($params[0])) { $title = Title::newFromText($params[0]); if ($title) { $vals2 = array(); ApiQueryBase::addTitleInfo($vals2, $title, 'new_'); $vals[$type] = $vals2; } } if (isset($params[1]) && $params[1]) { $vals[$type]['suppressedredirect'] = ''; } $params = null; break; case 'patrol': $vals2 = array(); list($vals2['cur'], $vals2['prev'], $vals2['auto']) = $params; $vals[$type] = $vals2; $params = null; break; case 'rights': $vals2 = array(); list($vals2['old'], $vals2['new']) = $params; $vals[$type] = $vals2; $params = null; break; case 'block': if ($action == 'unblock') { break; } $vals2 = array(); list($vals2['duration'], $vals2['flags']) = $params; // Indefinite blocks have no expiry time if (SpecialBlock::parseExpiryInput($params[0]) !== wfGetDB(DB_SLAVE)->getInfinity()) { $vals2['expiry'] = wfTimestamp(TS_ISO_8601, strtotime($params[0], wfTimestamp(TS_UNIX, $ts))); } $vals[$type] = $vals2; $params = null; break; } if (!is_null($params)) { $result->setIndexedTagName($params, 'param'); $vals = array_merge($vals, $params); } return $vals; }
/** * 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 ); }
/** * @param $result ApiResult * @param $vals array * @param $params string * @param $type string * @param $action string * @param $ts * @param $legacy bool * @return array */ public static function addLogParams($result, &$vals, $params, $type, $action, $ts, $legacy = false) { switch ($type) { case 'move': if ($legacy) { $targetKey = 0; $noredirKey = 1; } else { $targetKey = '4::target'; $noredirKey = '5::noredir'; } if (isset($params[$targetKey])) { $title = Title::newFromText($params[$targetKey]); if ($title) { $vals2 = array(); ApiQueryBase::addTitleInfo($vals2, $title, 'new_'); $vals[$type] = $vals2; } } if (isset($params[$noredirKey]) && $params[$noredirKey]) { $vals[$type]['suppressedredirect'] = ''; } $params = null; break; case 'patrol': if ($legacy) { $cur = 0; $prev = 1; $auto = 2; } else { $cur = '4::curid'; $prev = '5::previd'; $auto = '6::auto'; } $vals2 = array(); $vals2['cur'] = $params[$cur]; $vals2['prev'] = $params[$prev]; $vals2['auto'] = $params[$auto]; $vals[$type] = $vals2; $params = null; break; case 'rights': $vals2 = array(); list($vals2['old'], $vals2['new']) = $params; $vals[$type] = $vals2; $params = null; break; case 'block': if ($action == 'unblock') { break; } $vals2 = array(); list($vals2['duration'], $vals2['flags']) = $params; // Indefinite blocks have no expiry time if (SpecialBlock::parseExpiryInput($params[0]) !== wfGetDB(DB_SLAVE)->getInfinity()) { $vals2['expiry'] = wfTimestamp(TS_ISO_8601, strtotime($params[0], wfTimestamp(TS_UNIX, $ts))); } $vals[$type] = $vals2; $params = null; break; } if (!is_null($params)) { $result->setIndexedTagName($params, 'param'); $result->setIndexedTagName_recursive($params, 'param'); $vals = array_merge($vals, $params); } return $vals; }
public static function takeConsequenceAction($action, $parameters, $title, $vars, $rule_desc) { $display = ''; switch ($action) { case 'disallow': if (strlen($parameters[0])) { $display .= wfMsgExt($parameters[0], 'parseinline', array($rule_desc)) . "\n"; } else { // Generic message. $display .= wfMsgExt('abusefilter-disallowed', 'parseinline', array($rule_desc)) . "<br />\n"; } break; case 'block': global $wgUser, $wgAbuseFilterBlockDuration; $filterUser = AbuseFilter::getFilterUser(); // Create a block. $block = new Block(); $block->setTarget($wgUser->getName()); $block->setBlocker($filterUser); $block->mReason = wfMsgForContent('abusefilter-blockreason', $rule_desc); $block->isHardblock(false); $block->prevents('createaccount', true); $block->mExpiry = SpecialBlock::parseExpiryInput($wgAbuseFilterBlockDuration); $block->insert(); // Log it # Prepare log parameters $logParams = array(); if ($block->mExpiry == 'infinity') { $logParams[] = 'indefinite'; } else { $logParams[] = $wgAbuseFilterBlockDuration; } $logParams[] = 'nocreate, angry-autoblock'; $log = new LogPage('block'); $log->addEntry('block', Title::makeTitle(NS_USER, $wgUser->getName()), wfMsgForContent('abusefilter-blockreason', $rule_desc), $logParams, self::getFilterUser()); $display .= wfMsgExt('abusefilter-blocked-display', 'parseinline', array($rule_desc)) . "<br />\n"; break; case 'rangeblock': $filterUser = AbuseFilter::getFilterUser(); $range = IP::sanitizeRange(wfGetIP() . '/16'); // Create a block. $block = new Block(); $block->setTarget($range); $block->setBlocker($filterUser); $block->mReason = wfMsgForContent('abusefilter-blockreason', $rule_desc); $block->isHardblock(false); $block->prevents('createaccount', true); $block->mExpiry = SpecialBlock::parseExpiryInput('1 week'); $block->insert(); // Log it # Prepare log parameters $logParams = array(); $logParams[] = 'indefinite'; $logParams[] = 'nocreate, angry-autoblock'; $log = new LogPage('block'); $log->addEntry('block', Title::makeTitle(NS_USER, $range), wfMsgForContent('abusefilter-blockreason', $rule_desc), $logParams, self::getFilterUser()); $display .= wfMsgExt('abusefilter-blocked-display', 'parseinline', $rule_desc) . "<br />\n"; break; case 'degroup': global $wgUser; if (!$wgUser->isAnon()) { // Remove all groups from the user. Ouch. $groups = $wgUser->getGroups(); foreach ($groups as $group) { $wgUser->removeGroup($group); } $display .= wfMsgExt('abusefilter-degrouped', 'parseinline', array($rule_desc)) . "<br />\n"; // Don't log it if there aren't any groups being removed! if (!count($groups)) { break; } // Log it. $log = new LogPage('rights'); $log->addEntry('rights', $wgUser->getUserPage(), wfMsgForContent('abusefilter-degroupreason', $rule_desc), array(implode(', ', $groups), wfMsgForContent('rightsnone')), self::getFilterUser()); } break; case 'blockautopromote': global $wgUser, $wgMemc; if (!$wgUser->isAnon()) { $blockPeriod = (int) mt_rand(3 * 86400, 7 * 86400); // Block for 3-7 days. $wgMemc->set(self::autoPromoteBlockKey($wgUser), true, $blockPeriod); $display .= wfMsgExt('abusefilter-autopromote-blocked', 'parseinline', array($rule_desc)) . "<br />\n"; } break; case 'flag': // Do nothing. Here for completeness. break; case 'tag': // Mark with a tag on recentchanges. global $wgUser; $actionID = implode('-', array($title->getPrefixedText(), $wgUser->getName(), $vars->getVar('ACTION')->toString())); AbuseFilter::$tagsToSet[$actionID] = $parameters; break; default: wfDebugLog('AbuseFilter', "Unrecognised action {$action}"); } return $display; }
/** * @param $action string * @param $parameters array * @param $title Title * @param $vars AbuseFilterVariableHolder * @param $rule_desc * @param $rule_number int|string * * @return array|null a message describing the action that was taken, * or null if no action was taken. The message is given as an array * containing the message key followed by any message parameters. * * @note: Returning the message as an array instead of a Message object is * needed for compatibility with MW 1.20: we will be constructing a * Status object from these messages, and before 1.21, Status did * not accept Message objects to be added directly. */ public static function takeConsequenceAction($action, $parameters, $title, $vars, $rule_desc, $rule_number) { global $wgAbuseFilterCustomActionsHandlers, $wgRequest; $message = null; switch ($action) { case 'disallow': if (strlen($parameters[0])) { $message = array($parameters[0], $rule_desc, $rule_number); } else { // Generic message. $message = array('abusefilter-disallowed', $rule_desc, $rule_number); } break; case 'block': global $wgUser, $wgAbuseFilterBlockDuration, $wgAbuseFilterAnonBlockDuration; $filterUser = AbuseFilter::getFilterUser(); // Create a block. $block = new Block(); $block->setTarget($wgUser->getName()); $block->setBlocker($filterUser); $block->mReason = wfMessage('abusefilter-blockreason', $rule_desc, $rule_number)->inContentLanguage()->text(); $block->isHardblock(false); $block->isAutoblocking(true); $block->prevents('createaccount', true); $block->prevents('editownusertalk', false); if ($wgUser->isAnon() && $wgAbuseFilterAnonBlockDuration !== null) { // The user isn't logged in and the anon block duration doesn't default to $wgAbuseFilterBlockDuration $expiry = $wgAbuseFilterAnonBlockDuration; } else { $expiry = $wgAbuseFilterBlockDuration; } $block->mExpiry = SpecialBlock::parseExpiryInput($expiry); $block->insert(); // Log it # Prepare log parameters $logParams = array(); if ($block->mExpiry == 'infinity') { $logParams[] = 'indefinite'; } else { $logParams[] = $expiry; } $logParams[] = 'nocreate'; $log = new LogPage('block'); $log->addEntry('block', Title::makeTitle(NS_USER, $wgUser->getName()), wfMessage('abusefilter-blockreason', $rule_desc, $rule_number)->inContentLanguage()->text(), $logParams, self::getFilterUser()); $message = array('abusefilter-blocked-display', $rule_desc, $rule_number); break; case 'rangeblock': $filterUser = AbuseFilter::getFilterUser(); $range = IP::sanitizeRange($wgRequest->getIP() . '/16'); // Create a block. $block = new Block(); $block->setTarget($range); $block->setBlocker($filterUser); $block->mReason = wfMessage('abusefilter-blockreason', $rule_desc, $rule_number)->inContentLanguage()->text(); $block->isHardblock(false); $block->prevents('createaccount', true); $block->prevents('editownusertalk', false); $block->mExpiry = SpecialBlock::parseExpiryInput('1 week'); $block->insert(); // Log it # Prepare log parameters $logParams = array(); $logParams[] = 'indefinite'; $logParams[] = 'nocreate'; $log = new LogPage('block'); $log->addEntry('block', Title::makeTitle(NS_USER, $range), wfMessage('abusefilter-blockreason', $rule_desc, $rule_number)->inContentLanguage()->text(), $logParams, self::getFilterUser()); $message = array('abusefilter-blocked-display', $rule_desc, $rule_number); break; case 'degroup': global $wgUser; if (!$wgUser->isAnon()) { // Remove all groups from the user. Ouch. $groups = $wgUser->getGroups(); foreach ($groups as $group) { $wgUser->removeGroup($group); } $message = array('abusefilter-degrouped', $rule_desc, $rule_number); // Don't log it if there aren't any groups being removed! if (!count($groups)) { break; } // Log it. $log = new LogPage('rights'); $log->addEntry('rights', $wgUser->getUserPage(), wfMessage('abusefilter-degroupreason', $rule_desc, $rule_number)->inContentLanguage()->text(), array(implode(', ', $groups), ''), self::getFilterUser()); } break; case 'blockautopromote': global $wgUser, $wgMemc; if (!$wgUser->isAnon()) { $blockPeriod = (int) mt_rand(3 * 86400, 7 * 86400); // Block for 3-7 days. $wgMemc->set(self::autoPromoteBlockKey($wgUser), true, $blockPeriod); $message = array('abusefilter-autopromote-blocked', $rule_desc, $rule_number); } break; case 'flag': // Do nothing. Here for completeness. break; case 'tag': // Mark with a tag on recentchanges. global $wgUser; $actionID = implode('-', array($title->getPrefixedText(), $wgUser->getName(), $vars->getVar('ACTION')->toString())); if (!isset(AbuseFilter::$tagsToSet[$actionID])) { AbuseFilter::$tagsToSet[$actionID] = $parameters; } else { AbuseFilter::$tagsToSet[$actionID] = array_merge(AbuseFilter::$tagsToSet[$actionID], $parameters); } break; default: if (isset($wgAbuseFilterCustomActionsHandlers[$action])) { $custom_function = $wgAbuseFilterCustomActionsHandlers[$action]; if (is_callable($custom_function)) { $msg = call_user_func($custom_function, $action, $parameters, $title, $vars, $rule_desc, $rule_number); } if (isset($msg)) { $message = array($msg); } } else { wfDebugLog('AbuseFilter', "Unrecognised action {$action}"); } } return $message; }
/** * 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); }
/** * @todo Maybe translate block durations. Note that this function is somewhat misnamed: it * deals with translating the *duration* ("1 week", "4 days", etc), not the expiry time * (which is an absolute timestamp). Please note: do NOT add this blindly, as it is used * on old expiry lengths recorded in log entries. You'd need to provide the start date to * match up with it. * * @param $str String: the validated block duration in English * @return Somehow translated block duration * @see LanguageFi.php for example implementation */ function translateBlockExpiry($str) { $duration = SpecialBlock::getSuggestedDurations($this); foreach ($duration as $show => $value) { if (strcmp($str, $value) == 0) { return htmlspecialchars(trim($show)); } } // Since usually only infinite or indefinite is only on list, so try // equivalents if still here. $indefs = array('infinite', 'infinity', 'indefinite'); if (in_array($str, $indefs)) { foreach ($indefs as $val) { $show = array_search($val, $duration, true); if ($show !== false) { return htmlspecialchars(trim($show)); } } } // If all else fails, return the original string. return $str; }
/** * Convert a submitted expiry time, which may be relative ("2 weeks", etc) or absolute * ("24 May 2034"), into an absolute timestamp we can put into the database. * @param $expiry String: whatever was typed into the form * @return String: timestamp or "infinity" string for th DB implementation * @deprecated since 1.18 moved to SpecialBlock::parseExpiryInput() */ public static function parseExpiryInput($expiry) { wfDeprecated(__METHOD__, '1.18'); return SpecialBlock::parseExpiryInput($expiry); }