From 04d79f7eeb32ae912bddd2f43f91a38013638049 Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Sat, 25 Jun 2011 05:21:53 +0000 Subject: [PATCH] Follow-up r90749: pushed down accessing of $wgAutopromoteOnce to getAutopromoteOnceGroups() --- includes/Autopromote.php | 41 ++++++++++++++++++++-------------------- includes/User.php | 14 +++++--------- 2 files changed, 26 insertions(+), 29 deletions(-) diff --git a/includes/Autopromote.php b/includes/Autopromote.php index f06be2995a..85b2f47458 100644 --- a/includes/Autopromote.php +++ b/includes/Autopromote.php @@ -26,37 +26,38 @@ class Autopromote { return $promote; } - + /** * Get the groups for the given user based on the given criteria. * * Does not return groups the user already belongs to or has once belonged. * * @param $user The user to get the groups for - * @param $criteria array Groups and conditions the user must meet in order - * to be promoted to these groups. Array of the same format as - * \ref $wgAutopromote. + * @param $event String 'onEdit' or 'onView' (each one has groups/criteria) * * @return array Groups the user should be promoted to. */ - public static function getAutopromoteOnceGroups( User $user, $criteria ) { - $promote = array(); + public static function getAutopromoteOnceGroups( User $user, $event ) { + global $wgAutopromoteOnce; - $currentGroups = $user->getGroups(); + $promote = array(); - foreach ( $criteria as $group => $cond ) { - // Do not check if the user's already a member - if ( in_array( $group, $currentGroups ) ) { - continue; - } - // Do not autopromote if the user has belonged to the group - $formerGroups = $user->getFormerGroups(); - if ( in_array( $group, $formerGroups ) ) { - continue; - } - // Finally - check the conditions - if ( self::recCheckCondition( $cond, $user ) ) { - $promote[] = $group; + if ( isset( $wgAutopromoteOnce[$event] ) && count( $wgAutopromoteOnce[$event] ) ) { + $currentGroups = $user->getGroups(); + foreach ( $wgAutopromoteOnce[$event] as $group => $cond ) { + // Do not check if the user's already a member + if ( in_array( $group, $currentGroups ) ) { + continue; + } + // Do not autopromote if the user has belonged to the group + $formerGroups = $user->getFormerGroups(); + if ( in_array( $group, $formerGroups ) ) { + continue; + } + // Finally - check the conditions + if ( self::recCheckCondition( $cond, $user ) ) { + $promote[] = $group; + } } } diff --git a/includes/User.php b/includes/User.php index cffe90b3e7..5bae670e79 100644 --- a/includes/User.php +++ b/includes/User.php @@ -1117,16 +1117,12 @@ class User { * @see $wgAutopromote */ public function addAutopromoteOnceGroups( $event ) { - global $wgAutopromoteOnce; - if ( isset( $wgAutopromoteOnce[$event] ) ) { - $criteria = $wgAutopromoteOnce[$event]; // group/requirement pairs - if ( count( $criteria ) && $this->getId() ) { - $toPromote = Autopromote::getAutopromoteOnceGroups( $this, $criteria ); - foreach ( $toPromote as $group ) { - $this->addGroup( $group ); - } - return $toPromote; + if ( $this->getId() ) { + $toPromote = Autopromote::getAutopromoteOnceGroups( $this, $event ); + foreach ( $toPromote as $group ) { + $this->addGroup( $group ); } + return $toPromote; } return array(); } -- 2.20.1