public function execute()
 {
     $params = $this->extractRequestParams();
     $res = $this->getResult();
     $res->addValue(null, $this->getModuleName(), array('username' => $params['username']));
     $spoof = new SpoofUser($params['username']);
     if ($spoof->isLegal()) {
         $normalized = $spoof->getNormalized();
         $res->addValue(null, $this->getModuleName(), array('normalised' => $normalized));
         $unfilteredConflicts = $spoof->getConflicts();
         if (empty($unfilteredConflicts)) {
             $res->addValue(null, $this->getModuleName(), array('result' => 'pass'));
         } else {
             $hasSuppressed = false;
             $conflicts = array();
             foreach ($unfilteredConflicts as $conflict) {
                 if (!User::newFromName($conflict)->isHidden()) {
                     $conflicts[] = $conflict;
                 } else {
                     $hasSuppressed = true;
                 }
             }
             if ($hasSuppressed) {
                 $res->addValue(null, $this->getModuleName(), array('suppressed' => 'true'));
             }
             $res->addValue(null, $this->getModuleName(), array('result' => 'conflict'));
             $res->setIndexedTagName($conflicts, 'u');
             $res->addValue(array($this->getModuleName()), 'users', $conflicts);
         }
     } else {
         $error = $spoof->getError();
         $res->addValue('antispoof', 'result', 'error');
         $res->addValue('antispoof', 'error', $error);
     }
 }
 /**
  * Can be used to cancel user account creation
  *
  * @param $user User
  * @param $message string
  * @return bool true to continue, false to abort user creation
  */
 public static function asAbortNewAccountHook($user, &$message)
 {
     global $wgAntiSpoofAccounts, $wgUser, $wgRequest;
     if (!$wgAntiSpoofAccounts) {
         $mode = 'LOGGING ';
         $active = false;
     } elseif ($wgRequest->getCheck('wpIgnoreAntiSpoof') && $wgUser->isAllowed('override-antispoof')) {
         $mode = 'OVERRIDE ';
         $active = false;
     } else {
         $mode = '';
         $active = true;
     }
     $name = $user->getName();
     $spoof = new SpoofUser($name);
     if ($spoof->isLegal()) {
         $normalized = $spoof->getNormalized();
         $conflicts = $spoof->getConflicts();
         if (empty($conflicts)) {
             wfDebugLog('antispoof', "{$mode}PASS new account '{$name}' [{$normalized}]");
         } else {
             wfDebugLog('antispoof', "{$mode}CONFLICT new account '{$name}' [{$normalized}] spoofs " . implode(',', $conflicts));
             if ($active) {
                 $numConflicts = count($conflicts);
                 $message = wfMessage('antispoof-conflict-top', $name)->numParams($numConflicts)->parse();
                 $message .= '<ul>';
                 foreach ($conflicts as $simUser) {
                     $message .= '<li>' . wfMessage('antispoof-conflict-item', $simUser)->escaped() . '</li>';
                 }
                 $message .= '</ul>' . wfMessage('antispoof-conflict-bottom')->parse();
                 return false;
             }
         }
     } else {
         $error = $spoof->getError();
         wfDebugLog('antispoof', "{$mode}ILLEGAL new account '{$name}' {$error}");
         if ($active) {
             $message = wfMessage('antispoof-name-illegal', $name, $error)->text();
             return false;
         }
     }
     return true;
 }
Example #3
0
/**
 * Hook for user creation form submissions.
 * @param User $u
 * @param string $message
 * @return bool true to continue, false to abort user creation
 */
function asAbortNewAccountHook($user, &$message)
{
    global $wgAntiSpoofAccounts, $wgUser, $wgRequest;
    wfLoadExtensionMessages('AntiSpoof');
    if (!$wgAntiSpoofAccounts) {
        $mode = 'LOGGING ';
        $active = false;
    } elseif ($wgRequest->getCheck('wpIgnoreAntiSpoof') && $wgUser->isAllowed('override-antispoof')) {
        $mode = 'OVERRIDE ';
        $active = false;
    } else {
        $mode = '';
        $active = true;
    }
    $name = $user->getName();
    $spoof = new SpoofUser($name);
    if ($spoof->isLegal()) {
        $normalized = $spoof->getNormalized();
        $conflict = $spoof->getConflict();
        if ($conflict === false) {
            wfDebugLog('antispoof', "{$mode}PASS new account '{$name}' [{$normalized}]");
        } else {
            wfDebugLog('antispoof', "{$mode}CONFLICT new account '{$name}' [{$normalized}] spoofs '{$conflict}'");
            if ($active) {
                $message = wfMsg('antispoof-name-conflict', $name, $conflict);
                return false;
            }
        }
    } else {
        $error = $spoof->getError();
        wfDebugLog('antispoof', "{$mode}ILLEGAL new account '{$name}' {$error}");
        if ($active) {
            $message = wfMsg('antispoof-name-illegal', $name, $error);
            return false;
        }
    }
    return true;
}