* Add an editcontent hook.

master
joey 2007-08-26 21:33:25 +00:00
parent 68db2dceb8
commit 6c89a635bb
7 changed files with 58 additions and 16 deletions

View File

@ -401,19 +401,27 @@ sub cgi_editpage ($$) { #{{{
return; return;
} }
elsif ($form->submitted eq "Preview") { elsif ($form->submitted eq "Preview") {
my $content=$form->field('editcontent');
run_hooks(editcontent => sub {
$content=shift->(
content => $content,
page => $page,
cgi => $q,
session => $session,
);
});
$form->tmpl_param("page_preview", $form->tmpl_param("page_preview",
htmlize($page, $type, htmlize($page, $type,
linkify($page, "", linkify($page, "",
preprocess($page, $page, preprocess($page, $page,
filter($page, $page, $form->field('editcontent')), 0, 1)))); filter($page, $page, $content), 0, 1))));
} }
elsif ($form->submitted eq "Save Page") { elsif ($form->submitted eq "Save Page") {
$form->tmpl_param("page_preview", ""); $form->tmpl_param("page_preview", "");
} }
$form->tmpl_param("page_conflict", ""); $form->tmpl_param("page_conflict", "");
if ($form->submitted ne "Save Page" || if ($form->submitted ne "Save Page" || ! $form->validate) {
! $form->validate) {
if ($form->field("do") eq "create") { if ($form->field("do") eq "create") {
my @page_locs; my @page_locs;
my $best_loc; my $best_loc;
@ -531,7 +539,14 @@ sub cgi_editpage ($$) { #{{{
} }
my $content=$form->field('editcontent'); my $content=$form->field('editcontent');
run_hooks(editcontent => sub {
$content=shift->(
content => $content,
page => $page,
cgi => $q,
session => $session,
);
});
$content=~s/\r\n/\n/g; $content=~s/\r\n/\n/g;
$content=~s/\r/\n/g; $content=~s/\r/\n/g;

View File

@ -25,6 +25,7 @@ sub import { #{{{
hook(type => "auth", id => "skeleton", call => \&auth); hook(type => "auth", id => "skeleton", call => \&auth);
hook(type => "sessioncgi", id => "skeleton", call => \&sessioncgi); hook(type => "sessioncgi", id => "skeleton", call => \&sessioncgi);
hook(type => "canedit", id => "skeleton", call => \&canedit); hook(type => "canedit", id => "skeleton", call => \&canedit);
hook(type => "editcontent", id => "skeleton", call => \&editcontent);
hook(type => "formbuilder_setup", id => "skeleton", call => \&formbuilder_setup); hook(type => "formbuilder_setup", id => "skeleton", call => \&formbuilder_setup);
hook(type => "formbuilder", id => "skeleton", call => \&formbuilder); hook(type => "formbuilder", id => "skeleton", call => \&formbuilder);
hook(type => "savestate", id => "skeleton", call => \&savestate); hook(type => "savestate", id => "skeleton", call => \&savestate);
@ -135,6 +136,14 @@ sub canedit ($$$) { #{{{
debug("skeleton plugin running in canedit"); debug("skeleton plugin running in canedit");
} #}}} } #}}}
sub editcontent ($$$) { #{{{
my %params=@_;
debug("skeleton plugin running in editcontent");
return $params{content};
} #}}}
sub formbuilder_setup (@) { #{{{ sub formbuilder_setup (@) { #{{{
my %params=@_; my %params=@_;

6
debian/changelog vendored
View File

@ -1,3 +1,9 @@
ikiwiki (2.6.2) UNRELEASED; urgency=low
* Add an editcontent hook.
-- Joey Hess <joeyh@debian.org> Sun, 26 Aug 2007 16:50:24 -0400
ikiwiki (2.6.1) unstable; urgency=low ikiwiki (2.6.1) unstable; urgency=low
* Ye olde brown paper bag. * Ye olde brown paper bag.

View File

@ -251,6 +251,17 @@ by this hook, the hook should return an error message for the user to see.
If the hook has no opinion about whether the edit can proceed, return If the hook has no opinion about whether the edit can proceed, return
`undef`, and the next plugin will be asked to decide. `undef`, and the next plugin will be asked to decide.
### editcontent
hook(type => "editcontent", id => "foo", call => \&editcontent);
This hook is called when a page is saved (or previewed) using the web
interface. It is passed named parameters: `content`, `page`, `cgi`, and
`session`. These are, respectively, the new page content as entered by the
user, the page name, a `CGI` object, and the user's `CGI::Session`.
It can modify the content as desired, and should return the content.
### formbuilder ### formbuilder
hook(type => "formbuilder_setup", id => "foo", call => \&formbuilder_setup); hook(type => "formbuilder_setup", id => "foo", call => \&formbuilder_setup);

View File

@ -6,8 +6,6 @@ Suggestions of ideas for plugins:
> web-server-specific code to list all users, and openid can't feasibly do so > web-server-specific code to list all users, and openid can't feasibly do so
> at all. --[[JoshTriplett]] > at all. --[[JoshTriplett]]
* [[sigs]] ?
* Support [[RecentChanges]] as a regular page containing a plugin that * Support [[RecentChanges]] as a regular page containing a plugin that
updates each time there is a change, and statically builds the recent updates each time there is a change, and statically builds the recent
changes list. (Would this be too expensive/inflexible? There might be changes list. (Would this be too expensive/inflexible? There might be

View File

@ -1,8 +1,8 @@
Need a way to sign name in page that's easier to type than "--\[[Joey]]" Need a way to sign name in page that's easier to type than "--\[[Joey]]"
and that includes the date. and that includes the date.
What syntax do other wikis use for this? I'm considering "\[[--]]" (with What syntax do other wikis use for this? I'm considering "\[[--]]"
spaces removed) as it has a nice nmemonic. as it has a nice nmemonic.
OTOH, adding additional syntax for this would be counter to one of the OTOH, adding additional syntax for this would be counter to one of the
design goals for ikiwiki: keeping as much markup as possible out of the design goals for ikiwiki: keeping as much markup as possible out of the
@ -15,7 +15,11 @@ out svn commits.
--- ---
Alternate idea: Make a sig plugin, which would expand --Name to Or, just make a sig plugin that expands `~~~~` and `~~~` as wikipedia does.
--[[user/Name]] (the "user/" bit would be configurable). This would be very The plugin could be an editcontent hook, so it would take effect only when a
easy to do, although it would need to try to avoid false positives, such page was edited via the web.
as `--foo` in C code..
I tried implementing this, but to make the link to the user, I wanted to
use `userlink()`, which generates html. But the right thing to generate is
really a wikilink. Except for openid, when the best thing to generate is a
markdown link. Except when the page isn't formatted in markdown..

View File

@ -67,10 +67,9 @@ changes.diff:
prefer a translated underlay, and use the english version of untranslated prefer a translated underlay, and use the english version of untranslated
pages, for example. pages, for example.
* When is the WIKIWYG variable in misc.tmpl used? * When is the WIKIWYG variable in misc.tmpl used?
* I wish there were a good way to move the code to handle saving a part of * Could you move the code that handles saving a page of the page into the
a page into the plugin. But there doesn't seem to be one that's any plugin? I just added an editcontent hook, which should allow you to do
cleaner than keeping the code where it is. So I'll probably just apply that.
that hunk.
* Your patch exports run_hooks, but I don't see the plugin using that. * Your patch exports run_hooks, but I don't see the plugin using that.
* I don't know about exporting pagetitle. So far, only the inline plugin * I don't know about exporting pagetitle. So far, only the inline plugin
needs to use that function, I generally only export things after it's needs to use that function, I generally only export things after it's