diff options
author | John Keeping | 2015-08-14 12:47:17 +0100 |
---|---|---|
committer | Jason A. Donenfeld | 2015-08-14 15:46:51 +0200 |
commit | 892c5441f4af2f53a3b1906c4d7e458829e0cf0a (patch) | |
tree | 5db7624970e2663ccb61cb14c4bbc6cb03024272 | |
parent | refs: move layout to page function (diff) | |
download | cgit-892c5441f4af2f53a3b1906c4d7e458829e0cf0a.tar.gz cgit-892c5441f4af2f53a3b1906c4d7e458829e0cf0a.zip |
stats: move layout into page function
This also allows us to return proper HTTP error codes for invalid requests. Signed-off-by: John Keeping <john@keeping.me.uk>
-rw-r--r-- | cmd.c | 2 | ||||
-rw-r--r-- | ui-stats.c | 8 |
2 files changed, 7 insertions, 3 deletions
diff --git a/cmd.c b/cmd.c index ce66af9..4f8e71d 100644 --- a/cmd.c +++ b/cmd.c | |||
@@ -169,7 +169,7 @@ struct cgit_cmd *cgit_get_cmd(void) | |||
169 | def_cmd(refs, 1, 0, 0, 0), | 169 | def_cmd(refs, 1, 0, 0, 0), |
170 | def_cmd(repolist, 0, 0, 0, 0), | 170 | def_cmd(repolist, 0, 0, 0, 0), |
171 | def_cmd(snapshot, 1, 0, 0, 0), | 171 | def_cmd(snapshot, 1, 0, 0, 0), |
172 | def_cmd(stats, 1, 1, 1, 0), | 172 | def_cmd(stats, 1, 0, 1, 0), |
173 | def_cmd(summary, 1, 1, 0, 0), | 173 | def_cmd(summary, 1, 1, 0, 0), |
174 | def_cmd(tag, 1, 1, 0, 0), | 174 | def_cmd(tag, 1, 1, 0, 0), |
175 | def_cmd(tree, 1, 1, 1, 0), | 175 | def_cmd(tree, 1, 1, 1, 0), |
diff --git a/ui-stats.c b/ui-stats.c index 9cd8247..74ce0f7 100644 --- a/ui-stats.c +++ b/ui-stats.c | |||
@@ -372,11 +372,13 @@ void cgit_show_stats(void) | |||
372 | 372 | ||
373 | i = cgit_find_stats_period(code, &period); | 373 | i = cgit_find_stats_period(code, &period); |
374 | if (!i) { | 374 | if (!i) { |
375 | cgit_print_error("Unknown statistics type: %c", code[0]); | 375 | cgit_print_error_page(404, "Not found", |
376 | "Unknown statistics type: %c", code[0]); | ||
376 | return; | 377 | return; |
377 | } | 378 | } |
378 | if (i > ctx.repo->max_stats) { | 379 | if (i > ctx.repo->max_stats) { |
379 | cgit_print_error("Statistics type disabled: %s", period->name); | 380 | cgit_print_error_page(400, "Bad request", |
381 | "Statistics type disabled: %s", period->name); | ||
380 | return; | 382 | return; |
381 | } | 383 | } |
382 | authors = collect_stats(period); | 384 | authors = collect_stats(period); |
@@ -387,6 +389,7 @@ void cgit_show_stats(void) | |||
387 | if (!top) | 389 | if (!top) |
388 | top = 10; | 390 | top = 10; |
389 | 391 | ||
392 | cgit_print_layout_start(); | ||
390 | html("<div class='cgit-panel'>"); | 393 | html("<div class='cgit-panel'>"); |
391 | html("<b>stat options</b>"); | 394 | html("<b>stat options</b>"); |
392 | html("<form method='get' action=''>"); | 395 | html("<form method='get' action=''>"); |
@@ -421,5 +424,6 @@ void cgit_show_stats(void) | |||
421 | } | 424 | } |
422 | html("</h2>"); | 425 | html("</h2>"); |
423 | print_authors(&authors, top, period); | 426 | print_authors(&authors, top, period); |
427 | cgit_print_layout_end(); | ||
424 | } | 428 | } |
425 | 429 | ||