Example #1
0
 /**
  * As recCheckCondition, but *not* recursive.  The only valid conditions
  * are those whose first element is APCOND_EMAILCONFIRMED/APCOND_EDITCOUNT/
  * APCOND_AGE.  Other types will throw an exception if no extension evalu-
  * ates them.
  *
  * @param $cond Array: A condition, which must not contain other conditions
  * @param $user User The user to check the condition against
  * @return bool Whether the condition is true for the user
  */
 private static function checkCondition($cond, User $user)
 {
     global $wgEmailAuthentication, $wgEnableEditCountLocal;
     if (count($cond) < 1) {
         return false;
     }
     switch ($cond[0]) {
         case APCOND_EMAILCONFIRMED:
             if (Sanitizer::validateEmail($user->getEmail())) {
                 if ($wgEmailAuthentication) {
                     return (bool) $user->getEmailAuthenticationTimestamp();
                 } else {
                     return true;
                 }
             }
             return false;
         case APCOND_EDITCOUNT:
             if (!empty($wgEnableEditCountLocal)) {
                 return $user->getEditCountLocal() >= $cond[1];
             } else {
                 return $user->getEditCount() >= $cond[1];
             }
         case APCOND_AGE:
             $age = time() - wfTimestampOrNull(TS_UNIX, $user->getRegistration());
             return $age >= $cond[1];
         case APCOND_AGE_FROM_EDIT:
             $age = time() - wfTimestampOrNull(TS_UNIX, $user->getFirstEditTimestamp());
             return $age >= $cond[1];
         case APCOND_INGROUPS:
             $groups = array_slice($cond, 1);
             return count(array_intersect($groups, $user->getGroups())) == count($groups);
         case APCOND_ISIP:
             return $cond[1] == $user->getRequest()->getIP();
         case APCOND_IPINRANGE:
             return IP::isInRange($user->getRequest()->getIP(), $cond[1]);
         case APCOND_BLOCKED:
             return $user->isBlocked();
         case APCOND_ISBOT:
             return in_array('bot', User::getGroupPermissions($user->getGroups()));
         default:
             $result = null;
             wfRunHooks('AutopromoteCondition', array($cond[0], array_slice($cond, 1), $user, &$result));
             if ($result === null) {
                 throw new MWException("Unrecognized condition {$cond[0]} for autopromotion!");
             }
             return (bool) $result;
     }
 }
Example #2
0
 protected function makeUserLink(User $user)
 {
     if ($this->plaintext) {
         $element = $user->getName();
     } else {
         $element = Linker::userLink($user->getId(), $user->getName());
         if ($this->linkFlood) {
             $element .= Linker::userToolLinks($user->getId(), $user->getName(), true, 0, $user->getEditCountLocal());
         }
     }
     return $element;
 }