From eeb5011b56a0fb5b0f570070e62a1f43fbf0ef83 Mon Sep 17 00:00:00 2001 From: Petr Baudis Date: Wed, 4 Nov 2009 01:04:13 +0100 Subject: [PATCH] gitweb: polish the content tags support This patch integrates the tag filtering CGI parameter into the framework for parameter passing, dropping 'by_tag' and instead using query name 't' and symbolic name 'ctag_filter'. Compatibility support for 'by_tag' query name is retained. This means that content tag links are now created using $cgi->a() and the href() method, and that they now point to the proper action; project_list in case of global content tags, forks in case of per-fork content tags. Also any other arguments like sorting order of projects are replayed within the links. This patch also restores the ability to add tags if the ctags feature is set to a POST action rather than a positive integer. Signed-off-by: Petr Baudis Signed-off-by: Kyle J. McKay --- gitweb/gitweb.perl | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl index 7a5b23acf2..48bf7bef6e 100755 --- a/gitweb/gitweb.perl +++ b/gitweb/gitweb.perl @@ -814,6 +814,7 @@ our @cgi_param_mapping = ( searchtext => "s", searchtype => "st", snapshot_format => "sf", + ctag_filter => 't', extra_options => "opt", search_use_regexp => "sr", ctag => "by_tag", @@ -880,6 +881,11 @@ sub evaluate_query_params { $input_params{$name} = decode_utf8($cgi->param($symbol)); } } + + # Backwards compatibility - by_tag= <=> t= + if ($input_params{'ctag'}) { + $input_params{'ctag_filter'} = $input_params{'ctag'}; + } } # now read PATH_INFO and update the parameter list for missing parameters @@ -2953,7 +2959,7 @@ sub git_gather_all_ctags { } sub git_populate_project_tagcloud { - my $ctags = shift; + my ($ctags, $action) = @_; # First, merge different-cased tags; tags vote on casing my %ctags_lc; @@ -2967,7 +2973,7 @@ sub git_populate_project_tagcloud { } my $cloud; - my $matched = $input_params{'ctag'}; + my $matched = $input_params{'ctag_filter'}; if (eval { require HTML::TagCloud; 1; }) { $cloud = HTML::TagCloud->new; foreach my $ctag (sort keys %ctags_lc) { @@ -2980,7 +2986,7 @@ sub git_populate_project_tagcloud { if (defined $matched && $matched eq $ctag) { $title = qq($title); } - $cloud->add($title, href(project=>undef, ctag=>$ctag), + $cloud->add($title, href(-replay=>1, action=>$action, ctag_filter=>$ctag), $ctags_lc{$ctag}->{count}); } } else { @@ -2992,7 +2998,7 @@ sub git_populate_project_tagcloud { } $cloud->{$ctag}{count} = $ctags_lc{$ctag}->{count}; $cloud->{$ctag}{ctag} = - $cgi->a({-href=>href(project=>undef, ctag=>$ctag)}, $title); + $cgi->a({-href=>href(-replay=>1, action=>$action, ctag_filter=>$ctag)}, $title); } } return $cloud; @@ -5738,12 +5744,12 @@ sub git_project_list_rows { sub git_project_list_body { # actually uses global variable $project - my ($projlist, $order, $from, $to, $extra, $no_header) = @_; + my ($projlist, $order, $from, $to, $extra, $no_header, $ctags_action) = @_; my @projects = @$projlist; my $check_forks = gitweb_check_feature('forks'); my $show_ctags = gitweb_check_feature('ctags'); - my $tagfilter = $show_ctags ? $input_params{'ctag'} : undef; + my $tagfilter = $show_ctags ? $input_params{'ctag_filter'} : undef; $check_forks = undef if ($tagfilter || $search_regexp); @@ -5778,7 +5784,7 @@ sub git_project_list_body { if ($show_ctags) { my $ctags = git_gather_all_ctags(\@projects); - my $cloud = git_populate_project_tagcloud($ctags); + my $cloud = git_populate_project_tagcloud($ctags, $ctags_action||'project_list'); print git_show_project_tagcloud($cloud, 64); } @@ -6480,7 +6486,7 @@ sub git_forks { git_header_html(); git_print_page_nav('',''); git_print_header_div('summary', "$project forks"); - git_project_list_body(\@list, $order); + git_project_list_body(\@list, $order, undef, undef, undef, undef, 'forks'); git_footer_html(); } @@ -6570,10 +6576,16 @@ sub git_summary { my $ctags = git_get_project_ctags($project); if (%$ctags) { # without ability to add tags, don't show if there are none - my $cloud = git_populate_project_tagcloud($ctags); + my $cloud = git_populate_project_tagcloud($ctags, 'project_list'); print "" . - "content tags" . - "".git_show_project_tagcloud($cloud, 48)."" . + "Content tags:
"; + print "\n" unless %$ctags; + print "
" . + "" . + "Add:
" + unless $show_ctags =~ /^\d+$/; + print "\n" if %$ctags; + print git_show_project_tagcloud($cloud, 48)."" . "\n"; } } @@ -6623,7 +6635,7 @@ sub git_summary { git_project_list_body(\@forklist, 'age', 0, 15, $#forklist <= 15 ? undef : $cgi->a({-href => href(action=>"forks")}, "..."), - 'no_header'); + 'no_header', 'forks'); } git_footer_html(); -- 2.11.4.GIT