4 * This class checks if user can get extra rights
5 * because of conditions specified in $wgAutopromote
8 public static function autopromoteUser( $user ) {
11 foreach( $wgAutopromote as $group => $cond ) {
12 if( self
::recCheckCondition( $cond, $user ) )
19 static function recCheckCondition( $cond, $user ) {
20 $validOps = array( '&', '|', '^' );
21 if( is_array( $cond ) && count( $cond ) > 0 && in_array( $cond[0], $validOps ) ) {
22 if( $cond[0] == '&' ) {
23 foreach( array_slice( $cond, 1 ) as $subcond )
24 if( !self
::recCheckCondition( $subcond, $user ) )
27 } elseif( $cond[0] == '|' ) {
28 foreach( array_slice( $cond, 1 ) as $subcond )
29 if( self
::recCheckCondition( $subcond, $user ) )
32 } elseif( $cond[0] == '^' ) {
33 if( count( $cond ) < 3 )
35 return self
::recCheckCondition( $cond[1], $user )
36 xor self
::recCheckCondition( $cond[2], $user );
39 if( !is_array( $cond ) )
40 $cond = array( $cond );
41 return self
::checkCondition( $cond, $user );
44 static function checkCondition( $cond, $user ) {
45 if( count( $cond ) < 1 )
48 case APCOND_EMAILCONFIRMED
:
49 if( User
::isValidEmailAddr( $user->getEmail() ) ) {
50 global $wgEmailAuthentication;
51 if( $wgEmailAuthentication ) {
52 return $user->getEmailAuthenticationTimestamp() ?
true : false;
58 case APCOND_EDITCOUNT
:
59 return $user->getEditCount() > $cond[1];
61 $age = time() - wfTimestampOrNull( TS_UNIX
, $user->getRegistration() );
62 return $age >= $cond[1];
66 wfRunHooks( 'AutopromoteCondition', array( $cond[0], array_slice( $cond, 1 ), &$result ) );