Index: trunk/extensions/UserDailyContribs/api/ApiUserDailyContribs.php |
— | — | @@ -1,4 +1,4 @@ |
2 | | -<?php |
| 2 | +<?php |
3 | 3 | |
4 | 4 | class ApiUserDailyContribs extends ApiBase { |
5 | 5 | |
— | — | @@ -8,17 +8,18 @@ |
9 | 9 | |
10 | 10 | $userName = $params['user']; |
11 | 11 | $days = $params['daysago']; |
12 | | - $user = User::newFromName($userName); |
| 12 | + $user = User::newFromName( $userName ); |
| 13 | + |
13 | 14 | if ( !$user ) { |
14 | | - $this->dieUsage( 'Specified user does not exist', 'bad_user' ); |
| 15 | + $this->dieUsage( 'Invalid username', 'bad_user' ); |
15 | 16 | } |
16 | | - |
| 17 | + |
17 | 18 | $now = time(); |
18 | 19 | $result->addValue( $this->getModuleName() , |
19 | 20 | 'id', $user->getId() ); |
20 | 21 | // returns date of registration in YYYYMMDDHHMMSS format |
21 | 22 | $result->addValue( $this->getModuleName() , |
22 | | - 'registration', $user->getRegistration() ? '0' : $user->getRegistration() ); |
| 23 | + 'registration', !$user->getRegistration() ? '0' : $user->getRegistration() ); |
23 | 24 | // returns number of edits since daysago param |
24 | 25 | $result->addValue( $this->getModuleName() , |
25 | 26 | 'timeFrameEdits', getUserEditCountSince( $now - ($days * 60 *60 *24), $user ) ); |
— | — | @@ -30,13 +31,12 @@ |
31 | 32 | public function getAllowedParams() { |
32 | 33 | return array( |
33 | 34 | 'user' => array( |
34 | | - ApiBase::PARAM_TYPE => 'user', |
35 | | - ), |
| 35 | + ApiBase::PARAM_TYPE => 'user', |
| 36 | + ), |
36 | 37 | 'daysago' => array( |
37 | 38 | ApiBase::PARAM_TYPE => 'integer', |
38 | 39 | ApiBase::PARAM_MIN => 0, |
39 | | - ), |
40 | | - |
| 40 | + ), |
41 | 41 | ); |
42 | 42 | } |
43 | 43 | |
— | — | @@ -51,6 +51,12 @@ |
52 | 52 | return 'Get the total number of user edits, time of registration, and edits in a given timeframe'; |
53 | 53 | } |
54 | 54 | |
| 55 | + public function getPossibleErrors() { |
| 56 | + return array_merge( parent::getPossibleErrors(), array( |
| 57 | + array( 'code' => 'bad_user', 'info' => 'Invalid username' ) |
| 58 | + ) ); |
| 59 | + } |
| 60 | + |
55 | 61 | protected function getExamples() { |
56 | 62 | return 'api.php?action=userdailycontribs&user=WikiSysop&daysago=5'; |
57 | 63 | } |
— | — | @@ -58,5 +64,5 @@ |
59 | 65 | public function getVersion() { |
60 | 66 | return __CLASS__ . ': $Id$'; |
61 | 67 | } |
62 | | - |
| 68 | + |
63 | 69 | } |
\ No newline at end of file |
Index: trunk/extensions/UserDailyContribs/UserDailyContribs.php |
— | — | @@ -1,12 +1,12 @@ |
2 | 2 | <?php |
3 | 3 | /** |
4 | 4 | * User Daily Contributions extension |
5 | | - * |
| 5 | + * |
6 | 6 | * This extension adds a step to saving an article that incriments a counter for a user's activity in a given day. |
7 | | - * |
| 7 | + * |
8 | 8 | * @file |
9 | 9 | * @ingroup Extensions |
10 | | - * |
| 10 | + * |
11 | 11 | * @author Nimish Gautam <ngautam@wikimedia.org> |
12 | 12 | * @author Trevor Parscal <tparscal@wikimedia.org> |
13 | 13 | * @license GPL v2 or later |
— | — | @@ -35,11 +35,12 @@ |
36 | 36 | * Get the number of revisions a user has made since a given time |
37 | 37 | * |
38 | 38 | * @param $time beginning timestamp |
| 39 | + * @param $user User |
39 | 40 | * @return number of revsions this user has made |
40 | 41 | */ |
41 | 42 | function getUserEditCountSince( $time = null, User $user = null ) { |
42 | 43 | global $wgUser; |
43 | | - |
| 44 | + |
44 | 45 | // Fallback on current user |
45 | 46 | if ( is_null( $user ) ) { |
46 | 47 | $user = $wgUser; |