http://www.mediawiki.org/wiki/Special:Code/MediaWiki/73247
Revision: 73247
Author: tparscal
Date: 2010-09-17 21:26:52 +0000 (Fri, 17 Sep 2010)
Log Message:
-----------
Did a little cleaning, but mostly just removed a totally needless dependency on
UsabilityInitiative.php
Modified Paths:
--------------
trunk/extensions/UsabilityInitiative/PrefStats/PrefStats.hooks.php
trunk/extensions/UsabilityInitiative/PrefStats/PrefStats.php
Modified: trunk/extensions/UsabilityInitiative/PrefStats/PrefStats.hooks.php
===================================================================
--- trunk/extensions/UsabilityInitiative/PrefStats/PrefStats.hooks.php
2010-09-17 21:15:31 UTC (rev 73246)
+++ trunk/extensions/UsabilityInitiative/PrefStats/PrefStats.hooks.php
2010-09-17 21:26:52 UTC (rev 73247)
@@ -1,6 +1,6 @@
<?php
/**
- * Hooks for Usability Initiative PrefStats extension
+ * Hooks for PrefStats extension
*
* @file
* @ingroup Extensions
@@ -8,48 +8,69 @@
class PrefStatsHooks {
- /* Static Functions */
- public static function schema() {
+ /* Static Methods */
+
+ /**
+ * LoadExtensionSchemaUpdates hook
+ */
+ public static function loadExtensionSchemaUpdates() {
global $wgExtNewTables;
- $wgExtNewTables[] = array( 'prefstats',
- dirname( __FILE__ ) . '/PrefStats.sql' );
+ $wgExtNewTables[] = array( 'prefstats', dirname( __FILE__ ) .
'/PrefStats.sql' );
return true;
}
- public static function save( $user, &$options ) {
+ /**
+ * UserSaveOptions hook
+ */
+ public static function userSaveOptions( $user, &$options ) {
global $wgPrefStatsEnable, $wgPrefStatsTrackPrefs;
- if ( !$wgPrefStatsEnable )
+
+ if ( !$wgPrefStatsEnable ) {
return;
+ }
$dbw = wfGetDb( DB_MASTER );
foreach ( $wgPrefStatsTrackPrefs as $pref => $value ) {
- $start = $dbw->selectField( 'prefstats',
- 'ps_start', array(
+ $start = $dbw->selectField(
+ 'prefstats',
+ 'ps_start',
+ array(
'ps_user' => $user->getId(),
'ps_pref' => $pref,
'ps_end IS NULL'
- ), __METHOD__ );
- if ( isset( $options[$pref] ) && $options[$pref] ==
$value && !$start )
- $dbw->insert( 'prefstats', array(
+ ),
+ __METHOD__
+ );
+ if ( isset( $options[$pref] ) && $options[$pref] ==
$value && !$start ) {
+ $dbw->insert(
+ 'prefstats',
+ array(
'ps_user' => $user->getId(),
'ps_pref' => $pref,
'ps_value' => $value,
'ps_start' => $dbw->timestamp(
wfTimestamp() ),
'ps_end' => null,
'ps_duration' => null
- ), __METHOD__, array( 'IGNORE' ) );
- else if ( ( !isset( $options[$pref] ) ||
$options[$pref] != $value ) && $start ) {
+ ),
+ __METHOD__,
+ array( 'IGNORE' )
+ );
+ } else if ( ( !isset( $options[$pref] ) ||
$options[$pref] != $value ) && $start ) {
if ( $start ) {
- $duration = wfTimestamp( TS_UNIX ) -
- wfTimestamp( TS_UNIX, $start );
- $dbw->update( 'prefstats', array(
+ $duration = wfTimestamp( TS_UNIX ) -
wfTimestamp( TS_UNIX, $start );
+ $dbw->update(
+ 'prefstats',
+ array(
'ps_end' =>
$dbw->timestamp( wfTimestamp() ),
'ps_duration' =>
$duration
- ), array(
+ ),
+ array(
'ps_user' =>
$user->getId(),
'ps_pref' => $pref,
'ps_start' =>
$dbw->timestamp( $start )
- ), __METHOD__ );
+ ),
+ __METHOD__
+ );
}
}
}
Modified: trunk/extensions/UsabilityInitiative/PrefStats/PrefStats.php
===================================================================
--- trunk/extensions/UsabilityInitiative/PrefStats/PrefStats.php
2010-09-17 21:15:31 UTC (rev 73246)
+++ trunk/extensions/UsabilityInitiative/PrefStats/PrefStats.php
2010-09-17 21:26:52 UTC (rev 73247)
@@ -1,19 +1,14 @@
<?php
/**
- * Usability Initiative PrefStats extension
+ * PrefStats extension
*
* @file
* @ingroup Extensions
- *
- * This file contains the include file for the EditWarning portion of the
- * UsabilityInitiative extension of MediaWiki.
- *
- * Usage: Include the following line in your LocalSettings.php
- * require_once( "$IP/extensions/UsabilityInitiative/PrefStats/PrefStats.php"
);
- *
+ *
* @author Roan Kattouw <[email protected]>
+ * @author Trevor Parscal <[email protected]>
* @license GPL v2 or later
- * @version 0.1.1
+ * @version 0.2.0
*/
/* Configuration */
@@ -36,8 +31,7 @@
// Don't change this unless you know what you're doing
$wgPrefStatsTimeUnit = 60 * 60; // one hour
-// Multiples of $wgPrefStatsTimeUnit to offer
-// array( messagekey => factor )
+// Multiples of $wgPrefStatsTimeUnit to offer -- array( messagekey => factor )
$wgPrefStatsTimeFactors = array(
'prefstats-factor-hour' => 1,
'prefstats-factor-sixhours' => 6,
@@ -51,8 +45,7 @@
// How many bars to strive for in default scaling
$wgPrefStatsDefaultScaleBars = 15;
-// Whether to run possibly expensive COUNT(*) queries on the user_properties
-// table
+// Whether to run possibly expensive COUNT(*) queries on the user_properties
table
$wgPrefStatsExpensiveCounts = false;
// For how long statistics should be cached
@@ -61,34 +54,19 @@
/* Setup */
-// Credits
$wgExtensionCredits['other'][] = array(
'path' => __FILE__,
'name' => 'PrefStats',
- 'author' => 'Roan Kattouw',
- 'version' => '0.1.1',
+ 'author' => array( 'Roan Kattouw', 'Trevor Parscal' ),
+ 'version' => '0.2.0',
'url' => 'http://www.mediawiki.org/wiki/Extension:UsabilityInitiative',
'descriptionmsg' => 'prefstats-desc',
);
-
-// Includes parent extension
-require_once( dirname( dirname( __FILE__ ) ) . "/UsabilityInitiative.php" );
-
-// Adds Autoload Classes
-$wgAutoloadClasses['PrefStatsHooks'] =
- dirname( __FILE__ ) . '/PrefStats.hooks.php';
-$wgAutoloadClasses['SpecialPrefStats'] =
- dirname( __FILE__ ) . '/SpecialPrefStats.php';
-
+$wgAutoloadClasses['PrefStatsHooks'] = dirname( __FILE__ ) .
'/PrefStats.hooks.php';
+$wgAutoloadClasses['SpecialPrefStats'] = dirname( __FILE__ ) .
'/SpecialPrefStats.php';
$wgSpecialPages['PrefStats'] = 'SpecialPrefStats';
$wgSpecialPageGroups['PrefStats'] = 'wiki';
-
-// Adds Internationalized Messages
-$wgExtensionMessagesFiles['PrefStats'] =
- dirname( __FILE__ ) . '/PrefStats.i18n.php';
-$wgExtensionAliasesFiles['PrefStats'] =
- dirname( __FILE__ ) . '/PrefStats.alias.php';
-
-// Registers Hooks
-$wgHooks['LoadExtensionSchemaUpdates'][] = 'PrefStatsHooks::schema';
-$wgHooks['UserSaveOptions'][] = 'PrefStatsHooks::save';
+$wgExtensionMessagesFiles['PrefStats'] = dirname( __FILE__ ) .
'/PrefStats.i18n.php';
+$wgExtensionAliasesFiles['PrefStats'] = dirname( __FILE__ ) .
'/PrefStats.alias.php';
+$wgHooks['LoadExtensionSchemaUpdates'][] =
'PrefStatsHooks::loadExtensionSchemaUpdates';
+$wgHooks['UserSaveOptions'][] = 'PrefStatsHooks::userSaveOptions';
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs