|
From: <de...@de...> - 2011-04-23 10:15:26
|
Author: PeterThoeny Date: 2011-04-23 05:15:19 -0500 (Sat, 23 Apr 2011) New Revision: 21076 Trac url: http://develop.twiki.org/trac/changeset/21076 Modified: twiki/trunk/UsageStatisticsPlugin/data/TWiki/UsageStatisticsPlugin.txt twiki/trunk/UsageStatisticsPlugin/lib/TWiki/Plugins/UsageStatisticsPlugin.pm twiki/trunk/UsageStatisticsPlugin/lib/TWiki/Plugins/UsageStatisticsPlugin/Core.pm Log: Item6686: Initial version of UsageStatisticsPlugin - restrict user statistics to administrators only Modified: twiki/trunk/UsageStatisticsPlugin/data/TWiki/UsageStatisticsPlugin.txt =================================================================== --- twiki/trunk/UsageStatisticsPlugin/data/TWiki/UsageStatisticsPlugin.txt 2011-04-23 09:41:16 UTC (rev 21075) +++ twiki/trunk/UsageStatisticsPlugin/data/TWiki/UsageStatisticsPlugin.txt 2011-04-23 10:15:19 UTC (rev 21076) @@ -1,4 +1,4 @@ -%META:TOPICINFO{author="TWikiContributor" date="1303551266" format="1.1" version="$Rev$"}% +%META:TOPICINFO{author="TWikiContributor" date="1303553503" format="1.1" version="$Rev$"}% ---+!! !UsageStatisticsPlugin <!-- Contributions to this plugin are appreciated. Please update the plugin page at @@ -13,12 +13,14 @@ ---++ Overview -This plugins shows detailed usage statistics of TWiki. +This plugins shows detailed usage statistics of TWiki content and users. Visit the following pages: * *[[UsageStatisticsOverview]]* - overview statistics - * *[[UsageStatisticsByUser]]* - statistics by user (access might be restricted) + * *[[UsageStatisticsByUser]]* - statistics by user -%T% Usage statistics are based on the TWiki logs. +%T% __Notes:__ + * Access to user statistice is restricted to administrators for privacy reasons. + * Statistics are derived from the TWiki logs. ---++ Syntax Rules @@ -26,7 +28,7 @@ =%<nop>USAGESTATISTICS{ action="..." ... }%= -The =action= can be ="overview"=, ="user"=, ="monthlist"= +The =action= can be ="overview"=, ="user"= or ="monthlist"=. __Supported parameters for =action="overview"= to generate overview statistics:__ @@ -64,18 +66,20 @@ * Unzip ==%TOPIC%.zip== in your twiki installation directory. Content: | *File:* | *Description:* | | ==data/TWiki/%TOPIC%.txt== | Plugin topic | + | ==data/TWiki/UsageStatisticsOverview.txt== | Overview statistics topic | + | ==data/TWiki/UsageStatisticsByUser.txt== | User statistics topic | | ==lib/TWiki/Plugins/%TOPIC%.pm== | Plugin Perl module | + | ==lib/TWiki/Plugins/%TOPIC%/Core.pm== | Plugin Perl class | * Set the ownership of the extracted directories and files to the webserver user. * Plugin __configuration and testing__: * Run the [[%SCRIPTURL{configure}%][configure]] script and enable the plugin in the __Plugins__ section. - * Configure additional plugin settings in the __Extensions__ section. * Test if the installation was successful: See UsageStatisticsOverview, UsageStatisticsByUser ---++ Plugin Info * One line description, is shown in the %SYSTEMWEB%.TextFormattingRules topic: - * Set SHORTDESCRIPTION = Show detailed monthly usage statistics of TWiki + * Set SHORTDESCRIPTION = Show detailed monthly usage statistics of TWiki content and users | Plugin Author: | TWiki:Main.PeterThoeny | | Copyright: | © 2011 e-Ecosystems Inc <br /> © 2011 TWiki:TWiki.TWikiContributor | @@ -83,7 +87,7 @@ | Plugin Version: | 2011-04-26 | | Change History: | <!-- versions below in reverse order --> | | 2011-04-26: | Initial version | -| TWiki Dependency: | $TWiki::Plugins::VERSION 1.1 | +| TWiki Dependency: | $TWiki::Plugins::VERSION 1.2 | | CPAN Dependencies: | none | | Other Dependencies: | none | | Perl Version: | 5.005 | Modified: twiki/trunk/UsageStatisticsPlugin/lib/TWiki/Plugins/UsageStatisticsPlugin/Core.pm =================================================================== --- twiki/trunk/UsageStatisticsPlugin/lib/TWiki/Plugins/UsageStatisticsPlugin/Core.pm 2011-04-23 09:41:16 UTC (rev 21075) +++ twiki/trunk/UsageStatisticsPlugin/lib/TWiki/Plugins/UsageStatisticsPlugin/Core.pm 2011-04-23 10:15:19 UTC (rev 21076) @@ -144,26 +144,31 @@ # User statistics $rows = ''; - foreach( @{$systemData->{users}} ) { - $user = $_; - $rows .= '| <span style="white-space: nowrap">%ICON{person}% [[' - . $TWiki::cfg{UsersWebName} . ".$user][$user]]</span>" - . ' | <a href="%SCRIPTURL{view}%/%WEB%/UsageStatisticsByUser?user=' - . $user . '">%ICON{statistics}%</a> ' - . ' | ' . ( $logData->{users}{views}{$user} || 0 ) - . ' | ' . ( $logData->{users}{saves}{$user} || 0 ) - . ' | ' . ( $logData->{users}{uploads}{$user} || 0 ) - . ' | '; - my @saves = (); - my $i = 0; - for my $w ( sort keys( %{$logData->{users}{topicsaves}{$user}} ) ) { - for my $t ( sort keys( %{$logData->{users}{topicsaves}{$user}{$w}} ) ) { - push( @saves, "[[$w.$t][$t]]" ) if( $i++ < 10 ); + if( TWiki::Func::isAnAdmin() ) { + foreach( @{$systemData->{users}} ) { + $user = $_; + $rows .= '| <span style="white-space: nowrap">%ICON{person}% [[' + . $TWiki::cfg{UsersWebName} . ".$user][$user]]</span>" + . ' | <a href="%SCRIPTURL{view}%/%WEB%/UsageStatisticsByUser?user=' + . $user . '">%ICON{statistics}%</a> ' + . ' | ' . ( $logData->{users}{views}{$user} || 0 ) + . ' | ' . ( $logData->{users}{saves}{$user} || 0 ) + . ' | ' . ( $logData->{users}{uploads}{$user} || 0 ) + . ' | '; + my @saves = (); + my $i = 0; + for my $w ( sort keys( %{$logData->{users}{topicsaves}{$user}} ) ) { + for my $t ( sort keys( %{$logData->{users}{topicsaves}{$user}{$w}} ) ) { + push( @saves, "[[$w.$t][$t]]" ) if( $i++ < 10 ); + } } + push( @saves, '...' ) if( scalar @saves == 10 ); + $rows .= join( ', ', @saves ) if( @saves ); + $rows .= " |\n"; } - push( @saves, '...' ) if( scalar @saves == 10 ); - $rows .= join( ', ', @saves ) if( @saves ); - $rows .= " |\n"; + } else { + # user is not in the TWikiAdminGroup + $rows = '| Sorry, only administrators can view the user statistics. ||||||'; } $text =~ s/%S_USERSTATS%/$rows/g; @@ -175,6 +180,11 @@ { my ( $this, $session, $params ) = @_; + unless( TWiki::Func::isAnAdmin() ) { + # user is not in the TWikiAdminGroup + return 'ERROR: Sorry, only administrators can view the user statistics.'; + } + my $user = $params->{user}; $user =~ s/[^A-Za-z0-9_]//go; unless( $user ) { Modified: twiki/trunk/UsageStatisticsPlugin/lib/TWiki/Plugins/UsageStatisticsPlugin.pm =================================================================== --- twiki/trunk/UsageStatisticsPlugin/lib/TWiki/Plugins/UsageStatisticsPlugin.pm 2011-04-23 09:41:16 UTC (rev 21075) +++ twiki/trunk/UsageStatisticsPlugin/lib/TWiki/Plugins/UsageStatisticsPlugin.pm 2011-04-23 10:15:19 UTC (rev 21076) @@ -37,7 +37,7 @@ ( $topic, $web, $user, $installWeb ) = @_; # check for Plugins.pm versions - if( $TWiki::Plugins::VERSION < 1.1 ) { + if( $TWiki::Plugins::VERSION < 1.2 ) { TWiki::Func::writeWarning( "Version mismatch between UsageStatisticsPlugin and Plugins.pm" ); return 0; } |