]> sipb.mit.edu Git - ikiwiki.git/commitdiff
Add ACTIONS variable to page.tmpl, which allows plugins to add arbitrary links to...
authorJoey Hess <joey@kitenet.net>
Mon, 3 May 2010 16:15:40 +0000 (12:15 -0400)
committerJoey Hess <joey@kitenet.net>
Mon, 3 May 2010 16:46:52 +0000 (12:46 -0400)
(COMMENTSLINK and DISCUSSIONLINK could be folded into this, but are kept
separate for now to avoid breaking modified templates.)

IkiWiki/Plugin/skeleton.pm.example
IkiWiki/Render.pm
debian/changelog
doc/plugins/write.mdwn
templates/page.tmpl

index ddf2996d64ace9c2dce9a6f9e6222f041de85e98..a404e24af074ad3be5b75f7b9b2c0cf5e4bf7393 100644 (file)
@@ -24,6 +24,7 @@ sub import {
        hook(type => "format", id => "skeleton", call => \&format);
        hook(type => "pagetemplate", id => "skeleton", call => \&pagetemplate);
        hook(type => "templatefile", id => "skeleton", call => \&templatefile);
+       hook(type => "pageactions", id => "skeleton", call => \&pageactions);
        hook(type => "delete", id => "skeleton", call => \&delete);
        hook(type => "change", id => "skeleton", call => \&change);
        hook(type => "cgi", id => "skeleton", call => \&cgi);
@@ -146,6 +147,14 @@ sub templatefile (@) {
        debug("skeleton plugin running as a templatefile hook");
 }
 
+sub pageactions (@) {
+       my %params=@_;
+       my $page=$params{page};
+
+       debug("skeleton plugin running as a pageactions hook");
+       return ();
+}
+
 sub delete (@) {
        my @files=@_;
 
index cf6943e7d705c8d4fb3b9fd40f74af5d909c6897..a824ba5396e489714d069148878d5c3ea95a9868 100644 (file)
@@ -112,7 +112,14 @@ sub genpage ($$) {
                }
        }
 
-       if ($actions) {
+       my @actions;
+       run_hooks(pageactions => sub {
+               push @actions, map { { action => $_ } } 
+                       grep { defined } shift->(page => $page);
+       });
+       $template->param(actions => \@actions);
+
+       if ($actions || @actions) {
                $template->param(have_actions => 1);
        }
 
index 789fda1cea207ac3df60fae704303e9008fcb7c6..e03375bd3edec7d08577788efc5ecea9f4957bf3 100644 (file)
@@ -6,6 +6,10 @@ ikiwiki (3.20100502) UNRELEASED; urgency=low
   * In html5 mode, use all the nice new semantic tags. Care was taken
     to not change the id/class named used in the CSS, so only CSS
     that refers to tag types needed to be changed.
+  * Add ACTIONS variable to page.tmpl, which allows plugins to add arbitrary
+    links to the action bar without modifying the template further.
+    (COMMENTSLINK and DISCUSSIONLINK could be folded into this, but
+    are kept separate for now to avoid breaking modified templates.)
 
  -- Joey Hess <joeyh@debian.org>  Sun, 02 May 2010 13:22:50 -0400
 
index 5e7042c3b5d22c9a90a0c63a02a7d8b1615f81d2..3b1d770ebcd951004866c9cb1002088fa2eb6ab8 100644 (file)
@@ -319,6 +319,15 @@ should return the name of the template file to use (relative to the
 template directory), or undef if it doesn't want to change the default
 ("page.tmpl").
 
+### pageactions
+
+       hook(type => "pageactions", id => "foo", call => \&pageactions);
+
+This hook allows plugins to add arbitrary actions to the action bar on a
+page (next to Edit, RecentChanges, etc). The hook is passed a "page"
+parameter, and can return a list of html fragments to add to the action
+bar.
+
 ### sanitize
 
        hook(type => "sanitize", id => "foo", call => \&sanitize);
index 195ce788683d1308586595a9a9efac346d4a6d31..8a9911fae05a20645978734dab37e8c5cbc9dbf5 100644 (file)
 <TMPL_IF NAME="PREFSURL">
 <li><a href="<TMPL_VAR PREFSURL>">Preferences</a></li>
 </TMPL_IF>
+<TMPL_IF NAME="ACTIONS">
+<TMPL_LOOP NAME="ACTIONS">
+<li><TMPL_VAR ACTION></li>
+</TMPL_LOOP>
+</TMPL_IF>
 <TMPL_IF NAME="COMMENTSLINK">
-<li><TMPL_VAR COMMENTSLINK><br /></li>
+<li><TMPL_VAR COMMENTSLINK></li>
 <TMPL_ELSE>
 <TMPL_IF NAME="DISCUSSIONLINK">
-<li><TMPL_VAR DISCUSSIONLINK><br /></li>
+<li><TMPL_VAR DISCUSSIONLINK></li>
 </TMPL_IF>
 </TMPL_IF>
 </ul>