Skip to content

Commit

Permalink
Item8819: Allow topic data to be used without data structure. Some co…
Browse files Browse the repository at this point in the history
…de cleanup.

git-svn-id: http://svn.foswiki.org/trunk/TopicDataHelperPlugin@7039 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
ArthurClemens authored and ArthurClemens committed Apr 1, 2010
1 parent 8e4a929 commit 6a8b0d3
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 57 deletions.
32 changes: 15 additions & 17 deletions data/System/TopicDataHelperPlugin.txt
@@ -1,7 +1,9 @@
%META:TOPICINFO{author="ProjectContributor" date="1113307434" format="1.0" version="1.1"}%
---+!! Topic Data helper plugin

This plugin is to be used with other plugins - it is a helper plugin for collecting, filtering and sorting data objects. This plugin is used by Foswiki:Extensions/AttachmentListPlugin and Foswiki:Extensions/FormFieldListPlugin to process this kind of parameters:
Helper plugin for collecting, filtering and sorting data objects, to be used by other plugins.

This plugin is used by Foswiki:Extensions/AttachmentListPlugin and Foswiki:Extensions/FormFieldListPlugin to process this kind of parameters:

<verbatim>
%ATTACHMENTLIST{
Expand Down Expand Up @@ -499,31 +501,27 @@ my $list = Foswiki::Plugins::TopicDataHelperPlugin::stringifyTopicData($topicDat
my $text = join "\n", @$list;
</verbatim>

---++ Syntax Rules

None. See the plugin documentation in the =.pm= file on detailed usage instructions.

<!--
* Set SHORTDESCRIPTION = Helper plugin for collecting, filtering and sorting data objects.
-->

---++ Plugin Installation Instructions
%$INSTALL_INSTRUCTIONS%


---++ Plugin Info
<!--
* Set SHORTDESCRIPTION = %$SHORTDESCRIPTION%
-->

| Authors: | Foswiki:Main.ArthurClemens |
| Copyright &copy;: | Foswiki:Main.ArthurClemens |
| License: | [[http://www.gnu.org/copyleft/gpl.html][GPL]] |
| Plugin Version: | 20 Jun 2009 (V1.1.1) |
| Authors: | Foswiki:Main.ArthurClemens |
| Copyright &copy;: | Foswiki:Main.ArthurClemens |
| License: | [[http://www.gnu.org/copyleft/gpl.html][GPL]] |
| Version: | %$VERSION% |
| Release: | %$RELEASE% |
| Change History: | <!-- versions below in reverse order --> |
| 01 Apr 2010 | V.1.1.2 Arthur Clemens: Allow topic data to be used without data structure. |
| 20 Jun 2009 | V.1.1.1 Arthur Clemens: Fixed reading of =web.topic= notation in =createTopicData=. |
| 8 Jun 2009 | V.1.1: Foswiki:Main.WillNorris: Ported to Foswiki |
| 24 Oct 2008 | V.1.0: Initial version |
| Foswiki Dependency: | %$DEPENDENCIES% |
| CPAN Dependencies: | none |
| Other Dependencies: | none |
| Dependencies: | %$DEPENDENCIES% |
| Perl Version: | 5.005 |
| Home: | http://foswiki.org/Extensions/%TOPIC% |
| Support: | http://foswiki.org/Support/%TOPIC% |
| Home: | http://foswiki.org/Extensions/%TOPIC% |
| Support: | http://foswiki.org/Support/%TOPIC% |
92 changes: 55 additions & 37 deletions lib/Foswiki/Plugins/TopicDataHelperPlugin.pm
@@ -1,5 +1,5 @@
# Plugin for Foswiki - The Free and Open Source Wiki, http://foswiki.org/
# Copyright (C) 2008 Arthur Clemens, arthur@visiblearea.com
# Copyright (C) 2008-2010 Arthur Clemens, arthur@visiblearea.com
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
Expand All @@ -17,22 +17,14 @@ package Foswiki::Plugins::TopicDataHelperPlugin;
use strict;
use Foswiki::Func;

use vars qw($VERSION $RELEASE $debug
);

# This should always be $Rev$ so that Foswiki can determine the checked-in
# status of the plugin. It is used by the build automation tools, so
# you should leave it alone.
$VERSION = '$Rev$';

# This is a free-form string you can use to "name" your own plugin version.
# It is *not* used by the build automation tools, but is reported as part
# of the version number in PLUGINDESCRIPTIONS.
$RELEASE = '1.1.1';
our $VERSION = '$Rev$';
our $RELEASE = '1.1.2';
our $SHORTDESCRIPTION =
'helper plugin for collecting, filtering and sorting data objects';
our $NO_PREFS_IN_TOPIC = 1;

our $pluginName = 'TopicDataHelperPlugin';
our $debug;
our $NO_PREFS_IN_TOPIC = 1;
our %sortDirections = ( 'ASCENDING', 1, 'NONE', 0, 'DESCENDING', -1 );
my $topic;
my $web;
Expand All @@ -56,8 +48,7 @@ sub initPlugin {
$debug = Foswiki::Func::getPreferencesFlag('TOPICDATAHELPERPLUGIN_DEBUG');

# Plugin correctly initialized
_debug(
"Foswiki::Plugins::${pluginName}::initPlugin( $inWeb.$inTopic ) is OK");
_debug("initPlugin( $inWeb.$inTopic ) is OK");

return 1;
}
Expand All @@ -81,7 +72,7 @@ Creates a hash of web => topics, using this structure:
}
)
The value '1' is temporary to define which topic are valid, and will be replaced by a data structure later on.
The value '1' is temporary to define which topics are valid, and will be replaced by a data structure later on.
Use one paramater or all.
When no =inWebs= is passed, the current web is assumed.
Expand Down Expand Up @@ -112,24 +103,24 @@ sub createTopicData {
( $webs eq '*' )
? Foswiki::Func::getListOfWebs('allowed')
: split( qr/[\s,]+/o, $webs );
foreach my $web (@webs) {
next if $web =~ qr/^_.*?$/o; # do not list webs with underscore
next if $topicData{$web}; # already done
next if ( $$excludeWebs{$web} ); # skip if web is to be excluded
foreach my $listedWeb (@webs) {

next if $listedWeb =~ qr/^_.*?$/o; # do not list webs with underscore
next if $topicData{$listedWeb}; # already done
next if ( $$excludeWebs{$listedWeb} ); # skip if web is to be excluded

# get this web's topics
my @webTopics =
( $inTopics eq '*' )
? Foswiki::Func::getTopicList($web)
? Foswiki::Func::getTopicList($listedWeb)
: split( qr/[\s,]+/o, $inTopics );

# prefix with web name
foreach my $topic (@webTopics) {

foreach my $listedTopic (@webTopics) {
my $dotWeb = undef;
my $dotTopic = undef;
if ( $topic =~ m/^((.*?)\.)*(.*?)$/o ) {
$dotWeb = $2 || $web;
if ( $listedTopic =~ m/^((.*?)\.)*(.*?)$/o ) {
$dotWeb = $2 || $listedWeb;
$dotTopic = $3;
}
next if ( $$excludeWebs{$dotWeb} ); # skip if web is to be excluded
Expand All @@ -143,12 +134,10 @@ sub createTopicData {
$topicData{$dotWeb}{$dotTopic} = 1;
}

if ($debug) {
use Data::Dumper;
_debug("$pluginName -- createTopicData : just added to web $web:");
_debug( Dumper( $topicData{$web} ) );
}
_debug("createTopicData : just added to web $listedWeb:");
_debugData( $topicData{$listedWeb} );
}

return \%topicData;
}

Expand Down Expand Up @@ -233,7 +222,7 @@ sub insertObjectData {

if ($debug) {
use Data::Dumper;
_debug("$pluginName -- insertObjectData completed");
_debug("insertObjectData completed");
_debug( "inTopicData=" . Dumper($inTopicData) );
}
}
Expand Down Expand Up @@ -561,9 +550,17 @@ sub getListOfObjectData {
# {web} => hash of topics
while ( ( my $topic, my $objectDataHash ) = each %$topicHash ) {

while ( ( my $key, my $value ) = each %$objectDataHash ) {
if ( $objectDataHash != 1 ) {

push @objects, $$value;
while ( ( my $key, my $value ) = each %$objectDataHash ) {

push @objects, $$value;
}
}
else {

# no topic data, only the temporary value of 1
push @objects, $topic;
}
}
}
Expand Down Expand Up @@ -760,11 +757,32 @@ sub makeHashFromString {
return \%hash;
}

=pod
Shorthand debugging call.
=cut

sub _debug {
my ($inText) = @_;
my ($text) = @_;

Foswiki::Func::writeDebug($inText)
if $debug;
return if !$debug;

$text = "$pluginName: $text";

#print STDERR $text . "\n";
Foswiki::Func::writeDebug("$text");
}

sub _debugData {
my ( $text, $data ) = @_;

return if !$debug;
Foswiki::Func::writeDebug("$pluginName; $text:");
if ($data) {
eval
'use Data::Dumper; local $Data::Dumper::Terse = 1; local $Data::Dumper::Indent = 1; Foswiki::Func::writeDebug(Dumper($data));';
}
}

1;
17 changes: 14 additions & 3 deletions test/unit/TopicDataHelperPlugin/TopicDataHelperPluginTests.pm
@@ -1,13 +1,14 @@
use strict;

package TopicDataHelperPluginTests;
use FoswikiFnTestCase;
our @ISA = qw( FoswikiFnTestCase );
use strict;
use Error qw( :try );

use Foswiki;
use Foswiki::Meta;
use Foswiki::Func;
use Error qw( :try );
use Foswiki::Plugins::TopicDataHelperPlugin;
use Foswiki::UI::Save;
use Foswiki::OopsException;
use Devel::Symdump;
Expand Down Expand Up @@ -107,6 +108,8 @@ my $allFields = "Author, Status, Remarks";
my $allTopics =
"$testForms{topic1}{name}, $testForms{topic2}{name}, $testForms{topic3}{name}, $testForms{topic4}{name}, $testForms{topic5}{name}";

my $defaultUsersWeb = 'TemporaryTopicDataHelperPluginTestsUsersWeb';

sub new {
my $self = shift()->SUPER::new( 'TopicDataHelperPluginTests', @_ );
return $self;
Expand All @@ -117,6 +120,14 @@ sub set_up {

$this->SUPER::set_up();
$this->_createForms();
$this->{plugin_name} = 'TopicDataHelperPlugin';

$Foswiki::cfg{Plugins}{ $this->{plugin_name} }{Enabled} = 1;
$Foswiki::cfg{Plugins}{ $this->{plugin_name} }{Module} =
"Foswiki::Plugins::$this->{plugin_name}";
$this->{session}->finish();
$this->{session} = new Foswiki(); # default user
$Foswiki::Plugins::SESSION = $this->{session};
}

# This formats the text up to immediately before <nop>s are removed, so we
Expand Down Expand Up @@ -176,7 +187,7 @@ sub test_createTopicData_default_no_web {
Foswiki::Plugins::TopicDataHelperPlugin::createTopicData( $webs,
$excludeWebs, $topics, $excludeTopics );

my $resultTopics = $topicData->{'Main'};
my $resultTopics = $topicData->{ $defaultUsersWeb };
my @resultTopicsList = sort keys %{$resultTopics};
my $resultTopicsListString = join( ",", @resultTopicsList );
$this->assert_equals( 'WebHome,WebPreferences', $resultTopicsListString );
Expand Down

0 comments on commit 6a8b0d3

Please sign in to comment.