Allow linker to specify modules to search
authorJamie Cameron <jcameron@webmin.com>
Fri, 12 Jun 2009 22:40:07 +0000 (22:40 +0000)
committerJamie Cameron <jcameron@webmin.com>
Fri, 12 Jun 2009 22:40:07 +0000 (22:40 +0000)
webmin-search-lib.pl
webmin_search.cgi

index 3e98163..9d1b219 100644 (file)
@@ -1,6 +1,6 @@
 # Functions for searching the webmin docs and UI
 
-=head2 search_webmin(phrase, [callback-function])
+=head2 search_webmin(phrase, [callback-function], [&modules])
 
 Searches all Webmin help pages, UI text, module names and config.info files
 for entries matching the given phrase or word. Returns them sorted by relevance
@@ -19,7 +19,7 @@ order, each as a hash ref with the following keys :
 =cut
 sub search_webmin
 {
-my ($re, $cbfunc) = @_;
+my ($re, $cbfunc, $onlymods) = @_;
 
 # Work out this Webmin's URL base
 my $urlhost = $ENV{'HTTP_HOST'};
@@ -31,10 +31,18 @@ my $urlbase = ($ENV{'HTTPS'} eq 'ON' ? 'https://' : 'http://').$urlhost;
 # Search module names and add to results list
 my @rv = ( );
 my $pn = &get_product_name();
-my @mods = sort { $b->{'longdesc'} cmp $a->{'longdesc'} }
-            grep { !$_->{'clone'} }
-              grep { !$_->{'noui'} && !$_->{$pn.'_noui'} }
-                &get_available_module_infos();
+my @mods;
+if ($onlymods) {
+       # Modules specified by caller
+       @mods = @$onlymods;
+       }
+else {
+       # All reasonabel modules
+       @mods = grep { !$_->{'clone'} }
+                 grep { !$_->{'noui'} && !$_->{$pn.'_noui'} }
+                   &get_available_module_infos();
+       }
+@mods = sort { $b->{'longdesc'} cmp $a->{'longdesc'} } @mods;
 foreach my $m (@mods) {
        if ($m->{'desc'} =~ /\Q$re\E/i) {
                # Module description match
index 6ae8d61..9f01239 100644 (file)
@@ -1,6 +1,7 @@
 #!/usr/local/bin/perl
 # Search Webmin modules and help pages and text and config.info
 
+$trust_unknown_referers = 1;
 BEGIN { push(@INC, ".."); };
 use WebminCore;
 
@@ -23,7 +24,8 @@ $re =~ s/\s+$//;
 
 # Do the search
 print &text('wsearch_searching', "<i>".&html_escape($re)."</i>"),"\n";
-@rv = &search_webmin($re, \&print_search_dot);
+@rv = &search_webmin($re, \&print_search_dot,
+                    $in{'mod'} ? [ split(/\0/, $in{'mod'}) ] : undef);
 print &text('wsearch_found', scalar(@rv)),"<p>\n";
 
 # Show in table