Tags:
create new tag
, view all tags

Question

I have just learned how to do search forms using %URLPARAM{...}%.

Say the search is:

  • %SCRIPTURL%/view/%WEB%/BugSearch?priority=panic

When a users push the print-link this page is shown:

  • %SCRIPTURL%/view/%WEB%/BugSearch?skin=print

This page shows all bugs, not only the one we panic about.

I would like the print link to be:

  • %SCRIPTURL%/view/%WEB%/BugSearch?priority=panic&skin=print

Any suggestions about how to do this once and for all would be much appreciated?

Environment

TWiki version: TWikiRelease01Sep2004
TWiki plugins: -
Server OS: -
Web server: -
Perl version: -
Client OS: -
Web Browser: -

-- NielsKoldso - 25 Sep 2004

Answer

I have updated the answer - old but withdrawn suggestion in revision 1.3.

Step-1:
Add this to DefaultPlugin.pm

sub commonTagsHandler
{
...
    $_[0] =~ s/%CGIPARAMS%/&handleCgiParams()/ge;
    $_[0] =~ s/%CGIPARAMS{(.*?)}%/&handleCgiParams($1)/ge;
...
}

sub handleCgiParams
{
    my ($query_ammendment) = @_; # Callers responsibility to use proper URL encoded string ! 

    my $q = &TWiki::Func::getCgiQuery();
    return "" unless($q);

    # Now $q is a perl CGI object, cf. http://search.cpan.org/~lds/CGI.pm3.05/CGI.pm
    # Perl uses ; as seperator whereas CGI uses & - 
    # ... but I think TWiki searches escapes ; in CGI query-string with %3B, so ithopefuly work  :-O
    my $query_string = $q->query_string;
    $query_string = '?'.$query_string if($query_string);
    $query_string =~ s/\;/\&/g;

    # If argument supplied add it to query string (simply assume argument is urlencoded).
    $query_string.=($query_string?'&':'?').$query_ammendment if($query_ammendment);
    return $query_string;
}

Step-2: Update relevant template, e.g.: view.pattern.tmpl:

  • OLD: <a href="%SCRIPTURLPATH%/view%SCRIPTSUFFIX%/%WEB%/%TOPIC%?skin=print.pattern%REVARG%">Printable</a>
  • NEW: <a href="%SCRIPTURLPATH%/view%SCRIPTSUFFIX%/%WEB%/%TOPIC%%CGIPARAMS{skin=print.pattern}%">Printable</a>

I did exactly update view.tmpl (one place) and view.pattern.tmpl (two places).

Note:

  • The %REVARG% is not needed because %CGIPARAMS% remember the revision parameter.
  • I have made a feature request for this: PrintviewOfParameterisedSearch

-- NielsKoldso - 14 Nov 2004

Topic revision: r4 - 2004-11-14 - WillNorris
 
Twitter Delicious Facebook Digg Google Bookmarks E-mail LinkedIn Reddit StumbleUpon    
  • Download TWiki
TWiki logo Powered by Perl Hosted by OICcam.com Ideas, requests, problems regarding TWiki? Send feedback. Ask community in the support forum.
Copyright © 1999-2012 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.