Index: trunk/phase3/includes/Defines.php |
— | — | @@ -277,3 +277,7 @@ |
278 | 278 | # Flags for Parser::replaceLinkHolders |
279 | 279 | define( 'RLH_FOR_UPDATE', 1 ); |
280 | 280 | |
| 281 | +#Autopromote conditions |
| 282 | +define( 'APCOND_EDITCOUNT', 1 ); |
| 283 | +define( 'APCOND_AGE', 2 ); |
| 284 | +define( 'APCOND_EMAILCONFIRMED', 3 ); |
Index: trunk/phase3/includes/User.php |
— | — | @@ -1651,23 +1651,12 @@ |
1652 | 1652 | $this->mEffectiveGroups[] = '*'; |
1653 | 1653 | if( $this->mId ) { |
1654 | 1654 | $this->mEffectiveGroups[] = 'user'; |
1655 | | - |
1656 | | - global $wgAutoConfirmAge, $wgAutoConfirmCount; |
1657 | 1655 | |
1658 | | - $accountAge = time() - wfTimestampOrNull( TS_UNIX, $this->mRegistration ); |
1659 | | - if( $accountAge >= $wgAutoConfirmAge && $this->getEditCount() >= $wgAutoConfirmCount ) { |
1660 | | - $this->mEffectiveGroups[] = 'autoconfirmed'; |
1661 | | - } |
1662 | | - # Implicit group for users whose email addresses are confirmed |
1663 | | - global $wgEmailAuthentication; |
1664 | | - if( self::isValidEmailAddr( $this->mEmail ) ) { |
1665 | | - if( $wgEmailAuthentication ) { |
1666 | | - if( $this->mEmailAuthenticated ) |
1667 | | - $this->mEffectiveGroups[] = 'emailconfirmed'; |
1668 | | - } else { |
1669 | | - $this->mEffectiveGroups[] = 'emailconfirmed'; |
1670 | | - } |
1671 | | - } |
| 1656 | + $this->mEffectiveGroups = array_merge( |
| 1657 | + $this->mEffectiveGroups, |
| 1658 | + Autopromote::autopromoteUser( $this ) |
| 1659 | + ); |
| 1660 | + |
1672 | 1661 | # Hook for additional groups |
1673 | 1662 | wfRunHooks( 'UserEffectiveGroups', array( &$this, &$this->mEffectiveGroups ) ); |
1674 | 1663 | } |
— | — | @@ -2595,11 +2584,9 @@ |
2596 | 2585 | * @return array |
2597 | 2586 | */ |
2598 | 2587 | public static function getImplicitGroups() { |
2599 | | - static $groups = null; |
2600 | | - if( !is_array( $groups ) ) { |
2601 | | - $groups = array( '*', 'user', 'autoconfirmed', 'emailconfirmed' ); |
2602 | | - wfRunHooks( 'UserGetImplicitGroups', array( &$groups ) ); |
2603 | | - } |
| 2588 | + global $wgImplicitGroups; |
| 2589 | + $groups = $wgImplicitGroups; |
| 2590 | + wfRunHooks( 'UserGetImplicitGroups', array( &$groups ) ); #deprecated, use $wgImplictGroups instead |
2604 | 2591 | return $groups; |
2605 | 2592 | } |
2606 | 2593 | |
Index: trunk/phase3/includes/AutoLoader.php |
— | — | @@ -17,6 +17,7 @@ |
18 | 18 | 'AlphabeticPager' => 'includes/Pager.php', |
19 | 19 | 'Article' => 'includes/Article.php', |
20 | 20 | 'AuthPlugin' => 'includes/AuthPlugin.php', |
| 21 | + 'Autopromote' => 'includes/Autopromote.php', |
21 | 22 | 'BagOStuff' => 'includes/BagOStuff.php', |
22 | 23 | 'HashBagOStuff' => 'includes/BagOStuff.php', |
23 | 24 | 'SqlBagOStuff' => 'includes/BagOStuff.php', |
Index: trunk/phase3/includes/DefaultSettings.php |
— | — | @@ -1127,7 +1127,13 @@ |
1128 | 1128 | */ |
1129 | 1129 | # $wgGroupPermissions['developer']['siteadmin'] = true; |
1130 | 1130 | |
| 1131 | + |
1131 | 1132 | /** |
| 1133 | + * Implicit groups, aren't shown on Special:Listusers or somewhere else |
| 1134 | + */ |
| 1135 | +$wgImplicitGroups = array( '*', 'user', 'autoconfirmed', 'emailconfirmed' ); |
| 1136 | + |
| 1137 | +/** |
1132 | 1138 | * Set of available actions that can be restricted via action=protect |
1133 | 1139 | * You probably shouldn't change this. |
1134 | 1140 | * Translated trough restriction-* messages. |
— | — | @@ -1183,6 +1189,17 @@ |
1184 | 1190 | //$wgAutoConfirmCount = 50; |
1185 | 1191 | |
1186 | 1192 | /** |
| 1193 | + * Automatically promote user flags to users that matchs some conditions |
| 1194 | + */ |
| 1195 | +$wgAutopromote = array( |
| 1196 | + 'autoconfirmed' => array( '&', |
| 1197 | + array( APCOND_EDITCOUNT, &$wgAutoConfirmCount ), |
| 1198 | + array( APCOND_AGE, &$wgAutoConfirmAge ), |
| 1199 | + ), |
| 1200 | + 'emailconfirmed' => APCOND_EMAILCONFIRMED, |
| 1201 | +); |
| 1202 | + |
| 1203 | +/** |
1187 | 1204 | * These settings can be used to give finer control over who can assign which |
1188 | 1205 | * groups at Special:Userrights. Example configuration: |
1189 | 1206 | * |
Index: trunk/phase3/includes/Autopromote.php |
— | — | @@ -0,0 +1,70 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +/** |
| 5 | + * This class checks if user can get extra rights |
| 6 | + * because of conditions specified in $wgAutopromote |
| 7 | + */ |
| 8 | +class Autopromote { |
| 9 | + public static function autopromoteUser( $user ) { |
| 10 | + global $wgAutopromote; |
| 11 | + $promote = array(); |
| 12 | + foreach( $wgAutopromote as $group => $cond ) { |
| 13 | + if( self::recCheckCondition( $cond, $user ) ) |
| 14 | + $promote[] = $group; |
| 15 | + } |
| 16 | + return $promote; |
| 17 | + } |
| 18 | + |
| 19 | + //@private |
| 20 | + static function recCheckCondition( $cond, $user ) { |
| 21 | + $validOps = array( '&', '|', '^' ); |
| 22 | + if( is_array( $cond ) && count( $cond ) > 0 && in_array( $cond[0], $validOps ) ) { |
| 23 | + if( $cond[0] == '&' ) { |
| 24 | + foreach( array_slice( $cond, 1 ) as $subcond ) |
| 25 | + if( !self::recCheckCondition( $subcond, $user ) ) |
| 26 | + return false; |
| 27 | + return true; |
| 28 | + } elseif( $cond[0] == '|' ) { |
| 29 | + foreach( array_slice( $cond, 1 ) as $subcond ) |
| 30 | + if( self::recCheckCondition( $subcond, $user ) ) |
| 31 | + return true; |
| 32 | + return false; |
| 33 | + } elseif( $cond[0] == '^' ) { |
| 34 | + if( count( $cond ) < 3 ) |
| 35 | + return false; |
| 36 | + return self::recCheckCondition( $cond[1], $user ) |
| 37 | + xor self::recCheckCondition( $cond[2], $user ); |
| 38 | + } |
| 39 | + } |
| 40 | + if( !is_array( $cond ) ) |
| 41 | + $cond = array( $cond ); |
| 42 | + return self::checkCondition( $cond, $user ); |
| 43 | + } |
| 44 | + |
| 45 | + static function checkCondition( $cond, $user ) { |
| 46 | + if( count( $cond ) < 1 ) |
| 47 | + return false; |
| 48 | + switch( $cond[0] ) { |
| 49 | + case APCOND_EMAILCONFIRMED: |
| 50 | + if( User::isValidEmailAddr( $user->getEmail() ) ) { |
| 51 | + global $wgEmailAuthentication; |
| 52 | + if( $wgEmailAuthentication ) { |
| 53 | + return boolval( $user->getEmailAuthenticationTimestamp() ); |
| 54 | + } else { |
| 55 | + return true; |
| 56 | + } |
| 57 | + } |
| 58 | + return false; |
| 59 | + case APCOND_EDITCOUNT: |
| 60 | + return $user->getEditCount() > $cond[1]; |
| 61 | + case APCOND_AGE: |
| 62 | + $age = time() - wfTimestampOrNull( TS_UNIX, $user->getRegistration() ); |
| 63 | + return $age >= $cond[1]; |
| 64 | + case APCOND_INGROUPS: |
| 65 | + default: |
| 66 | + $result = false; |
| 67 | + wfRunHooks( 'AutopromoteCondition', array( $cond[0], array_slice( $cond, 1 ), &$result ) ); |
| 68 | + return $result; |
| 69 | + } |
| 70 | + } |
| 71 | +} |
\ No newline at end of file |
Property changes on: trunk/phase3/includes/Autopromote.php |
___________________________________________________________________ |
Name: svn:eol-style |
1 | 72 | + native |
Index: trunk/phase3/RELEASE-NOTES |
— | — | @@ -33,6 +33,9 @@ |
34 | 34 | remove the groups specified in $wgAddGroups and $wgRemoveGroups for |
35 | 35 | any groups they are in. |
36 | 36 | * New permission userrights-interwiki for changing user rights on foreign wikis. |
| 37 | +* $wgImplictGroups for groups that are hidden from Special:Listusers, etc. |
| 38 | +* $wgAutopromote: automatically promote user flags when user matches |
| 39 | + criterias |
37 | 40 | |
38 | 41 | === New features in 1.12 === |
39 | 42 | * (bug 10735) Add a warning for non-descriptive filenames at Special:Upload |