r73247 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r73246‎ | r73247 | r73248 >
Date:21:26, 17 September 2010
Author:tparscal
Status:ok
Tags:
Comment:
Did a little cleaning, but mostly just removed a totally needless dependency on UsabilityInitiative.php
Modified paths:
  • /trunk/extensions/UsabilityInitiative/PrefStats/PrefStats.hooks.php (modified) (history)
  • /trunk/extensions/UsabilityInitiative/PrefStats/PrefStats.php (modified) (history)

Diff [purge]

Index: trunk/extensions/UsabilityInitiative/PrefStats/PrefStats.php
@@ -1,19 +1,14 @@
22 <?php
33 /**
4 - * Usability Initiative PrefStats extension
 4+ * PrefStats extension
55 *
66 * @file
77 * @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+ *
159 * @author Roan Kattouw <roan.kattouw@gmail.com>
 10+ * @author Trevor Parscal <tparscal.kattouw@gmail.com>
1611 * @license GPL v2 or later
17 - * @version 0.1.1
 12+ * @version 0.2.0
1813 */
1914
2015 /* Configuration */
@@ -36,8 +31,7 @@
3732 // Don't change this unless you know what you're doing
3833 $wgPrefStatsTimeUnit = 60 * 60; // one hour
3934
40 -// Multiples of $wgPrefStatsTimeUnit to offer
41 -// array( messagekey => factor )
 35+// Multiples of $wgPrefStatsTimeUnit to offer -- array( messagekey => factor )
4236 $wgPrefStatsTimeFactors = array(
4337 'prefstats-factor-hour' => 1,
4438 'prefstats-factor-sixhours' => 6,
@@ -51,8 +45,7 @@
5246 // How many bars to strive for in default scaling
5347 $wgPrefStatsDefaultScaleBars = 15;
5448
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
5750 $wgPrefStatsExpensiveCounts = false;
5851
5952 // For how long statistics should be cached
@@ -61,34 +54,19 @@
6255
6356 /* Setup */
6457
65 -// Credits
6658 $wgExtensionCredits['other'][] = array(
6759 'path' => __FILE__,
6860 'name' => 'PrefStats',
69 - 'author' => 'Roan Kattouw',
70 - 'version' => '0.1.1',
 61+ 'author' => array( 'Roan Kattouw', 'Trevor Parscal' ),
 62+ 'version' => '0.2.0',
7163 'url' => 'http://www.mediawiki.org/wiki/Extension:UsabilityInitiative',
7264 'descriptionmsg' => 'prefstats-desc',
7365 );
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';
8468 $wgSpecialPages['PrefStats'] = 'SpecialPrefStats';
8569 $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 @@
22 <?php
33 /**
4 - * Hooks for Usability Initiative PrefStats extension
 4+ * Hooks for PrefStats extension
55 *
66 * @file
77 * @ingroup Extensions
@@ -8,48 +8,69 @@
99
1010 class PrefStatsHooks {
1111
12 - /* Static Functions */
13 - public static function schema() {
 12+ /* Static Methods */
 13+
 14+ /**
 15+ * LoadExtensionSchemaUpdates hook
 16+ */
 17+ public static function loadExtensionSchemaUpdates() {
1418 global $wgExtNewTables;
15 - $wgExtNewTables[] = array( 'prefstats',
16 - dirname( __FILE__ ) . '/PrefStats.sql' );
 19+ $wgExtNewTables[] = array( 'prefstats', dirname( __FILE__ ) . '/PrefStats.sql' );
1720 return true;
1821 }
1922
20 - public static function save( $user, &$options ) {
 23+ /**
 24+ * UserSaveOptions hook
 25+ */
 26+ public static function userSaveOptions( $user, &$options ) {
2127 global $wgPrefStatsEnable, $wgPrefStatsTrackPrefs;
22 - if ( !$wgPrefStatsEnable )
 28+
 29+ if ( !$wgPrefStatsEnable ) {
2330 return;
 31+ }
2432
2533 $dbw = wfGetDb( DB_MASTER );
2634 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(
2939 'ps_user' => $user->getId(),
3040 'ps_pref' => $pref,
3141 '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(
3549 'ps_user' => $user->getId(),
3650 'ps_pref' => $pref,
3751 'ps_value' => $value,
3852 'ps_start' => $dbw->timestamp( wfTimestamp() ),
3953 'ps_end' => null,
4054 '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 ) {
4360 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(
4765 'ps_end' => $dbw->timestamp( wfTimestamp() ),
4866 'ps_duration' => $duration
49 - ), array(
 67+ ),
 68+ array(
5069 'ps_user' => $user->getId(),
5170 'ps_pref' => $pref,
5271 'ps_start' => $dbw->timestamp( $start )
53 - ), __METHOD__ );
 72+ ),
 73+ __METHOD__
 74+ );
5475 }
5576 }
5677 }

Status & tagging log