r90757 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r90756‎ | r90757 | r90758 >
Date:05:21, 25 June 2011
Author:aaron
Status:ok
Tags:
Comment:
Follow-up r90749: pushed down accessing of $wgAutopromoteOnce to getAutopromoteOnceGroups()
Modified paths:
  • /trunk/phase3/includes/Autopromote.php (modified) (history)
  • /trunk/phase3/includes/User.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/User.php
@@ -1117,16 +1117,12 @@
11181118 * @see $wgAutopromote
11191119 */
11201120 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 );
11301125 }
 1126+ return $toPromote;
11311127 }
11321128 return array();
11331129 }
Index: trunk/phase3/includes/Autopromote.php
@@ -26,38 +26,39 @@
2727
2828 return $promote;
2929 }
30 -
 30+
3131 /**
3232 * Get the groups for the given user based on the given criteria.
3333 *
3434 * Does not return groups the user already belongs to or has once belonged.
3535 *
3636 * @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)
4038 *
4139 * @return array Groups the user should be promoted to.
4240 */
43 - public static function getAutopromoteOnceGroups( User $user, $criteria ) {
 41+ public static function getAutopromoteOnceGroups( User $user, $event ) {
 42+ global $wgAutopromoteOnce;
 43+
4444 $promote = array();
4545
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+ }
5262 }
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 - }
6263 }
6364
6465 return $promote;

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r90749Added one-time promote support via Autopromote::autopromoteOnceHook function....aaron02:52, 25 June 2011

Status & tagging log