]> sipb.mit.edu Git - ikiwiki.git/commitdiff
* Add an editcontent hook.
authorjoey <joey@0fa5a96a-9a0e-0410-b3b2-a0fd24251071>
Sun, 26 Aug 2007 21:33:25 +0000 (21:33 +0000)
committerjoey <joey@0fa5a96a-9a0e-0410-b3b2-a0fd24251071>
Sun, 26 Aug 2007 21:33:25 +0000 (21:33 +0000)
IkiWiki/CGI.pm
IkiWiki/Plugin/skeleton.pm
debian/changelog
doc/plugins/write.mdwn
doc/todo/plugin.mdwn
doc/todo/sigs.mdwn
doc/todo/wikiwyg/discussion.mdwn

index c800ddf6eab22d4d0b0fa9b91cfb3f7fcbd4f3a4..82b619592e1d9b916b0d9a1037df919edfe8502d 100644 (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;
 
index 72e0887702443c3bbd9eaa95e8d8b7749c54b589..0e7f2e01400d899816e2c94f3be0a1a3f67dd7be 100644 (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=@_;
        
index 09833ac062bba4c78bfcb72ffe896e6be4ace325..8552edfd147c6890182a0174722c91b5a78d2e2f 100644 (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.
index d09367f1b1be5784d136ca9b130de4de39431cfd..0c192eb6412dd1c5005deb562e7c01d9c01f2220 100644 (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);
index 4d034a81463dee48885ac912e67328fc261b0c00..0d702975f01ca227faa64b5171d958fc39b4f271 100644 (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
index f3ec2cbe8e65b710b7dbfbb84ab419fee7f09487..f4f8edf13f4ed85b052ab78375a9124dfa0b9ca9 100644 (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..
index 33554e12c374a575e2dddb93172be7789a364ddf..44d282a5a0a0e1b8cbe102152e78fe43cf629a3e 100644 (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