Index: trunk/phase3/includes/User.php |
— | — | @@ -1107,28 +1107,30 @@ |
1108 | 1108 | * |
1109 | 1109 | * Contrary to autopromotion by \ref $wgAutopromote, the group will be |
1110 | 1110 | * possible to remove manually via Special:UserRights. In such case it |
1111 | | - * will not be re-added autmoatically. The user will also not lose the |
| 1111 | + * will not be re-added automatically. The user will also not lose the |
1112 | 1112 | * group if they no longer meet the criteria. |
1113 | 1113 | * |
1114 | | - * @param $criteria array Groups and conditions the user must meet in order |
1115 | | - * to be promoted to these groups. Array of the same format as |
1116 | | - * \ref $wgAutopromote. |
| 1114 | + * @param $event String 'onEdit' or 'onView' (each one has groups/criteria) |
1117 | 1115 | * |
1118 | 1116 | * @return array Array of groups the user has been promoted to. |
1119 | 1117 | * |
1120 | 1118 | * @see $wgAutopromote |
1121 | | - * @see Autopromote::autopromoteOnceHook() |
1122 | 1119 | */ |
1123 | | - public function autopromoteOnce( $criteria ) { |
1124 | | - if ($this->getId()) { |
1125 | | - $toPromote = Autopromote::getAutopromoteOnceGroups($this, $criteria); |
1126 | | - foreach($toPromote as $group) |
1127 | | - $this->addGroup($group); |
1128 | | - return $toPromote; |
| 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; |
| 1130 | + } |
1129 | 1131 | } |
1130 | 1132 | return array(); |
1131 | 1133 | } |
1132 | | - |
| 1134 | + |
1133 | 1135 | /** |
1134 | 1136 | * Clear various cached data stored in this object. |
1135 | 1137 | * @param $reloadFrom String Reload user and user_groups table data from a |
— | — | @@ -2278,14 +2280,14 @@ |
2279 | 2281 | * @return array Names of the groups the user has belonged to. |
2280 | 2282 | */ |
2281 | 2283 | function getFormerGroups() { |
2282 | | - if(is_null($this->mFormerGroups)) { |
| 2284 | + if( is_null( $this->mFormerGroups ) ) { |
2283 | 2285 | $dbr = wfGetDB( DB_MASTER ); |
2284 | 2286 | $res = $dbr->select( 'user_former_groups', |
2285 | 2287 | array( 'ufg_group' ), |
2286 | 2288 | array( 'ufg_user' => $this->mId ), |
2287 | 2289 | __METHOD__ ); |
2288 | 2290 | $this->mFormerGroups = array(); |
2289 | | - while( $row = $dbr->fetchObject( $res ) ) { |
| 2291 | + foreach( $res as $row ) { |
2290 | 2292 | $this->mFormerGroups[] = $row->ufg_group; |
2291 | 2293 | } |
2292 | 2294 | } |
Index: trunk/phase3/includes/Article.php |
— | — | @@ -2347,6 +2347,9 @@ |
2348 | 2348 | wfRunHooks( 'ArticleSaveComplete', array( &$this, &$user, $text, $summary, |
2349 | 2349 | $flags & EDIT_MINOR, null, null, &$flags, $revision, &$status, $baseRevId ) ); |
2350 | 2350 | |
| 2351 | + # Promote user to any groups they meet the criteria for |
| 2352 | + $user->addAutopromoteOnceGroups( 'onEdit' ); |
| 2353 | + |
2351 | 2354 | wfProfileOut( __METHOD__ ); |
2352 | 2355 | return $status; |
2353 | 2356 | } |
Index: trunk/phase3/includes/Wiki.php |
— | — | @@ -113,6 +113,9 @@ |
114 | 114 | $output = $this->context->getOutput(); |
115 | 115 | $user = $this->context->getUser(); |
116 | 116 | |
| 117 | + # Promote user to any groups they meet the criteria for |
| 118 | + $user->addAutopromoteOnceGroups( 'onView' ); |
| 119 | + |
117 | 120 | if ( $request->getVal( 'printable' ) === 'yes' ) { |
118 | 121 | $output->setPrintable(); |
119 | 122 | } |
— | — | @@ -125,7 +128,7 @@ |
126 | 129 | $request, |
127 | 130 | $this |
128 | 131 | ) ); |
129 | | - |
| 132 | + |
130 | 133 | // Invalid titles. Bug 21776: The interwikis must redirect even if the page name is empty. |
131 | 134 | if ( $title instanceof BadTitle ) { |
132 | 135 | throw new ErrorPageError( 'badtitle', 'badtitletext' ); |
Index: trunk/phase3/includes/DefaultSettings.php |
— | — | @@ -3513,12 +3513,6 @@ |
3514 | 3514 | * |
3515 | 3515 | * If $wgEmailAuthentication is off, APCOND_EMAILCONFIRMED will be true for any |
3516 | 3516 | * user who has provided an e-mail address. |
3517 | | - * |
3518 | | - * If the groups should be removable, consider using |
3519 | | - * Autopromote::autopromoteOnceHook() instead. |
3520 | | - * |
3521 | | - * @see Autopromote::autopromoteOnceHook() |
3522 | | - * @see User::autopromoteOnce() |
3523 | 3517 | */ |
3524 | 3518 | $wgAutopromote = array( |
3525 | 3519 | 'autoconfirmed' => array( '&', |
— | — | @@ -3528,6 +3522,25 @@ |
3529 | 3523 | ); |
3530 | 3524 | |
3531 | 3525 | /** |
| 3526 | + * Automatically add a usergroup to any user who matches certain conditions. |
| 3527 | + * Does not add the user to the group again if it has been removed. |
| 3528 | + * Also, does not remove the group if the user no longer meets the criteria. |
| 3529 | + * |
| 3530 | + * The format is |
| 3531 | + * array( event => criteria, ... ) |
| 3532 | + * where event is |
| 3533 | + * 'onEdit' (when user edits) or 'onView' (when user views the wiki) |
| 3534 | + * and criteria has the same format as $wgAutopromote |
| 3535 | + * |
| 3536 | + * @see $wgAutopromote |
| 3537 | + * @since 1.18 |
| 3538 | + */ |
| 3539 | +$wgAutopromoteOnce = array( |
| 3540 | + 'onEdit' => array(), |
| 3541 | + 'onView' => array() |
| 3542 | +); |
| 3543 | + |
| 3544 | +/** |
3532 | 3545 | * $wgAddGroups and $wgRemoveGroups can be used to give finer control over who |
3533 | 3546 | * can assign which groups at Special:Userrights. Example configuration: |
3534 | 3547 | * |
Index: trunk/phase3/includes/Autopromote.php |
— | — | @@ -6,41 +6,6 @@ |
7 | 7 | |
8 | 8 | class Autopromote { |
9 | 9 | /** |
10 | | - * A function which may be assigned to a hook in order to check |
11 | | - * autopromotion of the current user (\ref $wgUser) to the specified |
12 | | - * group. |
13 | | - * |
14 | | - * Contrary to autopromotion by \ref $wgAutopromote, the group will be |
15 | | - * possible to remove manually via Special:UserRights. In such case it |
16 | | - * will not be re-added autmoatically. The user will also not lose the |
17 | | - * group if they no longer meet the criteria. |
18 | | - * |
19 | | - * Example configuration: |
20 | | - * \code $wgHooks['ArticleSaveComplete'][] = array ( |
21 | | - * 'Autopromote::autopromoteOnceHook', |
22 | | - * array( 'somegroup' => array(APCOND_EDITCOUNT, 200) ) |
23 | | - * ); \endcode |
24 | | - * |
25 | | - * The second array should be of the same format as \ref $wgAutopromote. |
26 | | - * |
27 | | - * This funciton simply runs User::autopromoteOnce() on $wgUser. You may |
28 | | - * run this method from your custom function if you wish. |
29 | | - * |
30 | | - * @param $criteria array Groups and conditions which must be met in order to |
31 | | - * aquire these groups. Array of the same format as \ref $wgAutopromote. |
32 | | - * |
33 | | - * @return Always true. |
34 | | - * |
35 | | - * @see User::autopromoteOnce() |
36 | | - * @see $wgAutopromote |
37 | | - */ |
38 | | - public static function autopromoteOnceHook($criteria) { |
39 | | - global $wgUser; |
40 | | - $wgUser->autopromoteOnce($criteria); |
41 | | - return true; |
42 | | - } |
43 | | - |
44 | | - /** |
45 | 10 | * Get the groups for the given user based on $wgAutopromote. |
46 | 11 | * |
47 | 12 | * @param $user User The user to get the groups for |
— | — | @@ -76,24 +41,25 @@ |
77 | 42 | */ |
78 | 43 | public static function getAutopromoteOnceGroups( User $user, $criteria ) { |
79 | 44 | $promote = array(); |
80 | | - |
81 | | - //get the current groups |
| 45 | + |
82 | 46 | $currentGroups = $user->getGroups(); |
83 | | - |
84 | | - foreach( $criteria as $group => $cond ) { |
85 | | - //do not check if the user's already a member |
86 | | - if ( in_array($group, $currentGroups)) |
| 47 | + |
| 48 | + foreach ( $criteria as $group => $cond ) { |
| 49 | + // Do not check if the user's already a member |
| 50 | + if ( in_array( $group, $currentGroups ) ) { |
87 | 51 | continue; |
88 | | - |
89 | | - //do not autopromote if the user has belonged to the group |
| 52 | + } |
| 53 | + // Do not autopromote if the user has belonged to the group |
90 | 54 | $formerGroups = $user->getFormerGroups(); |
91 | | - if ( in_array($group, $formerGroups) ) |
| 55 | + if ( in_array( $group, $formerGroups ) ) { |
92 | 56 | continue; |
93 | | - |
94 | | - //finally - check the conditions |
95 | | - if ( self::recCheckCondition($cond, $user) ) |
96 | | - $promote[] = $group; |
| 57 | + } |
| 58 | + // Finally - check the conditions |
| 59 | + if ( self::recCheckCondition( $cond, $user ) ) { |
| 60 | + $promote[] = $group; |
| 61 | + } |
97 | 62 | } |
| 63 | + |
98 | 64 | return $promote; |
99 | 65 | } |
100 | 66 | |