Index: trunk/phase3/includes/User.php |
— | — | @@ -1117,16 +1117,12 @@ |
1118 | 1118 | * @see $wgAutopromote |
1119 | 1119 | */ |
1120 | 1120 | public function addAutopromoteOnceGroups( $event ) { |
1121 | | - global $wgAutopromoteOnce; |
1122 | | - if ( isset( $wgAutopromoteOnce[$event] ) ) { |
1123 | | - $criteria = $wgAutopromoteOnce[$event]; // group/requirement pairs |
1124 | | - if ( count( $criteria ) && $this->getId() ) { |
1125 | | - $toPromote = Autopromote::getAutopromoteOnceGroups( $this, $criteria ); |
1126 | | - foreach ( $toPromote as $group ) { |
1127 | | - $this->addGroup( $group ); |
1128 | | - } |
1129 | | - return $toPromote; |
| 1121 | + if ( $this->getId() ) { |
| 1122 | + $toPromote = Autopromote::getAutopromoteOnceGroups( $this, $event ); |
| 1123 | + foreach ( $toPromote as $group ) { |
| 1124 | + $this->addGroup( $group ); |
1130 | 1125 | } |
| 1126 | + return $toPromote; |
1131 | 1127 | } |
1132 | 1128 | return array(); |
1133 | 1129 | } |
Index: trunk/phase3/includes/Autopromote.php |
— | — | @@ -26,38 +26,39 @@ |
27 | 27 | |
28 | 28 | return $promote; |
29 | 29 | } |
30 | | - |
| 30 | + |
31 | 31 | /** |
32 | 32 | * Get the groups for the given user based on the given criteria. |
33 | 33 | * |
34 | 34 | * Does not return groups the user already belongs to or has once belonged. |
35 | 35 | * |
36 | 36 | * @param $user The user to get the groups for |
37 | | - * @param $criteria array Groups and conditions the user must meet in order |
38 | | - * to be promoted to these groups. Array of the same format as |
39 | | - * \ref $wgAutopromote. |
| 37 | + * @param $event String 'onEdit' or 'onView' (each one has groups/criteria) |
40 | 38 | * |
41 | 39 | * @return array Groups the user should be promoted to. |
42 | 40 | */ |
43 | | - public static function getAutopromoteOnceGroups( User $user, $criteria ) { |
| 41 | + public static function getAutopromoteOnceGroups( User $user, $event ) { |
| 42 | + global $wgAutopromoteOnce; |
| 43 | + |
44 | 44 | $promote = array(); |
45 | 45 | |
46 | | - $currentGroups = $user->getGroups(); |
47 | | - |
48 | | - foreach ( $criteria as $group => $cond ) { |
49 | | - // Do not check if the user's already a member |
50 | | - if ( in_array( $group, $currentGroups ) ) { |
51 | | - continue; |
| 46 | + if ( isset( $wgAutopromoteOnce[$event] ) && count( $wgAutopromoteOnce[$event] ) ) { |
| 47 | + $currentGroups = $user->getGroups(); |
| 48 | + foreach ( $wgAutopromoteOnce[$event] as $group => $cond ) { |
| 49 | + // Do not check if the user's already a member |
| 50 | + if ( in_array( $group, $currentGroups ) ) { |
| 51 | + continue; |
| 52 | + } |
| 53 | + // Do not autopromote if the user has belonged to the group |
| 54 | + $formerGroups = $user->getFormerGroups(); |
| 55 | + if ( in_array( $group, $formerGroups ) ) { |
| 56 | + continue; |
| 57 | + } |
| 58 | + // Finally - check the conditions |
| 59 | + if ( self::recCheckCondition( $cond, $user ) ) { |
| 60 | + $promote[] = $group; |
| 61 | + } |
52 | 62 | } |
53 | | - // Do not autopromote if the user has belonged to the group |
54 | | - $formerGroups = $user->getFormerGroups(); |
55 | | - if ( in_array( $group, $formerGroups ) ) { |
56 | | - continue; |
57 | | - } |
58 | | - // Finally - check the conditions |
59 | | - if ( self::recCheckCondition( $cond, $user ) ) { |
60 | | - $promote[] = $group; |
61 | | - } |
62 | 63 | } |
63 | 64 | |
64 | 65 | return $promote; |