r25406 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r25405‎ | r25406 | r25407 >
Date:12:42, 2 September 2007
Author:aaron
Status:old
Tags:
Comment:
*Fix var name typo
*Make userpage requirement optional
*Add optional time spacing requirements
Modified paths:
  • /trunk/extensions/FlaggedRevs/FlaggedRevs.php (modified) (history)

Diff [purge]

Index: trunk/extensions/FlaggedRevs/FlaggedRevs.php
@@ -140,7 +140,14 @@
141141 $wgGroupPermissions['reviewer']['review'] = true;
142142
143143 # Define when users get automatically promoted to editors. Set as false to disable.
144 -$wgFlaggedRevsAutopromote = array('days' => 60, 'edits' => 300, 'email' => true);
 144+$wgFlaggedRevsAutopromote = array(
 145+ 'days' => 60,
 146+ 'edits' => 200,
 147+ 'spacing' => 5,
 148+ 'benchmarks' => 5, // keep this small
 149+ 'email' => true,
 150+ 'userpage' => true
 151+);
145152
146153 #
147154 ############ Variables below this point should probably not be modified ############
@@ -1122,6 +1129,7 @@
11231130 $now = time();
11241131 $usercreation = wfTimestamp(TS_UNIX,$user->mRegistration);
11251132 $userage = floor(($now-$usercreation) / 86400);
 1133+ $userpage = $user->getUserPage();
11261134 # Do not give this to current holders or bots
11271135 if( in_array( array('bot','editor'), $groups ) )
11281136 return true;
@@ -1132,32 +1140,56 @@
11331141 return true;
11341142 if( $wgFlaggedRevsAutopromote['email'] && !$wgUser->isAllowed('emailconfirmed') )
11351143 return true;
1136 - # User must have a user page and talk page
1137 - $up = $user->getUserPage();
1138 - $utp = $user->getTalkPage();
1139 - if( !$up->exists() || !$utp->exists() )
 1144+ if( $wgFlaggedRevsAutopromote['userpage'] && !$userpage->exists() )
11401145 return true;
 1146+ if( $user->isBlocked() )
 1147+ return true;
11411148 # Do not re-add status if it was previously removed...
1142 - $db = wfGetDB( DB_MASTER );
1143 - $removed = $dbw->selectField( 'logging', 'log_timestamp',
 1149+ $dbw = wfGetDB( DB_MASTER );
 1150+ $removed = $dbw->selectField( 'logging',
 1151+ 'log_timestamp',
11441152 array( 'log_namespace' => NS_USER,
11451153 'log_title' => $wgUser->getUserPage()->getDBkey(),
11461154 'log_type' => 'rights',
11471155 'log_action' => 'erevoke' ),
11481156 __METHOD__,
1149 - array('FORCE INDEX' => 'page_time') );
1150 -
1151 - if( $removed===false ) {
1152 - $newGroups = $groups ;
1153 - array_push( $newGroups, 'editor');
1154 -
1155 - # Lets NOT spam RC, set $RC to false
1156 - $log = new LogPage( 'rights', false );
1157 - $log->addEntry('rights', $user->getUserPage(), wfMsgHtml('makevalidate-autosum'),
1158 - array( implode(', ',$groups), implode(', ',$newGroups) ) );
1159 -
1160 - $user->addGroup('editor');
 1157+ array('USE INDEX' => 'page_time') );
 1158+ if( $removed )
 1159+ return true;
 1160+ # Check for edit spacing. This can be expensive...so check it last
 1161+ if( $wgFlaggedRevsAutopromote['spacing'] > 0 && $wgFlaggedRevsAutopromote['benchmarks'] > 1 ) {
 1162+ $spacing = $wgFlaggedRevsAutopromote['spacing'] * 24 * 3600; // Convert to hours
 1163+ # Check the oldest edit
 1164+ $dbr = wfGetDB( DB_SLAVE );
 1165+ $lower = $dbr->selectField( 'revision', 'rev_timestamp',
 1166+ array( 'rev_user' => $user->getID() ),
 1167+ array( 'ORDER BY' => 'rev_timestamp ASC',
 1168+ 'USE INDEX' => 'user_timestamp' ) );
 1169+ # Recursevly check for for an edit $spacing days later, until we are done.
 1170+ # The first edit counts, so we have one less scans to do...
 1171+ $benchmarks = 0;
 1172+ $needed = $wgFlaggedRevsAutopromote['benchmarks'] - 1;
 1173+ while( $lower && $benchmarks < $needed ) {
 1174+ $lower += $spacing;
 1175+ $lower = $dbr->selectField( 'revision', 'rev_timestamp',
 1176+ array( "rev_timestamp > {$lower}"),
 1177+ array( 'ORDER BY' => 'rev_timestamp ASC',
 1178+ 'USE INDEX' => 'user_timestamp' ) );
 1179+ if( $lower !==false )
 1180+ $benchmarks++;
 1181+ }
 1182+ if( $benchmarks < $wgFlaggedRevsAutopromote['benchmarks'] )
 1183+ return true;
11611184 }
 1185+ # Add editor rights
 1186+ $newGroups = $groups ;
 1187+ array_push( $newGroups, 'editor');
 1188+ # Lets NOT spam RC, set $RC to false
 1189+ $log = new LogPage( 'rights', false );
 1190+ $log->addEntry('rights', $user->getUserPage(), wfMsgHtml('makevalidate-autosum'),
 1191+ array( implode(', ',$groups), implode(', ',$newGroups) ) );
 1192+ $user->addGroup('editor');
 1193+
11621194 return true;
11631195 }
11641196

Status & tagging log