Skip to content

Commit

Permalink
Item14188: compatibility with different engines
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelDaum committed Sep 9, 2016
1 parent d4b2be6 commit 3be5511
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 28 deletions.
11 changes: 11 additions & 0 deletions .gitignore
@@ -0,0 +1,11 @@
*,v
igp_*
genpdf_*
*.swp
/SetVariablePlugin.md5
/SetVariablePlugin.sha1
/SetVariablePlugin.tgz
/SetVariablePlugin.txt
/SetVariablePlugin.zip
/SetVariablePlugin_installer
/SetVariablePlugin_installer.pl
34 changes: 19 additions & 15 deletions data/System/SetVariablePlugin.txt
@@ -1,9 +1,6 @@
---+!! <nop>%TOPIC%
%SHORTDESCRIPTION%
<!--
One line description, required for extensions repository catalog.
* Set SHORTDESCRIPTION = Flexible handling of topic variables
-->
%META:TOPICINFO{author="ProjectContributor" comment="" date="1262991297" format="1.1" reprev="1.2" version="1"}%
---+!! %TOPIC%
%FORMFIELD{"Description"}%

%TOC%

Expand Down Expand Up @@ -106,12 +103,11 @@ The =format= string may contain the standard escape parameters
---++ Installation Instructions
%$INSTALL_INSTRUCTIONS%

---++ Plugin Info
| Plugin Author: | Foswiki:Main.MichaelDaum |
| Copyright: | &copy; 2007-2013 Michael Daum http://michaeldaumconsulting.com |
| License: | GPL ([[http://www.gnu.org/copyleft/gpl.html][GNU General Public License]]) |
| Version: | %$VERSION% |
| Change History: | &nbsp; |
---++ Dependencies
%$DEPENDENCIES%

---++ Change History
| 09 Sep 2016: | add compatibility with different Foswiki engines |
| 12 Dec 2013: | still perform an beforeSaveHandler even on newer foswikies |
| 17 Dec 2012: | work around performance problem in common Foswiki engines reading templates repeatedly |
| 05 Nov 2012: | Module version string is incompatible with Foswiki extension installers before v1.1.6 |
Expand All @@ -123,6 +119,14 @@ The =format= string may contain the standard escape parameters
| 28 Sep 2011: | implement setting variables via view_templates |
| 17 Nov 2009: | SETVAR has higher priority than urlparams; fixed use in persistent perl envs |
| 23 Jun 2009: | initial release |
| Dependencies: | %$DEPENDENCIES% |
| Home: | Foswiki:Extensions/%TOPIC% |
| Support: | Foswiki:Support/%TOPIC% |

%META:FORM{name="PackageForm"}%
%META:FIELD{name="Author" title="Author" value="Foswiki:Main.MichaelDaum"}%
%META:FIELD{name="Copyright" title="Copyright" value="&copy; 2007-2016 Michael Daum http://michaeldaumconsulting.com"}%
%META:FIELD{name="Description" title="Description" value="%25$SHORTDESCRIPTION%25"}%
%META:FIELD{name="Home" title="Home" value="Foswiki:Extensions/%TOPIC%"}%
%META:FIELD{name="License" title="License" value="GPL ([[http://www.gnu.org/copyleft/gpl.html][GNU General Public License]])"}%
%META:FIELD{name="Release" title="Release" value="%$RELEASE%"}%
%META:FIELD{name="Repository" title="Repository" value="https://github.com/foswiki/%TOPIC%"}%
%META:FIELD{name="Support" title="Support" value="Foswiki:Support/%TOPIC%"}%
%META:FIELD{name="Version" title="Version" value="%$VERSION%"}%
16 changes: 13 additions & 3 deletions lib/Foswiki/Plugins/SetVariablePlugin.pm
@@ -1,6 +1,6 @@
# Plugin for Foswiki - The Free and Open Source Wiki, http://foswiki.org/
#
# Copyright (C) 2006-2013 Michael Daum http://michaeldaumconsulting.com
# Copyright (C) 2006-2016 Michael Daum http://michaeldaumconsulting.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 @@ -20,9 +20,19 @@ use warnings;

use Foswiki::Func ();
use Foswiki::Plugins ();
use Foswiki::Request ();

BEGIN {
# Backwards compatibility for Foswiki 1.1.x
unless (Foswiki::Request->can('multi_param')) {
no warnings 'redefine';
*Foswiki::Request::multi_param = \&Foswiki::Request::param;
use warnings 'redefine';
}
}

our $VERSION = "2.33";
our $RELEASE = "2.33";
our $VERSION = "2.34";
our $RELEASE = "09 Sep 2016";

our $SHORTDESCRIPTION = 'Flexible handling of topic variables';
our $NO_PREFS_IN_TOPIC = 1;
Expand Down
20 changes: 11 additions & 9 deletions lib/Foswiki/Plugins/SetVariablePlugin/Core.pm
@@ -1,4 +1,4 @@
# Copyright (C) 2007-2013 Michael Daum http://michaeldaumconsulting.com
# Copyright (C) 2007-2016 Michael Daum http://michaeldaumconsulting.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 @@ -16,10 +16,12 @@ package Foswiki::Plugins::SetVariablePlugin::Core;

use strict;
use warnings;
use constant DEBUG => 0; # toggle me

use Foswiki::Func ();

use constant TRACE => 0; # toggle me
use constant ACTION_UNSET => 0;
use constant ACTION_SET => 1;
use Foswiki::Func ();

###############################################################################
# constructor
Expand All @@ -32,8 +34,8 @@ sub new {
###############################################################################
# static
sub writeDebug {
#Foswiki::Func::writeDebug("- SetVariablePlugin - ".$_[0]) if DEBUG;
print STDERR "- SetVariablePlugin - ".$_[0]."\n" if DEBUG;
#Foswiki::Func::writeDebug("- SetVariablePlugin - ".$_[0]) if TRACE;
print STDERR "- SetVariablePlugin - ".$_[0]."\n" if TRACE;
}

###############################################################################
Expand All @@ -59,7 +61,7 @@ sub applyRules {

$text ||= '';

# if (DEBUG) {
# if (TRACE) {
# require Data::Dumper;
# writeDebug(Data::Dumper->Dump([$this->{rules}]));
# }
Expand Down Expand Up @@ -319,15 +321,15 @@ sub handleBeforeSave {
next unless $key =~ /^(Local|Set|Unset)\+(.*)$/;
my $type = $1;
my $name = $2;
my @values = $request->param($key);
my @values = $request->multi_param($key);
next unless @values;
@values = grep {!/^$/} @values if @values > 1;
@values = grep {!/^$/} grep {defined($_)} @values if @values > 1;
my $value = join(", ", @values);
writeDebug("key=$key, value=$value");

# convert a set to an unset if that's already default
if ($type =~ /Local|Set/) {
my @defaultValues = $request->param("Default+$name");
my @defaultValues = $request->multi_param("Default+$name");
if (@defaultValues) {
@defaultValues = grep {!/^$/} @defaultValues if @defaultValues > 1;
my $defaultValue = join(', ', @defaultValues);
Expand Down
2 changes: 1 addition & 1 deletion lib/Foswiki/Plugins/SetVariablePlugin/build.pl
@@ -1,4 +1,4 @@
#!/usr/bin/perl -w
#!/usr/bin/env perl
BEGIN {
unshift @INC, split( /:/, $ENV{FOSWIKI_LIBS} );
}
Expand Down

0 comments on commit 3be5511

Please sign in to comment.