Index: branches/wmf/1.18wmf1/extensions/UserDailyContribs/api/ApiUserDailyContribs.php |
— | — | @@ -7,25 +7,34 @@ |
8 | 8 | $result = $this->getResult(); |
9 | 9 | |
10 | 10 | $userName = $params['user']; |
11 | | - $days = $params['daysago']; |
| 11 | + $daysago = $params['daysago']; |
| 12 | + $basetimestamp = $params['basetimestamp']; |
12 | 13 | $user = User::newFromName( $userName ); |
13 | 14 | |
14 | 15 | if ( !$user ) { |
15 | 16 | $this->dieUsage( 'Invalid username', 'bad_user' ); |
16 | 17 | } |
17 | 18 | |
18 | | - $now = time(); |
| 19 | + |
| 20 | + // Defaults to 'now' if not given |
| 21 | + $totime = wfTimestamp( TS_UNIX, $basetimestamp ); |
| 22 | + |
| 23 | + $fromtime = $totime - ($daysago * 60 *60 *24); |
| 24 | + |
19 | 25 | $result->addValue( $this->getModuleName() , |
20 | 26 | 'id', $user->getId() ); |
21 | | - // returns date of registration in YYYYMMDDHHMMSS format |
| 27 | + |
| 28 | + // Returns date of registration in YYYYMMDDHHMMSS format |
| 29 | + $result->addValue( $this->getModuleName(), |
| 30 | + 'registration', $user->getRegistration() ? $user->getRegistration() : '0' ); |
| 31 | + |
| 32 | + // Returns number of edits between daysago date and basetimestamp (or today) |
| 33 | + $result->addValue( $this->getModuleName(), |
| 34 | + 'timeFrameEdits', getUserEditCountSince( $fromtime, $user, $totime ) ); |
| 35 | + |
| 36 | + // Returns total number of edits |
22 | 37 | $result->addValue( $this->getModuleName() , |
23 | | - 'registration', !$user->getRegistration() ? '0' : $user->getRegistration() ); |
24 | | - // returns number of edits since daysago param |
25 | | - $result->addValue( $this->getModuleName() , |
26 | | - 'timeFrameEdits', getUserEditCountSince( $now - ($days * 60 *60 *24), $user ) ); |
27 | | - // returns total number of edits |
28 | | - $result->addValue( $this->getModuleName() , |
29 | | - 'totalEdits', ($user->getEditCount() == NULL)?0:$user->getEditCount() ); |
| 38 | + 'totalEdits', $user->getEditCount() == NULL ? 0 : $user->getEditCount() ); |
30 | 39 | } |
31 | 40 | |
32 | 41 | public function getAllowedParams() { |
— | — | @@ -37,6 +46,9 @@ |
38 | 47 | ApiBase::PARAM_TYPE => 'integer', |
39 | 48 | ApiBase::PARAM_MIN => 0, |
40 | 49 | ), |
| 50 | + 'basetimestamp' => array( |
| 51 | + ApiBase::PARAM_TYPE => 'timestamp', |
| 52 | + ), |
41 | 53 | ); |
42 | 54 | } |
43 | 55 | |
— | — | @@ -44,6 +56,10 @@ |
45 | 57 | return array( |
46 | 58 | 'user' => 'Username to query', |
47 | 59 | 'daysago' => 'Number of edits since this many days ago', |
| 60 | + 'basetimestamp' => array( 'Date from which daysago will be calculated (instead of "today").', |
| 61 | + 'Count returned in timeFrameEdits will be editcount between this date and the date', |
| 62 | + '"daysago" from it.' |
| 63 | + ), |
48 | 64 | ); |
49 | 65 | } |
50 | 66 | |
Index: branches/wmf/1.18wmf1/extensions/UserDailyContribs/UserDailyContribs.php |
— | — | @@ -34,25 +34,34 @@ |
35 | 35 | /** |
36 | 36 | * Get the number of revisions a user has made since a given time |
37 | 37 | * |
38 | | - * @param $time beginning timestamp |
39 | | - * @param $user User |
| 38 | + * @param $fromtime: beginning timestamp |
| 39 | + * @param $user User: (optional) User object to get edit count for |
| 40 | + * @param $totime: (optional) ending timestamp |
40 | 41 | * @return number of revsions this user has made |
41 | 42 | */ |
42 | | -function getUserEditCountSince( $time = null, User $user = null ) { |
| 43 | +function getUserEditCountSince( $fromtime = null, User $user = null, $totime = null ) { |
43 | 44 | global $wgUser; |
44 | 45 | |
45 | 46 | // Fallback on current user |
46 | 47 | if ( is_null( $user ) ) { |
47 | 48 | $user = $wgUser; |
48 | 49 | } |
49 | | - // Round time down to a whole day |
50 | | - $time = gmdate( 'Y-m-d', wfTimestamp( TS_UNIX, $time ) ); |
| 50 | + |
| 51 | + // Round times down to a whole day, possibly letting a null value |
| 52 | + // pass to wfTimestamp which will give us today. |
| 53 | + $fromtime = gmdate( 'Y-m-d', wfTimestamp( TS_UNIX, $fromtime ) ); |
| 54 | + $totime = gmdate( 'Y-m-d', wfTimestamp( TS_UNIX, $totime ) ); |
| 55 | + |
51 | 56 | // Query the user contribs table |
52 | 57 | $dbr = wfGetDB( DB_SLAVE ); |
53 | 58 | $edits = $dbr->selectField( |
54 | 59 | 'user_daily_contribs', |
55 | 60 | 'SUM(contribs)', |
56 | | - array( 'user_id' => $user->getId(), 'day >= ' . $dbr->addQuotes( $time ) ), |
| 61 | + array( |
| 62 | + 'user_id' => $user->getId(), |
| 63 | + 'day >= ' . $dbr->addQuotes( $fromtime ), |
| 64 | + 'day <= ' . $dbr->addQuotes( $totime ) |
| 65 | + ), |
57 | 66 | __METHOD__ |
58 | 67 | ); |
59 | 68 | // Return edit count as an integer |
Property changes on: branches/wmf/1.18wmf1/extensions/UserDailyContribs |
___________________________________________________________________ |
Added: svn:mergeinfo |
60 | 69 | Merged /branches/new-installer/phase3/extensions/UserDailyContribs:r43664-66004 |
61 | 70 | Merged /branches/REL1_15/phase3/extensions/UserDailyContribs:r51646 |
62 | 71 | Merged /branches/REL1_18/extensions/UserDailyContribs:r101758,103190 |
63 | 72 | Merged /branches/REL1_17/phase3/extensions/UserDailyContribs:r81445,81448 |
64 | 73 | Merged /trunk/extensions/UserDailyContribs:r99592,99653,100092,100419,100686,100692,100699,103669,104337,104622,104736,105267 |
65 | 74 | Merged /branches/sqlite/extensions/UserDailyContribs:r58211-58321 |
66 | 75 | Merged /trunk/phase3/extensions/UserDailyContribs:r92580,92634,92713,92762,92765,92791,92854,92884,92886-92887,92894,92898,92907,92932,92958,93141,93149,93151,93233-93234,93258,93266,93303,93516-93518,93520,93818-93822,93847,93858,93891,93935-93936,94058,94062,94068,94107,94155,94235,94277,94346,94372,94422,94425,94444,94448,94456,94498,94517,94601,94630,94728,94738,94825,94862,94995-94997,95023,95042,95072-95073,95155,95327,95332,95410,95422,95426,95442,95468,95601,95812,98578,98598,98656 |