MediaWiki r28797 - Code Review

Jump to: navigation, search
Repository:MediaWiki
Revision:r28796‎ | r28797 (on ViewVC)‎ | r28798 >
Date:11:38, 23 December 2007
Author:vasilievvv
Status:old
Tags:
Comment:
Introduce new autopromotion system
Modified paths:

Diff [purge]

Index: trunk/phase3/includes/Defines.php
===================================================================
--- trunk/phase3/includes/Defines.php	(revision 28796)
+++ trunk/phase3/includes/Defines.php	(revision 28797)
@@ -277,3 +277,7 @@
 # Flags for Parser::replaceLinkHolders
 define( 'RLH_FOR_UPDATE', 1 );
 
+#Autopromote conditions
+define( 'APCOND_EDITCOUNT', 1 );
+define( 'APCOND_AGE', 2 );
+define( 'APCOND_EMAILCONFIRMED', 3 );
Index: trunk/phase3/includes/User.php
===================================================================
--- trunk/phase3/includes/User.php	(revision 28796)
+++ trunk/phase3/includes/User.php	(revision 28797)
@@ -1651,23 +1651,12 @@
 			$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 @@
 	 * @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;
 	}
 
Index: trunk/phase3/includes/AutoLoader.php
===================================================================
--- trunk/phase3/includes/AutoLoader.php	(revision 28796)
+++ trunk/phase3/includes/AutoLoader.php	(revision 28797)
@@ -17,6 +17,7 @@
 		'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',
Index: trunk/phase3/includes/DefaultSettings.php
===================================================================
--- trunk/phase3/includes/DefaultSettings.php	(revision 28796)
+++ trunk/phase3/includes/DefaultSettings.php	(revision 28797)
@@ -1127,7 +1127,13 @@
  */
 # $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.
  * Translated trough restriction-* messages.
@@ -1183,6 +1189,17 @@
 //$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:
  *
Index: trunk/phase3/includes/Autopromote.php
===================================================================
--- trunk/phase3/includes/Autopromote.php	(revision 0)
+++ trunk/phase3/includes/Autopromote.php	(revision 28797)
@@ -0,0 +1,70 @@
+<?php
+
+/**
+ * This class checks if user can get extra rights
+ * because of conditions specified in $wgAutopromote
+ */
+class Autopromote {	
+	public static function autopromoteUser( $user ) {
+		global $wgAutopromote;
+		$promote = array();
+		foreach( $wgAutopromote as $group => $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

Property changes on: trunk/phase3/includes/Autopromote.php
___________________________________________________________________
Name: svn:eol-style
   + native

Index: trunk/phase3/RELEASE-NOTES
===================================================================
--- trunk/phase3/RELEASE-NOTES	(revision 28796)
+++ trunk/phase3/RELEASE-NOTES	(revision 28797)
@@ -33,6 +33,9 @@
      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

Follow-up revisions

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

Status & tagging log

  • 15:23, 12 September 2011 Meno25 (Talk | contribs) changed the status of r28797 [removed: ok added: old]
Personal tools
Namespaces
Variants
Views
Actions
Site
Support
Download
Development
Communication
Toolbox