function revertAction($action, $result)
 {
     switch ($action) {
         case 'block':
             $block = Block::newFromTarget(User::whoIs($result['userid']));
             if (!$block || $block->getBy() != AbuseFilter::getFilterUser()->getId()) {
                 return false;
                 // Not blocked by abuse filter.
             }
             $block->delete();
             $log = new LogPage('block');
             $log->addEntry('unblock', Title::makeTitle(NS_USER, $result['user']), wfMsgForContent('abusefilter-revert-reason', $this->mPage->mFilter, $this->mReason));
             break;
         case 'blockautopromote':
             global $wgMemc;
             $wgMemc->delete(AbuseFilter::autopromoteBlockKey(User::newFromId($result['userid'])));
             break;
         case 'degroup':
             // Pull the user's groups from the vars.
             $oldGroups = $result['vars']['USER_GROUPS'];
             $oldGroups = explode(',', $oldGroups);
             $oldGroups = array_diff($oldGroups, array_intersect($oldGroups, User::getImplicitGroups()));
             $rows = array();
             foreach ($oldGroups as $group) {
                 $rows[] = array('ug_user' => $result['userid'], 'ug_group' => $group);
             }
             // Cheat a little bit. User::addGroup repeatedly is too slow.
             $user = User::newFromId($result['userid']);
             $currentGroups = $user->getGroups();
             $newGroups = array_merge($oldGroups, $currentGroups);
             // Don't do anything if there are no groups to add.
             if (!count(array_diff($newGroups, $currentGroups))) {
                 return;
             }
             $dbw = wfGetDB(DB_MASTER);
             $dbw->insert('user_groups', $rows, __METHOD__, array('IGNORE'));
             $user->invalidateCache();
             $log = new LogPage('rights');
             $log->addEntry('rights', $user->getUserPage(), wfMsgForContent('abusefilter-revert-reason', $this->mPage->mFilter, $this->mReason), array(implode(',', $currentGroups), implode(',', $newGroups)));
     }
 }
 /**
  * @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;
 }
 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;
 }