http://www.mediawiki.org/wiki/Special:Code/MediaWiki/90816

Revision: 90816
Author:   aaron
Date:     2011-06-26 04:12:05 +0000 (Sun, 26 Jun 2011)
Log Message:
-----------
* Core:
** Made addAutopromoteOnceGroups() put in a user rights log entry
** Added APCOND_ISBOT cond to autopromote and updated some docs
* FlaggedRevs:
** (bug 24948) Made $wgFlaggedRevsAutopromote a wrapper around 
$wgAutopromoteOnce and removed maybeMakeEditor()/recordDemote() (uses r90749)
** Split off new efSetFlaggedRevsOldAutopromoteConfig function
** Removed calls to FlaggedRevs class in setup function to avoid overhead
** Made cache keys in checkAutoPromoteCond() properly unique
** Made wasPreviouslyBlocked() protected and tweaked editSpacingCheck() param 
order

Modified Paths:
--------------
    trunk/extensions/FlaggedRevs/FlaggedRevs.php
    trunk/extensions/FlaggedRevs/FlaggedRevsDefines.php
    trunk/extensions/FlaggedRevs/dataclasses/FlaggedRevs.hooks.php
    trunk/phase3/includes/Autopromote.php
    trunk/phase3/includes/DefaultSettings.php
    trunk/phase3/includes/Defines.php
    trunk/phase3/includes/User.php
    trunk/phase3/languages/messages/MessagesEn.php
    trunk/phase3/maintenance/language/messages.inc

Modified: trunk/extensions/FlaggedRevs/FlaggedRevs.php
===================================================================
--- trunk/extensions/FlaggedRevs/FlaggedRevs.php        2011-06-26 03:00:37 UTC 
(rev 90815)
+++ trunk/extensions/FlaggedRevs/FlaggedRevs.php        2011-06-26 04:12:05 UTC 
(rev 90816)
@@ -473,8 +473,6 @@
 $wgHooks['NewRevisionFromEditComplete'][] = 
'FlaggedRevsHooks::maybeMakeEditReviewed';
 # Null edit review via checkbox
 $wgHooks['ArticleSaveComplete'][] = 'FlaggedRevsHooks::maybeNullEditReview';
-# Disable auto-promotion for demoted users
-$wgHooks['UserRights'][] = 'FlaggedRevsHooks::recordDemote';
 # User edit tallies
 $wgHooks['ArticleRollbackComplete'][] = 'FlaggedRevsHooks::incrementRollbacks';
 $wgHooks['NewRevisionFromEditComplete'][] = 
'FlaggedRevsHooks::incrementReverts';
@@ -525,13 +523,12 @@
 # ########
 
 function efSetFlaggedRevsConditionalHooks() {
-       global $wgHooks;
+       global $wgHooks, $wgFlaggedRevsProtection;
        # Mark items in user contribs
-       if ( !FlaggedRevs::useOnlyIfProtected() ) {
+       if ( !$wgFlaggedRevsProtection ) {
                $wgHooks['ContribsPager::getQueryInfo'][] = 
'FlaggedRevsUIHooks::addToContribsQuery';
                $wgHooks['ContributionsLineEnding'][] = 
'FlaggedRevsUIHooks::addToContribsLine';
-       }
-       if ( FlaggedRevs::useProtectionLevels() ) {
+       } else {
                # Add protection form field
                $wgHooks['ProtectionForm::buildForm'][] = 
'FlaggedRevsUIHooks::onProtectionForm';
                $wgHooks['ProtectionForm::showLogExtract'][] = 
'FlaggedRevsUIHooks::insertStabilityLog';
@@ -550,8 +547,10 @@
 
 # ####### END HOOK TRIGGERED FUNCTIONS  #########
 
+// Note: avoid calls to FlaggedRevs class here for performance
 function efLoadFlaggedRevs() {
-       global $wgFlaggedRevsRCCrap, $wgUseRCPatrol, $wgFlaggedRevsNamespaces;
+       global $wgFlaggedRevsRCCrap, $wgUseRCPatrol;
+       global $wgFlaggedRevsNamespaces, $wgFlaggedRevsProtection;
        if ( $wgFlaggedRevsRCCrap ) {
                # If patrolling is already on, then we know that it 
                # was intended to have all namespaces patrollable.
@@ -561,13 +560,29 @@
                }
                /* TODO: decouple from rc patrol */
                # Check if FlaggedRevs is enabled by default for pages...
-               if ( $wgFlaggedRevsNamespaces && 
!FlaggedRevs::useOnlyIfProtected() ) {
+               if ( $wgFlaggedRevsNamespaces && !$wgFlaggedRevsProtection ) {
                        # Use RC Patrolling to check for vandalism.
                        # Edits to reviewable pages must be flagged to be 
patrolled.
                        $wgUseRCPatrol = true;
                }
        }
-       global $wgFlaggedRevsAutoconfirm, $wgAutopromoteOnce;
+
+       # Conditional autopromote groups
+       efSetFlaggedRevsAutopromoteConfig();
+
+       # Conditional API modules
+       efSetFlaggedRevsConditionalAPIModules();
+       # Load hooks that aren't always set
+       efSetFlaggedRevsConditionalHooks();
+       # Remove conditionally applicable rights
+       efSetFlaggedRevsConditionalRights();
+       # Defaults for user preferences
+       efSetFlaggedRevsConditionalPreferences();
+}
+
+function efSetFlaggedRevsAutopromoteConfig() {
+       global $wgFlaggedRevsAutoconfirm, $wgFlaggedRevsAutopromote;
+       global $wgAutopromoteOnce, $wgGroupPermissions;
        # $wgFlaggedRevsAutoconfirm is now a wrapper around $wgAutopromoteOnce
        $req = $wgFlaggedRevsAutoconfirm; // convenience
        if ( is_array( $req ) ) {
@@ -589,20 +604,39 @@
                        $criteria[] = array( APCOND_FR_NEVERBOCKED );
                }
                $wgAutopromoteOnce['onEdit']['autoreview'] = $criteria;
+               $wgGroupPermissions['autoreview']['autoreview'] = true;
        }
-       # Conditional API modules
-       efSetFlaggedRevsConditionalAPIModules();
-       # Load hooks that aren't always set
-       efSetFlaggedRevsConditionalHooks();
-       # Remove conditionally applicable rights
-       efSetFlaggedRevsConditionalRights();
-       # Defaults for user preferences
-       efSetFlaggedRevsConditionalPreferences();
+
+       # $wgFlaggedRevsAutoconfirm is now a wrapper around $wgAutopromoteOnce
+       $req = $wgFlaggedRevsAutopromote; // convenience
+       if ( is_array( $req ) ) {
+               $criteria = array( '&', // AND
+                       array( APCOND_AGE, $req['days']*86400 ),
+                       array( APCOND_FR_EDITCOUNT, $req['edits'], 
$req['excludeLastDays']*86400 ),
+                       array( APCOND_FR_EDITSUMMARYCOUNT, $req['editComments'] 
),
+                       array( APCOND_FR_UNIQUEPAGECOUNT, 
$req['uniqueContentPages'] ),
+                       array( APCOND_FR_USERPAGEBYTES, $req['userpageBytes'] ),
+                       array( APCOND_FR_NEVERDEMOTED ), // for b/c
+                       array( APCOND_FR_EDITSPACING, $req['spacing'], 
$req['benchmarks'] ),
+                       array( '|', // OR
+                               array( APCOND_FR_CONTENTEDITCOUNT,
+                                       $req['totalContentEdits'], 
$req['excludeLastDays']*86400 ),
+                               array( APCOND_FR_CHECKEDEDITCOUNT,
+                                       $req['totalCheckedEdits'], 
$req['excludeLastDays']*86400 )
+                       ),
+                       array( APCOND_FR_MAXREVERTEDEDITRATIO, 
$req['maxRevertedEditRatio'] ),
+                       array( '!', APCOND_ISBOT )
+               );
+               if ( $req['neverBlocked'] ) {
+                       $criteria[] = array( APCOND_FR_NEVERBOCKED );
+               }
+               $wgAutopromoteOnce['onEdit']['editor'] = $criteria;
+       }
 }
 
 function efSetFlaggedRevsConditionalAPIModules() {
-       global $wgAPIModules, $wgAPIListModules;
-       if ( FlaggedRevs::useOnlyIfProtected() ) {
+       global $wgAPIModules, $wgAPIListModules, $wgFlaggedRevsProtection;
+       if ( $wgFlaggedRevsProtection ) {
                $wgAPIModules['stabilize'] = 'ApiStabilizeProtect';
        } else {
                $wgAPIModules['stabilize'] = 'ApiStabilizeGeneral';
@@ -613,8 +647,8 @@
 }
 
 function efSetFlaggedRevsConditionalRights() {
-       global $wgGroupPermissions, $wgFlaggedRevsAutoconfirm;
-       if ( FlaggedRevs::useOnlyIfProtected() ) {
+       global $wgGroupPermissions, $wgFlaggedRevsProtection;
+       if ( $wgFlaggedRevsProtection ) {
                // Removes sp:ListGroupRights cruft
                if ( isset( $wgGroupPermissions['editor'] ) ) {
                        unset( $wgGroupPermissions['editor']['unreviewedpages'] 
);
@@ -623,10 +657,6 @@
                        unset( 
$wgGroupPermissions['reviewer']['unreviewedpages'] );
                }
        }
-       if ( !empty( $wgFlaggedRevsAutoconfirm ) ) {
-               # Implicit autoreview group
-               $wgGroupPermissions['autoreview']['autoreview'] = true;
-       }
 }
 
 function efSetFlaggedRevsConditionalPreferences() {

Modified: trunk/extensions/FlaggedRevs/FlaggedRevsDefines.php
===================================================================
--- trunk/extensions/FlaggedRevs/FlaggedRevsDefines.php 2011-06-26 03:00:37 UTC 
(rev 90815)
+++ trunk/extensions/FlaggedRevs/FlaggedRevsDefines.php 2011-06-26 04:12:05 UTC 
(rev 90816)
@@ -29,11 +29,15 @@
 define( 'FR_SHOW_STABLE_NEVER', 2 );
 
 # Autopromote conds (F=70,R=82)
-# @TODO: move these 5 to core
+# @TODO: move these 6 to core
 define( 'APCOND_FR_EDITSUMMARYCOUNT', 70821 );
 define( 'APCOND_FR_NEVERBOCKED', 70822 );
 define( 'APCOND_FR_UNIQUEPAGECOUNT', 70823 );
-define( 'APCOND_FR_EDITSPACING', 70824 );
-define( 'APCOND_FR_CONTENTEDITCOUNT', 70825 );
+define( 'APCOND_FR_CONTENTEDITCOUNT', 70824 );
+define( 'APCOND_FR_USERPAGEBYTES', 70825 );
+define( 'APCOND_FR_EDITCOUNT', 70826 );
 
-define( 'APCOND_FR_CHECKEDEDITCOUNT', 70826 );
+define( 'APCOND_FR_EDITSPACING', 70827 );
+define( 'APCOND_FR_CHECKEDEDITCOUNT', 70828 );
+define( 'APCOND_FR_MAXREVERTEDEDITRATIO', 70829 );
+define( 'APCOND_FR_NEVERDEMOTED', 70830 );

Modified: trunk/extensions/FlaggedRevs/dataclasses/FlaggedRevs.hooks.php
===================================================================
--- trunk/extensions/FlaggedRevs/dataclasses/FlaggedRevs.hooks.php      
2011-06-26 03:00:37 UTC (rev 90815)
+++ trunk/extensions/FlaggedRevs/dataclasses/FlaggedRevs.hooks.php      
2011-06-26 04:12:05 UTC (rev 90816)
@@ -679,12 +679,12 @@
         * Check if a user meets the edit spacing requirements.
         * If the user does not, return a *lower bound* number of seconds
         * that must elapse for it to be possible for the user to meet them.
+        * @param User $user
         * @param int $spacingReq days apart (of edit points)
         * @param int $pointsReq number of edit points
-        * @param User $user
         * @return mixed (true if passed, int seconds on failure)
         */
-       protected static function editSpacingCheck( $spacingReq, $pointsReq, 
$user ) {
+       protected static function editSpacingCheck( User $user, $spacingReq, 
$pointsReq ) {
                $benchmarks = 0; // actual edit points
                # Convert days to seconds...
                $spacingReq = $spacingReq * 24 * 3600;
@@ -743,7 +743,7 @@
        /**
        * Checks if $user was previously blocked
        */
-       public static function wasPreviouslyBlocked( $user ) {
+       protected static function wasPreviouslyBlocked( $user ) {
                $dbr = wfGetDB( DB_SLAVE );
                return (bool)$dbr->selectField( 'logging', '1',
                        array(
@@ -756,6 +756,36 @@
                );
        }
 
+       protected static function recentEditCount( $uid, $seconds, $limit ) {
+               $dbr = wfGetDB( DB_SLAVE );
+               # Get cutoff timestamp (edits that are too recent)
+               $encCutoff = $dbr->addQuotes( $dbr->timestamp( time() - 
$seconds ) );
+               # Check all recent edits...
+               $res = $dbr->select( 'revision', '1',
+                       array( 'rev_user' => $uid, "rev_timestamp > $encCutoff" 
),
+                       __METHOD__,
+                       array( 'LIMIT' => $limit + 1 ) // hit as few rows as 
possible
+               );
+               return $dbr->numRows( $res );
+       }
+
+       protected static function recentContentEditCount( $uid, $seconds, 
$limit ) {
+               $dbr = wfGetDB( DB_SLAVE );
+               # Get cutoff timestamp (edits that are too recent)
+               $encCutoff = $dbr->addQuotes( $dbr->timestamp( time() - 
$seconds ) );
+               # Check all recent content edits...
+               $res = $dbr->select( array( 'revision', 'page' ), '1',
+                       array( 'rev_user' => $uid,
+                               "rev_timestamp > $encCutoff",
+                               'rev_page = page_id',
+                               'page_namespace' => 
MWNamespace::getContentNamespaces() ),
+                       __METHOD__,
+                       array( 'LIMIT' => $limit + 1,
+                               'USE INDEX' => array( 'revision' => 
'user_timestamp' ) )
+               );
+               return $dbr->numRows( $res );
+       }
+
        /**
        * Grant 'autoreview' rights to users with the 'bot' right
        */
@@ -787,9 +817,6 @@
                if ( $changed ) {
                        FRUserCounters::saveUserParams( $user->getId(), $p ); 
// save any updates
                }
-               if ( is_array( $wgFlaggedRevsAutopromote ) ) {
-                       self::maybeMakeEditor( $user, $p, 
$wgFlaggedRevsAutopromote );
-               }
                return true;
        }
 
@@ -803,27 +830,32 @@
                switch( $cond ) {
                        case APCOND_FR_EDITSUMMARYCOUNT:
                                $p = FRUserCounters::getParams( $user );
-                               $result = ( is_array( $p ) && 
$p['editComments'] >= $params[0] );
+                               $result = ( $p && $p['editComments'] >= 
$params[0] );
                                break;
                        case APCOND_FR_NEVERBOCKED:
-                               $key = wfMemcKey( 'flaggedrevs', 
'autopromote-blocked-ok', $user->getId() );
-                               $val = $wgMemc->get( $key );
-                               if ( $val === 'true' ) {
-                                       $result = true; // passed
-                               } elseif ( $val === 'false' ) {
+                               if ( $user->isBlocked() ) {
                                        $result = false; // failed
                                } else {
-                                       # Hit the DB only if the result is not 
cached...
-                                       $result = !self::wasPreviouslyBlocked( 
$user );
-                                       $wgMemc->set( $key, $result ? 'true' : 
'false', 3600 * 24 * 7 ); // cache results
+                                       $key = wfMemcKey( 'flaggedrevs', 
'autopromote-blocked', $user->getId() );
+                                       $val = $wgMemc->get( $key );
+                                       if ( $val === 'true' ) {
+                                               $result = true; // passed
+                                       } elseif ( $val === 'false' ) {
+                                               $result = false; // failed
+                                       } else {
+                                               # Hit the DB only if the result 
is not cached...
+                                               $result = 
!self::wasPreviouslyBlocked( $user );
+                                               $wgMemc->set( $key, $result ? 
'true' : 'false', 3600 * 24 * 7 );
+                                       }
                                }
                                break;
                        case APCOND_FR_UNIQUEPAGECOUNT:
                                $p = FRUserCounters::getParams( $user );
-                               $result = ( is_array( $p ) && 
$p['uniqueContentPages'] >= $params[0] );
+                               $result = ( $p && $p['uniqueContentPages'] >= 
$params[0] );
                                break;
                        case APCOND_FR_EDITSPACING:
-                               $key = wfMemcKey( 'flaggedrevs', 
'autopromote-spacing-ok', $user->getId() );
+                               $key = wfMemcKey( 'flaggedrevs', 
'autopromote-editspacing',
+                                       $user->getId(), $params[0], $params[1] 
);
                                $val = $wgMemc->get( $key );
                                if ( $val === 'true' ) {
                                        $result = true; // passed
@@ -831,7 +863,7 @@
                                        $result = false; // failed
                                } else {
                                        # Hit the DB only if the result is not 
cached...
-                                       $pass = self::editSpacingCheck( 
$params[0], $params[1], $user );
+                                       $pass = self::editSpacingCheck( $user, 
$params[0], $params[1] );
                                        # Make a key to store the results
                                        if ( $pass === true ) {
                                                $wgMemc->set( $key, 'true', 14 
* 24 * 3600 );
@@ -841,147 +873,55 @@
                                        $result = ( $pass === true );
                                }
                                break;
+                       case APCOND_FR_EDITCOUNT:
+                               # $maxNew is the *most* edits that can be too 
recent
+                               $maxNew = $user->getEditCount() - $params[0];
+                               if ( $maxNew < 0 ) {
+                                       $result = false; // doesn't meet count 
even *with* recent edits
+                               } elseif ( $params[1] <= 0 ) {
+                                       $result = true; // passed; we aren't 
excluding any recent edits
+                               } else {
+                                       # Check all recent edits...
+                                       $n = self::recentEditCount( 
$user->getId(), $params[1], $maxNew );
+                                       $result = ( $n <= $maxNew );
+                               }
+                               break;
                        case APCOND_FR_CONTENTEDITCOUNT:
                                $p = FRUserCounters::getParams( $user );
-                               $result = ( is_array( $p ) && 
$p['totalContentEdits'] >= $params[0] );
+                               if ( !$p ) {
+                                       $result = false;
+                               } else {
+                                       # $maxNew is the *most* edits that can 
be too recent
+                                       $maxNew = $p['totalContentEdits'] - 
$params[0];
+                                       if ( $maxNew < 0 ) {
+                                               $result = false; // doesn't 
meet count even *with* recent edits
+                                       } elseif ( $params[1] <= 0 ) {
+                                               $result = true; // passed; we 
aren't excluding any recent edits
+                                       } else {
+                                               # Check all recent content 
edits...
+                                               $n = 
self::recentContentEditCount( $user->getId(), $params[1], $maxNew );
+                                               $result = ( $n <= $maxNew );
+                                       }
+                               }
                                break;
                        case APCOND_FR_CHECKEDEDITCOUNT:
-                               $result = self::reviewedEditsCheck( $user, 
$params[0] );
+                               $result = self::reviewedEditsCheck( $user, 
$params[0], $params[1] );
                                break;
+                       case APCOND_FR_USERPAGEBYTES:
+                               $result = ( !$params[0] || 
$user->getUserPage()->getLength() >= $params[0] );
+                               break;
+                       case APCOND_FR_MAXREVERTEDEDITRATIO:
+                               $p = FRUserCounters::getParams( $user );
+                               $result = ( $p && 
$params[0]*$user->getEditCount() >= $p['revertedEdits'] );
+                               break;
+                       case APCOND_FR_NEVERDEMOTED: // b/c
+                               $p = FRUserCounters::getParams( $user );
+                               $result = ( $p && !$p['demoted'] );
+                               break;
                }
                return true;
        }
 
-       /**
-       * Autopromotes user according to the setting in 
$wgFlaggedRevsAutopromote.
-       * @param $user User
-       * @param $p array user tallies
-       * @param $conds array $wgFlaggedRevsAutopromote
-       */
-       protected static function maybeMakeEditor( User $user, array $p, array 
$conds ) {
-               global $wgMemc, $wgContentNamespaces;
-               $groups = $user->getGroups(); // current groups
-               $regTime = wfTimestampOrNull( TS_UNIX, $user->getRegistration() 
);
-               if (
-                       !$user->getId() ||
-                       # Do not give this to current holders
-                       in_array( 'editor', $groups ) ||
-                       # Do not give this right to bots
-                       $user->isAllowed( 'bot' ) ||
-                       # Do not re-add status if it was previously removed!
-                       ( isset( $p['demoted'] ) && $p['demoted'] ) ||
-                       # Check if user edited enough unique pages
-                       $conds['uniqueContentPages'] > count( 
$p['uniqueContentPages'] ) ||
-                       # Check edit summary usage
-                       $conds['editComments'] > $p['editComments'] ||
-                       # Check reverted edits
-                       $conds['maxRevertedEditRatio']*$user->getEditCount() < 
$p['revertedEdits'] ||
-                       # Check user edit count
-                       $conds['edits'] > $user->getEditCount() ||
-                       # Check account age
-                       ( $regTime && $conds['days'] > ( ( time() - $regTime ) 
/ 86400 ) ) ||
-                       # See if the page actually has sufficient content...
-                       $conds['userpageBytes'] > 
$user->getUserPage()->getLength() ||
-                       # Don't grant to currently blocked users...
-                       $user->isBlocked()
-               ) {
-                       return true; // not ready
-               }
-               # User needs to meet 'totalContentEdits' OR 'totalCheckedEdits'
-               $failedContentEdits = ( $conds['totalContentEdits'] > 
$p['totalContentEdits'] );
-
-               # More expensive checks below...
-               # Check if results are cached to avoid DB queries
-               $APSkipKey = wfMemcKey( 'flaggedrevs', 'autopromote-skip', 
$user->getId() );
-               if ( $wgMemc->get( $APSkipKey ) === 'true' ) {
-                       return true;
-               }
-               # Check if user was ever blocked before
-               if ( $conds['neverBlocked'] && self::wasPreviouslyBlocked( 
$user ) ) {
-                       $wgMemc->set( $APSkipKey, 'true', 3600 * 24 * 7 ); // 
cache results
-                       return true;
-               }
-               $dbr = wfGetDB( DB_SLAVE );
-               $cutoff_ts = 0;
-               # Check to see if the user has enough non-"last minute" edits.
-               if ( $conds['excludeLastDays'] > 0 ) {
-                       $minDiffAll = $user->getEditCount() - $conds['edits'] + 
1;
-                       # Get cutoff timestamp
-                       $cutoff_ts = time() - 86400*$conds['excludeLastDays'];
-                       $encCutoff = $dbr->addQuotes( $dbr->timestamp( 
$cutoff_ts ) );
-                       # Check all recent edits...
-                       $res = $dbr->select( 'revision', '1',
-                               array( 'rev_user' => $user->getId(), 
"rev_timestamp > $encCutoff" ),
-                               __METHOD__,
-                               array( 'LIMIT' => $minDiffAll )
-                       );
-                       if ( $dbr->numRows( $res ) >= $minDiffAll ) {
-                               return true; // delay promotion
-                       }
-                       # Check recent content edits...
-                       if ( !$failedContentEdits && $wgContentNamespaces ) {
-                               $minDiffContent = $p['totalContentEdits'] - 
$conds['totalContentEdits'] + 1;
-                               $res = $dbr->select( array( 'revision', 'page' 
), '1',
-                                       array( 'rev_user' => $user->getId(),
-                                               "rev_timestamp > $encCutoff",
-                                               'rev_page = page_id',
-                                               'page_namespace' => 
$wgContentNamespaces ),
-                                       __METHOD__,
-                                       array( 'USE INDEX' => array( 'revision' 
=> 'user_timestamp' ),
-                                               'LIMIT' => $minDiffContent )
-                               );
-                               if ( $dbr->numRows( $res ) >= $minDiffContent ) 
{
-                                       $failedContentEdits = true; // 
totalCheckedEdits needed
-                               }
-                       }
-               }
-               # Check for edit spacing. This lets us know that the account has
-               # been used over N different days, rather than all in one lump.
-               if ( $conds['spacing'] > 0 && $conds['benchmarks'] > 1 ) {
-                       $pass = self::editSpacingCheck( $conds['spacing'], 
$conds['benchmarks'], $user );
-                       if ( $pass !== true ) {
-                               $wgMemc->set( $APSkipKey, 'true', $pass /* wait 
time */ ); // cache results
-                               return true;
-                       }
-               }
-               # Check if there are enough implicitly reviewed edits
-               if ( $failedContentEdits && $conds['totalCheckedEdits'] > 0 ) {
-                       if ( !self::reviewedEditsCheck( $user, 
$conds['totalCheckedEdits'], $cutoff_ts ) ) {
-                               return true;
-                       }
-               }
-
-               # Add editor rights...
-               $newGroups = $groups;
-               array_push( $newGroups, 'editor' );
-               $log = new LogPage( 'rights', false /* $rc */ );
-               $log->addEntry( 'rights',
-                       $user->getUserPage(),
-                       wfMsgForContent( 'rights-editor-autosum' ),
-                       array( implode( ', ', $groups ), implode( ', ', 
$newGroups ) )
-               );
-               $user->addGroup( 'editor' );
-
-               return true;
-       }
-
-       /**
-       * Record demotion so that auto-promote will be disabled
-       */
-       public static function recordDemote( $user, array $addgroup, array 
$removegroup ) {
-               if ( $removegroup && in_array( 'editor', $removegroup ) ) {
-                       $dbName = false; // this wiki
-                       // Cross-wiki rights changes...
-                       if ( $user instanceof UserRightsProxy ) {
-                               $dbName = $user->getDBName(); // use foreign DB 
of the user
-                       }
-                       $p = FRUserCounters::getUserParams( $user->getId(), 
FR_FOR_UPDATE, $dbName );
-                       $p['demoted'] = 1;
-                       FRUserCounters::saveUserParams( $user->getId(), $p, 
$dbName );
-               }
-               return true;
-       }
-
        public static function stableDumpQuery( array &$tables, array &$opts, 
array &$join ) {
                $namespaces = FlaggedRevs::getReviewNamespaces();
                if ( $namespaces ) {
@@ -997,9 +937,11 @@
                return false; // final
        }
 
-       public static function gnsmQueryModifier( array $params, array &$joins, 
array &$conditions, array &$tables ) {
+       public static function gnsmQueryModifier(
+               array $params, array &$joins, array &$conditions, array &$tables
+       ) {
                $filterSet = array( GoogleNewsSitemap::OPT_ONLY => true,
-                               GoogleNewsSitemap::OPT_EXCLUDE => true
+                       GoogleNewsSitemap::OPT_EXCLUDE => true
                );
                # Either involves the same JOIN here...
                if ( isset( $filterSet[ $params['stable'] ] ) || isset( 
$filterSet[ $params['quality'] ] ) ) {

Modified: trunk/phase3/includes/Autopromote.php
===================================================================
--- trunk/phase3/includes/Autopromote.php       2011-06-26 03:00:37 UTC (rev 
90815)
+++ trunk/phase3/includes/Autopromote.php       2011-06-26 04:12:05 UTC (rev 
90816)
@@ -68,7 +68,7 @@
 
        /**
         * Recursively check a condition.  Conditions are in the form
-        *   array( '&' or '|' or '^', cond1, cond2, ... )
+        *   array( '&' or '|' or '^' or '!', cond1, cond2, ... )
         * where cond1, cond2, ... are themselves conditions; *OR*
         *   APCOND_EMAILCONFIRMED, *OR*
         *   array( APCOND_EMAILCONFIRMED ), *OR*
@@ -176,6 +176,8 @@
                                return IP::isInRange( wfGetIP(), $cond[1] );
                        case APCOND_BLOCKED:
                                return $user->isBlocked();
+                       case APCOND_ISBOT:
+                               return in_array( 'bot', 
User::getGroupPermissions( $user->getGroups() ) );
                        default:
                                $result = null;
                                wfRunHooks( 'AutopromoteCondition', array( 
$cond[0], array_slice( $cond, 1 ), $user, &$result ) );

Modified: trunk/phase3/includes/DefaultSettings.php
===================================================================
--- trunk/phase3/includes/DefaultSettings.php   2011-06-26 03:00:37 UTC (rev 
90815)
+++ trunk/phase3/includes/DefaultSettings.php   2011-06-26 04:12:05 UTC (rev 
90816)
@@ -3498,7 +3498,7 @@
 /**
  * Automatically add a usergroup to any user who matches certain conditions.
  * The format is
- *   array( '&' or '|' or '^', cond1, cond2, ... )
+ *   array( '&' or '|' or '^' or '!', cond1, cond2, ... )
  * where cond1, cond2, ... are themselves conditions; *OR*
  *   APCOND_EMAILCONFIRMED, *OR*
  *   array( APCOND_EMAILCONFIRMED ), *OR*
@@ -3509,6 +3509,7 @@
  *   array( APCOND_IPINRANGE, range ), *OR*
  *   array( APCOND_AGE_FROM_EDIT, seconds since first edit ), *OR*
  *   array( APCOND_BLOCKED ), *OR*
+ *   array( APCOND_ISBOT ), *OR*
  *   similar constructs defined by extensions.
  *
  * If $wgEmailAuthentication is off, APCOND_EMAILCONFIRMED will be true for any

Modified: trunk/phase3/includes/Defines.php
===================================================================
--- trunk/phase3/includes/Defines.php   2011-06-26 03:00:37 UTC (rev 90815)
+++ trunk/phase3/includes/Defines.php   2011-06-26 04:12:05 UTC (rev 90816)
@@ -249,4 +249,5 @@
 define( 'APCOND_IPINRANGE', 6 );
 define( 'APCOND_AGE_FROM_EDIT', 7 );
 define( 'APCOND_BLOCKED', 8 );
+define( 'APCOND_ISBOT', 9 );
 /**@}*/

Modified: trunk/phase3/includes/User.php
===================================================================
--- trunk/phase3/includes/User.php      2011-06-26 03:00:37 UTC (rev 90815)
+++ trunk/phase3/includes/User.php      2011-06-26 04:12:05 UTC (rev 90816)
@@ -1117,14 +1117,25 @@
         * @see $wgAutopromoteOnce
         */
        public function addAutopromoteOnceGroups( $event ) {
+               $toPromote = array();
                if ( $this->getId() ) {
                        $toPromote = Autopromote::getAutopromoteOnceGroups( 
$this, $event );
-                       foreach ( $toPromote as $group ) {
-                               $this->addGroup( $group );
+                       if ( count( $toPromote ) ) {
+                               $oldGroups = $this->getGroups(); // previous 
groups
+                               foreach ( $toPromote as $group ) {
+                                       $this->addGroup( $group );
+                               }
+                               $newGroups = array_merge( $oldGroups, 
$toPromote ); // all groups
+
+                               $log = new LogPage( 'rights', false /* not in 
RC */ );
+                               $log->addEntry( 'rights',
+                                       $this->getUserPage(),
+                                       wfMsgForContent( 'rightsautocomment' ),
+                                       array( implode( ', ', $oldGroups ), 
implode( ', ', $newGroups ) )
+                               );
                        }
-                       return $toPromote;
                }
-               return array(); 
+               return $toPromote; 
        }
 
        /**

Modified: trunk/phase3/languages/messages/MessagesEn.php
===================================================================
--- trunk/phase3/languages/messages/MessagesEn.php      2011-06-26 03:00:37 UTC 
(rev 90815)
+++ trunk/phase3/languages/messages/MessagesEn.php      2011-06-26 04:12:05 UTC 
(rev 90816)
@@ -1978,10 +1978,11 @@
 'right-sendemail'             => 'Send e-mail to other users',
 
 # User rights log
-'rightslog'      => 'User rights log',
-'rightslogtext'  => 'This is a log of changes to user rights.',
-'rightslogentry' => 'changed group membership for $1 from $2 to $3',
-'rightsnone'     => '(none)',
+'rightslog'          => 'User rights log',
+'rightslogtext'      => 'This is a log of changes to user rights.',
+'rightslogentry'     => 'changed group membership for $1 from $2 to $3',
+'rightsnone'         => '(none)',
+'rightsautocomment'  => 'automatically promoted',
 
 # Associated actions - in the sentence "You do not have permission to X"
 'action-read'                 => 'read this page',

Modified: trunk/phase3/maintenance/language/messages.inc
===================================================================
--- trunk/phase3/maintenance/language/messages.inc      2011-06-26 03:00:37 UTC 
(rev 90815)
+++ trunk/phase3/maintenance/language/messages.inc      2011-06-26 04:12:05 UTC 
(rev 90816)
@@ -1143,6 +1143,7 @@
                'rightslogtext',
                'rightslogentry',
                'rightsnone',
+               'rightsautocomment',
        ),
        'action' => array(
                'action-read',


_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to