r73184 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r73183‎ | r73184 | r73185 >
Date:23:52, 16 September 2010
Author:tparscal
Status:ok (Comments)
Tags:
Comment:
Removed unnessecary dependency on UsabilityInitiative.php. Refactored a bit, mostly just naming things nicer and adding comments.
Modified paths:
  • /trunk/extensions/UsabilityInitiative/UserDailyContribs/UserDailyContribs.hooks.php (modified) (history)
  • /trunk/extensions/UsabilityInitiative/UserDailyContribs/UserDailyContribs.php (modified) (history)
  • /trunk/extensions/UsabilityInitiative/UserDailyContribs/UserDailyContribs.sql (modified) (history)

Diff [purge]

Index: trunk/extensions/UsabilityInitiative/UserDailyContribs/UserDailyContribs.sql
@@ -3,17 +3,13 @@
44 --
55 -- Used in clicktracking to determine how active the user is
66 --
7 -
87 CREATE TABLE IF NOT EXISTS /*_*/user_daily_contribs (
98 -- user id
109 user_id integer NOT NULL default 0,
11 -
1210 -- day
1311 day DATE NOT NULL,
14 -
1512 -- contributions on that day by that user
1613 contribs integer NOT NULL default 0,
17 -
1814 -- a unique entry for a given user_id and day
1915 PRIMARY KEY(user_id, day)
2016 ) /*$wgDBTableOptions*/;
\ No newline at end of file
Index: trunk/extensions/UsabilityInitiative/UserDailyContribs/UserDailyContribs.php
@@ -1,44 +1,30 @@
22 <?php
33 /**
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+ *
68 * @file
79 * @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+ *
1511 * @author Nimish Gautam <ngautam@wikimedia.org>
 12+ * @author Trevor Parscal <tparscal@wikimedia.org>
1613 * @license GPL v2 or later
17 - * @version 0.1.1
 14+ * @version 0.2.0
1815 */
1916
20 -/* Configuration */
21 -
22 -// Credits
 17+/* Setup */
 18+
2319 $wgExtensionCredits['other'][] = array(
2420 'path' => __FILE__,
2521 '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',
2824 'url' => 'http://www.mediawiki.org/wiki/Extension:UsabilityInitiative',
2925 'descriptionmsg' => 'userdailycontribs-desc',
3026 );
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';
4531 $wgHooks['ParserTestTables'][] = 'UserDailyContribsHooks::parserTestTables';
Index: trunk/extensions/UsabilityInitiative/UserDailyContribs/UserDailyContribs.hooks.php
@@ -1,7 +1,6 @@
22 <?php
3 -
43 /**
5 - * Hooks for Usability Initiative UserDailyContribs extension
 4+ * Hooks for UserDailyContribs extension
65 *
76 * @file
87 * @ingroup Extensions
@@ -9,19 +8,21 @@
109
1110 class UserDailyContribsHooks {
1211
13 - public static function schema() {
 12+ /* Static Methods */
 13+
 14+ /**
 15+ * LoadExtensionSchemaUpdates hook
 16+ */
 17+ public static function loadExtensionSchemaUpdates() {
1418 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' );
2121 return true;
2222 }
2323
2424 /**
25 - * Hook for making sure parser tests pass
 25+ * ParserTestTables hook
 26+ *
2627 * @param $tables
2728 * @return unknown_type
2829 */
@@ -31,23 +32,30 @@
3233 }
3334
3435 /**
 36+ * ArticleSaveComplete hook
 37+ *
3538 * Stores a new contribution
 39+ *
3640 * @return true
3741 */
38 - public static function storeNewContrib(){
 42+ public static function articleSaveComplete(){
3943 global $wgUser;
 44+
4045 $today = gmdate( 'Ymd', time() );
4146 $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+ );
4959 }
50 -
5160 return true;
5261 }
53 -
5462 }
\ No newline at end of file

Follow-up revisions

RevisionCommit summaryAuthorDate
r74093Fixed indentation. (improves on r73184)tparscal19:34, 1 October 2010

Comments

#Comment by Catrope (talk | contribs)   18:24, 1 October 2010
+		$dbw->update(
+			'user_daily_contribs',
+			array( 'contribs=contribs+1' ), 
+    		array( 'day' => $today, 'user_id' => $wgUser->getId() ),
+  			__METHOD__
+  		);

The indentation looks wrong here.

#Comment by Trevor Parscal (WMF) (talk | contribs)   19:35, 1 October 2010

Whitespace is some sneeky stuff! Fixed in r74093.

Status & tagging log