* 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;
}
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",
htmlize($page, $type,
linkify($page, "",
preprocess($page, $page,
filter($page, $page, $form->field('editcontent')), 0, 1))));
filter($page, $page, $content), 0, 1))));
}
elsif ($form->submitted eq "Save Page") {
$form->tmpl_param("page_preview", "");
}
$form->tmpl_param("page_conflict", "");
if ($form->submitted ne "Save Page" ||
! $form->validate) {
if ($form->submitted ne "Save Page" || ! $form->validate) {
if ($form->field("do") eq "create") {
my @page_locs;
my $best_loc;
@ -531,7 +539,14 @@ sub cgi_editpage ($$) { #{{{
}
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/g;

View File

@ -25,6 +25,7 @@ sub import { #{{{
hook(type => "auth", id => "skeleton", call => \&auth);
hook(type => "sessioncgi", id => "skeleton", call => \&sessioncgi);
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", id => "skeleton", call => \&formbuilder);
hook(type => "savestate", id => "skeleton", call => \&savestate);
@ -135,6 +136,14 @@ sub canedit ($$$) { #{{{
debug("skeleton plugin running in canedit");
} #}}}
sub editcontent ($$$) { #{{{
my %params=@_;
debug("skeleton plugin running in editcontent");
return $params{content};
} #}}}
sub formbuilder_setup (@) { #{{{
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
* 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
`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
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
> at all. --[[JoshTriplett]]
* [[sigs]] ?
* Support [[RecentChanges]] as a regular page containing a plugin that
updates each time there is a change, and statically builds the recent
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]]"
and that includes the date.
What syntax do other wikis use for this? I'm considering "\[[--]]" (with
spaces removed) as it has a nice nmemonic.
What syntax do other wikis use for this? I'm considering "\[[--]]"
as it has a nice nmemonic.
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
@ -15,7 +15,11 @@ out svn commits.
---
Alternate idea: Make a sig plugin, which would expand --Name to
--[[user/Name]] (the "user/" bit would be configurable). This would be very
easy to do, although it would need to try to avoid false positives, such
as `--foo` in C code..
Or, just make a sig plugin that expands `~~~~` and `~~~` as wikipedia does.
The plugin could be an editcontent hook, so it would take effect only when a
page was edited via the web.
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
pages, for example.
* 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
a page into the plugin. But there doesn't seem to be one that's any
cleaner than keeping the code where it is. So I'll probably just apply
that hunk.
* Could you move the code that handles saving a page of the page into the
plugin? I just added an editcontent hook, which should allow you to do
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
needs to use that function, I generally only export things after it's