41 if ( self::recCheckCondition( $cond, $user ) ) {
46 Hooks::run(
'GetAutoPromoteGroups', [ $user, &$promote ] );
69 $currentGroups = $user->getGroups();
70 $formerGroups = $user->getFormerGroups();
73 if ( in_array( $group, $currentGroups ) ) {
77 if ( in_array( $group, $formerGroups ) ) {
81 if ( self::recCheckCondition( $cond, $user ) ) {
107 $validOps = [
'&',
'|',
'^',
'!' ];
109 if ( is_array( $cond ) && count( $cond ) >= 2 && in_array( $cond[0], $validOps ) ) {
110 # Recursive condition
111 if ( $cond[0] ==
'&' ) {
112 foreach ( array_slice( $cond, 1 ) as $subcond ) {
113 if ( !self::recCheckCondition( $subcond, $user ) ) {
119 } elseif ( $cond[0] ==
'|' ) {
120 foreach ( array_slice( $cond, 1 ) as $subcond ) {
121 if ( self::recCheckCondition( $subcond, $user ) ) {
127 } elseif ( $cond[0] ==
'^' ) {
128 if ( count( $cond ) > 3 ) {
129 wfWarn(
'recCheckCondition() given XOR ("^") condition on three or more conditions.' .
130 ' Check your $wgAutopromote and $wgAutopromoteOnce settings.' );
134 } elseif ( $cond[0] ==
'!' ) {
135 foreach ( array_slice( $cond, 1 ) as $subcond ) {
136 if ( self::recCheckCondition( $subcond, $user ) ) {
146 if ( !is_array( $cond ) ) {
165 if ( count( $cond ) < 1 ) {
169 switch ( $cond[0] ) {
171 if ( Sanitizer::validateEmail( $user->getEmail() ) ) {
173 return (
bool)$user->getEmailAuthenticationTimestamp();
180 $reqEditCount = $cond[1];
183 if ( $reqEditCount <= 0 ) {
186 return $user->getEditCount() >= $reqEditCount;
189 return $age >= $cond[1];
192 return $age >= $cond[1];
194 $groups = array_slice( $cond, 1 );
195 return count( array_intersect( $groups, $user->getGroups() ) ) == count( $groups );
197 return $cond[1] == $user->getRequest()->getIP();
199 return IP::isInRange( $user->getRequest()->getIP(), $cond[1] );
201 return $user->isBlocked();
203 return in_array(
'bot', User::getGroupPermissions( $user->getGroups() ) );
206 Hooks::run(
'AutopromoteCondition', [ $cond[0],
207 array_slice( $cond, 1 ), $user, &$result ] );
208 if ( $result ===
null ) {
209 throw new MWException(
"Unrecognized condition {$cond[0]} for autopromotion!" );
$wgAutopromote
Array containing the conditions of automatic promotion of a user to specific groups.
$wgEmailAuthentication
Require email authentication before sending mail to an email address.
$wgAutopromoteOnce
Automatically add a usergroup to any user who matches certain conditions.
wfWarn( $msg, $callerOffset=1, $level=E_USER_NOTICE)
Send a warning either to the debug log or in a PHP error depending on $wgDevelopmentWarnings.
wfTimestampOrNull( $outputtype=TS_UNIX, $ts=null)
Return a formatted timestamp, or null if input is null.
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
namespace being checked & $result
const APCOND_EMAILCONFIRMED
const APCOND_AGE_FROM_EDIT