diff options
Diffstat (limited to 'IkiWiki')
-rw-r--r-- | IkiWiki/CGI.pm | 19 | ||||
-rw-r--r-- | IkiWiki/Plugin/search.pm | 122 | ||||
-rw-r--r-- | IkiWiki/Plugin/skeleton.pm | 33 | ||||
-rw-r--r-- | IkiWiki/Render.pm | 73 | ||||
-rw-r--r-- | IkiWiki/Setup/Standard.pm | 9 | ||||
-rw-r--r-- | IkiWiki/Wrapper.pm | 1 |
6 files changed, 177 insertions, 80 deletions
diff --git a/IkiWiki/CGI.pm b/IkiWiki/CGI.pm index e219c8c1c..15e86651d 100644 --- a/IkiWiki/CGI.pm +++ b/IkiWiki/CGI.pm @@ -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 index 000000000..c71fef76e --- /dev/null +++ b/IkiWiki/Plugin/search.pm @@ -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 diff --git a/IkiWiki/Plugin/skeleton.pm b/IkiWiki/Plugin/skeleton.pm index 89308c45f..d6d8cc0ed 100644 --- a/IkiWiki/Plugin/skeleton.pm +++ b/IkiWiki/Plugin/skeleton.pm @@ -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 diff --git a/IkiWiki/Render.pm b/IkiWiki/Render.pm index f90f16335..a4efa0b74 100644 --- a/IkiWiki/Render.pm +++ b/IkiWiki/Render.pm @@ -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(); } } #}}} diff --git a/IkiWiki/Setup/Standard.pm b/IkiWiki/Setup/Standard.pm index 9883b922a..786ba70ac 100644 --- a/IkiWiki/Setup/Standard.pm +++ b/IkiWiki/Setup/Standard.pm @@ -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}) { diff --git a/IkiWiki/Wrapper.pm b/IkiWiki/Wrapper.pm index ee547cefb..52a7ca2c7 100644 --- a/IkiWiki/Wrapper.pm +++ b/IkiWiki/Wrapper.pm @@ -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"; |