r28797 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r28796‎ | r28797 | r28798 >
Date:11:38, 23 December 2007
Author:vasilievvv
Status:old
Tags:
Comment:
Introduce new autopromotion system
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/includes/AutoLoader.php (modified) (history)
  • /trunk/phase3/includes/Autopromote.php (added) (history)
  • /trunk/phase3/includes/DefaultSettings.php (modified) (history)
  • /trunk/phase3/includes/Defines.php (modified) (history)
  • /trunk/phase3/includes/User.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/Defines.php
@@ -277,3 +277,7 @@
278278 # Flags for Parser::replaceLinkHolders
279279 define( 'RLH_FOR_UPDATE', 1 );
280280
 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 @@
16521652 $this->mEffectiveGroups[] = '*';
16531653 if( $this->mId ) {
16541654 $this->mEffectiveGroups[] = 'user';
1655 -
1656 - global $wgAutoConfirmAge, $wgAutoConfirmCount;
16571655
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+
16721661 # Hook for additional groups
16731662 wfRunHooks( 'UserEffectiveGroups', array( &$this, &$this->mEffectiveGroups ) );
16741663 }
@@ -2595,11 +2584,9 @@
25962585 * @return array
25972586 */
25982587 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
26042591 return $groups;
26052592 }
26062593
Index: trunk/phase3/includes/AutoLoader.php
@@ -17,6 +17,7 @@
1818 'AlphabeticPager' => 'includes/Pager.php',
1919 'Article' => 'includes/Article.php',
2020 'AuthPlugin' => 'includes/AuthPlugin.php',
 21+ 'Autopromote' => 'includes/Autopromote.php',
2122 'BagOStuff' => 'includes/BagOStuff.php',
2223 'HashBagOStuff' => 'includes/BagOStuff.php',
2324 'SqlBagOStuff' => 'includes/BagOStuff.php',
Index: trunk/phase3/includes/DefaultSettings.php
@@ -1127,7 +1127,13 @@
11281128 */
11291129 # $wgGroupPermissions['developer']['siteadmin'] = true;
11301130
 1131+
11311132 /**
 1133+ * Implicit groups, aren't shown on Special:Listusers or somewhere else
 1134+ */
 1135+$wgImplicitGroups = array( '*', 'user', 'autoconfirmed', 'emailconfirmed' );
 1136+
 1137+/**
11321138 * Set of available actions that can be restricted via action=protect
11331139 * You probably shouldn't change this.
11341140 * Translated trough restriction-* messages.
@@ -1183,6 +1189,17 @@
11841190 //$wgAutoConfirmCount = 50;
11851191
11861192 /**
 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+/**
11871204 * These settings can be used to give finer control over who can assign which
11881205 * groups at Special:Userrights. Example configuration:
11891206 *
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
172 + native
Index: trunk/phase3/RELEASE-NOTES
@@ -33,6 +33,9 @@
3434 remove the groups specified in $wgAddGroups and $wgRemoveGroups for
3535 any groups they are in.
3636 * 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
3740
3841 === New features in 1.12 ===
3942 * (bug 10735) Add a warning for non-descriptive filenames at Special:Upload

Follow-up revisions

RevisionCommit summaryAuthorDate
r28805Fixes for r28797....simetrical19:53, 23 December 2007

Status & tagging log