Index: trunk/extensions/UserDailyContribs/UserDailyContribs.php |
— | — | @@ -28,3 +28,30 @@ |
29 | 29 | $wgHooks['LoadExtensionSchemaUpdates'][] = 'UserDailyContribsHooks::loadExtensionSchemaUpdates'; |
30 | 30 | $wgHooks['ArticleSaveComplete'][] = 'UserDailyContribsHooks::articleSaveComplete'; |
31 | 31 | $wgHooks['ParserTestTables'][] = 'UserDailyContribsHooks::parserTestTables'; |
| 32 | + |
| 33 | +/** |
| 34 | + * Get the number of revisions a user has made since a given time |
| 35 | + * |
| 36 | + * @param $time beginning timestamp |
| 37 | + * @return number of revsions this user has made |
| 38 | + */ |
| 39 | +function getUserEditCountSince( $time = null, User $user = null ) { |
| 40 | + global $wgUser; |
| 41 | + |
| 42 | + // Fallback on current user |
| 43 | + if ( is_null( $user ) ) { |
| 44 | + $user = $wgUser; |
| 45 | + } |
| 46 | + // Round time down to a whole day |
| 47 | + $time = gmdate( 'Y-m-d', wfTimestamp( TS_UNIX, $time ) ); |
| 48 | + // Query the user contribs table |
| 49 | + $dbr = wfGetDB( DB_SLAVE ); |
| 50 | + $edits = $dbr->selectField( |
| 51 | + 'user_daily_contribs', |
| 52 | + 'SUM(contribs)', |
| 53 | + array( 'user_id' => $user->getId(), 'day >= ' . $dbr->addQuotes( $time ) ), |
| 54 | + __METHOD__ |
| 55 | + ); |
| 56 | + // Return edit count as an integer |
| 57 | + return is_null( $edits ) ? 0 : (integer) $edits; |
| 58 | +} |