# Copyright (C) 2004 Brock Wilcox # (C) 2008 Eric Hsu # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the # Free Software Foundation, Inc. # 59 Temple Place, Suite 330 # Boston, MA 02111-1307 USA $ModulesDescription .= '

$Id: mysearchresults-bfc4.pl,v 0.2 2008/07/15 23:20:09 Eric Hsu Exp $

'; *OldPrintSearchResult = *PrintSearchResult; *PrintSearchResult = *NewPrintSearchResult; sub RunMyPrintSearchResults { my $success=0; foreach my $report (@MyPrintSearchResults) { $success = 1 if (&$report(@_)); last if ($success); }; return $success; } sub RunMyPrintSearchResultsPrefix { my $success=0; foreach my $report (@MyPrintSearchResultsPrefix) { $success = 1 if (&$report(@_)); last if ($success); }; return $success; } sub RunMyPrintSearchResultsSuffix { my $success=0; foreach my $report (@MyPrintSearchResultsSuffix) { $success = 1 if (&$report(@_)); last if ($success); }; return $success; } push @MyPrintSearchResultsSuffix, \&PrintTags; sub PrintTags { my ($name, $regex, $text, $type)=@_; $text =~ /^(Tags:.*)/; # print "
" . $text . "
"; print "
" . $1 . "
" if ($1); # print "HELLLLLLLLLLLLO!!!!"; } sub NewPrintSearchResult { my ($name, $regex) = @_; return PrintPage($name) if not GetParam('context',1); my $raw = GetParam('raw', 0); OpenPage($name); # should be open already, just making sure! my $text = $Page{text}; my ($type) = TextIsFile($text); # MIME type if an uploaded file my $prefixsuccess = RunMyPrintSearchResultsPrefix($name, $regex, $text, $type); my $specialresultsuccess = RunMyPrintSearchResults ($name, $regex, $text, $type); unless ($specialresultsuccess){ my %entry; # get the page, filter it, remove all tags $text =~ s/$FS//go; # Remove separators (paranoia) $text =~ s/[\s]+/ /g; # Shrink whitespace $text =~ s/([-_=\\*\\.]){10,}/$1$1$1$1$1/g ; # e.g. shrink "----------" $text =~ s/<(?:[^>'"]*|(['"]).*?\1)*>//gs; # remove HTML tags $text =~ s/\&\S+\;//g; # remove HTML entities # use HTML::Entities; # decode_entities($text); $entry{title} = $name; $entry{description} = $type || SearchExtract($text, $regex); $entry{size} = int((length($text)/1024)+1) . 'K'; $entry{'last-modified'} = TimeToText($Page{ts}); $entry{username} = $Page{username}; $entry{host} = $Page{host}; PrintSearchResultEntry(\%entry, $regex); } my $suffixsuccess = RunMyPrintSearchResultsSuffix($name, $regex, $text, $type); # if we are using a special display in the search results, then we # will add a note whether there are Tags or Comments. my @notes; my $has_tags; if ($specialresultsuccess) { if ($text =~ /Tags:/) { push @notes, "tags"; $has_tags=1; } my @hrs = ($text =~ /(----\s*\S)/gs); push @notes, "notes" if ((scalar @hrs) - $has_tags); # yes we assume each hr is a new note! There is one for each tag, though. my ($class, $resolved, $title, $has_comments) = ResolveId($CommentsPrefix . $name); push @notes, "comments" if ($has_comments); # # TEST # use Data::Dumper; # print "
";
		# print '@notes:', Dumper (@notes);
		# print '@hrs:', Dumper (@hrs);
		# print "
"; # # print "
$text
"; if (@notes) { if (scalar @notes > 1) { my $last = pop @notes; my $penult = pop @notes; push @notes, "$penult and $last"; } print "
(This item has " . join (", ", @notes) . ".)
"; } } print "
"; } __END__ # =================== # = mysearchresults = # =================== # This is meant to allow developers to give more detail in search results. It puts hooks into PrintSearchResult so that custom subroutines in @MyPrintSearchResults can claim the search result for a page before the default report happens. # You should push @MyPrintSearchResults, \&MyRoutine; # We pass the MyRoutine the ($name, $regex, $text, $type) of the page. # Make sure MyRoutine does return 1 if it is taking over. Otherwise, do return 0; # RunMyPrintSearchResults returns 1 if one of the routines did take over. # Otherwise, it falls through to the default display. # Similarly, there is a hook before and after any search results are printed for your routines. # push @MyPrintSearchResultsPrefix, \&MyRoutine; # push @MyPrintSearchResultsSuffix, \&MyRoutine; (0.2) For BFC4. Removed some debugging in PrintTags. Now strips HTML from search results (since the raw wikitext is HTML). (0.1) First working version.