gitweb: Sort CGI parameters returned by href()
[gitweb.git] / gitweb / gitweb.perl
index c4a4f7ffd7ea74b60013dddbc6acc23723e5f5e5..50083e3011d145a25c7c56d85d75dd04ef15adf3 100755 (executable)
@@ -155,11 +155,6 @@ sub feature_snapshot {
        if ($action =~ m/[^0-9a-zA-Z\.\-_]/) {
                die_error(undef, "Invalid action parameter");
        }
-       # action which does not check rest of parameters
-       if ($action eq "opml") {
-               git_opml();
-               exit;
-       }
 }
 
 our $project = ($cgi->param('p') || $ENV{'PATH_INFO'});
@@ -179,9 +174,6 @@ sub feature_snapshot {
                die_error(undef, "No such project");
        }
        $ENV{'GIT_DIR'} = "$projectroot/$project";
-} else {
-       git_project_list();
-       exit;
 }
 
 our $file_name = $cgi->param('f');
@@ -255,9 +247,16 @@ sub feature_snapshot {
        "tags" => \&git_tags,
        "tree" => \&git_tree,
        "snapshot" => \&git_snapshot,
+       # those below don't need $project
+       "opml" => \&git_opml,
+       "project_list" => \&git_project_list,
 );
 
-$action = 'summary' if (!defined($action));
+if (defined $project) {
+       $action ||= 'summary';
+} else {
+       $action ||= 'project_list';
+}
 if (!defined($actions{$action})) {
        die_error(undef, "Unknown action");
 }
@@ -268,7 +267,9 @@ sub feature_snapshot {
 ## action links
 
 sub href(%) {
-       my %mapping = (
+       my %params = @_;
+
+       my @mapping = (
                action => "a",
                project => "p",
                file_name => "f",
@@ -279,18 +280,18 @@ (%)
                page => "pg",
                searchtext => "s",
        );
+       my %mapping = @mapping;
 
-       my %params = @_;
        $params{"project"} ||= $project;
 
-       my $href = "$my_uri?";
-       $href .= esc_param( join(";",
-               map {
-                       "$mapping{$_}=$params{$_}" if defined $params{$_}
-               } keys %params
-       ) );
-
-       return $href;
+       my @result = ();
+       for (my $i = 0; $i < @mapping; $i += 2) {
+               my ($name, $symbol) = ($mapping[$i], $mapping[$i+1]);
+               if (defined $params{$name}) {
+                       push @result, $symbol . "=" . esc_param($params{$name});
+               }
+       }
+       return "$my_uri?" . join(';', @result);
 }
 
 
@@ -1186,11 +1187,13 @@ sub die_error {
        my $error = shift || "Malformed query, file missing or permission denied";
 
        git_header_html($status);
-       print "<div class=\"page_body\">\n" .
-             "<br/><br/>\n" .
-             "$status - $error\n" .
-             "<br/>\n" .
-             "</div>\n";
+       print <<EOF;
+<div class="page_body">
+<br /><br />
+$status - $error
+<br />
+</div>
+EOF
        git_footer_html();
        exit;
 }
@@ -2023,9 +2026,11 @@ sub git_blame2 {
        my $num_colors = scalar(@rev_color);
        my $current_color = 0;
        my $last_rev;
-       print "<div class=\"page_body\">\n";
-       print "<table class=\"blame\">\n";
-       print "<tr><th>Commit</th><th>Line</th><th>Data</th></tr>\n";
+       print <<HTML;
+<div class="page_body">
+<table class="blame">
+<tr><th>Commit</th><th>Line</th><th>Data</th></tr>
+HTML
        while (<$fd>) {
                /^([0-9a-fA-F]{40}).*?(\d+)\)\s{1}(\s*.*)/;
                my $full_rev = $1;
@@ -2567,9 +2572,10 @@ sub git_blobdiff {
                git_print_page_nav('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
                git_print_header_div('commit', esc_html($co{'title'}), $hash_base);
        } else {
-               print "<div class=\"page_nav\">\n" .
-                     "<br/><br/></div>\n" .
-                     "<div class=\"title\">$hash vs $hash_parent</div>\n";
+               print <<HTML;
+<div class="page_nav"><br/><br/></div>
+<div class="title">$hash vs $hash_parent</div>
+HTML
        }
        git_print_page_path($file_name, "blob", $hash_base);
        print "<div class=\"page_body\">\n" .
@@ -2705,9 +2711,11 @@ sub git_commitdiff_plain {
                           -content_disposition => "inline; filename=\"git-$hash.patch\"");
        my %ad = parse_date($co{'author_epoch'}, $co{'author_tz'});
        my $comment = $co{'comment'};
-       print "From: $co{'author'}\n" .
-             "Date: $ad{'rfc2822'} ($ad{'tz_local'})\n".
-             "Subject: $co{'title'}\n";
+       print <<TEXT;
+From: $co{'author'}
+Date: $ad{'rfc2822'} ($ad{'tz_local'})
+Subject: $co{'title'}
+TEXT
        if (defined $tagname) {
                print "X-Git-Tag: $tagname\n";
        }
@@ -2951,13 +2959,15 @@ sub git_rss {
        my @revlist = map { chomp; $_ } <$fd>;
        close $fd or die_error(undef, "Reading git-rev-list failed");
        print $cgi->header(-type => 'text/xml', -charset => 'utf-8');
-       print "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n".
-             "<rss version=\"2.0\" xmlns:content=\"http://purl.org/rss/1.0/modules/content/\">\n";
-       print "<channel>\n";
-       print "<title>$project</title>\n".
-             "<link>" . esc_html("$my_url?p=$project;a=summary") . "</link>\n".
-             "<description>$project log</description>\n".
-             "<language>en</language>\n";
+       print <<XML;
+<?xml version="1.0" encoding="utf-8"?>
+<rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
+<channel>
+<title>$project $my_uri $my_url</title>
+<link>${\esc_html("$my_url?p=$project;a=summary")}</link>
+<description>$project log</description>
+<language>en</language>
+XML
 
        for (my $i = 0; $i <= $#revlist; $i++) {
                my $commit = $revlist[$i];
@@ -3006,13 +3016,15 @@ sub git_opml {
        my @list = git_get_projects_list();
 
        print $cgi->header(-type => 'text/xml', -charset => 'utf-8');
-       print "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n".
-             "<opml version=\"1.0\">\n".
-             "<head>".
-             "  <title>$site_name Git OPML Export</title>\n".
-             "</head>\n".
-             "<body>\n".
-             "<outline text=\"git RSS feeds\">\n";
+       print <<XML;
+<?xml version="1.0" encoding="utf-8"?>
+<opml version="1.0">
+<head>
+  <title>$site_name Git OPML Export</title>
+</head>
+<body>
+<outline text="git RSS feeds">
+XML
 
        foreach my $pr (@list) {
                my %proj = %$pr;
@@ -3031,7 +3043,9 @@ sub git_opml {
                my $html = "$my_url?p=$proj{'path'};a=summary";
                print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";
        }
-       print "</outline>\n".
-             "</body>\n".
-             "</opml>\n";
+       print <<XML;
+</outline>
+</body>
+</opml>
+XML
 }