author | Lars Hjemli <hjemli@gmail.com> | 2007-11-03 10:15:56 (UTC) |
---|---|---|
committer | Lars Hjemli <hjemli@gmail.com> | 2007-11-03 10:15:56 (UTC) |
commit | 68cf9b4f853177544a5d1c7b4a9eea4d2f5749d5 (patch) (side-by-side diff) | |
tree | d5f4a784477c714e81ca3a4d675ce640a5989b94 /ui-shared.c | |
parent | 51140311bb3b0d4d0e859d5045ffe4c74478f5fe (diff) | |
download | cgit-68cf9b4f853177544a5d1c7b4a9eea4d2f5749d5.zip cgit-68cf9b4f853177544a5d1c7b4a9eea4d2f5749d5.tar.gz cgit-68cf9b4f853177544a5d1c7b4a9eea4d2f5749d5.tar.bz2 |
Fix search form action/hidden fields
The search form didn't properly honor the current path, so this commit
fixes cgit_fileurl() and add_hidden_formfields() to make the issue go
away.
Signed-off-by: Lars Hjemli <hjemli@gmail.com>
-rw-r--r-- | ui-shared.c | 42 |
1 files changed, 24 insertions, 18 deletions
diff --git a/ui-shared.c b/ui-shared.c index a03661a..88dd6b8 100644 --- a/ui-shared.c +++ b/ui-shared.c @@ -55,29 +55,31 @@ char *cgit_repourl(const char *reponame) } else { return fmt("?r=%s", reponame); } } char *cgit_fileurl(const char *reponame, const char *pagename, const char *filename, const char *query) { + char *tmp; + char *delim; + if (cgit_virtual_root) { - if (query) - return fmt("%s/%s/%s/%s?%s", cgit_virtual_root, reponame, - pagename, filename?filename:"", query); - else - return fmt("%s/%s/%s/", cgit_virtual_root, reponame, - pagename); + tmp = fmt("%s/%s/%s/%s", cgit_virtual_root, reponame, + pagename, (filename ? filename:"")); + delim = "?"; } else { - if (query) - return fmt("?r=%s&p=%s&%s", reponame, pagename, query); - else - return fmt("?r=%s&p=%s", reponame, pagename); + tmp = fmt("?url=%s/%s/%s", reponame, pagename, + (filename ? filename : "")); + delim = "&"; } + if (query) + tmp = fmt("%s%s%s", tmp, delim, query); + return tmp; } char *cgit_pageurl(const char *reponame, const char *pagename, const char *query) { return cgit_fileurl(reponame,pagename,0,query); } @@ -416,23 +418,25 @@ int print_archive_ref(const char *refname, const unsigned char *sha1, fmt("id=%s&path=%s", sha1_to_hex(fileid), buf)); html_link_open(url, NULL, "menu"); html_txt(strlpart(buf, 20)); html_link_close(); return 0; } -void add_hidden_formfields(int incl_head, int incl_search) +void add_hidden_formfields(int incl_head, int incl_search, char *page) { + char *url; + if (!cgit_virtual_root) { - if (cgit_query_repo) - html_hidden("r", cgit_query_repo); - if (cgit_query_page) - html_hidden("p", cgit_query_page); + url = fmt("%s/%s", cgit_query_repo, page); + if (cgit_query_path) + url = fmt("%s/%s", url, cgit_query_path); + html_hidden("url", url); } if (incl_head && strcmp(cgit_query_head, cgit_repo->defbranch)) html_hidden("h", cgit_query_head); if (cgit_query_sha1) html_hidden("id", cgit_query_sha1); if (cgit_query_sha2) @@ -478,27 +482,29 @@ void cgit_print_pageheader(char *title, int show_search) cgit_diff_link("diff", NULL, "menu", cgit_query_head, cgit_query_sha1, cgit_query_sha2, cgit_query_path); for_each_ref(print_archive_ref, &header); html("<p>\n<h1>branch</h1>\n"); html("<form method='get' action=''>\n"); - add_hidden_formfields(0, 1); + add_hidden_formfields(0, 1, cgit_query_page); html("<select name='h' onchange='this.form.submit();'>\n"); for_each_branch_ref(print_branch_option, cgit_query_head); html("</select>\n"); html("</form>\n"); html("<p>\n<h1>search</h1>\n"); html("<form method='get' action='"); - html_attr(cgit_pageurl(cgit_query_repo, "log", NULL)); + if (cgit_virtual_root) + html_attr(cgit_fileurl(cgit_query_repo, "log", + cgit_query_path, NULL)); html("'>\n"); - add_hidden_formfields(1, 0); + add_hidden_formfields(1, 0, "log"); html("<select name='qt'>\n"); html_option("grep", "log msg", cgit_query_grep); html_option("author", "author", cgit_query_grep); html_option("committer", "committer", cgit_query_grep); html("</select>\n"); html("<input class='txt' type='text' name='q' value='"); html_attr(cgit_query_search); html("'/>\n"); |