@matheusbsbs / matheus-bagliano / commits / d627f68fbb
Fork 0

gitweb: Add support for extending the action bar with custom links

This makes it possible to easily extend gitweb with custom functionality, e.g. git-browser or web-based repository administration system like the repo.or.cz/Girocco duct tape. Signed-off-by: Petr Baudis <pasky@suse.cz> Signed-off-by: Shawn O. Pearce <spearce@spearce.org>

Petr Baudis committed Oct 2, 2008 at 16:36 UTC d627f68fbbe0480337cd56cce442ed8c1efa230e
1 file changed +34 -1
gitweb/gitweb.perl
+34 -1
@@ -275,6 +275,26 @@ our %feature = (
275 'forks' => {
276 'override' => 0,
277 'default' => [0]},
278 +
279 + # Insert custom links to the action bar of all project pages.
280 + # This enables you mainly to link to third-party scripts integrating
281 + # into gitweb; e.g. git-browser for graphical history representation
282 + # or custom web-based repository administration interface.
283 +
284 + # The 'default' value consists of a list of triplets in the form
285 + # (label, link, position) where position is the label after which
286 + # to inster the link and link is a format string where %n expands
287 + # to the project name, %f to the project path within the filesystem,
288 + # %h to the current hash (h gitweb parameter) and %b to the current
289 + # hash base (hb gitweb parameter).
290 +
291 + # To enable system wide have in $GITWEB_CONFIG e.g.
292 + # $feature{'actions'}{'default'} = [('graphiclog',
293 + # '/git-browser/by-commit.html?r=%n', 'summary')];
294 + # Project specific override is not supported.
295 + 'actions' => {
296 + 'override' => 0,
297 + 'default' => []},
298 );
299
300 sub gitweb_check_feature {
@@ -2757,13 +2777,26 @@ sub git_print_page_nav {
2777 }
2778 }
2779 }
2780 +
2781 $arg{'tree'}{'hash'} = $treehead if defined $treehead;
2782 $arg{'tree'}{'hash_base'} = $treebase if defined $treebase;
2783
2784 + my @actions = gitweb_check_feature('actions');
2785 + while (@actions) {
2786 + my ($label, $link, $pos) = (shift(@actions), shift(@actions), shift(@actions));
2787 + @navs = map { $_ eq $pos ? ($_, $label) : $_ } @navs;
2788 + # munch munch
2789 + $link =~ s#%n#$project#g;
2790 + $link =~ s#%f#$git_dir#g;
2791 + $treehead ? $link =~ s#%h#$treehead#g : $link =~ s#%h##g;
2792 + $treebase ? $link =~ s#%b#$treebase#g : $link =~ s#%b##g;
2793 + $arg{$label}{'_href'} = $link;
2794 + }
2795 +
2796 print "<div class=\"page_nav\">\n" .
2797 (join " | ",
2798 map { $_ eq $current ?
2766 - $_ : $cgi->a({-href => href(%{$arg{$_}})}, "$_")
2799 + $_ : $cgi->a({-href => ($arg{$_}{_href} ? $arg{$_}{_href} : href(%{$arg{$_}}))}, "$_")
2800 } @navs);
2801 print "<br/>\n$extra<br/>\n" .
2802 "</div>\n";