summaryrefslogtreecommitdiffabout
authorLars Hjemli <hjemli@gmail.com>2007-11-03 10:15:56 (UTC)
committer Lars Hjemli <hjemli@gmail.com>2007-11-03 10:15:56 (UTC)
commit68cf9b4f853177544a5d1c7b4a9eea4d2f5749d5 (patch) (unidiff)
treed5f4a784477c714e81ca3a4d675ce640a5989b94
parent51140311bb3b0d4d0e859d5045ffe4c74478f5fe (diff)
downloadcgit-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>
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--ui-shared.c42
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
@@ -51,37 +51,39 @@ char *cgit_rooturl()
51char *cgit_repourl(const char *reponame) 51char *cgit_repourl(const char *reponame)
52{ 52{
53 if (cgit_virtual_root) { 53 if (cgit_virtual_root) {
54 return fmt("%s/%s/", cgit_virtual_root, reponame); 54 return fmt("%s/%s/", cgit_virtual_root, reponame);
55 } else { 55 } else {
56 return fmt("?r=%s", reponame); 56 return fmt("?r=%s", reponame);
57 } 57 }
58} 58}
59 59
60char *cgit_fileurl(const char *reponame, const char *pagename, 60char *cgit_fileurl(const char *reponame, const char *pagename,
61 const char *filename, const char *query) 61 const char *filename, const char *query)
62{ 62{
63 char *tmp;
64 char *delim;
65
63 if (cgit_virtual_root) { 66 if (cgit_virtual_root) {
64 if (query) 67 tmp = fmt("%s/%s/%s/%s", cgit_virtual_root, reponame,
65 return fmt("%s/%s/%s/%s?%s", cgit_virtual_root, reponame, 68 pagename, (filename ? filename:""));
66 pagename, filename?filename:"", query); 69 delim = "?";
67 else
68 return fmt("%s/%s/%s/", cgit_virtual_root, reponame,
69 pagename);
70 } else { 70 } else {
71 if (query) 71 tmp = fmt("?url=%s/%s/%s", reponame, pagename,
72 return fmt("?r=%s&amp;p=%s&amp;%s", reponame, pagename, query); 72 (filename ? filename : ""));
73 else 73 delim = "&";
74 return fmt("?r=%s&amp;p=%s", reponame, pagename);
75 } 74 }
75 if (query)
76 tmp = fmt("%s%s%s", tmp, delim, query);
77 return tmp;
76} 78}
77 79
78char *cgit_pageurl(const char *reponame, const char *pagename, 80char *cgit_pageurl(const char *reponame, const char *pagename,
79 const char *query) 81 const char *query)
80{ 82{
81 return cgit_fileurl(reponame,pagename,0,query); 83 return cgit_fileurl(reponame,pagename,0,query);
82} 84}
83 85
84const char *cgit_repobasename(const char *reponame) 86const char *cgit_repobasename(const char *reponame)
85{ 87{
86 /* I assume we don't need to store more than one repo basename */ 88 /* I assume we don't need to store more than one repo basename */
87 static char rvbuf[1024]; 89 static char rvbuf[1024];
@@ -412,31 +414,33 @@ int print_archive_ref(const char *refname, const unsigned char *sha1,
412 html("<p><h1>download</h1>"); 414 html("<p><h1>download</h1>");
413 *header = 1; 415 *header = 1;
414 } 416 }
415 url = cgit_pageurl(cgit_query_repo, "blob", 417 url = cgit_pageurl(cgit_query_repo, "blob",
416 fmt("id=%s&amp;path=%s", sha1_to_hex(fileid), 418 fmt("id=%s&amp;path=%s", sha1_to_hex(fileid),
417 buf)); 419 buf));
418 html_link_open(url, NULL, "menu"); 420 html_link_open(url, NULL, "menu");
419 html_txt(strlpart(buf, 20)); 421 html_txt(strlpart(buf, 20));
420 html_link_close(); 422 html_link_close();
421 return 0; 423 return 0;
422} 424}
423 425
424void add_hidden_formfields(int incl_head, int incl_search) 426void add_hidden_formfields(int incl_head, int incl_search, char *page)
425{ 427{
428 char *url;
429
426 if (!cgit_virtual_root) { 430 if (!cgit_virtual_root) {
427 if (cgit_query_repo) 431 url = fmt("%s/%s", cgit_query_repo, page);
428 html_hidden("r", cgit_query_repo); 432 if (cgit_query_path)
429 if (cgit_query_page) 433 url = fmt("%s/%s", url, cgit_query_path);
430 html_hidden("p", cgit_query_page); 434 html_hidden("url", url);
431 } 435 }
432 436
433 if (incl_head && strcmp(cgit_query_head, cgit_repo->defbranch)) 437 if (incl_head && strcmp(cgit_query_head, cgit_repo->defbranch))
434 html_hidden("h", cgit_query_head); 438 html_hidden("h", cgit_query_head);
435 439
436 if (cgit_query_sha1) 440 if (cgit_query_sha1)
437 html_hidden("id", cgit_query_sha1); 441 html_hidden("id", cgit_query_sha1);
438 if (cgit_query_sha2) 442 if (cgit_query_sha2)
439 html_hidden("id2", cgit_query_sha2); 443 html_hidden("id2", cgit_query_sha2);
440 444
441 if (incl_search) { 445 if (incl_search) {
442 if (cgit_query_grep) 446 if (cgit_query_grep)
@@ -474,35 +478,37 @@ void cgit_print_pageheader(char *title, int show_search)
474 cgit_tree_link("tree", NULL, "menu", cgit_query_head, 478 cgit_tree_link("tree", NULL, "menu", cgit_query_head,
475 cgit_query_sha1, NULL); 479 cgit_query_sha1, NULL);
476 cgit_commit_link("commit", NULL, "menu", cgit_query_head, 480 cgit_commit_link("commit", NULL, "menu", cgit_query_head,
477 cgit_query_sha1); 481 cgit_query_sha1);
478 cgit_diff_link("diff", NULL, "menu", cgit_query_head, 482 cgit_diff_link("diff", NULL, "menu", cgit_query_head,
479 cgit_query_sha1, cgit_query_sha2, 483 cgit_query_sha1, cgit_query_sha2,
480 cgit_query_path); 484 cgit_query_path);
481 485
482 for_each_ref(print_archive_ref, &header); 486 for_each_ref(print_archive_ref, &header);
483 487
484 html("<p>\n<h1>branch</h1>\n"); 488 html("<p>\n<h1>branch</h1>\n");
485 html("<form method='get' action=''>\n"); 489 html("<form method='get' action=''>\n");
486 add_hidden_formfields(0, 1); 490 add_hidden_formfields(0, 1, cgit_query_page);
487 html("<select name='h' onchange='this.form.submit();'>\n"); 491 html("<select name='h' onchange='this.form.submit();'>\n");
488 for_each_branch_ref(print_branch_option, cgit_query_head); 492 for_each_branch_ref(print_branch_option, cgit_query_head);
489 html("</select>\n"); 493 html("</select>\n");
490 html("</form>\n"); 494 html("</form>\n");
491 495
492 html("<p>\n<h1>search</h1>\n"); 496 html("<p>\n<h1>search</h1>\n");
493 html("<form method='get' action='"); 497 html("<form method='get' action='");
494 html_attr(cgit_pageurl(cgit_query_repo, "log", NULL)); 498 if (cgit_virtual_root)
499 html_attr(cgit_fileurl(cgit_query_repo, "log",
500 cgit_query_path, NULL));
495 html("'>\n"); 501 html("'>\n");
496 add_hidden_formfields(1, 0); 502 add_hidden_formfields(1, 0, "log");
497 html("<select name='qt'>\n"); 503 html("<select name='qt'>\n");
498 html_option("grep", "log msg", cgit_query_grep); 504 html_option("grep", "log msg", cgit_query_grep);
499 html_option("author", "author", cgit_query_grep); 505 html_option("author", "author", cgit_query_grep);
500 html_option("committer", "committer", cgit_query_grep); 506 html_option("committer", "committer", cgit_query_grep);
501 html("</select>\n"); 507 html("</select>\n");
502 html("<input class='txt' type='text' name='q' value='"); 508 html("<input class='txt' type='text' name='q' value='");
503 html_attr(cgit_query_search); 509 html_attr(cgit_query_search);
504 html("'/>\n"); 510 html("'/>\n");
505 html("</form>\n"); 511 html("</form>\n");
506 } else { 512 } else {
507 if (!cgit_index_info || html_include(cgit_index_info)) 513 if (!cgit_index_info || html_include(cgit_index_info))
508 html(default_info); 514 html(default_info);