Index: TWiki.pm =================================================================== --- TWiki.pm (revision 7869) +++ TWiki.pm (working copy) @@ -587,7 +587,7 @@ return $text; } - # Convert from ISO-8859-1 if it is the site charset + # Convert from ISO-8859-1 if it is t he site charset if ( $TWiki::cfg{Site}{CharSet} =~ /^iso-?8859-?15?$/i ) { # (conversion from 'perldoc perluniintro') $text =~ s/ ([\x80-\xFF])/ @@ -1357,6 +1357,7 @@ if( ref($user) && $user->isa('TWiki::User')) { $user = $user->wikiName(); } + if( $user eq $cfg{DefaultUserWikiName} ) { my $cgiQuery = $this->{cgiQuery}; if( $cgiQuery ) { @@ -2253,7 +2254,18 @@ } =pod +---++ ObjectMethod inContext( $id ) -> boolean +Returns true if the context specified by $id.is active. +(see =enterContext= for more information on contexts) +=cut + +sub inContext { + my ($this,$id)=@_; + return defined($this->{context}->{$id}); +} + +=pod ---++ ObjectMethod leaveContext( $id ) Remove the context id $id from the set of active contexts. @@ -2270,20 +2282,6 @@ =pod ----++ ObjectMethod inContext( $id ) - -Return the value for the given context id -(see =enterContext= for more information on contexts) - -=cut - -sub inContext { - my( $this, $id ) = @_; - return $this->{context}->{$id}; -} - -=pod - ---++ StaticMethod registerTagHandler( $tag, $fnref ) STATIC Add a tag handler to the function tag handlers. @@ -2786,6 +2784,9 @@ $params->{basetopic} = $topic; $params->{search} = $params->{_DEFAULT} if( $params->{_DEFAULT} ); $params->{type} = $this->{prefs}->getPreferencesValue( 'SEARCHVARDEFAULTTYPE' ) unless( $params->{type} ); + my $id=$params->{id} || ""; + $params->{start} = $this->{cgiQuery}->param( $id.'_start' ) || $params->{start} || "0"; + $params->{step} = $this->{cgiQuery}->param( $id.'_step' ) || $params->{step} || "0"; my $s = $this->{search}->searchWeb( %$params ); return $s; Index: TWiki/Search.pm =================================================================== --- TWiki/Search.pm (revision 7869) +++ TWiki/Search.pm (working copy) @@ -36,7 +36,8 @@ use TWiki::User; use TWiki::Time; -my $emptySearch = 'something.Very/unLikelyTo+search-for;-)'; +my $emptySearch = "something.Very/unLikelyTo+search-for;-)"; +my $maxVisibleSteps = 10; BEGIN { # 'Use locale' for internationalisation of Perl sorting and searching - @@ -384,6 +385,10 @@ my $header = $params{header} || ''; my $inline = $params{inline}; my $limit = $params{limit} || ''; + my $theStart = $params{start} || "0"; + my $theStep = $params{step} || "25"; #TODO: Put this in a preference? + my $thePaging = $params{pageresult} || ""; + my $theId = $params{id} || ""; my $doMultiple = TWiki::isTrue( $params{multiple} ); my $nonoise = TWiki::isTrue( $params{nonoise} ); my $noEmpty = TWiki::isTrue( $params{noempty}, $nonoise ); @@ -406,7 +411,7 @@ my $date = $params{date} || ''; my $recurse = $params{'recurse'} || ''; my $finalTerm = $inline ? ( $params{nofinalnewline} || 0 ) : 0; - + my $topicsFound = 0; $baseWeb =~ s/\./\//go; my $session = $this->{session}; @@ -697,9 +702,33 @@ } # output the list of topics in $web +########################## PAGING my $ntopics = 0; my $headerDone = $noHeader; + my $topicsDisplayed = 0; + + my $topicListSize=scalar @topicList; + $topicListSize=$limit if $topicListSize>$limit; + + $topicsFound+=$topicListSize; + + my $upperBound=($theStart+$theStep)-1; + if ($upperBound<$topicListSize) { + @topicList= @topicList[$theStart..$upperBound]; + } else { + @topicList= @topicList[$theStart..$topicListSize]; + } + + $topicsDisplayed = scalar @topicList; + +########################## PAGING foreach my $topic ( @topicList ) { + #SMELL: Sometimes $topic is empty. + if (!$topic) { + $topicsFound--; + $topicsDisplayed--; + next; + } my $forceRendering = 0; unless( exists( $topicInfo->{$topic} ) ) { # not previously cached @@ -898,16 +927,18 @@ } while( @multipleHitLines ); # multiple=on loop - $ntopics += 1; - +# $ntopics += 1; +# # delete topic info to clear any cached data undef $topicInfo->{$topic}; - - last if( $ntopics >= $limit ); +# +# last if( $ntopics >= $limit ); + } # end topic loop # output footer only if hits in web - if( $ntopics ) { +# if( $ntopics ) { + if( $topicsDisplayed ) { # output footer of $web $afterText = $session->handleCommonTags( $afterText, $web, @@ -931,8 +962,18 @@ # output number of topics (only if hits in web or if # only searching one web) if( $ntopics || scalar( @webs ) < 2 ) { +# if( $ntopics || @webList < 2 ) { unless( $noTotal ) { my $thisNumber = $tmplNumber; + my $ntopics=$topicsDisplayed; + + if ($thePaging eq "on") { + my $start=1 + $theStart; + + my $end= $theStart+$theStep; + $end = $limit if $end >$limit; + $ntopics= "$start - $end / $topicsFound"; + } $thisNumber =~ s/%NTOPICS%/$ntopics/go; if ( defined $callback ) { $thisNumber = @@ -946,7 +987,9 @@ } } } - return '' if ( $ntopics == 0 && $zeroResults ); + +# return '' if ( $ntopics == 0 && $noZeroResults ); + } if( $format && ! $finalTerm ) { @@ -974,6 +1017,16 @@ } return undef if ( defined $callback ); + + +# (RAF) What was I thinking when I did this? + my $pages=int (($topicsFound/$theStep) + 0.9); + if ($thePaging eq "on" && scalar( @webs ) ==1 && $pages > 1 ) { + my $pagingText=_createPaging($theStart,$theStep,$pages,$theId); + + $searchResult = $pagingText.$searchResult; + $searchResult .= $pagingText; + } return $searchResult if $inline; $searchResult = $session->handleCommonTags( $searchResult, @@ -986,6 +1039,57 @@ return $searchResult; } +sub _createPaging { + my ($theStart,$theStep,$pages,$theId)=@_; + my $startParam=$theId."_start"; + my $stepParam=$theId."_step"; + + my $pagingText="