Index: trunk/extensions/UsabilityInitiative/PrefStats/PrefStats.i18n.php |
— | — | @@ -0,0 +1,17 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * Internationalisation for Usability Initiative EditWarning extension |
| 5 | + * |
| 6 | + * @file |
| 7 | + * @ingroup Extensions |
| 8 | + */ |
| 9 | + |
| 10 | +$messages = array(); |
| 11 | + |
| 12 | +/** English |
| 13 | + * @author Roan Kattouw |
| 14 | + */ |
| 15 | +$messages['en'] = array( |
| 16 | + 'prefstats' => 'Preference statistics', |
| 17 | + 'prefstats-desc' => 'Track statistics about how many users have certain preferences enabled', |
| 18 | +); |
Property changes on: trunk/extensions/UsabilityInitiative/PrefStats/PrefStats.i18n.php |
___________________________________________________________________ |
Name: svn:eol-style |
1 | 19 | + native |
Index: trunk/extensions/UsabilityInitiative/PrefStats/PrefStats.php |
— | — | @@ -0,0 +1,50 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * Usability Initiative PrefStats extension |
| 5 | + * |
| 6 | + * @file |
| 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: This file is included automatically by ../UsabilityInitiative.php |
| 13 | + * |
| 14 | + * @author Roan Kattouw <roan.kattouw@gmail.com> |
| 15 | + * @license GPL v2 or later |
| 16 | + * @version 0.1.1 |
| 17 | + */ |
| 18 | + |
| 19 | +/* Configuration */ |
| 20 | + |
| 21 | +//.Set to false to disable tracking |
| 22 | +$wgPrefStatsEnable = true; |
| 23 | + |
| 24 | +// array('prefname' => 'value') |
| 25 | +// value can't be the default value |
| 26 | +// Tracking multiple values of the same preference is not possible |
| 27 | +$wgPrefStatsTrackPrefs = array(); |
| 28 | + |
| 29 | +/* Setup */ |
| 30 | + |
| 31 | +// Credits |
| 32 | +$wgExtensionCredits['other'][] = array( |
| 33 | + 'path' => __FILE__, |
| 34 | + 'name' => 'PrefStats', |
| 35 | + 'author' => 'Roan Kattouw', |
| 36 | + 'version' => '0.1.1', |
| 37 | + 'url' => 'http://www.mediawiki.org/wiki/Extension:UsabilityInitiative', |
| 38 | + 'descriptionmsg' => 'prefstats-desc', |
| 39 | +); |
| 40 | + |
| 41 | +// Adds Autoload Classes |
| 42 | +$wgAutoloadClasses['PrefStatsHooks'] = |
| 43 | + dirname( __FILE__ ) . '/PrefStats.hooks.php'; |
| 44 | + |
| 45 | +// Adds Internationalized Messages |
| 46 | +$wgExtensionMessagesFiles['PrefStats'] = |
| 47 | + dirname( __FILE__ ) . '/PrefStats.i18n.php'; |
| 48 | + |
| 49 | +// Registers Hooks |
| 50 | +$wgHooks['LoadExtensionSchemaUpdates'][] = 'PrefStatsHooks::schema'; |
| 51 | +$wgHooks['UserSaveOptions'][] = 'PrefStatsHooks::save'; |
Property changes on: trunk/extensions/UsabilityInitiative/PrefStats/PrefStats.php |
___________________________________________________________________ |
Name: svn:eol-style |
1 | 52 | + native |
Index: trunk/extensions/UsabilityInitiative/PrefStats/PrefStats.hooks.php |
— | — | @@ -0,0 +1,54 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * Hooks for Usability Initiative PrefStats extension |
| 5 | + * |
| 6 | + * @file |
| 7 | + * @ingroup Extensions |
| 8 | + */ |
| 9 | + |
| 10 | +class PrefStatsHooks { |
| 11 | + |
| 12 | + /* Static Functions */ |
| 13 | + public static function schema() { |
| 14 | + global $wgExtNewTables; |
| 15 | + $wgExtNewTables[] = array( 'prefstats', |
| 16 | + dirname( __FILE__ ) . '/PrefStats.sql' ); |
| 17 | + } |
| 18 | + |
| 19 | + public static function save($user, &$options) { |
| 20 | + global $wgPrefStatsEnable, $wgPrefStatsTrackPrefs; |
| 21 | + if( !$wgPrefStatsEnable ) |
| 22 | + return; |
| 23 | + |
| 24 | + $dbw = wfGetDb( DB_MASTER ); |
| 25 | + foreach( $wgPrefStatsTrackPrefs as $pref => $value ) { |
| 26 | + if( isset( $options[$pref] ) && $options[$pref] == $value ) |
| 27 | + // FIXME: if the user disables and re-enables, |
| 28 | + // we're not tracking that |
| 29 | + $dbw->insert( 'prefstats', array( |
| 30 | + 'ps_user' => $user->getId(), |
| 31 | + 'ps_pref' => $pref, |
| 32 | + 'ps_value' => $value, |
| 33 | + 'ps_start' => $dbw->timestamp( wfTimestamp() ), |
| 34 | + 'ps_end' => null, |
| 35 | + 'ps_duration' => -1 //hack |
| 36 | + ), __METHOD__, array( 'IGNORE' ) ); |
| 37 | + else { |
| 38 | + $start = $dbw->selectField( 'prefstats', |
| 39 | + 'ps_start', array( |
| 40 | + 'ps_user' => $user->getId(), |
| 41 | + 'ps_pref' => $pref |
| 42 | + ), __METHOD__ ); |
| 43 | + if( $start ) { |
| 44 | + $duration = wfTimestamp( TS_UNIX ) - |
| 45 | + wfTimestamp( TS_UNIX, $start ); |
| 46 | + $dbw->update( 'prefstats', array( |
| 47 | + 'ps_end' => $dbw->timestamp( wfTimestamp() ), |
| 48 | + 'ps_duration' => $dbw->timestamp( $duration ) |
| 49 | + ), __METHOD__ ); |
| 50 | + } |
| 51 | + } |
| 52 | + } |
| 53 | + } |
| 54 | + |
| 55 | +} |
Property changes on: trunk/extensions/UsabilityInitiative/PrefStats/PrefStats.hooks.php |
___________________________________________________________________ |
Name: svn:eol-style |
1 | 56 | + native |
Index: trunk/extensions/UsabilityInitiative/PrefStats/PrefStats.sql |
— | — | @@ -0,0 +1,15 @@ |
| 2 | +-- |
| 3 | +-- Schema for PrefStats |
| 4 | +-- |
| 5 | + |
| 6 | +CREATE TABLE IF NOT EXISTS prefstats ( |
| 7 | + ps_user int NOT NULL, |
| 8 | + ps_pref varbinary(32) NOT NULL, |
| 9 | + ps_value blob NOT NULL, |
| 10 | + ps_start binary(14) NOT NULL, |
| 11 | + ps_end binary(14) NULL, |
| 12 | + ps_duration unsigned int NOT NULL, |
| 13 | +); |
| 14 | + |
| 15 | +CREATE UNIQUE INDEX ps_user_pref ON prefstats (ps_user, ps_pref); |
| 16 | +CREATE INDEX ps_duration_start ON prefstats (ps_duration, ps_start); |
Property changes on: trunk/extensions/UsabilityInitiative/PrefStats/PrefStats.sql |
___________________________________________________________________ |
Name: svn:eol-style |
1 | 17 | + native |
Index: trunk/extensions/UsabilityInitiative/PrefStats/getstats.sql |
— | — | @@ -0,0 +1,42 @@ |
| 2 | +-- |
| 3 | +-- Grabs current data from the user_properties table |
| 4 | +-- and processes it into the prefstats table |
| 5 | +-- |
| 6 | +-- Meant to be run by a cron job on the toolserver, |
| 7 | +-- for if tracking changes directly isn't gonna fly |
| 8 | + |
| 9 | +-- VECTOR |
| 10 | + |
| 11 | +-- Update existing users |
| 12 | +UPDATE prefstats |
| 13 | +SET ps_end = IF(ISNULL( |
| 14 | + (SELECT up_user |
| 15 | + FROM enwiki_p.user_properties |
| 16 | + WHERE up_user=ps_user AND up_property='skin' AND up_value='vector' |
| 17 | + )), NOW(), NULL), |
| 18 | +ps_duration = TIMESTAMPDIFF(DAY, NOW(), ps_start) |
| 19 | +WHERE ps_pref='vector' AND ps_end IS NULL; |
| 20 | + |
| 21 | +-- Insert new users |
| 22 | +INSERT IGNORE INTO prefstats (ps_user, ps_pref, ps_start, ps_end, ps_duration) |
| 23 | +SELECT up_user, up_value, NOW(), NULL, 0 |
| 24 | +FROM enwiki_p.user_properties |
| 25 | +WHERE up_property='skin' AND up_value='vector'; |
| 26 | + |
| 27 | +-- TOOLBAR |
| 28 | + |
| 29 | +-- Update existing users |
| 30 | +UPDATE prefstats |
| 31 | +SET ps_end = IF(ISNULL( |
| 32 | + (SELECT up_user |
| 33 | + FROM enwiki_p.user_properties |
| 34 | + WHERE up_user=ps_user AND up_property='usebetatoolbar' AND up_value='1' |
| 35 | + )), NOW(), NULL), |
| 36 | +ps_duration = TIMESTAMPDIFF(DAY, NOW(), ps_start) |
| 37 | +WHERE ps_pref='vector' AND ps_end IS NULL; |
| 38 | + |
| 39 | +-- Insert new users |
| 40 | +INSERT IGNORE INTO prefstats (ps_user, ps_pref, ps_start, ps_end, ps_duration) |
| 41 | +SELECT up_user, up_value, NOW(), NULL, 0 |
| 42 | +FROM enwiki_p.user_properties |
| 43 | +WHERE up_property='usebetatoolbar' AND up_value='1'; |
Property changes on: trunk/extensions/UsabilityInitiative/PrefStats/getstats.sql |
___________________________________________________________________ |
Name: svn:eol-style |
1 | 44 | + native |
Name: svn:executable |
2 | 45 | + * |