X-Git-Url: https://sipb.mit.edu/gitweb.cgi/ikiwiki.git/blobdiff_plain/c8b34aa31c7d146adf4210c6171dfea2988a7688..d240f576643219905d7732a111e3ec94c5f9b46a:/IkiWiki/Plugin/search.pm diff --git a/IkiWiki/Plugin/search.pm b/IkiWiki/Plugin/search.pm index ff5d0ccbe..3f0b7c9ad 100644 --- a/IkiWiki/Plugin/search.pm +++ b/IkiWiki/Plugin/search.pm @@ -13,6 +13,7 @@ sub import { hook(type => "indexhtml", id => "search", call => \&indexhtml); hook(type => "delete", id => "search", call => \&delete); hook(type => "cgi", id => "search", call => \&cgi); + hook(type => "disable", id => "search", call => \&disable); } sub getsetup () { @@ -57,7 +58,7 @@ sub pagetemplate (@) { if ($template->query(name => "searchform")) { if (! defined $form) { my $searchform = template("searchform.tmpl", blind_cache => 1); - $searchform->param(searchaction => $config{cgiurl}); + $searchform->param(searchaction => IkiWiki::cgiurl()); $searchform->param(html5 => $config{html5}); $form=$searchform->output; } @@ -175,7 +176,7 @@ sub cgi ($) { # only works for GET requests chdir("$config{wikistatedir}/xapian") || error("chdir: $!"); $ENV{OMEGA_CONFIG_FILE}="./omega.conf"; - $ENV{CGIURL}=$config{cgiurl}, + $ENV{CGIURL}=IkiWiki::cgiurl(); IkiWiki::loadindex(); $ENV{HELPLINK}=htmllink("", "", "ikiwiki/searching", noimageinline => 1, linktext => "Help"); @@ -189,15 +190,15 @@ sub pageterm ($) { # 240 is the number used by omindex to decide when to hash an # overlong term. This does not use a compatible hash method though. if (length $page > 240) { - eval q{use Digest::SHA1}; + eval q{use Digest::SHA}; if ($@) { - debug("search: ".sprintf(gettext("need Digest::SHA1 to index %s"), $page)) if $@; + debug("search: ".sprintf(gettext("need Digest::SHA to index %s"), $page)) if $@; return undef; } # Note no colon, therefore it's guaranteed to not overlap # with a page with the same name as the hash.. - return "U".lc(Digest::SHA1::sha1_hex($page)); + return "U".lc(Digest::SHA::sha1_hex($page)); } else { return "U:".$page; @@ -226,23 +227,30 @@ sub setupfiles () { "database_dir .\n". "template_dir ./templates\n"); - # Avoid omega interpreting anything in the misctemplate + # Avoid omega interpreting anything in the cgitemplate # as an omegascript command. - my $misctemplate=IkiWiki::misctemplate(gettext("search"), "\0", + eval q{use IkiWiki::CGI}; + my $template=IkiWiki::cgitemplate(undef, gettext("search"), "\0", searchform => "", # avoid showing the small search form ); eval q{use HTML::Entities}; error $@ if $@; - $misctemplate=encode_entities($misctemplate, '\$'); + $template=encode_entities($template, '\$'); my $querytemplate=readfile(IkiWiki::template_file("searchquery.tmpl")); - $misctemplate=~s/\0/$querytemplate/; + $template=~s/\0/$querytemplate/; writefile("query", $config{wikistatedir}."/xapian/templates", - $misctemplate); + $template); $setup=1; } } } +sub disable () { + if (-d $config{wikistatedir}."/xapian") { + system("rm", "-rf", $config{wikistatedir}."/xapian"); + } +} + 1