Lars Hjemli | 5a106eb | 2006-12-11 16:38:30 +0100 | [diff] [blame] | 1 | /* ui-shared.c: common web output functions |
| 2 | * |
Lukas Fleischer | f7f26f8 | 2014-01-08 15:10:49 +0100 | [diff] [blame] | 3 | * Copyright (C) 2006-2014 cgit Development Team <cgit@lists.zx2c4.com> |
Lars Hjemli | 5a106eb | 2006-12-11 16:38:30 +0100 | [diff] [blame] | 4 | * |
| 5 | * Licensed under GNU General Public License v2 |
| 6 | * (see COPYING for full license text) |
| 7 | */ |
| 8 | |
| 9 | #include "cgit.h" |
John Keeping | 8f20879 | 2013-04-06 11:37:59 +0100 | [diff] [blame] | 10 | #include "ui-shared.h" |
Lars Hjemli | f135569 | 2008-04-12 15:53:31 +0200 | [diff] [blame] | 11 | #include "cmd.h" |
Lars Hjemli | b1f9b9c | 2008-02-23 22:45:33 +0100 | [diff] [blame] | 12 | #include "html.h" |
Lars Hjemli | 5a106eb | 2006-12-11 16:38:30 +0100 | [diff] [blame] | 13 | |
| 14 | const char cgit_doctype[] = |
| 15 | "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"\n" |
| 16 | " \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n"; |
| 17 | |
| 18 | static char *http_date(time_t t) |
| 19 | { |
Lars Hjemli | 6fb7d09 | 2007-05-15 00:22:03 +0200 | [diff] [blame] | 20 | static char day[][4] = |
Lars Hjemli | 5a106eb | 2006-12-11 16:38:30 +0100 | [diff] [blame] | 21 | {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"}; |
Lars Hjemli | 6fb7d09 | 2007-05-15 00:22:03 +0200 | [diff] [blame] | 22 | static char month[][4] = |
Lars Hjemli | 5a106eb | 2006-12-11 16:38:30 +0100 | [diff] [blame] | 23 | {"Jan", "Feb", "Mar", "Apr", "May", "Jun", |
Danijel TaĊĦov | e34a3b5 | 2009-11-02 22:10:04 +0100 | [diff] [blame] | 24 | "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}; |
Lars Hjemli | 5a106eb | 2006-12-11 16:38:30 +0100 | [diff] [blame] | 25 | struct tm *tm = gmtime(&t); |
| 26 | return fmt("%s, %02d %s %04d %02d:%02d:%02d GMT", day[tm->tm_wday], |
Lukas Fleischer | 53bc747 | 2013-03-03 16:04:29 +0100 | [diff] [blame] | 27 | tm->tm_mday, month[tm->tm_mon], 1900 + tm->tm_year, |
Lars Hjemli | 5a106eb | 2006-12-11 16:38:30 +0100 | [diff] [blame] | 28 | tm->tm_hour, tm->tm_min, tm->tm_sec); |
| 29 | } |
| 30 | |
John Keeping | ed5bd30 | 2013-04-06 11:23:52 +0100 | [diff] [blame] | 31 | void cgit_print_error(const char *fmt, ...) |
Lars Hjemli | 5a106eb | 2006-12-11 16:38:30 +0100 | [diff] [blame] | 32 | { |
John Keeping | ed5bd30 | 2013-04-06 11:23:52 +0100 | [diff] [blame] | 33 | va_list ap; |
| 34 | va_start(ap, fmt); |
| 35 | cgit_vprint_error(fmt, ap); |
| 36 | va_end(ap); |
| 37 | } |
| 38 | |
| 39 | void cgit_vprint_error(const char *fmt, va_list ap) |
| 40 | { |
| 41 | va_list cp; |
Lars Hjemli | 5a106eb | 2006-12-11 16:38:30 +0100 | [diff] [blame] | 42 | html("<div class='error'>"); |
John Keeping | ed5bd30 | 2013-04-06 11:23:52 +0100 | [diff] [blame] | 43 | va_copy(cp, ap); |
| 44 | html_vtxtf(fmt, cp); |
| 45 | va_end(cp); |
Lars Hjemli | 5a106eb | 2006-12-11 16:38:30 +0100 | [diff] [blame] | 46 | html("</div>\n"); |
| 47 | } |
Lars Hjemli | 74620f1 | 2006-12-11 16:48:03 +0100 | [diff] [blame] | 48 | |
Lukas Fleischer | 996f86e | 2013-04-01 17:11:13 +0200 | [diff] [blame] | 49 | const char *cgit_httpscheme() |
Diego Ongaro | 87a89ae | 2009-06-10 18:09:55 -0500 | [diff] [blame] | 50 | { |
Lars Hjemli | 60a2627 | 2009-08-10 08:21:09 +0200 | [diff] [blame] | 51 | if (ctx.env.https && !strcmp(ctx.env.https, "on")) |
Diego Ongaro | 87a89ae | 2009-06-10 18:09:55 -0500 | [diff] [blame] | 52 | return "https://"; |
| 53 | else |
| 54 | return "http://"; |
| 55 | } |
| 56 | |
Lukas Fleischer | 996f86e | 2013-04-01 17:11:13 +0200 | [diff] [blame] | 57 | const char *cgit_hosturl() |
Lars Hjemli | b2a3d31 | 2008-05-21 08:17:54 +0200 | [diff] [blame] | 58 | { |
Lars Hjemli | 60a2627 | 2009-08-10 08:21:09 +0200 | [diff] [blame] | 59 | if (ctx.env.http_host) |
| 60 | return ctx.env.http_host; |
| 61 | if (!ctx.env.server_name) |
| 62 | return NULL; |
| 63 | if (!ctx.env.server_port || atoi(ctx.env.server_port) == 80) |
| 64 | return ctx.env.server_name; |
John Keeping | fb3655d | 2013-04-06 10:28:57 +0100 | [diff] [blame] | 65 | return fmtalloc("%s:%s", ctx.env.server_name, ctx.env.server_port); |
Lars Hjemli | b2a3d31 | 2008-05-21 08:17:54 +0200 | [diff] [blame] | 66 | } |
| 67 | |
Jason A. Donenfeld | 6bcda2f | 2015-03-03 17:18:42 +0100 | [diff] [blame] | 68 | const char *cgit_currenturl() |
| 69 | { |
| 70 | if (!ctx.qry.url) |
| 71 | return cgit_rooturl(); |
| 72 | return ctx.qry.url; |
| 73 | } |
| 74 | |
Lukas Fleischer | 996f86e | 2013-04-01 17:11:13 +0200 | [diff] [blame] | 75 | const char *cgit_rooturl() |
Lars Hjemli | 66cacd0 | 2007-02-17 13:46:18 +0100 | [diff] [blame] | 76 | { |
Lars Hjemli | b228d4f | 2008-02-16 13:07:13 +0100 | [diff] [blame] | 77 | if (ctx.cfg.virtual_root) |
John Keeping | b1f17f1 | 2013-04-01 19:03:34 +0100 | [diff] [blame] | 78 | return ctx.cfg.virtual_root; |
Lars Hjemli | 66cacd0 | 2007-02-17 13:46:18 +0100 | [diff] [blame] | 79 | else |
Lars Hjemli | b228d4f | 2008-02-16 13:07:13 +0100 | [diff] [blame] | 80 | return ctx.cfg.script_name; |
Lars Hjemli | 66cacd0 | 2007-02-17 13:46:18 +0100 | [diff] [blame] | 81 | } |
| 82 | |
Jason A. Donenfeld | a431326 | 2014-01-16 23:21:54 +0100 | [diff] [blame] | 83 | const char *cgit_loginurl() |
| 84 | { |
| 85 | static const char *login_url = 0; |
| 86 | if (!login_url) |
| 87 | login_url = fmtalloc("%s?p=login", cgit_rooturl()); |
| 88 | return login_url; |
| 89 | } |
| 90 | |
Lars Hjemli | 74620f1 | 2006-12-11 16:48:03 +0100 | [diff] [blame] | 91 | char *cgit_repourl(const char *reponame) |
| 92 | { |
John Keeping | fb3655d | 2013-04-06 10:28:57 +0100 | [diff] [blame] | 93 | if (ctx.cfg.virtual_root) |
| 94 | return fmtalloc("%s%s/", ctx.cfg.virtual_root, reponame); |
| 95 | else |
| 96 | return fmtalloc("?r=%s", reponame); |
Lars Hjemli | 74620f1 | 2006-12-11 16:48:03 +0100 | [diff] [blame] | 97 | } |
| 98 | |
Michael Krelin | 0df096f | 2007-07-21 13:13:40 +0200 | [diff] [blame] | 99 | char *cgit_fileurl(const char *reponame, const char *pagename, |
| 100 | const char *filename, const char *query) |
Lars Hjemli | 74620f1 | 2006-12-11 16:48:03 +0100 | [diff] [blame] | 101 | { |
John Keeping | fb3655d | 2013-04-06 10:28:57 +0100 | [diff] [blame] | 102 | struct strbuf sb = STRBUF_INIT; |
Lars Hjemli | 68cf9b4 | 2007-11-03 11:15:56 +0100 | [diff] [blame] | 103 | char *delim; |
| 104 | |
Lars Hjemli | b228d4f | 2008-02-16 13:07:13 +0100 | [diff] [blame] | 105 | if (ctx.cfg.virtual_root) { |
John Keeping | fb3655d | 2013-04-06 10:28:57 +0100 | [diff] [blame] | 106 | strbuf_addf(&sb, "%s%s/%s/%s", ctx.cfg.virtual_root, reponame, |
| 107 | pagename, (filename ? filename:"")); |
Lars Hjemli | 68cf9b4 | 2007-11-03 11:15:56 +0100 | [diff] [blame] | 108 | delim = "?"; |
Lars Hjemli | 74620f1 | 2006-12-11 16:48:03 +0100 | [diff] [blame] | 109 | } else { |
John Keeping | fb3655d | 2013-04-06 10:28:57 +0100 | [diff] [blame] | 110 | strbuf_addf(&sb, "?url=%s/%s/%s", reponame, pagename, |
| 111 | (filename ? filename : "")); |
William Bell | c366bd6 | 2012-10-09 20:45:58 +0200 | [diff] [blame] | 112 | delim = "&"; |
Lars Hjemli | 74620f1 | 2006-12-11 16:48:03 +0100 | [diff] [blame] | 113 | } |
Lars Hjemli | 68cf9b4 | 2007-11-03 11:15:56 +0100 | [diff] [blame] | 114 | if (query) |
John Keeping | fb3655d | 2013-04-06 10:28:57 +0100 | [diff] [blame] | 115 | strbuf_addf(&sb, "%s%s", delim, query); |
| 116 | return strbuf_detach(&sb, NULL); |
Lars Hjemli | 74620f1 | 2006-12-11 16:48:03 +0100 | [diff] [blame] | 117 | } |
| 118 | |
Michael Krelin | 0df096f | 2007-07-21 13:13:40 +0200 | [diff] [blame] | 119 | char *cgit_pageurl(const char *reponame, const char *pagename, |
| 120 | const char *query) |
| 121 | { |
Lukas Fleischer | 53bc747 | 2013-03-03 16:04:29 +0100 | [diff] [blame] | 122 | return cgit_fileurl(reponame, pagename, 0, query); |
Michael Krelin | 0df096f | 2007-07-21 13:13:40 +0200 | [diff] [blame] | 123 | } |
| 124 | |
Michael Krelin | 1cb8bed | 2007-07-21 15:24:07 +0200 | [diff] [blame] | 125 | const char *cgit_repobasename(const char *reponame) |
| 126 | { |
| 127 | /* I assume we don't need to store more than one repo basename */ |
| 128 | static char rvbuf[1024]; |
| 129 | int p; |
| 130 | const char *rv; |
Lukas Fleischer | 53bc747 | 2013-03-03 16:04:29 +0100 | [diff] [blame] | 131 | strncpy(rvbuf, reponame, sizeof(rvbuf)); |
Jason A. Donenfeld | bdae1d8 | 2013-03-03 23:21:33 -0500 | [diff] [blame] | 132 | if (rvbuf[sizeof(rvbuf)-1]) |
Michael Krelin | 1cb8bed | 2007-07-21 15:24:07 +0200 | [diff] [blame] | 133 | die("cgit_repobasename: truncated repository name '%s'", reponame); |
| 134 | p = strlen(rvbuf)-1; |
| 135 | /* strip trailing slashes */ |
Jason A. Donenfeld | bdae1d8 | 2013-03-03 23:21:33 -0500 | [diff] [blame] | 136 | while (p && rvbuf[p] == '/') rvbuf[p--] = 0; |
Michael Krelin | 1cb8bed | 2007-07-21 15:24:07 +0200 | [diff] [blame] | 137 | /* strip trailing .git */ |
Christian Hesse | 79c985e | 2014-05-29 17:35:46 +0200 | [diff] [blame] | 138 | if (p >= 3 && starts_with(&rvbuf[p-3], ".git")) { |
Michael Krelin | 1cb8bed | 2007-07-21 15:24:07 +0200 | [diff] [blame] | 139 | p -= 3; rvbuf[p--] = 0; |
| 140 | } |
| 141 | /* strip more trailing slashes if any */ |
Jason A. Donenfeld | bdae1d8 | 2013-03-03 23:21:33 -0500 | [diff] [blame] | 142 | while ( p && rvbuf[p] == '/') rvbuf[p--] = 0; |
Michael Krelin | 1cb8bed | 2007-07-21 15:24:07 +0200 | [diff] [blame] | 143 | /* find last slash in the remaining string */ |
| 144 | rv = strrchr(rvbuf,'/'); |
Jason A. Donenfeld | bdae1d8 | 2013-03-03 23:21:33 -0500 | [diff] [blame] | 145 | if (rv) |
Michael Krelin | 1cb8bed | 2007-07-21 15:24:07 +0200 | [diff] [blame] | 146 | return ++rv; |
| 147 | return rvbuf; |
| 148 | } |
Michael Krelin | 0df096f | 2007-07-21 13:13:40 +0200 | [diff] [blame] | 149 | |
Jason A. Donenfeld | 2e4a41e | 2015-03-03 17:23:40 +0100 | [diff] [blame^] | 150 | static void site_url(const char *page, const char *search, const char *sort, int ofs, int always_root) |
Lars Hjemli | 71adba1 | 2008-04-29 01:09:41 +0200 | [diff] [blame] | 151 | { |
| 152 | char *delim = "?"; |
| 153 | |
Jason A. Donenfeld | 2e4a41e | 2015-03-03 17:23:40 +0100 | [diff] [blame^] | 154 | if (always_root || page) |
Jason A. Donenfeld | db4b735 | 2015-03-03 17:13:52 +0100 | [diff] [blame] | 155 | html_attr(cgit_rooturl()); |
Jason A. Donenfeld | 2e4a41e | 2015-03-03 17:23:40 +0100 | [diff] [blame^] | 156 | else |
| 157 | html_attr(cgit_currenturl()); |
Lars Hjemli | 71adba1 | 2008-04-29 01:09:41 +0200 | [diff] [blame] | 158 | |
| 159 | if (page) { |
| 160 | htmlf("?p=%s", page); |
William Bell | c366bd6 | 2012-10-09 20:45:58 +0200 | [diff] [blame] | 161 | delim = "&"; |
Lars Hjemli | 71adba1 | 2008-04-29 01:09:41 +0200 | [diff] [blame] | 162 | } |
| 163 | if (search) { |
| 164 | html(delim); |
| 165 | html("q="); |
| 166 | html_attr(search); |
William Bell | c366bd6 | 2012-10-09 20:45:58 +0200 | [diff] [blame] | 167 | delim = "&"; |
Lars Hjemli | 141f1c3 | 2008-05-03 10:37:02 +0200 | [diff] [blame] | 168 | } |
Tobias Grimm | 7530d94 | 2011-07-31 02:44:05 +0200 | [diff] [blame] | 169 | if (sort) { |
| 170 | html(delim); |
| 171 | html("s="); |
| 172 | html_attr(sort); |
William Bell | c366bd6 | 2012-10-09 20:45:58 +0200 | [diff] [blame] | 173 | delim = "&"; |
Tobias Grimm | 7530d94 | 2011-07-31 02:44:05 +0200 | [diff] [blame] | 174 | } |
Lars Hjemli | 141f1c3 | 2008-05-03 10:37:02 +0200 | [diff] [blame] | 175 | if (ofs) { |
| 176 | html(delim); |
| 177 | htmlf("ofs=%d", ofs); |
Lars Hjemli | 71adba1 | 2008-04-29 01:09:41 +0200 | [diff] [blame] | 178 | } |
| 179 | } |
| 180 | |
Johan Herland | c3f23d4 | 2010-06-10 01:09:24 +0200 | [diff] [blame] | 181 | static void site_link(const char *page, const char *name, const char *title, |
Jason A. Donenfeld | 2e4a41e | 2015-03-03 17:23:40 +0100 | [diff] [blame^] | 182 | const char *class, const char *search, const char *sort, int ofs, int always_root) |
Lars Hjemli | 71adba1 | 2008-04-29 01:09:41 +0200 | [diff] [blame] | 183 | { |
| 184 | html("<a"); |
| 185 | if (title) { |
| 186 | html(" title='"); |
| 187 | html_attr(title); |
| 188 | html("'"); |
| 189 | } |
| 190 | if (class) { |
| 191 | html(" class='"); |
| 192 | html_attr(class); |
| 193 | html("'"); |
| 194 | } |
| 195 | html(" href='"); |
Jason A. Donenfeld | 2e4a41e | 2015-03-03 17:23:40 +0100 | [diff] [blame^] | 196 | site_url(page, search, sort, ofs, always_root); |
Lars Hjemli | 71adba1 | 2008-04-29 01:09:41 +0200 | [diff] [blame] | 197 | html("'>"); |
| 198 | html_txt(name); |
| 199 | html("</a>"); |
| 200 | } |
| 201 | |
Johan Herland | c3f23d4 | 2010-06-10 01:09:24 +0200 | [diff] [blame] | 202 | void cgit_index_link(const char *name, const char *title, const char *class, |
Jason A. Donenfeld | 2e4a41e | 2015-03-03 17:23:40 +0100 | [diff] [blame^] | 203 | const char *pattern, const char *sort, int ofs, int always_root) |
Lars Hjemli | 141f1c3 | 2008-05-03 10:37:02 +0200 | [diff] [blame] | 204 | { |
Jason A. Donenfeld | 2e4a41e | 2015-03-03 17:23:40 +0100 | [diff] [blame^] | 205 | site_link(NULL, name, title, class, pattern, sort, ofs, always_root); |
Lars Hjemli | 141f1c3 | 2008-05-03 10:37:02 +0200 | [diff] [blame] | 206 | } |
| 207 | |
Johan Herland | c3f23d4 | 2010-06-10 01:09:24 +0200 | [diff] [blame] | 208 | static char *repolink(const char *title, const char *class, const char *page, |
| 209 | const char *head, const char *path) |
Lars Hjemli | 44947bf | 2007-06-17 01:23:08 +0200 | [diff] [blame] | 210 | { |
| 211 | char *delim = "?"; |
| 212 | |
| 213 | html("<a"); |
| 214 | if (title) { |
| 215 | html(" title='"); |
| 216 | html_attr(title); |
| 217 | html("'"); |
| 218 | } |
| 219 | if (class) { |
| 220 | html(" class='"); |
| 221 | html_attr(class); |
| 222 | html("'"); |
| 223 | } |
| 224 | html(" href='"); |
Lars Hjemli | b228d4f | 2008-02-16 13:07:13 +0100 | [diff] [blame] | 225 | if (ctx.cfg.virtual_root) { |
Lars Hjemli | 44b208a | 2008-10-05 16:54:44 +0200 | [diff] [blame] | 226 | html_url_path(ctx.cfg.virtual_root); |
Lars Hjemli | 44b208a | 2008-10-05 16:54:44 +0200 | [diff] [blame] | 227 | html_url_path(ctx.repo->url); |
Lars Hjemli | d1f3bbe | 2008-02-16 13:56:09 +0100 | [diff] [blame] | 228 | if (ctx.repo->url[strlen(ctx.repo->url) - 1] != '/') |
Lars Hjemli | 44947bf | 2007-06-17 01:23:08 +0200 | [diff] [blame] | 229 | html("/"); |
Lars Hjemli | b8be028 | 2007-06-18 00:18:42 +0200 | [diff] [blame] | 230 | if (page) { |
Lars Hjemli | 44b208a | 2008-10-05 16:54:44 +0200 | [diff] [blame] | 231 | html_url_path(page); |
Lars Hjemli | b8be028 | 2007-06-18 00:18:42 +0200 | [diff] [blame] | 232 | html("/"); |
| 233 | if (path) |
Lars Hjemli | 44b208a | 2008-10-05 16:54:44 +0200 | [diff] [blame] | 234 | html_url_path(path); |
Lars Hjemli | b8be028 | 2007-06-18 00:18:42 +0200 | [diff] [blame] | 235 | } |
Lars Hjemli | 44947bf | 2007-06-17 01:23:08 +0200 | [diff] [blame] | 236 | } else { |
John Keeping | a45030f | 2014-01-12 19:45:16 +0000 | [diff] [blame] | 237 | html_url_path(ctx.cfg.script_name); |
Lars Hjemli | 44947bf | 2007-06-17 01:23:08 +0200 | [diff] [blame] | 238 | html("?url="); |
Lars Hjemli | b575115 | 2008-10-05 12:52:25 +0200 | [diff] [blame] | 239 | html_url_arg(ctx.repo->url); |
Lars Hjemli | d1f3bbe | 2008-02-16 13:56:09 +0100 | [diff] [blame] | 240 | if (ctx.repo->url[strlen(ctx.repo->url) - 1] != '/') |
Lars Hjemli | 44947bf | 2007-06-17 01:23:08 +0200 | [diff] [blame] | 241 | html("/"); |
Lars Hjemli | b8be028 | 2007-06-18 00:18:42 +0200 | [diff] [blame] | 242 | if (page) { |
Lars Hjemli | b575115 | 2008-10-05 12:52:25 +0200 | [diff] [blame] | 243 | html_url_arg(page); |
Lars Hjemli | b8be028 | 2007-06-18 00:18:42 +0200 | [diff] [blame] | 244 | html("/"); |
| 245 | if (path) |
Lars Hjemli | b575115 | 2008-10-05 12:52:25 +0200 | [diff] [blame] | 246 | html_url_arg(path); |
Lars Hjemli | b8be028 | 2007-06-18 00:18:42 +0200 | [diff] [blame] | 247 | } |
Lars Hjemli | 44947bf | 2007-06-17 01:23:08 +0200 | [diff] [blame] | 248 | delim = "&"; |
| 249 | } |
Lars Hjemli | d1f3bbe | 2008-02-16 13:56:09 +0100 | [diff] [blame] | 250 | if (head && strcmp(head, ctx.repo->defbranch)) { |
Lars Hjemli | 44947bf | 2007-06-17 01:23:08 +0200 | [diff] [blame] | 251 | html(delim); |
| 252 | html("h="); |
Lars Hjemli | b575115 | 2008-10-05 12:52:25 +0200 | [diff] [blame] | 253 | html_url_arg(head); |
Lars Hjemli | 44947bf | 2007-06-17 01:23:08 +0200 | [diff] [blame] | 254 | delim = "&"; |
| 255 | } |
| 256 | return fmt("%s", delim); |
| 257 | } |
| 258 | |
Johan Herland | c3f23d4 | 2010-06-10 01:09:24 +0200 | [diff] [blame] | 259 | static void reporevlink(const char *page, const char *name, const char *title, |
| 260 | const char *class, const char *head, const char *rev, |
| 261 | const char *path) |
Lars Hjemli | 44947bf | 2007-06-17 01:23:08 +0200 | [diff] [blame] | 262 | { |
| 263 | char *delim; |
| 264 | |
Lars Hjemli | 48c487d | 2007-06-17 13:57:51 +0200 | [diff] [blame] | 265 | delim = repolink(title, class, page, head, path); |
Florian Pritz | 8d94607 | 2010-02-01 17:55:37 +0100 | [diff] [blame] | 266 | if (rev && ctx.qry.head != NULL && strcmp(rev, ctx.qry.head)) { |
Lars Hjemli | 44947bf | 2007-06-17 01:23:08 +0200 | [diff] [blame] | 267 | html(delim); |
| 268 | html("id="); |
Lars Hjemli | b575115 | 2008-10-05 12:52:25 +0200 | [diff] [blame] | 269 | html_url_arg(rev); |
Lars Hjemli | 44947bf | 2007-06-17 01:23:08 +0200 | [diff] [blame] | 270 | } |
| 271 | html("'>"); |
| 272 | html_txt(name); |
| 273 | html("</a>"); |
| 274 | } |
Lars Hjemli | 148fb96 | 2006-12-16 00:33:28 +0100 | [diff] [blame] | 275 | |
Johan Herland | c3f23d4 | 2010-06-10 01:09:24 +0200 | [diff] [blame] | 276 | void cgit_summary_link(const char *name, const char *title, const char *class, |
| 277 | const char *head) |
Lars Hjemli | e9d3bd5 | 2008-10-05 16:55:50 +0200 | [diff] [blame] | 278 | { |
| 279 | reporevlink(NULL, name, title, class, head, NULL, NULL); |
| 280 | } |
| 281 | |
Johan Herland | c3f23d4 | 2010-06-10 01:09:24 +0200 | [diff] [blame] | 282 | void cgit_tag_link(const char *name, const char *title, const char *class, |
John Keeping | c422b9b | 2015-01-15 22:18:14 +0000 | [diff] [blame] | 283 | const char *tag) |
Lars Hjemli | cf61ad4 | 2008-10-05 21:18:45 +0200 | [diff] [blame] | 284 | { |
John Keeping | c422b9b | 2015-01-15 22:18:14 +0000 | [diff] [blame] | 285 | reporevlink("tag", name, title, class, tag, NULL, NULL); |
Lars Hjemli | cf61ad4 | 2008-10-05 21:18:45 +0200 | [diff] [blame] | 286 | } |
| 287 | |
Johan Herland | c3f23d4 | 2010-06-10 01:09:24 +0200 | [diff] [blame] | 288 | void cgit_tree_link(const char *name, const char *title, const char *class, |
| 289 | const char *head, const char *rev, const char *path) |
Lars Hjemli | 48c487d | 2007-06-17 13:57:51 +0200 | [diff] [blame] | 290 | { |
| 291 | reporevlink("tree", name, title, class, head, rev, path); |
| 292 | } |
| 293 | |
Johan Herland | c3f23d4 | 2010-06-10 01:09:24 +0200 | [diff] [blame] | 294 | void cgit_plain_link(const char *name, const char *title, const char *class, |
| 295 | const char *head, const char *rev, const char *path) |
Lars Hjemli | 65b7b87 | 2008-08-06 11:07:13 +0200 | [diff] [blame] | 296 | { |
| 297 | reporevlink("plain", name, title, class, head, rev, path); |
| 298 | } |
| 299 | |
Johan Herland | c3f23d4 | 2010-06-10 01:09:24 +0200 | [diff] [blame] | 300 | void cgit_log_link(const char *name, const char *title, const char *class, |
| 301 | const char *head, const char *rev, const char *path, |
| 302 | int ofs, const char *grep, const char *pattern, int showmsg) |
Lars Hjemli | 48c487d | 2007-06-17 13:57:51 +0200 | [diff] [blame] | 303 | { |
Lars Hjemli | 103940f | 2007-06-29 20:27:41 +0200 | [diff] [blame] | 304 | char *delim; |
| 305 | |
| 306 | delim = repolink(title, class, "log", head, path); |
Eric Wong | 21418ec | 2012-01-04 09:01:51 +0000 | [diff] [blame] | 307 | if (rev && ctx.qry.head && strcmp(rev, ctx.qry.head)) { |
Lars Hjemli | 103940f | 2007-06-29 20:27:41 +0200 | [diff] [blame] | 308 | html(delim); |
| 309 | html("id="); |
Lars Hjemli | b575115 | 2008-10-05 12:52:25 +0200 | [diff] [blame] | 310 | html_url_arg(rev); |
William Bell | c366bd6 | 2012-10-09 20:45:58 +0200 | [diff] [blame] | 311 | delim = "&"; |
Lars Hjemli | 103940f | 2007-06-29 20:27:41 +0200 | [diff] [blame] | 312 | } |
Lars Hjemli | 5114031 | 2007-11-03 10:42:37 +0100 | [diff] [blame] | 313 | if (grep && pattern) { |
| 314 | html(delim); |
| 315 | html("qt="); |
Lars Hjemli | b575115 | 2008-10-05 12:52:25 +0200 | [diff] [blame] | 316 | html_url_arg(grep); |
William Bell | c366bd6 | 2012-10-09 20:45:58 +0200 | [diff] [blame] | 317 | delim = "&"; |
Lars Hjemli | 5114031 | 2007-11-03 10:42:37 +0100 | [diff] [blame] | 318 | html(delim); |
| 319 | html("q="); |
Lars Hjemli | b575115 | 2008-10-05 12:52:25 +0200 | [diff] [blame] | 320 | html_url_arg(pattern); |
Lars Hjemli | 5114031 | 2007-11-03 10:42:37 +0100 | [diff] [blame] | 321 | } |
Lars Hjemli | 103940f | 2007-06-29 20:27:41 +0200 | [diff] [blame] | 322 | if (ofs > 0) { |
| 323 | html(delim); |
| 324 | html("ofs="); |
| 325 | htmlf("%d", ofs); |
William Bell | c366bd6 | 2012-10-09 20:45:58 +0200 | [diff] [blame] | 326 | delim = "&"; |
Lars Hjemli | 0274b57 | 2008-11-29 18:39:41 +0100 | [diff] [blame] | 327 | } |
| 328 | if (showmsg) { |
| 329 | html(delim); |
| 330 | html("showmsg=1"); |
Lars Hjemli | 103940f | 2007-06-29 20:27:41 +0200 | [diff] [blame] | 331 | } |
| 332 | html("'>"); |
| 333 | html_txt(name); |
| 334 | html("</a>"); |
Lars Hjemli | 48c487d | 2007-06-17 13:57:51 +0200 | [diff] [blame] | 335 | } |
| 336 | |
Johan Herland | c3f23d4 | 2010-06-10 01:09:24 +0200 | [diff] [blame] | 337 | void cgit_commit_link(char *name, const char *title, const char *class, |
John Keeping | eeddb5b | 2014-10-05 10:59:02 +0100 | [diff] [blame] | 338 | const char *head, const char *rev, const char *path) |
Lars Hjemli | 42a7eb9 | 2007-06-17 14:53:02 +0200 | [diff] [blame] | 339 | { |
Lars Hjemli | b228d4f | 2008-02-16 13:07:13 +0100 | [diff] [blame] | 340 | if (strlen(name) > ctx.cfg.max_msg_len && ctx.cfg.max_msg_len >= 15) { |
| 341 | name[ctx.cfg.max_msg_len] = '\0'; |
| 342 | name[ctx.cfg.max_msg_len - 1] = '.'; |
| 343 | name[ctx.cfg.max_msg_len - 2] = '.'; |
| 344 | name[ctx.cfg.max_msg_len - 3] = '.'; |
Lars Hjemli | 42a7eb9 | 2007-06-17 14:53:02 +0200 | [diff] [blame] | 345 | } |
Ragnar Ouchterlony | c358aa3 | 2009-09-14 20:19:02 +0200 | [diff] [blame] | 346 | |
| 347 | char *delim; |
| 348 | |
Johan Herland | 685872b | 2010-06-10 01:09:35 +0200 | [diff] [blame] | 349 | delim = repolink(title, class, "commit", head, path); |
Eric Wong | 21418ec | 2012-01-04 09:01:51 +0000 | [diff] [blame] | 350 | if (rev && ctx.qry.head && strcmp(rev, ctx.qry.head)) { |
Ragnar Ouchterlony | c358aa3 | 2009-09-14 20:19:02 +0200 | [diff] [blame] | 351 | html(delim); |
| 352 | html("id="); |
| 353 | html_url_arg(rev); |
| 354 | delim = "&"; |
| 355 | } |
John Keeping | 1830271 | 2014-10-05 10:59:04 +0100 | [diff] [blame] | 356 | if (ctx.qry.difftype) { |
Ragnar Ouchterlony | c358aa3 | 2009-09-14 20:19:02 +0200 | [diff] [blame] | 357 | html(delim); |
John Keeping | 1830271 | 2014-10-05 10:59:04 +0100 | [diff] [blame] | 358 | htmlf("dt=%d", ctx.qry.difftype); |
Johan Herland | d20313e | 2010-06-10 20:15:51 +0200 | [diff] [blame] | 359 | delim = "&"; |
| 360 | } |
| 361 | if (ctx.qry.context > 0 && ctx.qry.context != 3) { |
| 362 | html(delim); |
| 363 | html("context="); |
| 364 | htmlf("%d", ctx.qry.context); |
| 365 | delim = "&"; |
Ragnar Ouchterlony | c358aa3 | 2009-09-14 20:19:02 +0200 | [diff] [blame] | 366 | } |
Johan Herland | 72ef913 | 2010-06-24 17:53:20 +0200 | [diff] [blame] | 367 | if (ctx.qry.ignorews) { |
| 368 | html(delim); |
| 369 | html("ignorews=1"); |
| 370 | delim = "&"; |
| 371 | } |
Ragnar Ouchterlony | c358aa3 | 2009-09-14 20:19:02 +0200 | [diff] [blame] | 372 | html("'>"); |
Christian Franke | fe1bb0e | 2012-10-28 18:36:08 +0100 | [diff] [blame] | 373 | if (name[0] != '\0') |
| 374 | html_txt(name); |
| 375 | else |
| 376 | html_txt("(no commit message)"); |
Ragnar Ouchterlony | c358aa3 | 2009-09-14 20:19:02 +0200 | [diff] [blame] | 377 | html("</a>"); |
Lars Hjemli | 42a7eb9 | 2007-06-17 14:53:02 +0200 | [diff] [blame] | 378 | } |
| 379 | |
Johan Herland | c3f23d4 | 2010-06-10 01:09:24 +0200 | [diff] [blame] | 380 | void cgit_refs_link(const char *name, const char *title, const char *class, |
| 381 | const char *head, const char *rev, const char *path) |
Lars Hjemli | ac1f493 | 2007-10-27 10:47:44 +0200 | [diff] [blame] | 382 | { |
| 383 | reporevlink("refs", name, title, class, head, rev, path); |
| 384 | } |
| 385 | |
Johan Herland | c3f23d4 | 2010-06-10 01:09:24 +0200 | [diff] [blame] | 386 | void cgit_snapshot_link(const char *name, const char *title, const char *class, |
| 387 | const char *head, const char *rev, |
| 388 | const char *archivename) |
Lars Hjemli | eb45342 | 2007-07-23 00:11:15 +0200 | [diff] [blame] | 389 | { |
| 390 | reporevlink("snapshot", name, title, class, head, rev, archivename); |
| 391 | } |
| 392 | |
Johan Herland | c3f23d4 | 2010-06-10 01:09:24 +0200 | [diff] [blame] | 393 | void cgit_diff_link(const char *name, const char *title, const char *class, |
| 394 | const char *head, const char *new_rev, const char *old_rev, |
John Keeping | 03f537f | 2014-10-05 10:59:03 +0100 | [diff] [blame] | 395 | const char *path) |
Lars Hjemli | 4a0be58 | 2007-06-17 18:12:03 +0200 | [diff] [blame] | 396 | { |
| 397 | char *delim; |
| 398 | |
| 399 | delim = repolink(title, class, "diff", head, path); |
Florian Pritz | 8d94607 | 2010-02-01 17:55:37 +0100 | [diff] [blame] | 400 | if (new_rev && ctx.qry.head != NULL && strcmp(new_rev, ctx.qry.head)) { |
Lars Hjemli | 4a0be58 | 2007-06-17 18:12:03 +0200 | [diff] [blame] | 401 | html(delim); |
| 402 | html("id="); |
Lars Hjemli | b575115 | 2008-10-05 12:52:25 +0200 | [diff] [blame] | 403 | html_url_arg(new_rev); |
Lars Hjemli | 4a0be58 | 2007-06-17 18:12:03 +0200 | [diff] [blame] | 404 | delim = "&"; |
| 405 | } |
| 406 | if (old_rev) { |
| 407 | html(delim); |
| 408 | html("id2="); |
Lars Hjemli | b575115 | 2008-10-05 12:52:25 +0200 | [diff] [blame] | 409 | html_url_arg(old_rev); |
Ragnar Ouchterlony | c358aa3 | 2009-09-14 20:19:02 +0200 | [diff] [blame] | 410 | delim = "&"; |
| 411 | } |
John Keeping | 1830271 | 2014-10-05 10:59:04 +0100 | [diff] [blame] | 412 | if (ctx.qry.difftype) { |
Ragnar Ouchterlony | c358aa3 | 2009-09-14 20:19:02 +0200 | [diff] [blame] | 413 | html(delim); |
John Keeping | 1830271 | 2014-10-05 10:59:04 +0100 | [diff] [blame] | 414 | htmlf("dt=%d", ctx.qry.difftype); |
Johan Herland | d20313e | 2010-06-10 20:15:51 +0200 | [diff] [blame] | 415 | delim = "&"; |
| 416 | } |
| 417 | if (ctx.qry.context > 0 && ctx.qry.context != 3) { |
| 418 | html(delim); |
| 419 | html("context="); |
| 420 | htmlf("%d", ctx.qry.context); |
| 421 | delim = "&"; |
Lars Hjemli | 4a0be58 | 2007-06-17 18:12:03 +0200 | [diff] [blame] | 422 | } |
Johan Herland | 72ef913 | 2010-06-24 17:53:20 +0200 | [diff] [blame] | 423 | if (ctx.qry.ignorews) { |
| 424 | html(delim); |
| 425 | html("ignorews=1"); |
| 426 | delim = "&"; |
| 427 | } |
Lars Hjemli | 4a0be58 | 2007-06-17 18:12:03 +0200 | [diff] [blame] | 428 | html("'>"); |
| 429 | html_txt(name); |
| 430 | html("</a>"); |
| 431 | } |
| 432 | |
Johan Herland | c3f23d4 | 2010-06-10 01:09:24 +0200 | [diff] [blame] | 433 | void cgit_patch_link(const char *name, const char *title, const char *class, |
Johan Herland | eac1b67 | 2010-06-10 01:09:33 +0200 | [diff] [blame] | 434 | const char *head, const char *rev, const char *path) |
Lars Hjemli | 620bb3e | 2007-12-10 21:47:29 +0100 | [diff] [blame] | 435 | { |
Johan Herland | eac1b67 | 2010-06-10 01:09:33 +0200 | [diff] [blame] | 436 | reporevlink("patch", name, title, class, head, rev, path); |
Lars Hjemli | 620bb3e | 2007-12-10 21:47:29 +0100 | [diff] [blame] | 437 | } |
| 438 | |
Johan Herland | c3f23d4 | 2010-06-10 01:09:24 +0200 | [diff] [blame] | 439 | void cgit_stats_link(const char *name, const char *title, const char *class, |
| 440 | const char *head, const char *path) |
Lars Hjemli | eaf2d25 | 2008-12-07 13:34:16 +0100 | [diff] [blame] | 441 | { |
| 442 | reporevlink("stats", name, title, class, head, NULL, path); |
| 443 | } |
| 444 | |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 445 | static void cgit_self_link(char *name, const char *title, const char *class) |
Johan Herland | 24fd7e5 | 2010-06-10 01:09:29 +0200 | [diff] [blame] | 446 | { |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 447 | if (!strcmp(ctx.qry.page, "repolist")) |
| 448 | cgit_index_link(name, title, class, ctx.qry.search, ctx.qry.sort, |
Jason A. Donenfeld | 2e4a41e | 2015-03-03 17:23:40 +0100 | [diff] [blame^] | 449 | ctx.qry.ofs, 1); |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 450 | else if (!strcmp(ctx.qry.page, "summary")) |
| 451 | cgit_summary_link(name, title, class, ctx.qry.head); |
| 452 | else if (!strcmp(ctx.qry.page, "tag")) |
John Keeping | c422b9b | 2015-01-15 22:18:14 +0000 | [diff] [blame] | 453 | cgit_tag_link(name, title, class, ctx.qry.has_sha1 ? |
| 454 | ctx.qry.sha1 : ctx.qry.head); |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 455 | else if (!strcmp(ctx.qry.page, "tree")) |
| 456 | cgit_tree_link(name, title, class, ctx.qry.head, |
| 457 | ctx.qry.has_sha1 ? ctx.qry.sha1 : NULL, |
| 458 | ctx.qry.path); |
| 459 | else if (!strcmp(ctx.qry.page, "plain")) |
| 460 | cgit_plain_link(name, title, class, ctx.qry.head, |
| 461 | ctx.qry.has_sha1 ? ctx.qry.sha1 : NULL, |
| 462 | ctx.qry.path); |
| 463 | else if (!strcmp(ctx.qry.page, "log")) |
| 464 | cgit_log_link(name, title, class, ctx.qry.head, |
| 465 | ctx.qry.has_sha1 ? ctx.qry.sha1 : NULL, |
| 466 | ctx.qry.path, ctx.qry.ofs, |
| 467 | ctx.qry.grep, ctx.qry.search, |
| 468 | ctx.qry.showmsg); |
| 469 | else if (!strcmp(ctx.qry.page, "commit")) |
| 470 | cgit_commit_link(name, title, class, ctx.qry.head, |
| 471 | ctx.qry.has_sha1 ? ctx.qry.sha1 : NULL, |
John Keeping | eeddb5b | 2014-10-05 10:59:02 +0100 | [diff] [blame] | 472 | ctx.qry.path); |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 473 | else if (!strcmp(ctx.qry.page, "patch")) |
| 474 | cgit_patch_link(name, title, class, ctx.qry.head, |
| 475 | ctx.qry.has_sha1 ? ctx.qry.sha1 : NULL, |
| 476 | ctx.qry.path); |
| 477 | else if (!strcmp(ctx.qry.page, "refs")) |
| 478 | cgit_refs_link(name, title, class, ctx.qry.head, |
| 479 | ctx.qry.has_sha1 ? ctx.qry.sha1 : NULL, |
| 480 | ctx.qry.path); |
| 481 | else if (!strcmp(ctx.qry.page, "snapshot")) |
| 482 | cgit_snapshot_link(name, title, class, ctx.qry.head, |
| 483 | ctx.qry.has_sha1 ? ctx.qry.sha1 : NULL, |
| 484 | ctx.qry.path); |
| 485 | else if (!strcmp(ctx.qry.page, "diff")) |
| 486 | cgit_diff_link(name, title, class, ctx.qry.head, |
| 487 | ctx.qry.sha1, ctx.qry.sha2, |
John Keeping | 03f537f | 2014-10-05 10:59:03 +0100 | [diff] [blame] | 488 | ctx.qry.path); |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 489 | else if (!strcmp(ctx.qry.page, "stats")) |
| 490 | cgit_stats_link(name, title, class, ctx.qry.head, |
| 491 | ctx.qry.path); |
John Keeping | 6d8a789 | 2013-03-06 20:51:54 +0000 | [diff] [blame] | 492 | else { |
| 493 | /* Don't known how to make link for this page */ |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 494 | repolink(title, class, ctx.qry.page, ctx.qry.head, ctx.qry.path); |
John Keeping | 6d8a789 | 2013-03-06 20:51:54 +0000 | [diff] [blame] | 495 | html("><!-- cgit_self_link() doesn't know how to make link for page '"); |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 496 | html_txt(ctx.qry.page); |
John Keeping | 6d8a789 | 2013-03-06 20:51:54 +0000 | [diff] [blame] | 497 | html("' -->"); |
| 498 | html_txt(name); |
| 499 | html("</a>"); |
| 500 | } |
Johan Herland | 24fd7e5 | 2010-06-10 01:09:29 +0200 | [diff] [blame] | 501 | } |
| 502 | |
Lars Hjemli | 4e9107a | 2007-07-22 23:42:55 +0200 | [diff] [blame] | 503 | void cgit_object_link(struct object *obj) |
| 504 | { |
Lars Hjemli | c57aceb | 2008-12-01 21:58:59 +0100 | [diff] [blame] | 505 | char *page, *shortrev, *fullrev, *name; |
Lars Hjemli | 4e9107a | 2007-07-22 23:42:55 +0200 | [diff] [blame] | 506 | |
Lars Hjemli | c57aceb | 2008-12-01 21:58:59 +0100 | [diff] [blame] | 507 | fullrev = sha1_to_hex(obj->sha1); |
| 508 | shortrev = xstrdup(fullrev); |
| 509 | shortrev[10] = '\0'; |
Lars Hjemli | 4e9107a | 2007-07-22 23:42:55 +0200 | [diff] [blame] | 510 | if (obj->type == OBJ_COMMIT) { |
Lukas Fleischer | 53bc747 | 2013-03-03 16:04:29 +0100 | [diff] [blame] | 511 | cgit_commit_link(fmt("commit %s...", shortrev), NULL, NULL, |
John Keeping | eeddb5b | 2014-10-05 10:59:02 +0100 | [diff] [blame] | 512 | ctx.qry.head, fullrev, NULL); |
Lars Hjemli | 4e9107a | 2007-07-22 23:42:55 +0200 | [diff] [blame] | 513 | return; |
Lars Hjemli | 8b5fc6d | 2008-10-05 21:12:08 +0200 | [diff] [blame] | 514 | } else if (obj->type == OBJ_TREE) |
Lars Hjemli | 4e9107a | 2007-07-22 23:42:55 +0200 | [diff] [blame] | 515 | page = "tree"; |
Lars Hjemli | 8b5fc6d | 2008-10-05 21:12:08 +0200 | [diff] [blame] | 516 | else if (obj->type == OBJ_TAG) |
Lars Hjemli | fc5880f | 2007-10-28 15:40:47 +0100 | [diff] [blame] | 517 | page = "tag"; |
Lars Hjemli | 8b5fc6d | 2008-10-05 21:12:08 +0200 | [diff] [blame] | 518 | else |
Lars Hjemli | 4e9107a | 2007-07-22 23:42:55 +0200 | [diff] [blame] | 519 | page = "blob"; |
Lars Hjemli | c57aceb | 2008-12-01 21:58:59 +0100 | [diff] [blame] | 520 | name = fmt("%s %s...", typename(obj->type), shortrev); |
| 521 | reporevlink(page, name, NULL, NULL, ctx.qry.head, fullrev, NULL); |
Lars Hjemli | 4e9107a | 2007-07-22 23:42:55 +0200 | [diff] [blame] | 522 | } |
| 523 | |
Lukas Fleischer | bafab42 | 2013-03-04 08:52:33 +0100 | [diff] [blame] | 524 | static struct string_list_item *lookup_path(struct string_list *list, |
| 525 | const char *path) |
Lars Hjemli | 6857bec | 2011-06-15 10:04:13 +0200 | [diff] [blame] | 526 | { |
| 527 | struct string_list_item *item; |
| 528 | |
| 529 | while (path && path[0]) { |
| 530 | if ((item = string_list_lookup(list, path))) |
| 531 | return item; |
| 532 | if (!(path = strchr(path, '/'))) |
| 533 | break; |
| 534 | path++; |
| 535 | } |
| 536 | return NULL; |
| 537 | } |
| 538 | |
| 539 | void cgit_submodule_link(const char *class, char *path, const char *rev) |
| 540 | { |
| 541 | struct string_list *list; |
| 542 | struct string_list_item *item; |
| 543 | char tail, *dir; |
| 544 | size_t len; |
| 545 | |
Jason A. Donenfeld | 40e1d9b | 2013-03-20 20:43:13 +0100 | [diff] [blame] | 546 | len = 0; |
Lars Hjemli | 6857bec | 2011-06-15 10:04:13 +0200 | [diff] [blame] | 547 | tail = 0; |
| 548 | list = &ctx.repo->submodules; |
| 549 | item = lookup_path(list, path); |
| 550 | if (!item) { |
| 551 | len = strlen(path); |
| 552 | tail = path[len - 1]; |
| 553 | if (tail == '/') { |
| 554 | path[len - 1] = 0; |
| 555 | item = lookup_path(list, path); |
| 556 | } |
| 557 | } |
| 558 | html("<a "); |
| 559 | if (class) |
| 560 | htmlf("class='%s' ", class); |
| 561 | html("href='"); |
| 562 | if (item) { |
John Keeping | fb3655d | 2013-04-06 10:28:57 +0100 | [diff] [blame] | 563 | html_attrf(item->util, rev); |
Lars Hjemli | 6857bec | 2011-06-15 10:04:13 +0200 | [diff] [blame] | 564 | } else if (ctx.repo->module_link) { |
| 565 | dir = strrchr(path, '/'); |
| 566 | if (dir) |
| 567 | dir++; |
| 568 | else |
| 569 | dir = path; |
John Keeping | fb3655d | 2013-04-06 10:28:57 +0100 | [diff] [blame] | 570 | html_attrf(ctx.repo->module_link, dir, rev); |
Lars Hjemli | 6857bec | 2011-06-15 10:04:13 +0200 | [diff] [blame] | 571 | } else { |
| 572 | html("#"); |
| 573 | } |
| 574 | html("'>"); |
| 575 | html_txt(path); |
| 576 | html("</a>"); |
John Keeping | fb3655d | 2013-04-06 10:28:57 +0100 | [diff] [blame] | 577 | html_txtf(" @ %.7s", rev); |
Lars Hjemli | 6857bec | 2011-06-15 10:04:13 +0200 | [diff] [blame] | 578 | if (item && tail) |
| 579 | path[len - 1] = tail; |
| 580 | } |
| 581 | |
Johan Herland | c3f23d4 | 2010-06-10 01:09:24 +0200 | [diff] [blame] | 582 | void cgit_print_date(time_t secs, const char *format, int local_time) |
Lars Hjemli | 148fb96 | 2006-12-16 00:33:28 +0100 | [diff] [blame] | 583 | { |
Lars Hjemli | 5db3917 | 2007-05-22 23:08:46 +0200 | [diff] [blame] | 584 | char buf[64]; |
Lars Hjemli | 148fb96 | 2006-12-16 00:33:28 +0100 | [diff] [blame] | 585 | struct tm *time; |
| 586 | |
Lars Hjemli | fc4c4ba | 2007-12-02 22:11:35 +0100 | [diff] [blame] | 587 | if (!secs) |
| 588 | return; |
Jason A. Donenfeld | bdae1d8 | 2013-03-03 23:21:33 -0500 | [diff] [blame] | 589 | if (local_time) |
Stefan Naewe | 0f0ab14 | 2008-08-01 14:54:38 +0200 | [diff] [blame] | 590 | time = localtime(&secs); |
| 591 | else |
| 592 | time = gmtime(&secs); |
Lars Hjemli | 5db3917 | 2007-05-22 23:08:46 +0200 | [diff] [blame] | 593 | strftime(buf, sizeof(buf)-1, format, time); |
Lars Hjemli | 148fb96 | 2006-12-16 00:33:28 +0100 | [diff] [blame] | 594 | html_txt(buf); |
Lars Hjemli | 148fb96 | 2006-12-16 00:33:28 +0100 | [diff] [blame] | 595 | } |
| 596 | |
John Keeping | caed6cb | 2014-12-20 13:59:39 +0000 | [diff] [blame] | 597 | static void print_rel_date(time_t t, double value, |
| 598 | const char *class, const char *suffix) |
| 599 | { |
| 600 | char buf[64]; |
| 601 | struct tm *time; |
| 602 | |
| 603 | if (ctx.cfg.local_time) |
| 604 | time = localtime(&t); |
| 605 | else |
| 606 | time = gmtime(&t); |
| 607 | strftime(buf, sizeof(buf) - 1, FMT_LONGDATE, time); |
| 608 | |
| 609 | htmlf("<span class='%s' title='", class); |
| 610 | html_attr(buf); |
| 611 | htmlf("'>%.0f %s</span>", value, suffix); |
| 612 | } |
| 613 | |
Johan Herland | c3f23d4 | 2010-06-10 01:09:24 +0200 | [diff] [blame] | 614 | void cgit_print_age(time_t t, time_t max_relative, const char *format) |
Lars Hjemli | 5db3917 | 2007-05-22 23:08:46 +0200 | [diff] [blame] | 615 | { |
| 616 | time_t now, secs; |
| 617 | |
Lars Hjemli | fc4c4ba | 2007-12-02 22:11:35 +0100 | [diff] [blame] | 618 | if (!t) |
| 619 | return; |
Lars Hjemli | 5db3917 | 2007-05-22 23:08:46 +0200 | [diff] [blame] | 620 | time(&now); |
| 621 | secs = now - t; |
Jason A. Donenfeld | bb3cc0d | 2014-01-17 15:41:41 +0100 | [diff] [blame] | 622 | if (secs < 0) |
| 623 | secs = 0; |
Lars Hjemli | 5db3917 | 2007-05-22 23:08:46 +0200 | [diff] [blame] | 624 | |
| 625 | if (secs > max_relative && max_relative >= 0) { |
Stefan Naewe | 0f0ab14 | 2008-08-01 14:54:38 +0200 | [diff] [blame] | 626 | cgit_print_date(t, format, ctx.cfg.local_time); |
Lars Hjemli | 5db3917 | 2007-05-22 23:08:46 +0200 | [diff] [blame] | 627 | return; |
| 628 | } |
| 629 | |
| 630 | if (secs < TM_HOUR * 2) { |
John Keeping | caed6cb | 2014-12-20 13:59:39 +0000 | [diff] [blame] | 631 | print_rel_date(t, secs * 1.0 / TM_MIN, "age-mins", "min."); |
Lars Hjemli | 5db3917 | 2007-05-22 23:08:46 +0200 | [diff] [blame] | 632 | return; |
| 633 | } |
| 634 | if (secs < TM_DAY * 2) { |
John Keeping | caed6cb | 2014-12-20 13:59:39 +0000 | [diff] [blame] | 635 | print_rel_date(t, secs * 1.0 / TM_HOUR, "age-hours", "hours"); |
Lars Hjemli | 5db3917 | 2007-05-22 23:08:46 +0200 | [diff] [blame] | 636 | return; |
| 637 | } |
| 638 | if (secs < TM_WEEK * 2) { |
John Keeping | caed6cb | 2014-12-20 13:59:39 +0000 | [diff] [blame] | 639 | print_rel_date(t, secs * 1.0 / TM_DAY, "age-days", "days"); |
Lars Hjemli | 5db3917 | 2007-05-22 23:08:46 +0200 | [diff] [blame] | 640 | return; |
| 641 | } |
| 642 | if (secs < TM_MONTH * 2) { |
John Keeping | caed6cb | 2014-12-20 13:59:39 +0000 | [diff] [blame] | 643 | print_rel_date(t, secs * 1.0 / TM_WEEK, "age-weeks", "weeks"); |
Lars Hjemli | 5db3917 | 2007-05-22 23:08:46 +0200 | [diff] [blame] | 644 | return; |
| 645 | } |
| 646 | if (secs < TM_YEAR * 2) { |
John Keeping | caed6cb | 2014-12-20 13:59:39 +0000 | [diff] [blame] | 647 | print_rel_date(t, secs * 1.0 / TM_MONTH, "age-months", "months"); |
Lars Hjemli | 5db3917 | 2007-05-22 23:08:46 +0200 | [diff] [blame] | 648 | return; |
| 649 | } |
John Keeping | caed6cb | 2014-12-20 13:59:39 +0000 | [diff] [blame] | 650 | print_rel_date(t, secs * 1.0 / TM_YEAR, "age-years", "years"); |
Lars Hjemli | 5db3917 | 2007-05-22 23:08:46 +0200 | [diff] [blame] | 651 | } |
| 652 | |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 653 | void cgit_print_http_headers(void) |
Lars Hjemli | 5a106eb | 2006-12-11 16:38:30 +0100 | [diff] [blame] | 654 | { |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 655 | if (ctx.env.no_http && !strcmp(ctx.env.no_http, "1")) |
Lars Hjemli | 0cbb508 | 2009-01-22 23:33:56 +0100 | [diff] [blame] | 656 | return; |
| 657 | |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 658 | if (ctx.page.status) |
| 659 | htmlf("Status: %d %s\n", ctx.page.status, ctx.page.statusmsg); |
| 660 | if (ctx.page.mimetype && ctx.page.charset) |
| 661 | htmlf("Content-Type: %s; charset=%s\n", ctx.page.mimetype, |
| 662 | ctx.page.charset); |
| 663 | else if (ctx.page.mimetype) |
| 664 | htmlf("Content-Type: %s\n", ctx.page.mimetype); |
| 665 | if (ctx.page.size) |
| 666 | htmlf("Content-Length: %zd\n", ctx.page.size); |
| 667 | if (ctx.page.filename) |
Lars Hjemli | f3c1a18 | 2008-03-24 00:51:19 +0100 | [diff] [blame] | 668 | htmlf("Content-Disposition: inline; filename=\"%s\"\n", |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 669 | ctx.page.filename); |
| 670 | if (!ctx.env.authenticated) |
Jason A. Donenfeld | d6e9200 | 2014-01-14 21:49:31 +0100 | [diff] [blame] | 671 | html("Cache-Control: no-cache, no-store\n"); |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 672 | htmlf("Last-Modified: %s\n", http_date(ctx.page.modified)); |
| 673 | htmlf("Expires: %s\n", http_date(ctx.page.expires)); |
| 674 | if (ctx.page.etag) |
| 675 | htmlf("ETag: \"%s\"\n", ctx.page.etag); |
Lars Hjemli | 5a106eb | 2006-12-11 16:38:30 +0100 | [diff] [blame] | 676 | html("\n"); |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 677 | if (ctx.env.request_method && !strcmp(ctx.env.request_method, "HEAD")) |
Lars Hjemli | 3ff58dd | 2009-02-19 23:24:15 +0100 | [diff] [blame] | 678 | exit(0); |
Lars Hjemli | f3c1a18 | 2008-03-24 00:51:19 +0100 | [diff] [blame] | 679 | } |
| 680 | |
John Keeping | 3c53ebf | 2014-08-01 22:14:19 +0100 | [diff] [blame] | 681 | static void print_rel_vcs_link(const char *url) |
| 682 | { |
| 683 | html("<link rel='vcs-git' href='"); |
| 684 | html_attr(url); |
| 685 | html("' title='"); |
| 686 | html_attr(ctx.repo->name); |
| 687 | html(" Git repository'/>\n"); |
| 688 | } |
| 689 | |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 690 | void cgit_print_docstart(void) |
Lars Hjemli | f3c1a18 | 2008-03-24 00:51:19 +0100 | [diff] [blame] | 691 | { |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 692 | if (ctx.cfg.embedded) { |
| 693 | if (ctx.cfg.header) |
| 694 | html_include(ctx.cfg.header); |
Lars Hjemli | 0cbb508 | 2009-01-22 23:33:56 +0100 | [diff] [blame] | 695 | return; |
Lars Hjemli | 80550bb | 2009-08-11 10:12:35 +0200 | [diff] [blame] | 696 | } |
Lars Hjemli | 0cbb508 | 2009-01-22 23:33:56 +0100 | [diff] [blame] | 697 | |
Lukas Fleischer | 996f86e | 2013-04-01 17:11:13 +0200 | [diff] [blame] | 698 | const char *host = cgit_hosturl(); |
Lars Hjemli | 5a106eb | 2006-12-11 16:38:30 +0100 | [diff] [blame] | 699 | html(cgit_doctype); |
Lars Hjemli | 2915483 | 2007-11-11 13:04:28 +0100 | [diff] [blame] | 700 | html("<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en' lang='en'>\n"); |
Lars Hjemli | 5a106eb | 2006-12-11 16:38:30 +0100 | [diff] [blame] | 701 | html("<head>\n"); |
| 702 | html("<title>"); |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 703 | html_txt(ctx.page.title); |
Lars Hjemli | 5a106eb | 2006-12-11 16:38:30 +0100 | [diff] [blame] | 704 | html("</title>\n"); |
Lars Hjemli | f692503 | 2007-06-18 09:42:10 +0200 | [diff] [blame] | 705 | htmlf("<meta name='generator' content='cgit %s'/>\n", cgit_version); |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 706 | if (ctx.cfg.robots && *ctx.cfg.robots) |
| 707 | htmlf("<meta name='robots' content='%s'/>\n", ctx.cfg.robots); |
Lars Hjemli | 5a106eb | 2006-12-11 16:38:30 +0100 | [diff] [blame] | 708 | html("<link rel='stylesheet' type='text/css' href='"); |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 709 | html_attr(ctx.cfg.css); |
Lars Hjemli | 5a106eb | 2006-12-11 16:38:30 +0100 | [diff] [blame] | 710 | html("'/>\n"); |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 711 | if (ctx.cfg.favicon) { |
Lars Hjemli | 502865a | 2008-07-19 20:40:30 +0200 | [diff] [blame] | 712 | html("<link rel='shortcut icon' href='"); |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 713 | html_attr(ctx.cfg.favicon); |
Lars Hjemli | 502865a | 2008-07-19 20:40:30 +0200 | [diff] [blame] | 714 | html("'/>\n"); |
| 715 | } |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 716 | if (host && ctx.repo && ctx.qry.head) { |
John Keeping | fb3655d | 2013-04-06 10:28:57 +0100 | [diff] [blame] | 717 | struct strbuf sb = STRBUF_INIT; |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 718 | strbuf_addf(&sb, "h=%s", ctx.qry.head); |
John Keeping | fb3655d | 2013-04-06 10:28:57 +0100 | [diff] [blame] | 719 | |
Diego Ongaro | 694dd43 | 2009-06-10 18:18:34 -0500 | [diff] [blame] | 720 | html("<link rel='alternate' title='Atom feed' href='"); |
| 721 | html(cgit_httpscheme()); |
Lars Hjemli | b2a3d31 | 2008-05-21 08:17:54 +0200 | [diff] [blame] | 722 | html_attr(cgit_hosturl()); |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 723 | html_attr(cgit_fileurl(ctx.repo->url, "atom", ctx.qry.vpath, |
John Keeping | fb3655d | 2013-04-06 10:28:57 +0100 | [diff] [blame] | 724 | sb.buf)); |
Mark Lodato | b5a3a20 | 2009-03-15 00:11:54 -0400 | [diff] [blame] | 725 | html("' type='application/atom+xml'/>\n"); |
John Keeping | fb3655d | 2013-04-06 10:28:57 +0100 | [diff] [blame] | 726 | strbuf_release(&sb); |
Lars Hjemli | b2a3d31 | 2008-05-21 08:17:54 +0200 | [diff] [blame] | 727 | } |
John Keeping | 3c53ebf | 2014-08-01 22:14:19 +0100 | [diff] [blame] | 728 | if (ctx.repo) |
| 729 | cgit_add_clone_urls(print_rel_vcs_link); |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 730 | if (ctx.cfg.head_include) |
| 731 | html_include(ctx.cfg.head_include); |
Lars Hjemli | 5a106eb | 2006-12-11 16:38:30 +0100 | [diff] [blame] | 732 | html("</head>\n"); |
| 733 | html("<body>\n"); |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 734 | if (ctx.cfg.header) |
| 735 | html_include(ctx.cfg.header); |
Lars Hjemli | 5a106eb | 2006-12-11 16:38:30 +0100 | [diff] [blame] | 736 | } |
| 737 | |
| 738 | void cgit_print_docend() |
| 739 | { |
Lars Hjemli | 80550bb | 2009-08-11 10:12:35 +0200 | [diff] [blame] | 740 | html("</div> <!-- class=content -->\n"); |
| 741 | if (ctx.cfg.embedded) { |
| 742 | html("</div> <!-- id=cgit -->\n"); |
| 743 | if (ctx.cfg.footer) |
| 744 | html_include(ctx.cfg.footer); |
| 745 | return; |
| 746 | } |
Lars Hjemli | de5e928 | 2008-06-26 13:53:30 +0200 | [diff] [blame] | 747 | if (ctx.cfg.footer) |
| 748 | html_include(ctx.cfg.footer); |
| 749 | else { |
Jason A. Donenfeld | 2159414 | 2014-03-19 03:11:45 -0600 | [diff] [blame] | 750 | htmlf("<div class='footer'>generated by <a href='http://git.zx2c4.com/cgit/about/'>cgit %s</a> at ", |
Lars Hjemli | b9aabf0 | 2008-10-05 19:09:58 +0200 | [diff] [blame] | 751 | cgit_version); |
Stefan Naewe | 0f0ab14 | 2008-08-01 14:54:38 +0200 | [diff] [blame] | 752 | cgit_print_date(time(NULL), FMT_LONGDATE, ctx.cfg.local_time); |
Lars Hjemli | de5e928 | 2008-06-26 13:53:30 +0200 | [diff] [blame] | 753 | html("</div>\n"); |
| 754 | } |
Lars Hjemli | 80550bb | 2009-08-11 10:12:35 +0200 | [diff] [blame] | 755 | html("</div> <!-- id=cgit -->\n"); |
Lars Hjemli | de5e928 | 2008-06-26 13:53:30 +0200 | [diff] [blame] | 756 | html("</body>\n</html>\n"); |
Lars Hjemli | 0c8e184 | 2007-10-30 10:47:38 +0100 | [diff] [blame] | 757 | } |
| 758 | |
John Keeping | bbfa006 | 2014-08-01 22:14:17 +0100 | [diff] [blame] | 759 | static void add_clone_urls(void (*fn)(const char *), char *txt, char *suffix) |
| 760 | { |
Lukas Fleischer | 1a9e566 | 2015-02-05 10:11:42 +0100 | [diff] [blame] | 761 | struct strbuf **url_list = strbuf_split_str(txt, ' ', 0); |
| 762 | int i; |
John Keeping | bbfa006 | 2014-08-01 22:14:17 +0100 | [diff] [blame] | 763 | |
Lukas Fleischer | 1a9e566 | 2015-02-05 10:11:42 +0100 | [diff] [blame] | 764 | for (i = 0; url_list[i]; i++) { |
| 765 | strbuf_rtrim(url_list[i]); |
| 766 | if (url_list[i]->len == 0) |
| 767 | continue; |
| 768 | if (suffix && *suffix) |
| 769 | strbuf_addf(url_list[i], "/%s", suffix); |
| 770 | fn(url_list[i]->buf); |
John Keeping | bbfa006 | 2014-08-01 22:14:17 +0100 | [diff] [blame] | 771 | } |
| 772 | |
Lukas Fleischer | 1a9e566 | 2015-02-05 10:11:42 +0100 | [diff] [blame] | 773 | strbuf_list_free(url_list); |
John Keeping | bbfa006 | 2014-08-01 22:14:17 +0100 | [diff] [blame] | 774 | } |
| 775 | |
| 776 | void cgit_add_clone_urls(void (*fn)(const char *)) |
| 777 | { |
| 778 | if (ctx.repo->clone_url) |
| 779 | add_clone_urls(fn, expand_macros(ctx.repo->clone_url), NULL); |
| 780 | else if (ctx.cfg.clone_prefix) |
| 781 | add_clone_urls(fn, ctx.cfg.clone_prefix, ctx.repo->url); |
| 782 | } |
| 783 | |
Lukas Fleischer | bafab42 | 2013-03-04 08:52:33 +0100 | [diff] [blame] | 784 | static int print_branch_option(const char *refname, const unsigned char *sha1, |
| 785 | int flags, void *cb_data) |
Lars Hjemli | 0c8e184 | 2007-10-30 10:47:38 +0100 | [diff] [blame] | 786 | { |
| 787 | char *name = (char *)refname; |
Lars Hjemli | d14d77f | 2008-02-16 11:53:40 +0100 | [diff] [blame] | 788 | html_option(name, name, ctx.qry.head); |
Lars Hjemli | 0c8e184 | 2007-10-30 10:47:38 +0100 | [diff] [blame] | 789 | return 0; |
| 790 | } |
| 791 | |
Johan Herland | c3f23d4 | 2010-06-10 01:09:24 +0200 | [diff] [blame] | 792 | void cgit_add_hidden_formfields(int incl_head, int incl_search, |
| 793 | const char *page) |
Lars Hjemli | 0c8e184 | 2007-10-30 10:47:38 +0100 | [diff] [blame] | 794 | { |
Lars Hjemli | b228d4f | 2008-02-16 13:07:13 +0100 | [diff] [blame] | 795 | if (!ctx.cfg.virtual_root) { |
John Keeping | fb3655d | 2013-04-06 10:28:57 +0100 | [diff] [blame] | 796 | struct strbuf url = STRBUF_INIT; |
| 797 | |
| 798 | strbuf_addf(&url, "%s/%s", ctx.qry.repo, page); |
Johan Herland | c8e3295 | 2010-06-10 01:09:27 +0200 | [diff] [blame] | 799 | if (ctx.qry.vpath) |
John Keeping | fb3655d | 2013-04-06 10:28:57 +0100 | [diff] [blame] | 800 | strbuf_addf(&url, "/%s", ctx.qry.vpath); |
| 801 | html_hidden("url", url.buf); |
| 802 | strbuf_release(&url); |
Lars Hjemli | 0c8e184 | 2007-10-30 10:47:38 +0100 | [diff] [blame] | 803 | } |
| 804 | |
Lars Hjemli | 25c8432 | 2008-07-27 12:32:08 +0200 | [diff] [blame] | 805 | if (incl_head && ctx.qry.head && ctx.repo->defbranch && |
| 806 | strcmp(ctx.qry.head, ctx.repo->defbranch)) |
Lars Hjemli | d14d77f | 2008-02-16 11:53:40 +0100 | [diff] [blame] | 807 | html_hidden("h", ctx.qry.head); |
Lars Hjemli | 0c8e184 | 2007-10-30 10:47:38 +0100 | [diff] [blame] | 808 | |
Lars Hjemli | d14d77f | 2008-02-16 11:53:40 +0100 | [diff] [blame] | 809 | if (ctx.qry.sha1) |
| 810 | html_hidden("id", ctx.qry.sha1); |
| 811 | if (ctx.qry.sha2) |
| 812 | html_hidden("id2", ctx.qry.sha2); |
Lars Hjemli | 0274b57 | 2008-11-29 18:39:41 +0100 | [diff] [blame] | 813 | if (ctx.qry.showmsg) |
| 814 | html_hidden("showmsg", "1"); |
Lars Hjemli | 0c8e184 | 2007-10-30 10:47:38 +0100 | [diff] [blame] | 815 | |
| 816 | if (incl_search) { |
Lars Hjemli | d14d77f | 2008-02-16 11:53:40 +0100 | [diff] [blame] | 817 | if (ctx.qry.grep) |
| 818 | html_hidden("qt", ctx.qry.grep); |
| 819 | if (ctx.qry.search) |
| 820 | html_hidden("q", ctx.qry.search); |
Lars Hjemli | 0c8e184 | 2007-10-30 10:47:38 +0100 | [diff] [blame] | 821 | } |
Lars Hjemli | 5a106eb | 2006-12-11 16:38:30 +0100 | [diff] [blame] | 822 | } |
| 823 | |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 824 | static const char *hc(const char *page) |
Lars Hjemli | f135569 | 2008-04-12 15:53:31 +0200 | [diff] [blame] | 825 | { |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 826 | return strcmp(ctx.qry.page, page) ? NULL : "active"; |
Lars Hjemli | f135569 | 2008-04-12 15:53:31 +0200 | [diff] [blame] | 827 | } |
| 828 | |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 829 | static void cgit_print_path_crumbs(char *path) |
Johan Herland | 24fd7e5 | 2010-06-10 01:09:29 +0200 | [diff] [blame] | 830 | { |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 831 | char *old_path = ctx.qry.path; |
Johan Herland | 24fd7e5 | 2010-06-10 01:09:29 +0200 | [diff] [blame] | 832 | char *p = path, *q, *end = path + strlen(path); |
| 833 | |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 834 | ctx.qry.path = NULL; |
| 835 | cgit_self_link("root", NULL, NULL); |
| 836 | ctx.qry.path = p = path; |
Johan Herland | 24fd7e5 | 2010-06-10 01:09:29 +0200 | [diff] [blame] | 837 | while (p < end) { |
| 838 | if (!(q = strchr(p, '/'))) |
| 839 | q = end; |
| 840 | *q = '\0'; |
| 841 | html_txt("/"); |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 842 | cgit_self_link(p, NULL, NULL); |
Johan Herland | 24fd7e5 | 2010-06-10 01:09:29 +0200 | [diff] [blame] | 843 | if (q < end) |
| 844 | *q = '/'; |
| 845 | p = q + 1; |
| 846 | } |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 847 | ctx.qry.path = old_path; |
Johan Herland | 24fd7e5 | 2010-06-10 01:09:29 +0200 | [diff] [blame] | 848 | } |
| 849 | |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 850 | static void print_header(void) |
Lars Hjemli | 5a106eb | 2006-12-11 16:38:30 +0100 | [diff] [blame] | 851 | { |
Bernhard Reutner-Fischer | 808c685 | 2010-12-23 12:47:54 +0100 | [diff] [blame] | 852 | char *logo = NULL, *logo_link = NULL; |
| 853 | |
Lars Hjemli | f135569 | 2008-04-12 15:53:31 +0200 | [diff] [blame] | 854 | html("<table id='header'>\n"); |
| 855 | html("<tr>\n"); |
Matthew Metnetsky | 6421dc3 | 2009-06-29 21:27:51 -0400 | [diff] [blame] | 856 | |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 857 | if (ctx.repo && ctx.repo->logo && *ctx.repo->logo) |
| 858 | logo = ctx.repo->logo; |
Bernhard Reutner-Fischer | 808c685 | 2010-12-23 12:47:54 +0100 | [diff] [blame] | 859 | else |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 860 | logo = ctx.cfg.logo; |
| 861 | if (ctx.repo && ctx.repo->logo_link && *ctx.repo->logo_link) |
| 862 | logo_link = ctx.repo->logo_link; |
Bernhard Reutner-Fischer | 808c685 | 2010-12-23 12:47:54 +0100 | [diff] [blame] | 863 | else |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 864 | logo_link = ctx.cfg.logo_link; |
Bernhard Reutner-Fischer | 808c685 | 2010-12-23 12:47:54 +0100 | [diff] [blame] | 865 | if (logo && *logo) { |
Matthew Metnetsky | 6421dc3 | 2009-06-29 21:27:51 -0400 | [diff] [blame] | 866 | html("<td class='logo' rowspan='2'><a href='"); |
Bernhard Reutner-Fischer | 808c685 | 2010-12-23 12:47:54 +0100 | [diff] [blame] | 867 | if (logo_link && *logo_link) |
| 868 | html_attr(logo_link); |
Matthew Metnetsky | 6421dc3 | 2009-06-29 21:27:51 -0400 | [diff] [blame] | 869 | else |
| 870 | html_attr(cgit_rooturl()); |
| 871 | html("'><img src='"); |
Bernhard Reutner-Fischer | 808c685 | 2010-12-23 12:47:54 +0100 | [diff] [blame] | 872 | html_attr(logo); |
Matthew Metnetsky | 6421dc3 | 2009-06-29 21:27:51 -0400 | [diff] [blame] | 873 | html("' alt='cgit logo'/></a></td>\n"); |
| 874 | } |
Lars Hjemli | 931fc6d | 2008-04-13 10:57:11 +0200 | [diff] [blame] | 875 | |
Lars Hjemli | f135569 | 2008-04-12 15:53:31 +0200 | [diff] [blame] | 876 | html("<td class='main'>"); |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 877 | if (ctx.repo) { |
Jason A. Donenfeld | 2e4a41e | 2015-03-03 17:23:40 +0100 | [diff] [blame^] | 878 | cgit_index_link("index", NULL, NULL, NULL, NULL, 0, 1); |
Lars Hjemli | 17890d0 | 2008-05-03 12:44:20 +0200 | [diff] [blame] | 879 | html(" : "); |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 880 | cgit_summary_link(ctx.repo->name, ctx.repo->name, NULL, NULL); |
| 881 | if (ctx.env.authenticated) { |
Jason A. Donenfeld | d6e9200 | 2014-01-14 21:49:31 +0100 | [diff] [blame] | 882 | html("</td><td class='form'>"); |
| 883 | html("<form method='get' action=''>\n"); |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 884 | cgit_add_hidden_formfields(0, 1, ctx.qry.page); |
Jason A. Donenfeld | d6e9200 | 2014-01-14 21:49:31 +0100 | [diff] [blame] | 885 | html("<select name='h' onchange='this.form.submit();'>\n"); |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 886 | for_each_branch_ref(print_branch_option, ctx.qry.head); |
Jason A. Donenfeld | d6e9200 | 2014-01-14 21:49:31 +0100 | [diff] [blame] | 887 | html("</select> "); |
| 888 | html("<input type='submit' name='' value='switch'/>"); |
| 889 | html("</form>"); |
| 890 | } |
Lars Hjemli | 7c0d2d9 | 2008-04-12 19:59:41 +0200 | [diff] [blame] | 891 | } else |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 892 | html_txt(ctx.cfg.root_title); |
Lars Hjemli | 3cfcb08 | 2008-04-15 00:00:11 +0200 | [diff] [blame] | 893 | html("</td></tr>\n"); |
Lars Hjemli | 931fc6d | 2008-04-13 10:57:11 +0200 | [diff] [blame] | 894 | |
Lars Hjemli | 2d6ee03 | 2008-07-27 12:22:16 +0200 | [diff] [blame] | 895 | html("<tr><td class='sub'>"); |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 896 | if (ctx.repo) { |
| 897 | html_txt(ctx.repo->desc); |
Lars Hjemli | 2d6ee03 | 2008-07-27 12:22:16 +0200 | [diff] [blame] | 898 | html("</td><td class='sub right'>"); |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 899 | html_txt(ctx.repo->owner); |
Lars Hjemli | 3cfcb08 | 2008-04-15 00:00:11 +0200 | [diff] [blame] | 900 | } else { |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 901 | if (ctx.cfg.root_desc) |
| 902 | html_txt(ctx.cfg.root_desc); |
| 903 | else if (ctx.cfg.index_info) |
| 904 | html_include(ctx.cfg.index_info); |
Lars Hjemli | 931fc6d | 2008-04-13 10:57:11 +0200 | [diff] [blame] | 905 | } |
Lars Hjemli | 3cfcb08 | 2008-04-15 00:00:11 +0200 | [diff] [blame] | 906 | html("</td></tr></table>\n"); |
Lars Hjemli | ef0c6aa | 2009-07-25 12:19:31 +0200 | [diff] [blame] | 907 | } |
| 908 | |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 909 | void cgit_print_pageheader(void) |
Lars Hjemli | ef0c6aa | 2009-07-25 12:19:31 +0200 | [diff] [blame] | 910 | { |
Lars Hjemli | ef0c6aa | 2009-07-25 12:19:31 +0200 | [diff] [blame] | 911 | html("<div id='cgit'>"); |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 912 | if (!ctx.env.authenticated || !ctx.cfg.noheader) |
| 913 | print_header(); |
Lars Hjemli | f135569 | 2008-04-12 15:53:31 +0200 | [diff] [blame] | 914 | |
| 915 | html("<table class='tabs'><tr><td>\n"); |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 916 | if (ctx.env.authenticated && ctx.repo) { |
Jason A. Donenfeld | 3cbbb8e | 2014-01-17 13:53:37 +0100 | [diff] [blame] | 917 | if (ctx.repo->readme.nr) |
| 918 | reporevlink("about", "about", NULL, |
| 919 | hc("about"), ctx.qry.head, NULL, |
| 920 | NULL); |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 921 | cgit_summary_link("summary", NULL, hc("summary"), |
| 922 | ctx.qry.head); |
| 923 | cgit_refs_link("refs", NULL, hc("refs"), ctx.qry.head, |
| 924 | ctx.qry.sha1, NULL); |
| 925 | cgit_log_link("log", NULL, hc("log"), ctx.qry.head, |
| 926 | NULL, ctx.qry.vpath, 0, NULL, NULL, |
| 927 | ctx.qry.showmsg); |
| 928 | cgit_tree_link("tree", NULL, hc("tree"), ctx.qry.head, |
| 929 | ctx.qry.sha1, ctx.qry.vpath); |
| 930 | cgit_commit_link("commit", NULL, hc("commit"), |
John Keeping | eeddb5b | 2014-10-05 10:59:02 +0100 | [diff] [blame] | 931 | ctx.qry.head, ctx.qry.sha1, ctx.qry.vpath); |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 932 | cgit_diff_link("diff", NULL, hc("diff"), ctx.qry.head, |
John Keeping | 03f537f | 2014-10-05 10:59:03 +0100 | [diff] [blame] | 933 | ctx.qry.sha1, ctx.qry.sha2, ctx.qry.vpath); |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 934 | if (ctx.repo->max_stats) |
| 935 | cgit_stats_link("stats", NULL, hc("stats"), |
| 936 | ctx.qry.head, ctx.qry.vpath); |
Lars Hjemli | 931fc6d | 2008-04-13 10:57:11 +0200 | [diff] [blame] | 937 | html("</td><td class='form'>"); |
| 938 | html("<form class='right' method='get' action='"); |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 939 | if (ctx.cfg.virtual_root) |
| 940 | html_url_path(cgit_fileurl(ctx.qry.repo, "log", |
| 941 | ctx.qry.vpath, NULL)); |
Lars Hjemli | 931fc6d | 2008-04-13 10:57:11 +0200 | [diff] [blame] | 942 | html("'>\n"); |
Lars Hjemli | c3c925f | 2008-12-07 15:52:35 +0100 | [diff] [blame] | 943 | cgit_add_hidden_formfields(1, 0, "log"); |
Lars Hjemli | 931fc6d | 2008-04-13 10:57:11 +0200 | [diff] [blame] | 944 | html("<select name='qt'>\n"); |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 945 | html_option("grep", "log msg", ctx.qry.grep); |
| 946 | html_option("author", "author", ctx.qry.grep); |
| 947 | html_option("committer", "committer", ctx.qry.grep); |
| 948 | html_option("range", "range", ctx.qry.grep); |
Lars Hjemli | 931fc6d | 2008-04-13 10:57:11 +0200 | [diff] [blame] | 949 | html("</select>\n"); |
Lars Hjemli | 536b054 | 2008-04-13 11:57:10 +0200 | [diff] [blame] | 950 | html("<input class='txt' type='text' size='10' name='q' value='"); |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 951 | html_attr(ctx.qry.search); |
Lars Hjemli | 931fc6d | 2008-04-13 10:57:11 +0200 | [diff] [blame] | 952 | html("'/>\n"); |
| 953 | html("<input type='submit' value='search'/>\n"); |
| 954 | html("</form>\n"); |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 955 | } else if (ctx.env.authenticated) { |
Jason A. Donenfeld | 2e4a41e | 2015-03-03 17:23:40 +0100 | [diff] [blame^] | 956 | site_link(NULL, "index", NULL, hc("repolist"), NULL, NULL, 0, 1); |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 957 | if (ctx.cfg.root_readme) |
| 958 | site_link("about", "about", NULL, hc("about"), |
Jason A. Donenfeld | 2e4a41e | 2015-03-03 17:23:40 +0100 | [diff] [blame^] | 959 | NULL, NULL, 0, 1); |
Lars Hjemli | 536b054 | 2008-04-13 11:57:10 +0200 | [diff] [blame] | 960 | html("</td><td class='form'>"); |
| 961 | html("<form method='get' action='"); |
Jason A. Donenfeld | 6bcda2f | 2015-03-03 17:18:42 +0100 | [diff] [blame] | 962 | html_attr(cgit_currenturl()); |
Lars Hjemli | 536b054 | 2008-04-13 11:57:10 +0200 | [diff] [blame] | 963 | html("'>\n"); |
| 964 | html("<input type='text' name='q' size='10' value='"); |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 965 | html_attr(ctx.qry.search); |
Lars Hjemli | 536b054 | 2008-04-13 11:57:10 +0200 | [diff] [blame] | 966 | html("'/>\n"); |
| 967 | html("<input type='submit' value='search'/>\n"); |
| 968 | html("</form>"); |
Lars Hjemli | e39d738 | 2006-12-28 02:01:49 +0100 | [diff] [blame] | 969 | } |
Lars Hjemli | f135569 | 2008-04-12 15:53:31 +0200 | [diff] [blame] | 970 | html("</td></tr></table>\n"); |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 971 | if (ctx.env.authenticated && ctx.qry.vpath) { |
Johan Herland | c93ef96 | 2010-06-10 01:09:28 +0200 | [diff] [blame] | 972 | html("<div class='path'>"); |
| 973 | html("path: "); |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 974 | cgit_print_path_crumbs(ctx.qry.vpath); |
Johan Herland | c93ef96 | 2010-06-10 01:09:28 +0200 | [diff] [blame] | 975 | html("</div>"); |
| 976 | } |
Lars Hjemli | f135569 | 2008-04-12 15:53:31 +0200 | [diff] [blame] | 977 | html("<div class='content'>"); |
Lars Hjemli | 5a106eb | 2006-12-11 16:38:30 +0100 | [diff] [blame] | 978 | } |
Lars Hjemli | ab2ab95 | 2007-02-08 13:53:13 +0100 | [diff] [blame] | 979 | |
Lars Hjemli | b1f9b9c | 2008-02-23 22:45:33 +0100 | [diff] [blame] | 980 | void cgit_print_filemode(unsigned short mode) |
| 981 | { |
| 982 | if (S_ISDIR(mode)) |
| 983 | html("d"); |
| 984 | else if (S_ISLNK(mode)) |
| 985 | html("l"); |
| 986 | else if (S_ISGITLINK(mode)) |
| 987 | html("m"); |
| 988 | else |
| 989 | html("-"); |
| 990 | html_fileperm(mode >> 6); |
| 991 | html_fileperm(mode >> 3); |
| 992 | html_fileperm(mode); |
| 993 | } |
| 994 | |
Lars Hjemli | f34478c | 2008-03-24 16:00:27 +0100 | [diff] [blame] | 995 | void cgit_print_snapshot_links(const char *repo, const char *head, |
| 996 | const char *hex, int snapshots) |
| 997 | { |
| 998 | const struct cgit_snapshot_format* f; |
John Keeping | fb3655d | 2013-04-06 10:28:57 +0100 | [diff] [blame] | 999 | struct strbuf filename = STRBUF_INIT; |
| 1000 | size_t prefixlen; |
Lars Hjemli | 1303272 | 2009-10-16 02:03:32 +0200 | [diff] [blame] | 1001 | unsigned char sha1[20]; |
Lars Hjemli | f34478c | 2008-03-24 16:00:27 +0100 | [diff] [blame] | 1002 | |
Lars Hjemli | 1303272 | 2009-10-16 02:03:32 +0200 | [diff] [blame] | 1003 | if (get_sha1(fmt("refs/tags/%s", hex), sha1) == 0 && |
| 1004 | (hex[0] == 'v' || hex[0] == 'V') && isdigit(hex[1])) |
| 1005 | hex++; |
John Keeping | fb3655d | 2013-04-06 10:28:57 +0100 | [diff] [blame] | 1006 | strbuf_addf(&filename, "%s-%s", cgit_repobasename(repo), hex); |
| 1007 | prefixlen = filename.len; |
Lars Hjemli | f34478c | 2008-03-24 16:00:27 +0100 | [diff] [blame] | 1008 | for (f = cgit_snapshot_formats; f->suffix; f++) { |
| 1009 | if (!(snapshots & f->bit)) |
| 1010 | continue; |
John Keeping | fb3655d | 2013-04-06 10:28:57 +0100 | [diff] [blame] | 1011 | strbuf_setlen(&filename, prefixlen); |
| 1012 | strbuf_addstr(&filename, f->suffix); |
| 1013 | cgit_snapshot_link(filename.buf, NULL, NULL, NULL, NULL, |
| 1014 | filename.buf); |
Lars Hjemli | f34478c | 2008-03-24 16:00:27 +0100 | [diff] [blame] | 1015 | html("<br/>"); |
| 1016 | } |
John Keeping | fb3655d | 2013-04-06 10:28:57 +0100 | [diff] [blame] | 1017 | strbuf_release(&filename); |
Lars Hjemli | f34478c | 2008-03-24 16:00:27 +0100 | [diff] [blame] | 1018 | } |