gitweb: add project_filter to limit project list to a subdirectory

This commit changes the project listing views (project_list, project_index and opml) to limit the output to only projects in a subdirectory if the new optional parameter ?pf=directory name is used. The implementation of the filter reuses the implementation used for the 'forks' action (i.e. listing all projects within that directory from the projects list file (GITWEB_LIST) or only projects in the given subdirectory of the project root directory without a projects list file). Reusing $project instead of adding a new parameter would have been nicer from a UI point-of-view (including PATH_INFO support) but would complicate the $project validating code that is currently being used to ensure nothing is exported that should not be viewable. Signed-off-by: Bernhard R. Link <brlink@debian.org> Acked-by: Jakub Narebski <jnareb@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Bernhard R. Link committed Jan 30, 2012 at 21:07 UTC 19d2d23998bba7c7f0ee87451ddbbf8906381939
1 file changed +25 -6
gitweb/gitweb.perl
+25 -6
@@ -760,6 +760,7 @@ our @cgi_param_mapping = (
760 search_use_regexp => "sr",
761 ctag => "by_tag",
762 diff_style => "ds",
763 + project_filter => "pf",
764 # this must be last entry (for manipulation from JavaScript)
765 javascript => "js"
766 );
@@ -976,7 +977,7 @@ sub evaluate_path_info {
977
978 our ($action, $project, $file_name, $file_parent, $hash, $hash_parent, $hash_base,
979 $hash_parent_base, @extra_options, $page, $searchtype, $search_use_regexp,
979 - $searchtext, $search_regexp);
980 + $searchtext, $search_regexp, $project_filter);
981 sub evaluate_and_validate_params {
982 our $action = $input_params{'action'};
983 if (defined $action) {
@@ -994,6 +995,13 @@ sub evaluate_and_validate_params {
995 }
996 }
997
998 + our $project_filter = $input_params{'project_filter'};
999 + if (defined $project_filter) {
1000 + if (!validate_pathname($project_filter)) {
1001 + die_error(404, "Invalid project_filter parameter");
1002 + }
1003 + }
1004 +
1005 our $file_name = $input_params{'file_name'};
1006 if (defined $file_name) {
1007 if (!validate_pathname($file_name)) {
@@ -3732,7 +3740,12 @@ sub run_highlighter {
3740 sub get_page_title {
3741 my $title = to_utf8($site_name);
3742
3735 - return $title unless (defined $project);
3743 + unless (defined $project) {
3744 + if (defined $project_filter) {
3745 + $title .= " - " . to_utf8($project_filter);
3746 + }
3747 + return $title;
3748 + }
3749 $title .= " - " . to_utf8($project);
3750
3751 return $title unless (defined $action);
@@ -5982,7 +5995,7 @@ sub git_project_list {
5995 die_error(400, "Unknown order parameter");
5996 }
5997
5985 - my @list = git_get_projects_list();
5998 + my @list = git_get_projects_list($project_filter, $strict_export);
5999 if (!@list) {
6000 die_error(404, "No projects found");
6001 }
@@ -6023,7 +6036,7 @@ sub git_forks {
6036 }
6037
6038 sub git_project_index {
6026 - my @projects = git_get_projects_list();
6039 + my @projects = git_get_projects_list($project_filter, $strict_export);
6040 if (!@projects) {
6041 die_error(404, "No projects found");
6042 }
@@ -7862,7 +7875,7 @@ sub git_atom {
7875 }
7876
7877 sub git_opml {
7865 - my @list = git_get_projects_list();
7878 + my @list = git_get_projects_list($project_filter, $strict_export);
7879 if (!@list) {
7880 die_error(404, "No projects found");
7881 }
@@ -7873,11 +7886,17 @@ sub git_opml {
7886 -content_disposition => 'inline; filename="opml.xml"');
7887
7888 my $title = esc_html($site_name);
7889 + my $filter = " within subdirectory ";
7890 + if (defined $project_filter) {
7891 + $filter .= esc_html($project_filter);
7892 + } else {
7893 + $filter = "";
7894 + }
7895 print <<XML;
7896 <?xml version="1.0" encoding="utf-8"?>
7897 <opml version="1.0">
7898 <head>
7880 - <title>$title OPML Export</title>
7899 + <title>$title OPML Export$filter</title>
7900 </head>
7901 <body>
7902 <outline text="git RSS feeds">