public static function getAutopromoteGroups( User $user ) {
global $wgAutopromote;
- $promote = array();
+ $promote = [];
foreach ( $wgAutopromote as $group => $cond ) {
if ( self::recCheckCondition( $cond, $user ) ) {
}
}
- Hooks::run( 'GetAutoPromoteGroups', array( $user, &$promote ) );
+ Hooks::run( 'GetAutoPromoteGroups', [ $user, &$promote ] );
return $promote;
}
public static function getAutopromoteOnceGroups( User $user, $event ) {
global $wgAutopromoteOnce;
- $promote = array();
+ $promote = [];
if ( isset( $wgAutopromoteOnce[$event] ) && count( $wgAutopromoteOnce[$event] ) ) {
$currentGroups = $user->getGroups();
/**
* Recursively check a condition. Conditions are in the form
- * array( '&' or '|' or '^' or '!', cond1, cond2, ... )
+ * [ '&' or '|' or '^' or '!', cond1, cond2, ... ]
* where cond1, cond2, ... are themselves conditions; *OR*
* APCOND_EMAILCONFIRMED, *OR*
- * array( APCOND_EMAILCONFIRMED ), *OR*
- * array( APCOND_EDITCOUNT, number of edits ), *OR*
- * array( APCOND_AGE, seconds since registration ), *OR*
+ * [ APCOND_EMAILCONFIRMED ], *OR*
+ * [ APCOND_EDITCOUNT, number of edits ], *OR*
+ * [ APCOND_AGE, seconds since registration ], *OR*
* similar constructs defined by extensions.
* This function evaluates the former type recursively, and passes off to
* self::checkCondition for evaluation of the latter type.
* @return bool Whether the condition is true
*/
private static function recCheckCondition( $cond, User $user ) {
- $validOps = array( '&', '|', '^', '!' );
+ $validOps = [ '&', '|', '^', '!' ];
if ( is_array( $cond ) && count( $cond ) >= 2 && in_array( $cond[0], $validOps ) ) {
# Recursive condition
// If we got here, the array presumably does not contain other conditions;
// it's not recursive. Pass it off to self::checkCondition.
if ( !is_array( $cond ) ) {
- $cond = array( $cond );
+ $cond = [ $cond ];
}
return self::checkCondition( $cond, $user );
}
return false;
case APCOND_EDITCOUNT:
- return $user->getEditCount() >= $cond[1];
+ $reqEditCount = $cond[1];
+
+ // T157718: Avoid edit count lookup if specified edit count is 0 or invalid
+ if ( $reqEditCount <= 0 ) {
+ return true;
+ }
+ return $user->getEditCount() >= $reqEditCount;
case APCOND_AGE:
$age = time() - wfTimestampOrNull( TS_UNIX, $user->getRegistration() );
return $age >= $cond[1];
case APCOND_IPINRANGE:
return IP::isInRange( $user->getRequest()->getIP(), $cond[1] );
case APCOND_BLOCKED:
- return $user->isBlocked();
+ // @TODO Should partial blocks prevent auto promote?
+ return (bool)$user->getBlock();
case APCOND_ISBOT:
return in_array( 'bot', User::getGroupPermissions( $user->getGroups() ) );
default:
$result = null;
- Hooks::run( 'AutopromoteCondition', array( $cond[0],
- array_slice( $cond, 1 ), $user, &$result ) );
+ Hooks::run( 'AutopromoteCondition', [ $cond[0],
+ array_slice( $cond, 1 ), $user, &$result ] );
if ( $result === null ) {
throw new MWException( "Unrecognized condition {$cond[0]} for autopromotion!" );
}