refactor template actions
authorJoey Hess <joey@kitenet.net>
Sat, 15 May 2010 00:20:41 +0000 (20:20 -0400)
committerJoey Hess <joey@kitenet.net>
Sat, 15 May 2010 00:20:41 +0000 (20:20 -0400)
IkiWiki.pm
IkiWiki/Render.pm

index 46c29abe38a045b813a8a32a632c3f97c729faa8..a42f56bf0c6d2320c7403af19618e3b65f5f966a 100644 (file)
@@ -1755,18 +1755,32 @@ sub misctemplate ($$;@) {
                html5 => $config{html5},
                @_,
        );
+
+       templateactions($template, "");
        
+       return $template->output;
+}
+
+sub templateactions ($$) {
+       my $template=shift;
+       my $page=shift;
+
+       my $have_actions=0;
        my @actions;
        run_hooks(pageactions => sub {
                push @actions, map { { action => $_ } } 
-                       grep { defined } shift->(page => "");
+                       grep { defined } shift->(page => $page);
        });
        $template->param(actions => \@actions);
-       if (@actions) {
-               $template->param(have_actions => 1);
+
+       if ($config{cgiurl} && exists $hooks{auth}) {
+               $template->param(prefsurl => cgiurl(do => "prefs"));
+               $have_actions=1;
        }
 
-       return $template->output;
+       if ($have_actions || @actions) {
+               $template->param(have_actions => 1);
+       }
 }
 
 sub hook (@) {
index 8b1b9aef4353daec5612c98d3b28dde58d832113..833fcaaff0d0412ce97faca6405a406c26fd4807 100644 (file)
@@ -84,19 +84,14 @@ sub genpage ($$) {
                $template=template('page.tmpl', 
                        blind_cache => 1);
        }
-       my $actions=0;
 
+       my $actions=0;
        if (length $config{cgiurl}) {
                if (IkiWiki->can("cgi_editpage")) {
                        $template->param(editurl => cgiurl(do => "edit", page => $page));
                        $actions++;
                }
-               if (exists $hooks{auth}) {
-                       $template->param(prefsurl => cgiurl(do => "prefs"));
-                       $actions++;
-               }
        }
-               
        if (defined $config{historyurl} && length $config{historyurl}) {
                my $u=$config{historyurl};
                $u=~s/\[\[file\]\]/$pagesources{$page}/g;
@@ -111,17 +106,10 @@ sub genpage ($$) {
                        $actions++;
                }
        }
-
-       my @actions;
-       run_hooks(pageactions => sub {
-               push @actions, map { { action => $_ } } 
-                       grep { defined } shift->(page => $page);
-       });
-       $template->param(actions => \@actions);
-
-       if ($actions || @actions) {
+       if ($actions) {
                $template->param(have_actions => 1);
        }
+       templateactions($template, $page);
 
        my @backlinks=sort { $a->{page} cmp $b->{page} } backlinks($page);
        my ($backlinks, $more_backlinks);