r23480 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r23479‎ | r23480 | r23481 >
Date:14:41, 27 June 2007
Author:robchurch
Status:old
Tags:
Comment:
Extension provides a convenient method to configure automatic group memberships for accounts meeting certain criteria
Modified paths:
  • /trunk/extensions/AutomaticGroups (added) (history)
  • /trunk/extensions/AutomaticGroups/AutomaticGroups.php (added) (history)
  • /trunk/extensions/AutomaticGroups/LICENSE (added) (history)
  • /trunk/extensions/AutomaticGroups/README (added) (history)

Diff [purge]

Index: trunk/extensions/AutomaticGroups/LICENSE
@@ -0,0 +1,27 @@
 2+Copyright © 2007 Rob Church.
 3+All rights reserved.
 4+
 5+Redistribution and use in source and binary forms, with or without
 6+modification, are permitted provided that the following conditions
 7+are met:
 8+
 9+ 1. Redistributions of source code must retain the above copyright
 10+ notice, this list of conditions and the following disclaimer.
 11+
 12+ 2. Redistributions in binary form must reproduce the above
 13+ copyright notice, this list of conditions and the following
 14+ disclaimer in the documentation and/or other materials provided
 15+ with the distribution.
 16+
 17+THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
 18+IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 19+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 20+DISCLAIMED.
 21+
 22+IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
 23+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
 24+BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
 25+OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 26+ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
 27+TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
 28+USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
\ No newline at end of file
Index: trunk/extensions/AutomaticGroups/AutomaticGroups.php
@@ -0,0 +1,63 @@
 2+<?php
 3+
 4+/**
 5+ * Extension provides convenient configuration of additional
 6+ * effective groups based on a user's account age and edit count
 7+ *
 8+ * @addtogroup Extensions
 9+ * @author Rob Church <robchur@gmail.com>
 10+ */
 11+if( defined( 'MEDIAWIKI' ) ) {
 12+
 13+ $wgExtensionCredits['other'][] = array(
 14+ 'name' => 'Automatic Groups',
 15+ 'author' => 'Rob Church',
 16+ 'url' => '',
 17+ 'description' => 'Provides a convenient means to configure automatic group
 18+ membership based on user account age and edit count',
 19+ );
 20+
 21+ /**
 22+ * Register hook callback
 23+ */
 24+ $wgHooks['UserEffectiveGroups'][] = 'efAutomaticGroups';
 25+
 26+ /**
 27+ * Automatic group configuration
 28+ *
 29+ * Index is the group being assigned, with a second array
 30+ * of account properties; acceptable keys are 'age' and 'edits'
 31+ */
 32+ $wgAutomaticGroups = array();
 33+ // Example: "autoconfirmed" for accounts which are 4 days old
 34+ //$wgAutomaticGroups['autoconfirmed'] = array( 'age' => 86400 * 4 );
 35+ // Example: "patroller" for accounts with 250 edits
 36+ //$wgAutomaticGroups['patroller'] = array( 'edits' => 250 );
 37+
 38+ /**
 39+ * Main execution function
 40+ *
 41+ * @param User $user User to set groups for
 42+ * @param array $groups User's explicit groups
 43+ * @return bool
 44+ */
 45+ function efAutomaticGroups( $user, &$groups ) {
 46+ global $wgAutomaticGroups;
 47+ $age = time() - wfTimestampOrNull( TS_UNIX, $user->getRegistration() );
 48+ foreach( $wgAutomaticGroups as $group => $criteria ) {
 49+ if( isset( $criteria['age'] ) && $age < $criteria['age'] )
 50+ continue;
 51+ if( isset( $criteria['edits'] ) && $user->getEditCount() < $criteria['edits'] )
 52+ continue;
 53+ # User qualifies for this group
 54+ $groups[] = $group;
 55+ }
 56+ return true;
 57+ }
 58+
 59+} else {
 60+ echo( "This file is an extension to MediaWiki and cannot be used standalone.\n" );
 61+ exit( 1 );
 62+}
 63+
 64+?>
\ No newline at end of file
Property changes on: trunk/extensions/AutomaticGroups/AutomaticGroups.php
___________________________________________________________________
Name: svn:eol-style
165 + native
Index: trunk/extensions/AutomaticGroups/README
@@ -0,0 +1,40 @@
 2+Automatic Groups Extension
 3+© 2007 Rob Church
 4+See LICENSE file for full licencing information
 5+
 6+== Overview ==
 7+
 8+The Automatic Groups extension provides a convenient means to configure
 9+additional automatic groups for users matching specific criteria.
 10+
 11+Groups can be added based on
 12+
 13+ * account age
 14+ * edit count
 15+
 16+== Configuration ==
 17+
 18+Group criteria are set using the $wgAutomaticGroups global, which is an
 19+array mapping group names to an array of criteria.
 20+
 21+The criteria are indexed by attribute, mapping to the minimum value
 22+required for that criterion. Multiple criteria are supported per group.
 23+
 24+Valid criteria are
 25+
 26+ * 'edits'
 27+ Minimum edit count
 28+ * 'age'
 29+ Account age (in seconds)
 30+
 31+=== Examples ===
 32+
 33+To assign the group 'uploaders' to all accounts at least 4 days old, one
 34+might use
 35+
 36+ $wgAutomaticGroups['uploaders'] = array( 'age' => 86400 * 4 );
 37+
 38+To assign the group 'patrollers' to all accounts at least 4 days old
 39+with at least 250 edits, one might use
 40+
 41+ $wgAutomaticGroups['patrollers'] = array( 'age' => 86400 * 4, 'edits' => 250 );
\ No newline at end of file

Status & tagging log