From: <Cra...@nt...> - 2005-11-09 14:09:30
|
Author: CrawfordCurrie Date: 2005-11-09 06:07:55 -0800 (Wed, 09 Nov 2005) New Revision: 7397 Modified: twiki/branches/DEVELOP/data/TWiki/IfStatements.txt twiki/branches/DEVELOP/data/TWiki/WebSearch.txt twiki/branches/DEVELOP/lib/TWiki/If.pm Log: Item915: made %IF handle url parameters as well as vars more intelligently. Modified: twiki/branches/DEVELOP/data/TWiki/IfStatements.txt =================================================================== --- twiki/branches/DEVELOP/data/TWiki/IfStatements.txt 2005-11-09 11:23:48 UTC (rev 7396) +++ twiki/branches/DEVELOP/data/TWiki/IfStatements.txt 2005-11-09 14:07:55 UTC (rev 7397) @@ -31,12 +31,20 @@ | <nop>=, !<nop>= | String comparison | | <, >, <=, >= | Number comparison (there is no explicit numeric =) | | context | True if the current context is set (see below) | -| defined | True if a user preference variable of this name is defined | -| $ | expands a variable name. Plugins handlers *are not called*. Returns the empty string if not defined. Built-in variables and user-defined preferences are supported, but you *cannot* pass parameters. | +| defined | True if a preference variable or url parameter of this name is defined. | +| $ | expands a URL parameter or TWikiVariable. Plugins handlers *are not called*. Built-in variables and user-defined preferences are supported. You can pass a limited subset of parameters to TWiki variables by enclosing the variable name in single quotes; for example, =$ 'VARIABLE{value}'=. The quoted string may *not* contain quotes (' or "). | examples: <verbatim> +%IF{"defined WIKINAME" then="WIKINAME is defined" else="WIKINAME is not defined"}% + You are %IF{ "$ WIKINAME='TWikiGuest' and not defined OPEN_DAY" then="not" }% allowed to %IF{ "context view" then="view" else="edit"}% this TWiki today. + +%IF{ "defined search" then="Search: %URLPARAM{search}%" else="No search passed in"}% + +url param t is %IF{ "0 < $ t and $ t < 1000" then="in" else="out of"}% range. + +%IF{ "$'URLPARAM{scope}'='text'" then="Plain text search"}% </verbatim> Given * Set OPEN_DAY = yes Modified: twiki/branches/DEVELOP/data/TWiki/WebSearch.txt =================================================================== --- twiki/branches/DEVELOP/data/TWiki/WebSearch.txt 2005-11-09 11:23:48 UTC (rev 7396) +++ twiki/branches/DEVELOP/data/TWiki/WebSearch.txt 2005-11-09 14:07:55 UTC (rev 7397) @@ -2,6 +2,8 @@ %META:TOPICPARENT{name="WebHome"}% ---+ %MAKETEXT{"Web Search"}% +%IF{"defined search" then='<span class="twistyMakeVisible"><a href="#" style="text-decoration:none;" onclick="location.hash=\'twikiSearchForm\'; return false;">%ICON{down}% <span class="patternLinkLabel">%MAKETEXT{Modify search}%</span></a>'}% + %SEARCH{ "%URLPARAM{search}%" type="keyword" Modified: twiki/branches/DEVELOP/lib/TWiki/If.pm =================================================================== --- twiki/branches/DEVELOP/lib/TWiki/If.pm 2005-11-09 11:23:48 UTC (rev 7396) +++ twiki/branches/DEVELOP/lib/TWiki/If.pm 2005-11-09 14:07:55 UTC (rev 7397) @@ -97,6 +97,9 @@ exec => sub { my( $twiki, $a, $b ) = @_; my $text = $b->evaluate($twiki) || ''; + if( $text && defined( $twiki->{cgiQuery}->param( $text ))) { + return $twiki->{cgiQuery}->param( $text ); + } $text = "%$text%"; $twiki->_expandAllTags(\$text, $twiki->{topicName}, @@ -110,8 +113,11 @@ type => 0, # unary exec => sub { my( $twiki, $a, $b ) = @_; - my $eval = $b->evaluate($twiki) || ''; - return defined( $twiki->{prefs}->getPreferencesValue( $eval )); + my $eval = $b->evaluate($twiki); + return 0 unless $eval; + return 1 if( defined( $twiki->{cgiQuery}->param( $eval ))); + return 1 if( defined( $twiki->{prefs}->getPreferencesValue( $eval ))); + return 0; } }; $defOps{'='} = @@ -138,7 +144,9 @@ type => 1, # binary exec => sub { my( $twiki, $a, $b ) = @_; - return $a->evaluate($twiki) >= $b->evaluate($twiki); + my $ea = $a->evaluate($twiki) || 0; + my $eb = $b->evaluate($twiki) || 0; + return $ea >= $eb; } }; $defOps{'<='} = @@ -147,7 +155,9 @@ type => 1, # binary exec => sub { my( $twiki, $a, $b ) = @_; - return $a->evaluate($twiki) <= $b->evaluate($twiki); + my $ea = $a->evaluate($twiki) || 0; + my $eb = $b->evaluate($twiki) || 0; + return $ea <= $eb; } }; $defOps{'>'} = @@ -156,7 +166,9 @@ type => 1, # binary exec => sub { my( $twiki, $a, $b ) = @_; - return $a->evaluate($twiki) > $b->evaluate($twiki); + my $ea = $a->evaluate($twiki) || 0; + my $eb = $b->evaluate($twiki) || 0; + return $ea > $eb; } }; $defOps{'<'} = @@ -165,7 +177,9 @@ type => 1, # binary exec => sub { my( $twiki, $a, $b ) = @_; - return $a->evaluate($twiki) < $b->evaluate($twiki); + my $ea = $a->evaluate($twiki) || 0; + my $eb = $b->evaluate($twiki) || 0; + return $ea < $eb; } }; $defOps{not} = |