Index: trunk/extensions/UsabilityInitiative/UserDailyContribs/UserDailyContribs.sql |
— | — | @@ -3,17 +3,13 @@ |
4 | 4 | -- |
5 | 5 | -- Used in clicktracking to determine how active the user is |
6 | 6 | -- |
7 | | - |
8 | 7 | CREATE TABLE IF NOT EXISTS /*_*/user_daily_contribs ( |
9 | 8 | -- user id |
10 | 9 | user_id integer NOT NULL default 0, |
11 | | - |
12 | 10 | -- day |
13 | 11 | day DATE NOT NULL, |
14 | | - |
15 | 12 | -- contributions on that day by that user |
16 | 13 | contribs integer NOT NULL default 0, |
17 | | - |
18 | 14 | -- a unique entry for a given user_id and day |
19 | 15 | PRIMARY KEY(user_id, day) |
20 | 16 | ) /*$wgDBTableOptions*/; |
\ No newline at end of file |
Index: trunk/extensions/UsabilityInitiative/UserDailyContribs/UserDailyContribs.php |
— | — | @@ -1,44 +1,30 @@ |
2 | 2 | <?php |
3 | 3 | /** |
4 | | - * Usability Initiative User Daily Contributions (for Click Tracking) extension |
5 | | - * |
| 4 | + * User Daily Contributions extension |
| 5 | + * |
| 6 | + * This extension adds a step to saving an article that incriments a counter for a user's activity in a given day. |
| 7 | + * |
6 | 8 | * @file |
7 | 9 | * @ingroup Extensions |
8 | | - * |
9 | | - * This file contains the include file for the User Daily Contributions table in the |
10 | | - * UsabilityInitiative extension of MediaWiki. |
11 | | - * |
12 | | - * Usage: Include the following line in your LocalSettings.php |
13 | | - * require_once( "$IP/extensions/UsabilityInitiative/UserDailyContribs/UserDailyContribs.php" ); |
14 | | - * |
| 10 | + * |
15 | 11 | * @author Nimish Gautam <ngautam@wikimedia.org> |
| 12 | + * @author Trevor Parscal <tparscal@wikimedia.org> |
16 | 13 | * @license GPL v2 or later |
17 | | - * @version 0.1.1 |
| 14 | + * @version 0.2.0 |
18 | 15 | */ |
19 | 16 | |
20 | | -/* Configuration */ |
21 | | - |
22 | | -// Credits |
| 17 | +/* Setup */ |
| 18 | + |
23 | 19 | $wgExtensionCredits['other'][] = array( |
24 | 20 | 'path' => __FILE__, |
25 | 21 | 'name' => 'User Daily Contributions', |
26 | | - 'author' => 'Nimish Gautam', |
27 | | - 'version' => '0.1.1', |
| 22 | + 'author' => array( 'Nimish Gautam', 'Trevor Parscal' ), |
| 23 | + 'version' => '0.2.0', |
28 | 24 | 'url' => 'http://www.mediawiki.org/wiki/Extension:UsabilityInitiative', |
29 | 25 | 'descriptionmsg' => 'userdailycontribs-desc', |
30 | 26 | ); |
31 | | - |
32 | | -// Includes parent extension |
33 | | -require_once( dirname( dirname( __FILE__ ) ) . "/UsabilityInitiative.php" ); |
34 | | - |
35 | | -// Adds Autoload Classes |
36 | | -$dir = dirname( __FILE__ ) . '/'; |
37 | | -$wgAutoloadClasses['UserDailyContribsHooks'] = $dir . 'UserDailyContribs.hooks.php'; |
38 | | - |
39 | | -// Adds Internationalized Messages |
40 | | -$wgExtensionMessagesFiles['UserDailyContribs'] = $dir . 'UserDailyContribs.i18n.php'; |
41 | | - |
42 | | -// Hooked functions |
43 | | -$wgHooks['LoadExtensionSchemaUpdates'][] = 'UserDailyContribsHooks::schema'; |
44 | | -$wgHooks['ArticleSaveComplete'][] = 'UserDailyContribsHooks::storeNewContrib'; |
| 27 | +$wgAutoloadClasses['UserDailyContribsHooks'] = dirname( __FILE__ ) . '/UserDailyContribs.hooks.php'; |
| 28 | +$wgExtensionMessagesFiles['UserDailyContribs'] = dirname( __FILE__ ) . '/UserDailyContribs.i18n.php'; |
| 29 | +$wgHooks['LoadExtensionSchemaUpdates'][] = 'UserDailyContribsHooks::loadExtensionSchemaUpdates'; |
| 30 | +$wgHooks['ArticleSaveComplete'][] = 'UserDailyContribsHooks::articleSaveComplete'; |
45 | 31 | $wgHooks['ParserTestTables'][] = 'UserDailyContribsHooks::parserTestTables'; |
Index: trunk/extensions/UsabilityInitiative/UserDailyContribs/UserDailyContribs.hooks.php |
— | — | @@ -1,7 +1,6 @@ |
2 | 2 | <?php |
3 | | - |
4 | 3 | /** |
5 | | - * Hooks for Usability Initiative UserDailyContribs extension |
| 4 | + * Hooks for UserDailyContribs extension |
6 | 5 | * |
7 | 6 | * @file |
8 | 7 | * @ingroup Extensions |
— | — | @@ -9,19 +8,21 @@ |
10 | 9 | |
11 | 10 | class UserDailyContribsHooks { |
12 | 11 | |
13 | | - public static function schema() { |
| 12 | + /* Static Methods */ |
| 13 | + |
| 14 | + /** |
| 15 | + * LoadExtensionSchemaUpdates hook |
| 16 | + */ |
| 17 | + public static function loadExtensionSchemaUpdates() { |
14 | 18 | global $wgExtNewTables; |
15 | | - |
16 | | - $wgExtNewTables[] = array( |
17 | | - 'user_daily_contribs', |
18 | | - dirname( __FILE__ ) . '/UserDailyContribs.sql' |
19 | | - ); |
20 | | - |
| 19 | + |
| 20 | + $wgExtNewTables[] = array( 'user_daily_contribs', dirname( __FILE__ ) . '/UserDailyContribs.sql' ); |
21 | 21 | return true; |
22 | 22 | } |
23 | 23 | |
24 | 24 | /** |
25 | | - * Hook for making sure parser tests pass |
| 25 | + * ParserTestTables hook |
| 26 | + * |
26 | 27 | * @param $tables |
27 | 28 | * @return unknown_type |
28 | 29 | */ |
— | — | @@ -31,23 +32,30 @@ |
32 | 33 | } |
33 | 34 | |
34 | 35 | /** |
| 36 | + * ArticleSaveComplete hook |
| 37 | + * |
35 | 38 | * Stores a new contribution |
| 39 | + * |
36 | 40 | * @return true |
37 | 41 | */ |
38 | | - public static function storeNewContrib(){ |
| 42 | + public static function articleSaveComplete(){ |
39 | 43 | global $wgUser; |
| 44 | + |
40 | 45 | $today = gmdate( 'Ymd', time() ); |
41 | 46 | $dbw = wfGetDB( DB_MASTER ); |
42 | | - |
43 | | - $dbw->update( 'user_daily_contribs', array( 'contribs=contribs+1' ), |
44 | | - array( 'day' => $today, 'user_id' => $wgUser->getId() ), |
45 | | - __METHOD__ ); |
46 | | - |
47 | | - if($dbw->affectedRows() == 0){ |
48 | | - $dbw->insert("user_daily_contribs", array("user_id" => $wgUser->getId(), "day" => $today, "contribs" => 1), __METHOD__); |
| 47 | + $dbw->update( |
| 48 | + 'user_daily_contribs', |
| 49 | + array( 'contribs=contribs+1' ), |
| 50 | + array( 'day' => $today, 'user_id' => $wgUser->getId() ), |
| 51 | + __METHOD__ |
| 52 | + ); |
| 53 | + if ( $dbw->affectedRows() == 0 ){ |
| 54 | + $dbw->insert( |
| 55 | + 'user_daily_contribs', |
| 56 | + array( 'user_id' => $wgUser->getId(), 'day' => $today, 'contribs' => 1 ), |
| 57 | + __METHOD__ |
| 58 | + ); |
49 | 59 | } |
50 | | - |
51 | 60 | return true; |
52 | 61 | } |
53 | | - |
54 | 62 | } |
\ No newline at end of file |