Index: trunk/extensions/FlaggedRevs/FlaggedRevs.php |
— | — | @@ -140,7 +140,14 @@ |
141 | 141 | $wgGroupPermissions['reviewer']['review'] = true; |
142 | 142 | |
143 | 143 | # 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 | +); |
145 | 152 | |
146 | 153 | # |
147 | 154 | ############ Variables below this point should probably not be modified ############ |
— | — | @@ -1122,6 +1129,7 @@ |
1123 | 1130 | $now = time(); |
1124 | 1131 | $usercreation = wfTimestamp(TS_UNIX,$user->mRegistration); |
1125 | 1132 | $userage = floor(($now-$usercreation) / 86400); |
| 1133 | + $userpage = $user->getUserPage(); |
1126 | 1134 | # Do not give this to current holders or bots |
1127 | 1135 | if( in_array( array('bot','editor'), $groups ) ) |
1128 | 1136 | return true; |
— | — | @@ -1132,32 +1140,56 @@ |
1133 | 1141 | return true; |
1134 | 1142 | if( $wgFlaggedRevsAutopromote['email'] && !$wgUser->isAllowed('emailconfirmed') ) |
1135 | 1143 | 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() ) |
1140 | 1145 | return true; |
| 1146 | + if( $user->isBlocked() ) |
| 1147 | + return true; |
1141 | 1148 | # 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', |
1144 | 1152 | array( 'log_namespace' => NS_USER, |
1145 | 1153 | 'log_title' => $wgUser->getUserPage()->getDBkey(), |
1146 | 1154 | 'log_type' => 'rights', |
1147 | 1155 | 'log_action' => 'erevoke' ), |
1148 | 1156 | __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; |
1161 | 1184 | } |
| 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 | + |
1162 | 1194 | return true; |
1163 | 1195 | } |
1164 | 1196 | |