--- Search.pm 2003-04-27 03:07:50.000000000 -0700 +++ Search.pm.patrick 2003-06-24 06:39:20.000000000 -0700 @@ -63,6 +63,9 @@ $doShowLock, $noEmpty, $theTemplate, $theHeader, $theFormat, @junk ) = @_; + + + ##TWiki::writeDebug "Search locale is $TWiki::siteLocale"; ## 0501 kk : vvv new option to limit results @@ -96,6 +99,7 @@ # Search what webs? "" current web, list gets the list, all gets # all (unless marked in WebPrefs as NOSEARCHALL) + if( $theWebName ) { foreach my $web ( split( /[\,\s]+/, $theWebName ) ) { # the web processing loop filters for valid web names, so don't do it here. @@ -204,23 +208,16 @@ } } - # Construct command line with 'ls' and 'grep. Note that 'ls' does not - # need to be locale-aware as long as it does not transform filenames - - # all results are sorted by Perl 'sort'. However, 'grep' must use - # locales if needed, for case-insensitive searching. - my $cmd = ""; - if( $theScope eq "topic" ) { - $cmd = "$TWiki::lsCmd %FILES% | %GREP% %SWITCHES% -- $TWiki::cmdQuote%TOKEN%$TWiki::cmdQuote"; - } else { - $cmd = "%GREP% %SWITCHES% -l -- $TWiki::cmdQuote%TOKEN%$TWiki::cmdQuote %FILES%"; - } if( $caseSensitive ) { $tempVal = ""; } else { $tempVal = "-i"; } - $cmd =~ s/%SWITCHES%/$tempVal/go; + + # Construct command line for grep. + # 'grep' must use locales if needed, for case-insensitive searching. + my $cmd = "%GREP% $tempVal -l -- $TWiki::cmdQuote%TOKEN%$TWiki::cmdQuote %FILES%"; my @tokens; if( $theRegex ) { @@ -280,29 +277,48 @@ # do grep search chdir( "$sDir" ); _traceExec( "chdir to $sDir", "" ); - @topicList = ( "*.txt" ); - foreach my $token ( @tokens ) { - my $acmd = $cmd; - $acmd =~ s/%TOKEN%/$token/o; - $acmd =~ s/%FILES%/@topicList/; - $acmd =~ /(.*)/; - $acmd = "$1"; # untaint variable (NOTE: Needs a better check!) - $tempVal = `$acmd`; - _traceExec( $acmd, $tempVal ); - @topicList = split( /\n/, $tempVal ); - last if( ! @topicList ); - } - # cut .txt extension - my @tmpList = map { /(.*)\.txt$/; $_ = $1; } @topicList; - @topicList = (); - my $lastTopic = ""; - foreach( @tmpList ) { - $tempVal = $_; - # make topic unique - if( $tempVal ne $lastTopic ) { - push @topicList, $tempVal; + if( $theScope eq "topic" ) { + @topicList = undef; + foreach my $token ( @tokens ) { + opendir( DIR, "."); + my @tmpList; + if( $caseSensitive ) { + @tmpList = grep /.*$token.*\.txt$/, readdir DIR; + } else { + @tmpList = grep /.*$token.*\.txt$/i, readdir DIR; + } + closedir DIR; + @topicList = (@topicList, @tmpList); } - } + } else { # Scope is TEXT --> grep in TOPICs + @topicList = ( "*.txt" ); + + # Search in RCS files too ? + if ( $theScope eq "rcs" ) { + push (@topicList, "*.txt,v") ; + } + + foreach my $token ( @tokens ) { + my $acmd = $cmd; + $acmd =~ s/%TOKEN%/$token/o; + $acmd =~ s/%FILES%/@topicList/; + $acmd =~ /(.*)/; + $acmd = "$1"; # untaint variable (NOTE: Needs a better check!) + $tempVal = `$acmd`; + _traceExec( $acmd, $tempVal ); + @topicList = split( /\n/, $tempVal ); + last if( ! @topicList ); + } + } + + # cut .txt extension and make Topics uniques + my %tmpList; + foreach (@topicList) { + if (/(.*)\.(txt|txt,v)$/) { + $tmpList{"$1"}=1; + } + } + @topicList = keys(%tmpList); } next if ( $noEmpty && ! @topicList ); # Nothing to show for this topic @@ -447,15 +463,30 @@ ##TWiki::writeDebug "Topic list after sort = @topicList"; } - # header and footer of $thisWebName + # output header of $thisWebName my( $beforeText, $repeatText, $afterText ) = split( /%REPEAT%/, $tmplTable ); if( $theHeader ) { $theHeader =~ s/\$n\(\)/\n/gos; # expand "$n()" to new line # TODO: i18n fix $theHeader =~ s/\$n([^a-zA-Z])/\n$1/gos; # expand "$n" to new line + $theHeader =~ s/([^\n])$/$1\n/gos; $beforeText = $theHeader; $beforeText =~ s/\$web/$thisWebName/gos; - $beforeText =~ s/([^\n])$/$1\n/os; + } + + $beforeText =~ s/%WEBBGCOLOR%/$thisWebBGColor/go; + $beforeText =~ s/%WEB%/$thisWebName/go; + $beforeText = &TWiki::handleCommonTags( $beforeText, $topic ); + $afterText = &TWiki::handleCommonTags( $afterText, $topic ); + if( ! $noHeader ) { + if( $doInline || $theFormat ) { + # print at the end if formatted search because of table rendering + $searchResult .= $beforeText; + } else { + $beforeText = &TWiki::getRenderedVersion( $beforeText, $thisWebName ); + $beforeText =~ s|||goi; # remove tag + print $beforeText; + } } # output the list of topics in $thisWebName @@ -553,6 +584,8 @@ $tempVal = &TWiki::getRenderedVersion( $tempVal ); } + + if( $doRenameView ) { # added JET 19 Feb 2000 my $rawText = &TWiki::Store::readTopicRaw( $thisWebName, $topic ); my $changeable = ""; @@ -651,22 +684,6 @@ $tempVal =~ s/%TEXTHEAD%/$head/go; } - # lazy output of header (only if needed for the first time) - unless( $ntopics || $noHeader ) { - $beforeText =~ s/%WEBBGCOLOR%/$thisWebBGColor/go; - $beforeText =~ s/%WEB%/$thisWebName/go; - $beforeText = &TWiki::handleCommonTags( $beforeText, $topic ); - if( $doInline || $theFormat ) { - # print at the end if formatted search because of table rendering - $searchResult .= $beforeText; - } else { - $beforeText = &TWiki::getRenderedVersion( $beforeText, $thisWebName ); - $beforeText =~ s|||goi; # remove tag - print $beforeText; - } - } - - # output topic if( $doInline || $theFormat ) { # print at the end if formatted search because of table rendering $searchResult .= $tempVal; @@ -677,37 +694,31 @@ } $ntopics += 1; - last if( $ntopics >= $theLimit ); - } # end topic loop in a web + last if $ntopics >= $theLimit; + } + + # output footer of $thisWebName + if( $doInline || $theFormat ) { + # print at the end if formatted search because of table rendering + $afterText =~ s/\n$//gos; # remove trailing new line + $searchResult .= $afterText; + } else { + $afterText = &TWiki::getRenderedVersion( $afterText, $thisWebName ); + $afterText =~ s|||goi; # remove tag + print $afterText; + } - # output footer only if hits in web - if( $ntopics ) { - # output footer of $thisWebName - $afterText = &TWiki::handleCommonTags( $afterText, $topic ); + if( ! $noTotal ) { + # print "Number of topics:" part + my $thisNumber = $tmplNumber; + $thisNumber =~ s/%NTOPICS%/$ntopics/go; if( $doInline || $theFormat ) { # print at the end if formatted search because of table rendering - $afterText =~ s/\n$//gos; # remove trailing new line - $searchResult .= $afterText; + $searchResult .= $thisNumber; } else { - $afterText = &TWiki::getRenderedVersion( $afterText, $thisWebName ); - $afterText =~ s|||goi; # remove tag - print $afterText; - } - } - - # output number of topics (only if hits in web or if search only one web) - if( $ntopics || @webList < 2 ) { - unless( $noTotal ) { - my $thisNumber = $tmplNumber; - $thisNumber =~ s/%NTOPICS%/$ntopics/go; - if( $doInline || $theFormat ) { - # print at the end if formatted search because of table rendering - $searchResult .= $thisNumber; - } else { - $thisNumber = &TWiki::getRenderedVersion( $thisNumber, $thisWebName ); - $thisNumber =~ s|||goi; # remove tag - print $thisNumber; - } + $thisNumber = &TWiki::getRenderedVersion( $thisNumber, $thisWebName ); + $thisNumber =~ s|||goi; # remove tag + print $thisNumber; } } }