From 8a7c8bdec681deae9a0c92be8541f9cbba91bdf7 Mon Sep 17 00:00:00 2001 From: Victor Vasiliev Date: Sun, 23 Dec 2007 11:38:24 +0000 Subject: [PATCH] Introduce new autopromotion system --- RELEASE-NOTES | 3 ++ includes/AutoLoader.php | 1 + includes/Autopromote.php | 70 ++++++++++++++++++++++++++++++++++++ includes/DefaultSettings.php | 17 +++++++++ includes/Defines.php | 4 +++ includes/User.php | 29 +++++---------- 6 files changed, 103 insertions(+), 21 deletions(-) create mode 100644 includes/Autopromote.php diff --git a/RELEASE-NOTES b/RELEASE-NOTES index 93367e6aa9..e3bf47af0f 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -33,6 +33,9 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN remove the groups specified in $wgAddGroups and $wgRemoveGroups for any groups they are in. * New permission userrights-interwiki for changing user rights on foreign wikis. +* $wgImplictGroups for groups that are hidden from Special:Listusers, etc. +* $wgAutopromote: automatically promote user flags when user matches + criterias === New features in 1.12 === * (bug 10735) Add a warning for non-descriptive filenames at Special:Upload diff --git a/includes/AutoLoader.php b/includes/AutoLoader.php index 2a01444f7c..4f92f65fb5 100644 --- a/includes/AutoLoader.php +++ b/includes/AutoLoader.php @@ -17,6 +17,7 @@ function __autoload($className) { 'AlphabeticPager' => 'includes/Pager.php', 'Article' => 'includes/Article.php', 'AuthPlugin' => 'includes/AuthPlugin.php', + 'Autopromote' => 'includes/Autopromote.php', 'BagOStuff' => 'includes/BagOStuff.php', 'HashBagOStuff' => 'includes/BagOStuff.php', 'SqlBagOStuff' => 'includes/BagOStuff.php', diff --git a/includes/Autopromote.php b/includes/Autopromote.php new file mode 100644 index 0000000000..97ea48d8c1 --- /dev/null +++ b/includes/Autopromote.php @@ -0,0 +1,70 @@ + $cond ) { + if( self::recCheckCondition( $cond, $user ) ) + $promote[] = $group; + } + return $promote; + } + + //@private + static function recCheckCondition( $cond, $user ) { + $validOps = array( '&', '|', '^' ); + if( is_array( $cond ) && count( $cond ) > 0 && in_array( $cond[0], $validOps ) ) { + if( $cond[0] == '&' ) { + foreach( array_slice( $cond, 1 ) as $subcond ) + if( !self::recCheckCondition( $subcond, $user ) ) + return false; + return true; + } elseif( $cond[0] == '|' ) { + foreach( array_slice( $cond, 1 ) as $subcond ) + if( self::recCheckCondition( $subcond, $user ) ) + return true; + return false; + } elseif( $cond[0] == '^' ) { + if( count( $cond ) < 3 ) + return false; + return self::recCheckCondition( $cond[1], $user ) + xor self::recCheckCondition( $cond[2], $user ); + } + } + if( !is_array( $cond ) ) + $cond = array( $cond ); + return self::checkCondition( $cond, $user ); + } + + static function checkCondition( $cond, $user ) { + if( count( $cond ) < 1 ) + return false; + switch( $cond[0] ) { + case APCOND_EMAILCONFIRMED: + if( User::isValidEmailAddr( $user->getEmail() ) ) { + global $wgEmailAuthentication; + if( $wgEmailAuthentication ) { + return boolval( $user->getEmailAuthenticationTimestamp() ); + } else { + return true; + } + } + return false; + case APCOND_EDITCOUNT: + return $user->getEditCount() > $cond[1]; + case APCOND_AGE: + $age = time() - wfTimestampOrNull( TS_UNIX, $user->getRegistration() ); + return $age >= $cond[1]; + case APCOND_INGROUPS: + default: + $result = false; + wfRunHooks( 'AutopromoteCondition', array( $cond[0], array_slice( $cond, 1 ), &$result ) ); + return $result; + } + } +} \ No newline at end of file diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index f066a119b4..fde53de9c6 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -1127,6 +1127,12 @@ $wgGroupPermissions['bureaucrat']['userrights'] = true; */ # $wgGroupPermissions['developer']['siteadmin'] = true; + +/** + * Implicit groups, aren't shown on Special:Listusers or somewhere else + */ +$wgImplicitGroups = array( '*', 'user', 'autoconfirmed', 'emailconfirmed' ); + /** * Set of available actions that can be restricted via action=protect * You probably shouldn't change this. @@ -1182,6 +1188,17 @@ $wgAutoConfirmAge = 0; $wgAutoConfirmCount = 0; //$wgAutoConfirmCount = 50; +/** + * Automatically promote user flags to users that matchs some conditions + */ +$wgAutopromote = array( + 'autoconfirmed' => array( '&', + array( APCOND_EDITCOUNT, &$wgAutoConfirmCount ), + array( APCOND_AGE, &$wgAutoConfirmAge ), + ), + 'emailconfirmed' => APCOND_EMAILCONFIRMED, +); + /** * These settings can be used to give finer control over who can assign which * groups at Special:Userrights. Example configuration: diff --git a/includes/Defines.php b/includes/Defines.php index 2ee527d589..d76b34718a 100644 --- a/includes/Defines.php +++ b/includes/Defines.php @@ -277,3 +277,7 @@ define( 'SFH_OBJECT_ARGS', 2 ); # Flags for Parser::replaceLinkHolders define( 'RLH_FOR_UPDATE', 1 ); +#Autopromote conditions +define( 'APCOND_EDITCOUNT', 1 ); +define( 'APCOND_AGE', 2 ); +define( 'APCOND_EMAILCONFIRMED', 3 ); diff --git a/includes/User.php b/includes/User.php index 0d2865c61f..10048a62fb 100644 --- a/includes/User.php +++ b/includes/User.php @@ -1651,23 +1651,12 @@ class User { $this->mEffectiveGroups[] = '*'; if( $this->mId ) { $this->mEffectiveGroups[] = 'user'; - - global $wgAutoConfirmAge, $wgAutoConfirmCount; - $accountAge = time() - wfTimestampOrNull( TS_UNIX, $this->mRegistration ); - if( $accountAge >= $wgAutoConfirmAge && $this->getEditCount() >= $wgAutoConfirmCount ) { - $this->mEffectiveGroups[] = 'autoconfirmed'; - } - # Implicit group for users whose email addresses are confirmed - global $wgEmailAuthentication; - if( self::isValidEmailAddr( $this->mEmail ) ) { - if( $wgEmailAuthentication ) { - if( $this->mEmailAuthenticated ) - $this->mEffectiveGroups[] = 'emailconfirmed'; - } else { - $this->mEffectiveGroups[] = 'emailconfirmed'; - } - } + $this->mEffectiveGroups = array_merge( + $this->mEffectiveGroups, + Autopromote::autopromoteUser( $this ) + ); + # Hook for additional groups wfRunHooks( 'UserEffectiveGroups', array( &$this, &$this->mEffectiveGroups ) ); } @@ -2595,11 +2584,9 @@ class User { * @return array */ public static function getImplicitGroups() { - static $groups = null; - if( !is_array( $groups ) ) { - $groups = array( '*', 'user', 'autoconfirmed', 'emailconfirmed' ); - wfRunHooks( 'UserGetImplicitGroups', array( &$groups ) ); - } + global $wgImplicitGroups; + $groups = $wgImplicitGroups; + wfRunHooks( 'UserGetImplicitGroups', array( &$groups ) ); #deprecated, use $wgImplictGroups instead return $groups; } -- 2.20.1