http://www.mediawiki.org/wiki/Special:Code/MediaWiki/90757

Revision: 90757
Author:   aaron
Date:     2011-06-25 05:21:53 +0000 (Sat, 25 Jun 2011)
Log Message:
-----------
Follow-up r90749: pushed down accessing of $wgAutopromoteOnce to 
getAutopromoteOnceGroups()

Modified Paths:
--------------
    trunk/phase3/includes/Autopromote.php
    trunk/phase3/includes/User.php

Modified: trunk/phase3/includes/Autopromote.php
===================================================================
--- trunk/phase3/includes/Autopromote.php       2011-06-25 05:05:26 UTC (rev 
90756)
+++ trunk/phase3/includes/Autopromote.php       2011-06-25 05:21:53 UTC (rev 
90757)
@@ -26,38 +26,39 @@
 
                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 
) {
+       public static function getAutopromoteOnceGroups( User $user, $event ) {
+               global $wgAutopromoteOnce;
+
                $promote = array();
 
-               $currentGroups = $user->getGroups();
-
-               foreach ( $criteria as $group => $cond ) {
-                       // Do not check if the user's already a member
-                       if ( in_array( $group, $currentGroups ) ) {
-                               continue;
+               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;
+                               }
                        }
-                       // 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;
-                       }
                }
 
                return $promote;

Modified: trunk/phase3/includes/User.php
===================================================================
--- trunk/phase3/includes/User.php      2011-06-25 05:05:26 UTC (rev 90756)
+++ trunk/phase3/includes/User.php      2011-06-25 05:21:53 UTC (rev 90757)
@@ -1117,16 +1117,12 @@
         * @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(); 
        }


_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to