]> sipb.mit.edu Git - ikiwiki.git/commitdiff
rather a lot of changes to make hyperestraier search be a plugin, allowing
authorjoey <joey@0fa5a96a-9a0e-0410-b3b2-a0fd24251071>
Wed, 3 May 2006 21:50:39 +0000 (21:50 +0000)
committerjoey <joey@0fa5a96a-9a0e-0410-b3b2-a0fd24251071>
Wed, 3 May 2006 21:50:39 +0000 (21:50 +0000)
for other types of search engine plugins if wanted, and also opening up a
lot of new possibilities for other kinds of plugins later

some notable changes along the way:

- lots of new hook types: cgi, render, delete
- wrapper files fixed to support config strings with newlines in them
- HEADERCONTENT in page template useful for plugins. Probably needs to be
  expanded to more such for other places plugins might want to add content.
- remove unnecessary wrappers field from config info stored in wrappers

15 files changed:
IkiWiki.pm
IkiWiki/CGI.pm
IkiWiki/Plugin/search.pm [new file with mode: 0644]
IkiWiki/Plugin/skeleton.pm
IkiWiki/Render.pm
IkiWiki/Setup/Standard.pm
IkiWiki/Wrapper.pm
debian/NEWS
debian/changelog
doc/hyperestraier.mdwn
doc/ikiwiki.setup
doc/plugins/search.mdwn [new file with mode: 0644]
doc/usage.mdwn
ikiwiki
templates/page.tmpl

index 9a7b4fe911a284f7a11dfc19060ffbddef2b2401..960d26de93f94e4e95a44098b2b616a3b089f5a2 100644 (file)
@@ -16,9 +16,6 @@ sub checkconfig () { #{{{
        if ($config{rss} && ! length $config{url}) {
                error("Must specify url to wiki with --url when using --rss\n");
        }
-       if ($config{hyperestraier} && ! length $config{url}) {
-               error("Must specify --url when using --hyperestraier\n");
-       }
        
        $config{wikistatedir}="$config{srcdir}/.ikiwiki"
                unless exists $config{wikistatedir};
@@ -40,6 +37,12 @@ sub checkconfig () { #{{{
                        error("Failed to load plugin $mod: $@");
                }
        }
+
+       if (exists $hooks{checkconfig}) {
+                foreach my $id (keys %{$hooks{checkconfig}}) {
+                        $hooks{checkconfig}{$id}{call}->();
+                }
+        }
 } #}}}
 
 sub error ($) { #{{{
index e219c8c1cce88317601f6f1853476e8f5b3f56d8..15e86651d419f64e4b8e48dd5797feaafe8057ef 100644 (file)
@@ -484,26 +484,21 @@ sub cgi_editpage ($$) { #{{{
        }
 } #}}}
 
-sub cgi_hyperestraier () { #{{{
-       # only works for GET requests
-       chdir("$config{wikistatedir}/hyperestraier") || error("chdir: $!");
-       exec("./".basename($config{cgiurl})) || error("estseek.cgi failed");
-} #}}}
-
 sub cgi () { #{{{
        eval q{use CGI};
        eval q{use CGI::Session};
        
        my $q=CGI->new;
        
+       if (exists $hooks{cgi}) {
+               foreach my $id (keys %{$hooks{cgi}}) {
+                       $hooks{cgi}{$id}{call}->($q);
+               }
+       }
+       
        my $do=$q->param('do');
        if (! defined $do || ! length $do) {
-               if (defined $q->param('phrase')) {
-                       cgi_hyperestraier();
-               }
-               else {
-                       error("\"do\" parameter missing");
-               }
+               error("\"do\" parameter missing");
        }
        
        # Things that do not need a session.
diff --git a/IkiWiki/Plugin/search.pm b/IkiWiki/Plugin/search.pm
new file mode 100644 (file)
index 0000000..c71fef7
--- /dev/null
@@ -0,0 +1,122 @@
+#!/usr/bin/perl
+# hyperestraier search engine plugin
+package IkiWiki::Plugin::search;
+
+use warnings;
+use strict;
+use IkiWiki;
+
+sub import { #{{{
+       IkiWiki::hook(type => "checkconfig", id => "hyperestraier",
+               call => \&checkconfig);
+       IkiWiki::hook(type => "delete", id => "hyperestraier",
+               call => \&delete);
+       IkiWiki::hook(type => "render", id => "hyperestraier",
+               call => \&render);
+       IkiWiki::hook(type => "cgi", id => "hyperestraier",
+               call => \&cgi);
+} # }}}
+
+sub checkconfig () { #{{{
+       foreach my $required (qw(url cgiurl)) {
+               if (! length $IkiWiki::config{$required}) {
+                       IkiWiki::error("Must specify $required when using the search plugin\n");
+               }
+       }
+
+       $IkiWiki::config{headercontent}.=qq{
+<form method="get" action="$IkiWiki::config{cgiurl}" id="searchform">
+<div>
+<input type="text" name="phrase" value="" size="16" />
+<input type="hidden" name="enc" value="UTF-8" />
+<input type="hidden" name="do" value="hyperestraier" />
+</div>
+</form>
+};
+} #}}}
+
+sub delete (@) { #{{{
+       IkiWiki::debug("cleaning hyperestraier search index");
+       IkiWiki::estcmd("purge -cl");
+       IkiWiki::estcfg();
+} #}}}
+
+sub render (@) { #{{{
+       IkiWiki::debug("updating hyperestraier search index");
+       IkiWiki::estcmd("gather -cm -bc -cl -sd",
+               map {
+                       $IkiWiki::config{destdir}."/".$IkiWiki::renderedfiles{IkiWiki::pagename($_)}
+               } @_
+       );
+       IkiWiki::estcfg();
+} #}}}
+
+sub cgi ($) { #{{{
+       my $cgi=shift;
+
+       if (defined $cgi->param('phrase')) {
+               # only works for GET requests
+               chdir("$IkiWiki::config{wikistatedir}/hyperestraier") || IkiWiki::error("chdir: $!");
+               exec("./".IkiWiki::basename($IkiWiki::config{cgiurl})) || IkiWiki::error("estseek.cgi failed");
+       }
+} #}}}
+
+# Easier to keep these in the IkiWiki namespace.
+package IkiWiki;
+
+my $configured=0;
+sub estcfg () { #{{{
+       return if $configured;
+       $configured=1;
+       
+       my $estdir="$config{wikistatedir}/hyperestraier";
+       my $cgi=basename($config{cgiurl});
+       $cgi=~s/\..*$//;
+       open(TEMPLATE, ">$estdir/$cgi.tmpl") ||
+               error("write $estdir/$cgi.tmpl: $!");
+       print TEMPLATE misctemplate("search", 
+               "<!--ESTFORM-->\n\n<!--ESTRESULT-->\n\n<!--ESTINFO-->\n\n");
+       close TEMPLATE;
+       open(TEMPLATE, ">$estdir/$cgi.conf") ||
+               error("write $estdir/$cgi.conf: $!");
+       my $template=HTML::Template->new(
+               filename => "$config{templatedir}/estseek.conf"
+       );
+       eval q{use Cwd 'abs_path'};
+       $template->param(
+               index => $estdir,
+               tmplfile => "$estdir/$cgi.tmpl",
+               destdir => abs_path($config{destdir}),
+               url => $config{url},
+       );
+       print TEMPLATE $template->output;
+       close TEMPLATE;
+       $cgi="$estdir/".basename($config{cgiurl});
+       unlink($cgi);
+       symlink("/usr/lib/estraier/estseek.cgi", $cgi) ||
+               error("symlink $cgi: $!");
+} # }}}
+
+sub estcmd ($;@) { #{{{
+       my @params=split(' ', shift);
+       push @params, "-cl", "$config{wikistatedir}/hyperestraier";
+       if (@_) {
+               push @params, "-";
+       }
+       
+       my $pid=open(CHILD, "|-");
+       if ($pid) {
+               # parent
+               foreach (@_) {
+                       print CHILD "$_\n";
+               }
+               close(CHILD) || error("estcmd @params exited nonzero: $?");
+       }
+       else {
+               # child
+               open(STDOUT, "/dev/null"); # shut it up (closing won't work)
+               exec("estcmd", @params) || error("can't run estcmd");
+       }
+} #}}}
+
+1
index 89308c45fb973fbf3a6643a14d86b6f2e3cc684b..d6d8cc0eddf588804519895d7355941c5d1ed9df 100644 (file)
@@ -1,6 +1,7 @@
 #!/usr/bin/perl
 # Ikiwiki skeleton plugin. Replace "skeleton" with the name of your plugin
-# in the lines below, and flesh out the code to make it do something.
+# in the lines below, remove hooks you don't use, and flesh out the code to
+# make it do something.
 package IkiWiki::Plugin::skeleton;
 
 use warnings;
@@ -8,14 +9,44 @@ use strict;
 use IkiWiki;
 
 sub import { #{{{
+       IkiWiki::hook(type => "checkconfig", id => "skeleton", 
+               call => \&checkconfig);
        IkiWiki::hook(type => "preprocess", id => "skeleton", 
                call => \&preprocess);
+       IkiWiki::hook(type => "delete", id => "skeleton", 
+               call => \&delete);
+       IkiWiki::hook(type => "render", id => "skeleton", 
+               call => \&render);
+       IkiWiki::hook(type => "cgi", id => "skeleton", 
+               call => \&cgi);
 } # }}}
 
+sub checkconfig () { #{{{
+       IkiWiki::debug("skeleton plugin checkconfig");
+} #}}}
+
 sub preprocess (@) { #{{{
        my %params=@_;
 
        return "skeleton plugin result";
 } # }}}
 
+sub delete (@) { #{{{
+       my @files=@_;
+
+       IkiWiki::debug("skeleton plugin told that files were deleted: @files");
+} #}}}
+
+sub render (@) { #{{{
+       my @files=@_;
+
+       IkiWiki::debug("skeleton plugin told that files were rendered: @files");
+} #}}}
+
+sub cgi ($) { #{{{
+       my $cgi=shift;
+
+       IkiWiki::debug("skeleton plugin running in cgi");
+} #}}}
+
 1
index f90f16335ead61cf034b4f78da8872b775fd6dd2..a4efa0b74511a1b88faefd4e0519242e04736fe4 100644 (file)
@@ -206,9 +206,7 @@ sub genpage ($$$) { #{{{
                $u=~s/\[\[file\]\]/$pagesources{$page}/g;
                $template->param(historyurl => $u);
        }
-       if ($config{hyperestraier}) {
-               $template->param(hyperestraierurl => cgiurl());
-       }
+       $template->param(headercontent => $config{headercontent});
 
        $template->param(
                title => $title,
@@ -300,57 +298,6 @@ sub prune ($) { #{{{
        }
 } #}}}
 
-sub estcfg () { #{{{
-       my $estdir="$config{wikistatedir}/hyperestraier";
-       my $cgi=basename($config{cgiurl});
-       $cgi=~s/\..*$//;
-       open(TEMPLATE, ">$estdir/$cgi.tmpl") ||
-               error("write $estdir/$cgi.tmpl: $!");
-       print TEMPLATE misctemplate("search", 
-               "<!--ESTFORM-->\n\n<!--ESTRESULT-->\n\n<!--ESTINFO-->\n\n");
-       close TEMPLATE;
-       open(TEMPLATE, ">$estdir/$cgi.conf") ||
-               error("write $estdir/$cgi.conf: $!");
-       my $template=HTML::Template->new(
-               filename => "$config{templatedir}/estseek.conf"
-       );
-       eval q{use Cwd 'abs_path'};
-       $template->param(
-               index => $estdir,
-               tmplfile => "$estdir/$cgi.tmpl",
-               destdir => abs_path($config{destdir}),
-               url => $config{url},
-       );
-       print TEMPLATE $template->output;
-       close TEMPLATE;
-       $cgi="$estdir/".basename($config{cgiurl});
-       unlink($cgi);
-       symlink("/usr/lib/estraier/estseek.cgi", $cgi) ||
-               error("symlink $cgi: $!");
-} # }}}
-
-sub estcmd ($;@) { #{{{
-       my @params=split(' ', shift);
-       push @params, "-cl", "$config{wikistatedir}/hyperestraier";
-       if (@_) {
-               push @params, "-";
-       }
-       
-       my $pid=open(CHILD, "|-");
-       if ($pid) {
-               # parent
-               foreach (@_) {
-                       print CHILD "$_\n";
-               }
-               close(CHILD) || error("estcmd @params exited nonzero: $?");
-       }
-       else {
-               # child
-               open(STDOUT, "/dev/null"); # shut it up (closing won't work)
-               exec("estcmd", @params) || error("can't run estcmd");
-       }
-} #}}}
-
 sub refresh () { #{{{
        # find existing pages
        my %exists;
@@ -516,19 +463,15 @@ FILE:             foreach my $file (@files) {
                }
        }
 
-       if ($config{hyperestraier} && (%rendered || @del)) {
-               debug("updating hyperestraier search index");
-               if (%rendered) {
-                       estcmd("gather -cm -bc -cl -sd", 
-                               map { $config{destdir}."/".$renderedfiles{pagename($_)} }
-                               keys %rendered);
+       if (@del && exists $hooks{delete}) {
+               foreach my $id (keys %{$hooks{delete}}) {
+                       $hooks{delete}{$id}{call}->(@del);
                }
-               if (@del) {
-                       estcmd("purge -cl");
+       }
+       if (%rendered && exists $hooks{render}) {
+               foreach my $id (keys %{$hooks{render}}) {
+                       $hooks{render}{$id}{call}->(keys %rendered);
                }
-               
-               debug("generating hyperestraier cgi config");
-               estcfg();
        }
 } #}}}
 
index 9883b922a5514da91ce5d820dfe2da2bca148f06..786ba70ace16abfaaa02498e3afb7e39a74f321a 100644 (file)
@@ -21,15 +21,20 @@ sub setup_standard {
 
        if (! $config{refresh}) {
                debug("generating wrappers..");
+               my @wrappers=@{$setup{wrappers}};
+               delete $setup{wrappers};
                my %startconfig=(%config);
-               foreach my $wrapper (@{$setup{wrappers}}) {
+               foreach my $wrapper (@wrappers) {
                        %config=(%startconfig, verbose => 0, %setup, %{$wrapper});
                        checkconfig();
                        gen_wrapper();
                }
                %config=(%startconfig);
-               delete $config{wrappers};
        }
+       else {
+               delete $setup{wrappers};
+       }
+       
        foreach my $c (keys %setup) {
                if (defined $setup{$c}) {
                        if (! ref $setup{$c}) {
index ee547cefb9e7945ea12015a3197a2a79737e3fa7..52a7ca2c70e4ab05b45e5b3c2b852e43e57731f0 100644 (file)
@@ -51,6 +51,7 @@ EOF
        my $configstring=Data::Dumper->Dump([\%config], ['*config']);
        $configstring=~s/\\/\\\\/g;
        $configstring=~s/"/\\"/g;
+       $configstring=~s/\n/\\\n/g;
        
        open(OUT, ">$wrapper.c") || error("failed to write $wrapper.c: $!");;
        print OUT <<"EOF";
index 1b05f36e896492c0a595a7f84ab8dfc5b647f96b..130d1bd57fda7a6b3c2a9d798263dbc64211aebf 100644 (file)
@@ -5,6 +5,10 @@ ikiwiki (1.1) unstable; urgency=low
   be changed to set rcs => "svn"; if your setup file sets svn => 0
   then change it to use rcs => "" to disable svn.
 
+  The --hyperestraier switch is gone too. To enable searching, turn on the
+  search plugin, by passing --plugin=search or through the plugin setting in
+  the config file.
+
   You will need to rebuild your wiki when upgrading to this version.
   If you listed your wiki in /etc/ikiwiki/wikilist this will be done
   automatically.
index c072c237b3a3dbc7f600edcf9fab291d448f2e0d..02e78816dd0230715716faa4f100b0cab573af1f 100644 (file)
@@ -11,7 +11,7 @@ ikiwiki (1.1) UNRELEASED; urgency=low
   * Which means that more than one blog is now supported to appear on a
     single page. (With some limitations, like only the last one getting an
     rss file.)
-  * Added plugin system, currently only supporting for PreProcessorDirectives.
+  * Added a plugin system.
   * Added a pagecount plugin, enabled by default.
   * Support PreProcessorDirectives with no parameters, ie "[[pagecount ]]".
   * Fixed/optimised backlinks code, to avoid rebuilding pages to update
@@ -37,6 +37,8 @@ ikiwiki (1.1) UNRELEASED; urgency=low
   * Load whatever rcs module is specified, so new ones can be just dropped in
     as plugins and work. (Well, in theory.)
   * Add some basic docs about writing RCS modules.
+  * Broke search capability out into a plugin, removed the --hyperestraier
+    switch.
 
  -- Joey Hess <joeyh@debian.org>  Tue,  2 May 2006 14:13:59 -0400
 
index e208ee6317510ec341568739e31bf91d4f0e0903..e1246436ada3f165dc4eb7318921687755253da8 100644 (file)
@@ -1,3 +1,3 @@
-[Hyper Estraier](http://hyperestraier.sourceforge.net/) is a full text search engine. Ikiwiki can be configured to use it as the search engine for the wiki (see [[usage]]). This makes ikiwiki call Hyper Ertaier to update its index of pages each time a change is made to the wiki.
-
-It's possible to configure Hyper Estraier via one of ikiwiki's [[templates]].
\ No newline at end of file
+[Hyper Estraier](http://hyperestraier.sourceforge.net/) is a full text
+search engine. Ikiwiki can be configured to use it as the search engine for
+the wiki, using the [[search_plugin|plugins/search]].
index d6ca7bb0bfc27fbfae523e55e8e77b6d8f578185..3bc15891e285435bd664ae13b23b6b3fc3a628c5 100644 (file)
@@ -48,10 +48,8 @@ use IkiWiki::Setup::Standard {
        #anonok => 1,
        # Generate rss feeds for pages?
        rss => 1,
-       # Use the Hyper Estraier search engine?
-       #hyperestraier => 1,
        # Sanitize html?
        sanitize => 1,
        # To change the enabled plugins, edit this list
-       #plugin => [qw{pagecount inline brokenlinks}],
+       #plugin => [qw{pagecount inline brokenlinks hyperestraier}],
 }
diff --git a/doc/plugins/search.mdwn b/doc/plugins/search.mdwn
new file mode 100644 (file)
index 0000000..afeb0d4
--- /dev/null
@@ -0,0 +1,5 @@
+This plugin is included in ikiwiki, but is not enabled by default. It adds
+full text search to ikiwiki, using the [[HyperEstraier]] engine.
+
+It's possible to configure Hyper Estraier via one of ikiwiki's
+[[templates]].
index c30d799fdb9aa6a6020c19313eaad86779747c1b..eac72cdc728d46c3be2b77aece19ee447d40ddb3 100644 (file)
@@ -172,11 +172,6 @@ These options configure the wiki.
   Enables the use of the specified plugin in the wiki. See [[plugins]] for
   details. Note that plugin names are case sensative.
 
-* --hyperestraier
-
-  Enables use of the [[HyperEstraier]] search engine for full test page
-  searches.
-
 * --verbose
 
   Be vebose about what is being done.
diff --git a/ikiwiki b/ikiwiki
index 5b4972ab7797dec2b6cd6331dff8ccdb70031934..745dfddd4ca870376844d913516d5962e2682f8e 100755 (executable)
--- a/ikiwiki
+++ b/ikiwiki
@@ -34,7 +34,6 @@ sub getconfig () { #{{{
                        rebuild => 0,
                        refresh => 0,
                        getctime => 0,
-                       hyperestraier => 0,
                        wrapper => undef,
                        wrappermode => undef,
                        svnrepo => undef,
@@ -47,6 +46,7 @@ sub getconfig () { #{{{
                        adminuser => undef,
                        adminemail => undef,
                        plugin => [qw{inline}],
+                       headercontent => '',
                );
 
                eval q{use Getopt::Long};
@@ -61,7 +61,6 @@ sub getconfig () { #{{{
                        "rcs=s" => \$config{rcs},
                        "no-rcs" => sub { $config{rcs}="" },
                        "anonok!" => \$config{anonok},
-                       "hyperestraier" => \$config{hyperestraier},
                        "rss!" => \$config{rss},
                        "cgi!" => \$config{cgi},
                        "notify!" => \$config{notify},
@@ -104,6 +103,9 @@ sub getconfig () { #{{{
                # wrapper passes a full config structure in the environment
                # variable
                eval possibly_foolish_untaint($ENV{WRAPPED_OPTIONS});
+               if ($@) {
+                       error("WRAPPED_OPTIONS: $@");
+               }
                checkconfig();
        }
 } #}}}
index 4dc8e11394afa26da4d8d1f209d675d996fabbe4..5ac162b2d726a8dd4dc5a28718e50b64b8550cf2 100644 (file)
 </TMPL_LOOP>
 <TMPL_VAR TITLE>
 </h1>
-<TMPL_IF NAME="HYPERESTRAIERURL">
-<form method="get" action="<TMPL_VAR HYPERESTRAIERURL>" id="searchform">
-<div>
-<input type="text" name="phrase" value="" size="16" />
-<input type="hidden" name="enc" value="UTF-8" />
-<input type="hidden" name="do" value="hyperestraier" />
-</div>
-</form>
-</TMPL_IF>
+<TMPL_VAR HEADERCONTENT>
 </div>
 
 <div id="actions">