Index: trunk/extensions/UsabilityInitiative/PrefStats/PrefStats.php |
— | — | @@ -1,19 +1,14 @@ |
2 | 2 | <?php |
3 | 3 | /** |
4 | | - * Usability Initiative PrefStats extension |
| 4 | + * PrefStats extension |
5 | 5 | * |
6 | 6 | * @file |
7 | 7 | * @ingroup Extensions |
8 | | - * |
9 | | - * This file contains the include file for the EditWarning portion of the |
10 | | - * UsabilityInitiative extension of MediaWiki. |
11 | | - * |
12 | | - * Usage: Include the following line in your LocalSettings.php |
13 | | - * require_once( "$IP/extensions/UsabilityInitiative/PrefStats/PrefStats.php" ); |
14 | | - * |
| 8 | + * |
15 | 9 | * @author Roan Kattouw <roan.kattouw@gmail.com> |
| 10 | + * @author Trevor Parscal <tparscal.kattouw@gmail.com> |
16 | 11 | * @license GPL v2 or later |
17 | | - * @version 0.1.1 |
| 12 | + * @version 0.2.0 |
18 | 13 | */ |
19 | 14 | |
20 | 15 | /* Configuration */ |
— | — | @@ -36,8 +31,7 @@ |
37 | 32 | // Don't change this unless you know what you're doing |
38 | 33 | $wgPrefStatsTimeUnit = 60 * 60; // one hour |
39 | 34 | |
40 | | -// Multiples of $wgPrefStatsTimeUnit to offer |
41 | | -// array( messagekey => factor ) |
| 35 | +// Multiples of $wgPrefStatsTimeUnit to offer -- array( messagekey => factor ) |
42 | 36 | $wgPrefStatsTimeFactors = array( |
43 | 37 | 'prefstats-factor-hour' => 1, |
44 | 38 | 'prefstats-factor-sixhours' => 6, |
— | — | @@ -51,8 +45,7 @@ |
52 | 46 | // How many bars to strive for in default scaling |
53 | 47 | $wgPrefStatsDefaultScaleBars = 15; |
54 | 48 | |
55 | | -// Whether to run possibly expensive COUNT(*) queries on the user_properties |
56 | | -// table |
| 49 | +// Whether to run possibly expensive COUNT(*) queries on the user_properties table |
57 | 50 | $wgPrefStatsExpensiveCounts = false; |
58 | 51 | |
59 | 52 | // For how long statistics should be cached |
— | — | @@ -61,34 +54,19 @@ |
62 | 55 | |
63 | 56 | /* Setup */ |
64 | 57 | |
65 | | -// Credits |
66 | 58 | $wgExtensionCredits['other'][] = array( |
67 | 59 | 'path' => __FILE__, |
68 | 60 | 'name' => 'PrefStats', |
69 | | - 'author' => 'Roan Kattouw', |
70 | | - 'version' => '0.1.1', |
| 61 | + 'author' => array( 'Roan Kattouw', 'Trevor Parscal' ), |
| 62 | + 'version' => '0.2.0', |
71 | 63 | 'url' => 'http://www.mediawiki.org/wiki/Extension:UsabilityInitiative', |
72 | 64 | 'descriptionmsg' => 'prefstats-desc', |
73 | 65 | ); |
74 | | - |
75 | | -// Includes parent extension |
76 | | -require_once( dirname( dirname( __FILE__ ) ) . "/UsabilityInitiative.php" ); |
77 | | - |
78 | | -// Adds Autoload Classes |
79 | | -$wgAutoloadClasses['PrefStatsHooks'] = |
80 | | - dirname( __FILE__ ) . '/PrefStats.hooks.php'; |
81 | | -$wgAutoloadClasses['SpecialPrefStats'] = |
82 | | - dirname( __FILE__ ) . '/SpecialPrefStats.php'; |
83 | | - |
| 66 | +$wgAutoloadClasses['PrefStatsHooks'] = dirname( __FILE__ ) . '/PrefStats.hooks.php'; |
| 67 | +$wgAutoloadClasses['SpecialPrefStats'] = dirname( __FILE__ ) . '/SpecialPrefStats.php'; |
84 | 68 | $wgSpecialPages['PrefStats'] = 'SpecialPrefStats'; |
85 | 69 | $wgSpecialPageGroups['PrefStats'] = 'wiki'; |
86 | | - |
87 | | -// Adds Internationalized Messages |
88 | | -$wgExtensionMessagesFiles['PrefStats'] = |
89 | | - dirname( __FILE__ ) . '/PrefStats.i18n.php'; |
90 | | -$wgExtensionAliasesFiles['PrefStats'] = |
91 | | - dirname( __FILE__ ) . '/PrefStats.alias.php'; |
92 | | - |
93 | | -// Registers Hooks |
94 | | -$wgHooks['LoadExtensionSchemaUpdates'][] = 'PrefStatsHooks::schema'; |
95 | | -$wgHooks['UserSaveOptions'][] = 'PrefStatsHooks::save'; |
| 70 | +$wgExtensionMessagesFiles['PrefStats'] = dirname( __FILE__ ) . '/PrefStats.i18n.php'; |
| 71 | +$wgExtensionAliasesFiles['PrefStats'] = dirname( __FILE__ ) . '/PrefStats.alias.php'; |
| 72 | +$wgHooks['LoadExtensionSchemaUpdates'][] = 'PrefStatsHooks::loadExtensionSchemaUpdates'; |
| 73 | +$wgHooks['UserSaveOptions'][] = 'PrefStatsHooks::userSaveOptions'; |
Index: trunk/extensions/UsabilityInitiative/PrefStats/PrefStats.hooks.php |
— | — | @@ -1,6 +1,6 @@ |
2 | 2 | <?php |
3 | 3 | /** |
4 | | - * Hooks for Usability Initiative PrefStats extension |
| 4 | + * Hooks for PrefStats extension |
5 | 5 | * |
6 | 6 | * @file |
7 | 7 | * @ingroup Extensions |
— | — | @@ -8,48 +8,69 @@ |
9 | 9 | |
10 | 10 | class PrefStatsHooks { |
11 | 11 | |
12 | | - /* Static Functions */ |
13 | | - public static function schema() { |
| 12 | + /* Static Methods */ |
| 13 | + |
| 14 | + /** |
| 15 | + * LoadExtensionSchemaUpdates hook |
| 16 | + */ |
| 17 | + public static function loadExtensionSchemaUpdates() { |
14 | 18 | global $wgExtNewTables; |
15 | | - $wgExtNewTables[] = array( 'prefstats', |
16 | | - dirname( __FILE__ ) . '/PrefStats.sql' ); |
| 19 | + $wgExtNewTables[] = array( 'prefstats', dirname( __FILE__ ) . '/PrefStats.sql' ); |
17 | 20 | return true; |
18 | 21 | } |
19 | 22 | |
20 | | - public static function save( $user, &$options ) { |
| 23 | + /** |
| 24 | + * UserSaveOptions hook |
| 25 | + */ |
| 26 | + public static function userSaveOptions( $user, &$options ) { |
21 | 27 | global $wgPrefStatsEnable, $wgPrefStatsTrackPrefs; |
22 | | - if ( !$wgPrefStatsEnable ) |
| 28 | + |
| 29 | + if ( !$wgPrefStatsEnable ) { |
23 | 30 | return; |
| 31 | + } |
24 | 32 | |
25 | 33 | $dbw = wfGetDb( DB_MASTER ); |
26 | 34 | foreach ( $wgPrefStatsTrackPrefs as $pref => $value ) { |
27 | | - $start = $dbw->selectField( 'prefstats', |
28 | | - 'ps_start', array( |
| 35 | + $start = $dbw->selectField( |
| 36 | + 'prefstats', |
| 37 | + 'ps_start', |
| 38 | + array( |
29 | 39 | 'ps_user' => $user->getId(), |
30 | 40 | 'ps_pref' => $pref, |
31 | 41 | 'ps_end IS NULL' |
32 | | - ), __METHOD__ ); |
33 | | - if ( isset( $options[$pref] ) && $options[$pref] == $value && !$start ) |
34 | | - $dbw->insert( 'prefstats', array( |
| 42 | + ), |
| 43 | + __METHOD__ |
| 44 | + ); |
| 45 | + if ( isset( $options[$pref] ) && $options[$pref] == $value && !$start ) { |
| 46 | + $dbw->insert( |
| 47 | + 'prefstats', |
| 48 | + array( |
35 | 49 | 'ps_user' => $user->getId(), |
36 | 50 | 'ps_pref' => $pref, |
37 | 51 | 'ps_value' => $value, |
38 | 52 | 'ps_start' => $dbw->timestamp( wfTimestamp() ), |
39 | 53 | 'ps_end' => null, |
40 | 54 | 'ps_duration' => null |
41 | | - ), __METHOD__, array( 'IGNORE' ) ); |
42 | | - else if ( ( !isset( $options[$pref] ) || $options[$pref] != $value ) && $start ) { |
| 55 | + ), |
| 56 | + __METHOD__, |
| 57 | + array( 'IGNORE' ) |
| 58 | + ); |
| 59 | + } else if ( ( !isset( $options[$pref] ) || $options[$pref] != $value ) && $start ) { |
43 | 60 | if ( $start ) { |
44 | | - $duration = wfTimestamp( TS_UNIX ) - |
45 | | - wfTimestamp( TS_UNIX, $start ); |
46 | | - $dbw->update( 'prefstats', array( |
| 61 | + $duration = wfTimestamp( TS_UNIX ) - wfTimestamp( TS_UNIX, $start ); |
| 62 | + $dbw->update( |
| 63 | + 'prefstats', |
| 64 | + array( |
47 | 65 | 'ps_end' => $dbw->timestamp( wfTimestamp() ), |
48 | 66 | 'ps_duration' => $duration |
49 | | - ), array( |
| 67 | + ), |
| 68 | + array( |
50 | 69 | 'ps_user' => $user->getId(), |
51 | 70 | 'ps_pref' => $pref, |
52 | 71 | 'ps_start' => $dbw->timestamp( $start ) |
53 | | - ), __METHOD__ ); |
| 72 | + ), |
| 73 | + __METHOD__ |
| 74 | + ); |
54 | 75 | } |
55 | 76 | } |
56 | 77 | } |