Follow-up r90749: pushed down accessing of $wgAutopromoteOnce to getAutopromoteOnceGr...
authorAaron Schulz <aaron@users.mediawiki.org>
Sat, 25 Jun 2011 05:21:53 +0000 (05:21 +0000)
committerAaron Schulz <aaron@users.mediawiki.org>
Sat, 25 Jun 2011 05:21:53 +0000 (05:21 +0000)
includes/Autopromote.php
includes/User.php

index f06be29..85b2f47 100644 (file)
@@ -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;
+                               }
                        }
                }
 
index cffe90b..5bae670 100644 (file)
@@ -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(); 
        }