(file) Return to Search.pm CVS log (file) (dir) Up to [RizwankCVS] / geekymedia_web / twiki / lib / TWiki / UI

  1 rizwank 1.1 # TWiki Collaboration Platform, http://TWiki.org/
  2             #
  3             # Copyright (C) 1999-2004 Peter Thoeny, peter@thoeny.com
  4             #
  5             # For licensing info read license.txt file in the TWiki root.
  6             # This program is free software; you can redistribute it and/or
  7             # modify it under the terms of the GNU General Public License
  8             # as published by the Free Software Foundation; either version 2
  9             # of the License, or (at your option) any later version.
 10             #
 11             # This program is distributed in the hope that it will be useful,
 12             # but WITHOUT ANY WARRANTY; without even the implied warranty of
 13             # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 14             # GNU General Public License for more details, published at 
 15             # http://www.gnu.org/copyleft/gpl.html
 16             =begin twiki
 17             
 18             ---+ TWiki::UI::Search
 19             
 20             UI functions for searchng.
 21             
 22 rizwank 1.1 =cut
 23             
 24             package TWiki::UI::Search;
 25             
 26             use strict;
 27             use TWiki;
 28             use TWiki::UI;
 29             
 30             =pod
 31             
 32             ---+++ search( $web, $topic, $query )
 33             Perform a search as dictated by CGI parameters:
 34             | query_string | is the actual search string |
 35             | =search= | |
 36             | =web= | |
 37             | =topic= | |
 38             | =excludetopic= | |
 39             | =scope= | |
 40             | =order= | |
 41             | =type= | |
 42             | =regex= | |
 43 rizwank 1.1 | =limit= | |
 44             | =reverse= | |
 45             | =casesensitive= | |
 46             | =nosummary= | |
 47             | =nosearch= | |
 48             | =noheader= | |
 49             | =nototal= | |
 50             | =bookview= | |
 51             | =renameview= | |
 52             | =showlock= | |
 53             | =expandvariables= | |
 54             | =noempty= | |
 55             | =template= | |
 56             | =header= | |
 57             | =format= | |
 58             | =multiple= | |
 59             | =separator= | |
 60             See the documentation on %SEARCH for a full description of parameters.
 61             =cut
 62             
 63             sub search {
 64 rizwank 1.1     my ($webName, $topic, $query ) = @_;
 65             
 66                 return unless TWiki::UI::webExists( $webName, $topic );
 67             
 68                 # The CGI.pm docs claim that it returns all of the values in a
 69                 # multiple select if called in a list context, but that may not
 70                 # work (didn't on the dev box -- perl 5.004_4 and CGI.pm 2.36 on
 71                 # Linux (Slackware 2.0.33) with Apache 1.2.  That being the case,
 72                 # we need to parse them out here.
 73             
 74             #    my @webs          = $query->param( "web" ) || ( $webName ); #doesn't work
 75             
 76                 # Note for those unused to Perlishness:
 77                 # -------------------------------------
 78                 # The pipeline at the end of this assignment splits the full query
 79                 # string on '&' or ';' and selects out the params that begin with 'web=',
 80                 # replacing them with whatever is after that.  In the case of a
 81                 # single list of webs passed as a string (say, from a text entry
 82                 # field) it does more processing than it needs to to get the
 83                 # correct string, but so what?  The pipline is the second
 84                 # parameter to the join, and consists of the last two lines.  The
 85 rizwank 1.1     # join takes the results of the pipeline and strings them back
 86                 # together, space delimited, which is exactly what &searchWikiWeb
 87                 # needs.
 88                 # Note that mod_perl/cgi appears to use ';' as separator, whereas plain cgi uses '&'
 89             
 90                 my $attrWeb       = join ' ',
 91                                     grep { s/^web=(.*)$/$1/ }
 92                                     split(/[&;]/, $query->query_string);
 93                 # need to unescape URL-encoded data since we use the raw query_string
 94                 # suggested by JeromeBouvattier
 95                 $attrWeb =~ tr/+/ /;       # pluses become spaces
 96                 $attrWeb =~ s/%([0-9a-fA-F]{2})/pack("c",hex($1))/ge;  # %20 becomes space
 97             
 98                 &TWiki::writeHeader( $query );
 99                 &TWiki::Search::searchWeb(
100                     "inline"        => "0",
101                     "search"        => scalar $query->param( "search" ),
102                     "web"           => $attrWeb,
103                     "topic"         => scalar $query->param( "topic" ),
104                     "excludetopic"  => scalar $query->param( "excludetopic" ),
105                     "scope"         => scalar $query->param( "scope" ),
106 rizwank 1.1         "order"         => scalar $query->param( "order" ),
107                     "type"          => scalar $query->param( "type" )
108                                     || TWiki::Prefs::getPreferencesValue( "SEARCHDEFAULTTTYPE" ),
109                     "regex"         => scalar $query->param( "regex" ),
110                     "limit"         => scalar $query->param( "limit" ),
111                     "reverse"       => scalar $query->param( "reverse" ),
112                     "casesensitive" => scalar $query->param( "casesensitive" ),
113                     "nosummary"     => scalar $query->param( "nosummary" ),
114                     "nosearch"      => scalar $query->param( "nosearch" ),
115                     "noheader"      => scalar $query->param( "noheader" ),
116                     "nototal"       => scalar $query->param( "nototal" ),
117                     "bookview"      => scalar $query->param( "bookview" ),
118                     "renameview"    => scalar $query->param( "renameview" ),
119                     "showlock"      => scalar $query->param( "showlock" ),
120                     "expandvariables" => scalar $query->param( "expandvariables" ),
121                     "noempty"       => scalar $query->param( "noempty" ),
122                     "template"      => scalar $query->param( "template" ),
123                     "header"        => scalar $query->param( "header" ),
124                     "format"        => scalar $query->param( "format" ),
125                     "multiple"      => scalar $query->param( "multiple" ),
126                     "separator"     => scalar $query->param( "separator" ),
127 rizwank 1.1     );
128             }
129             
130             1;
131             

Rizwan Kassim
Powered by
ViewCVS 0.9.2