Skip to content

Commit

Permalink
Item11743: use Foswiki::Func::pushTopicContext() instead of Foswiki::…
Browse files Browse the repository at this point in the history
…Func::getPreferencesValue() to retrieve default values from web scope

git-svn-id: http://svn.foswiki.org/trunk/SetVariablePlugin@14590 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
MichaelDaum authored and MichaelDaum committed Apr 10, 2012
1 parent f4db88f commit 85a2f01
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
2 changes: 1 addition & 1 deletion data/System/SetVariablePlugin.txt
Expand Up @@ -113,6 +113,7 @@ The =format= string may contain the standard escape parameters
| Release: | %$RELEASE% |
| Version: | %$VERSION% |
| Change History: |   |
| 10 Apr 2012: | fixing scope="web"; finxign reading the view template yet again |
| 27 Feb 2012: | added scope="global"; fixed reading view templates when there is none |
| 02 Dec 2011: | improving save times, thanks to Foswiki:Main.PaulHarvey |
| 28 Sep 2011: | implement setting variables via view_templates |
Expand All @@ -121,4 +122,3 @@ The =format= string may contain the standard escape parameters
| Dependencies: | %$DEPENDENCIES% |
| Home: | Foswiki:Extensions/%TOPIC% |
| Support: | Foswiki:Support/%TOPIC% |

2 changes: 1 addition & 1 deletion lib/Foswiki/Plugins/SetVariablePlugin.pm
Expand Up @@ -23,7 +23,7 @@ use vars qw(
);

$VERSION = '$Rev: 4287 (2009-06-23) $';
$RELEASE = '2.10';
$RELEASE = '2.20';

$SHORTDESCRIPTION = 'Flexible handling of topic variables';
$NO_PREFS_IN_TOPIC = 1;
Expand Down
21 changes: 13 additions & 8 deletions lib/Foswiki/Plugins/SetVariablePlugin/Core.pm
Expand Up @@ -15,6 +15,7 @@
package Foswiki::Plugins::SetVariablePlugin::Core;

use strict;
use warnings;
use constant DEBUG => 0; # toggle me
use constant ACTION_UNSET => 0;
use constant ACTION_SET => 1;
Expand Down Expand Up @@ -181,16 +182,19 @@ sub handleGetVar {
@metas = $meta->find($theType);
#writeDebug("found ".scalar(@metas)." metas");
} elsif ($theScope eq 'web') {
my $value = Foswiki::Func::getPreferencesValue($theVar, $theWeb);
my ($prefsWeb, $prefsTopic) = Foswiki::Func::normalizeWebTopicName($theWeb, $Foswiki::cfg{WebPrefsTopicName});
Foswiki::Func::pushTopicContext($prefsWeb, $prefsTopic);
my $value = Foswiki::Func::getPreferencesValue($theVar);
if (defined $value) {
my $meta = {
name=> $theVar,
title=> $theVar,
value=> $value,
type => 'Web',
type => 'Global',
};
push @metas, $meta;
}
Foswiki::Func::popTopicContext();
} elsif ($theScope eq 'session') {
my @keys = Foswiki::Func::getSessionKeys();
foreach my $key (@keys) {
Expand Down Expand Up @@ -269,11 +273,12 @@ sub handleBeforeSave {
writeDebug("handleBeforeSave($web.$topic)");

# get the rules NOW
my $template = Foswiki::Func::getPreferencesValue('VIEW_TEMPLATE') || 'view';
my $tmpl = Foswiki::Func::readTemplate($template);
$tmpl = Foswiki::Func::readTemplate('view') unless $tmpl && $template eq 'view';
my $viewTemplate = Foswiki::Func::getPreferencesValue('VIEW_TEMPLATE');
my $tmpl;
$tmpl = Foswiki::Func::readTemplate($viewTemplate) if $viewTemplate;
$tmpl = Foswiki::Func::readTemplate('view') unless $tmpl;

if ($tmpl =~ /\%TEXT%/) {
if ($tmpl && $tmpl =~ /\%TEXT%/) {
$tmpl =~ s/\%TEXT%/$text/g;
$text = $tmpl;
}
Expand All @@ -284,7 +289,7 @@ sub handleBeforeSave {

#writeDebug("text=$text\n");

$text = Foswiki::Func::expandCommonVariables($tmpl, $topic, $web);
$text = Foswiki::Func::expandCommonVariables($text, $topic, $web);

# create rules from Set+VARNAME, Local+VARNAME, Unset+VARNAME and Default+VARNAME urlparams
my $request = Foswiki::Func::getCgiQuery();
Expand All @@ -307,7 +312,7 @@ sub handleBeforeSave {
my $defaultValue = join(', ', @defaultValues);
if ($defaultValue eq $value) {
$type = 'Unset';
#writeDebug("found set to default/undef ... unsetting ".$name);
writeDebug("found set to default/undef ... unsetting ".$name);
}
}
}
Expand Down

0 comments on commit 85a2f01

Please sign in to comment.