* Add a run_hooks function for the common task of running all hooks of a

given type.
* Add a savestate hook.
* Don't put blog post forms on pages if there's no cgiurl set.
* Reformat front page.
master
joey 2006-07-30 00:20:11 +00:00
parent 584fe78075
commit ab75c0323b
10 changed files with 82 additions and 67 deletions

View File

@ -93,11 +93,7 @@ sub checkconfig () { #{{{
require IkiWiki::Rcs::Stub; require IkiWiki::Rcs::Stub;
} }
if (exists $hooks{checkconfig}) { run_hooks(checkconfig => sub { shift->() });
foreach my $id (keys %{$hooks{checkconfig}}) {
$hooks{checkconfig}{$id}{call}->();
}
}
} #}}} } #}}}
sub loadplugins () { #{{{ sub loadplugins () { #{{{
@ -503,4 +499,17 @@ sub hook (@) { # {{{
$hooks{$param{type}}{$param{id}}=\%param; $hooks{$param{type}}{$param{id}}=\%param;
} # }}} } # }}}
sub run_hooks ($$) { # {{{
# Calls the given sub for each hook of the given type,
# passing it the hook function to call.
my $type=shift;
my $sub=shift;
if (exists $hooks{$type}) {
foreach my $id (keys %{$hooks{$type}}) {
$sub->($hooks{$type}{$id}{call});
}
}
} #}}}
1 1

View File

@ -567,11 +567,7 @@ sub cgi () { #{{{
my $q=CGI->new; my $q=CGI->new;
if (exists $hooks{cgi}) { run_hooks(cgi => sub { shift->($q) });
foreach my $id (keys %{$hooks{cgi}}) {
$hooks{cgi}{$id}{call}->($q);
}
}
my $do=$q->param('do'); my $do=$q->param('do');
if (! defined $do || ! length $do) { if (! defined $do || ! length $do) {

View File

@ -58,7 +58,7 @@ sub preprocess_inline (@) { #{{{
my $ret=""; my $ret="";
if (exists $params{rootpage}) { if (exists $params{rootpage} && $config{cgiurl}) {
# Add a blog post form, with a rss link button. # Add a blog post form, with a rss link button.
my $formtemplate=template("blogpost.tmpl", blind_cache => 1); my $formtemplate=template("blogpost.tmpl", blind_cache => 1);
$formtemplate->param(cgiurl => $config{cgiurl}); $formtemplate->param(cgiurl => $config{cgiurl});
@ -88,15 +88,10 @@ sub preprocess_inline (@) { #{{{
if $params{archive} eq "no"; if $params{archive} eq "no";
$template->param(ctime => displaytime($pagectime{$page})); $template->param(ctime => displaytime($pagectime{$page}));
if (exists $hooks{pagetemplate}) { run_hooks(pagetemplate => sub {
foreach my $id (keys %{$hooks{pagetemplate}}) { shift->(page => $page, destpage => $params{page},
$hooks{pagetemplate}{$id}{call}->( template => $template,);
page => $page, });
destpage => $params{page},
template => $template,
);
}
}
$ret.=$template->output; $ret.=$template->output;
$template->clear_params; $template->clear_params;
@ -181,13 +176,10 @@ sub genrss ($@) { #{{{
items => \@items, items => \@items,
); );
foreach my $id (keys %{$hooks{pagetemplate}}) { run_hooks(pagetemplate => sub {
$hooks{pagetemplate}{$id}{call}->( shift->(page => $page, destpage => $page,
page => $page, template => $template);
destpage => $page, });
template => $template,
);
}
return $template->output; return $template->output;
} #}}} } #}}}

View File

@ -29,6 +29,8 @@ sub import { #{{{
call => \&change); call => \&change);
IkiWiki::hook(type => "cgi", id => "skeleton", IkiWiki::hook(type => "cgi", id => "skeleton",
call => \&cgi); call => \&cgi);
IkiWiki::hook(type => "cgi", id => "savestate",
call => \&savestate);
} # }}} } # }}}
sub getopt () { #{{{ sub getopt () { #{{{
@ -95,4 +97,8 @@ sub cgi ($) { #{{{
IkiWiki::debug("skeleton plugin running in cgi"); IkiWiki::debug("skeleton plugin running in cgi");
} #}}} } #}}}
sub savestate () { #{{{
IkiWiki::debug("skeleton plugin running in savestate");
} #}}}
1 1

View File

@ -31,11 +31,9 @@ sub htmlize ($$) { #{{{
error("htmlization of $type not supported"); error("htmlization of $type not supported");
} }
if (exists $hooks{sanitize}) { run_hooks(sanitize => sub {
foreach my $id (keys %{$hooks{sanitize}}) { $content=shift->($content);
$content=$hooks{sanitize}{$id}{call}->($content); });
}
}
return $content; return $content;
} #}}} } #}}}
@ -206,15 +204,9 @@ sub genpage ($$$) { #{{{
styleurl => styleurl($page), styleurl => styleurl($page),
); );
if (exists $hooks{pagetemplate}) { run_hooks(pagetemplate => sub {
foreach my $id (keys %{$hooks{pagetemplate}}) { shift->(page => $page, destpage => $page, template => $template);
$hooks{pagetemplate}{$id}{call}->( });
page => $page,
destpage => $page,
template => $template,
);
}
}
return $template->output; return $template->output;
} #}}} } #}}}
@ -268,14 +260,9 @@ sub filter ($$) {
my $page=shift; my $page=shift;
my $content=shift; my $content=shift;
if (exists $hooks{filter}) { run_hooks(filter => sub {
foreach my $id (keys %{$hooks{filter}}) { $content=shift->(page => $page, content => $content);
$content=$hooks{filter}{$id}{call}->( });
page => $page,
content => $content
);
}
}
return $content; return $content;
} }
@ -496,15 +483,11 @@ FILE: foreach my $file (@files) {
} }
} }
if (@del && exists $hooks{delete}) { if (@del) {
foreach my $id (keys %{$hooks{delete}}) { run_hooks(delete => sub { shift->(@del) });
$hooks{delete}{$id}{call}->(@del);
}
} }
if (%rendered && exists $hooks{change}) { if (%rendered) {
foreach my $id (keys %{$hooks{change}}) { run_hooks(change => sub { shift->(keys %rendered) });
$hooks{change}{$id}{call}->(keys %rendered);
}
} }
} #}}} } #}}}

10
debian/changelog vendored
View File

@ -1,3 +1,13 @@
ikiwiki (1.13) UNRELEASED; urgency=low
* Add a run_hooks function for the common task of running all hooks of a
given type.
* Add a savestate hook.
* Don't put blog post forms on pages if there's no cgiurl set.
* Reformat front page.
-- Joey Hess <joeyh@debian.org> Sat, 29 Jul 2006 20:10:51 -0400
ikiwiki (1.12) unstable; urgency=low ikiwiki (1.12) unstable; urgency=low
"Viva l'Italia!" "Viva l'Italia!"

View File

@ -4,15 +4,23 @@ into html pages suitable for publishing on a website. Unlike a traditional
wiki, ikiwiki does not have its own means of storing page history. wiki, ikiwiki does not have its own means of storing page history.
Instead it can use [[Subversion]] (or [[Git]]). Instead it can use [[Subversion]] (or [[Git]]).
* [[News]] is a blog (built using ikiwiki) of news items about ikiwiki. It's the best way to find out when there's a new version to [[Download]]. * [[News]] is a blog (built using ikiwiki) of news items about ikiwiki.
It's the best way to find out when there's a new version to [[Download]].
* See [[Features]] for a list of ikiwiki's features. [[RoadMap]], [[TODO]] and [[bugs]] might also be of interest. Feel free to post your thoughts about ikiwiki to [[Discussion]]. * See [[Features]] for a list of ikiwiki's features. [[RoadMap]], [[TODO]]
and [[bugs]] might also be of interest. Feel free to post your thoughts
about ikiwiki to [[Discussion]].
* [[Setup]] has a tutorial for setting up ikiwiki, and [[Usage]] documents the parameters and usage of the ikiwiki program. If you use ikiwiki, please add your wiki to [[IkiWikiUsers]]. * [[Setup]] has a tutorial for setting up ikiwiki, and [[Usage]] documents
the parameters and usage of the ikiwiki program. If you use ikiwiki,
please add your wiki to [[IkiWikiUsers]].
* [[Security]] lists potential security problems. ikiwiki is still being developed, and is being written with security as a priority, so don't expect things to stay in this list for long. * [[Security]] lists potential security problems. ikiwiki is still being
developed, and is being written with security as a priority, so don't
expect things to stay in this list for long.
* Developers, please document any ikiwiki patches you have in the [[PatchQueue]]. * Developers, please document any ikiwiki patches you have in the
[[PatchQueue]].
All wikis are supposed to have a [[SandBox]], so this one does too. All wikis are supposed to have a [[SandBox]], so this one does too.

View File

@ -157,6 +157,14 @@ called in turn, and passed a CGI object. The hook should examine the
parameters, and if it will handle this CGI request, output a page and parameters, and if it will handle this CGI request, output a page and
terminate the program. terminate the program.
## savestate
IkiWiki::hook(type => "savestate", id => "foo", call => \&savestate);
This hook is called wheneven ikiwiki normally saves its state, just before
the state is saved. The function can save other state, modify values before
they're saved, etc.
# Wiki configuration # Wiki configuration
A plugin can access the wiki's configuration via the `%IkiWiki::config` A plugin can access the wiki's configuration via the `%IkiWiki::config`

View File

@ -15,3 +15,10 @@ poor-man's news aggregator.
better would be to use preprocessor directives in a wiki page, probably better would be to use preprocessor directives in a wiki page, probably
the same page that inlines all the pages together. the same page that inlines all the pages together.
* Where to store when a feed was last pulled? * Where to store when a feed was last pulled?
So I need:
* A way to store info from the preprocessor directives about what pages
to pull and expiry.
* A way to store info on last pull time, guids, etc.
* Switch for a mode that a) pulls b) expires old c) rebuilds wiki (for cron)

View File

@ -68,11 +68,7 @@ sub getconfig () { #{{{
if (! $config{setup}) { if (! $config{setup}) {
loadplugins(); loadplugins();
if (exists $hooks{getopt}) { run_hooks(getopt => sub { shift->() });
foreach my $id (keys %{$hooks{getopt}}) {
$hooks{getopt}{$id}{call}->();
}
}
if (grep /^-/, @ARGV) { if (grep /^-/, @ARGV) {
print STDERR "Unknown option: $_\n" print STDERR "Unknown option: $_\n"
foreach grep /^-/, @ARGV; foreach grep /^-/, @ARGV;