Fossil SCM
If /attachadd fails due to a size limit violation, re-render the input form and populate the description field (we can't repopulate the file selector).
Commit
c206c78e1598848495884fd3641fa9d013314ece834b32e0f2721c94de8ce082
Parent
2a03fc1dbd4f7ee…
1 file changed
+13
-9
+13
-9
| --- src/attach.c | ||
| +++ src/attach.c | ||
| @@ -414,13 +414,14 @@ | ||
| 414 | 414 | const char *zTkt = P("tkt"); |
| 415 | 415 | const char *zTechNote = P("technote"); |
| 416 | 416 | const char *zFrom = P("from"); |
| 417 | 417 | const char *aContent = P("f"); |
| 418 | 418 | const char *zName = PD("f:filename","unknown"); |
| 419 | + const char *zComment = PD("comment", ""); | |
| 419 | 420 | const char *zTarget; |
| 420 | 421 | char * zTo = 0; |
| 421 | - char *zTargetType; | |
| 422 | + char *zTargetType = 0; | |
| 422 | 423 | char *zExtraFree = 0; |
| 423 | 424 | int szContent = atoi(PD("f:bytes","0")); |
| 424 | 425 | int goodCaptcha = 1; |
| 425 | 426 | int szLimit = 0; |
| 426 | 427 | |
| @@ -428,15 +429,10 @@ | ||
| 428 | 429 | if( P("cancel") ) cgi_redirect(zFrom); |
| 429 | 430 | if( (!!zPage + !!zTkt + !!zTechNote + !!zForumPost)!=1 ){ |
| 430 | 431 | webpage_error("Requires exactly one one: page=X, tkt=X, forumpost=X, or technote=X"); |
| 431 | 432 | } |
| 432 | 433 | login_check_credentials(); |
| 433 | - szLimit = db_get_int("attachment-size-limit", 0); | |
| 434 | - if( szContent<0 || (szLimit && szContent>szLimit) ){ | |
| 435 | - webpage_error("Attachment %s is too large. Limit is %d bytes.", zName, | |
| 436 | - szLimit ? szLimit : 0x7fffffff); | |
| 437 | - } | |
| 438 | 434 | if( zForumPost ){ |
| 439 | 435 | int fpid; |
| 440 | 436 | if( g.perm.AttachForum==0 ){ |
| 441 | 437 | login_needed(g.anon.AttachForum); |
| 442 | 438 | return; |
| @@ -492,18 +488,25 @@ | ||
| 492 | 488 | } |
| 493 | 489 | zTarget = zTkt; |
| 494 | 490 | zTargetType = mprintf("Ticket <a href=\"%R/tktview/%s\">%S</a>", |
| 495 | 491 | zTkt, zTkt); |
| 496 | 492 | } |
| 497 | - if( P("ok") && szContent>0 && (goodCaptcha = captcha_is_correct(0)) ){ | |
| 493 | + szLimit = db_get_int("attachment-size-limit", 0); | |
| 494 | + if( szContent<0 || (szLimit && szContent>szLimit) ){ | |
| 495 | + /* This check must be done late so that zTargetType is set up. */ | |
| 496 | + @ <p class="generalError">Attachment %s(zName) is too large. | |
| 497 | + @ <a href="%R/help/attachment-size-limit">Limit</a> is | |
| 498 | + @ %d(szLimit ? szLimit : 0x7fffffff) bytes</p> | |
| 499 | + /* Fall through and render form. */ | |
| 500 | + }else if( P("ok") && szContent>0 && (goodCaptcha = captcha_is_correct(0)) ){ | |
| 498 | 501 | int needModerator = (zForumPost!=0 && forum_need_moderation()) || |
| 499 | 502 | (zTkt!=0 && ticket_need_moderation(0)) || |
| 500 | 503 | (zPage!=0 && wiki_need_moderation(0)); |
| 501 | - const char *zComment = PD("comment", ""); | |
| 502 | 504 | attach_commit(zName, zTarget, aContent, szContent, needModerator, zComment); |
| 503 | 505 | cgi_redirect(zTo ? zTo : zFrom); |
| 504 | 506 | } |
| 507 | + | |
| 505 | 508 | style_set_current_feature("attach"); |
| 506 | 509 | style_header("Add Attachment"); |
| 507 | 510 | if( !goodCaptcha ){ |
| 508 | 511 | @ <p class="generalError">Error: Incorrect security code.</p> |
| 509 | 512 | } |
| @@ -511,11 +514,12 @@ | ||
| 511 | 514 | form_begin("enctype='multipart/form-data'", "%R/attachadd"); |
| 512 | 515 | @ <div> |
| 513 | 516 | @ File to Attach: |
| 514 | 517 | @ <input type="file" name="f" size="60"><br> |
| 515 | 518 | @ Description:<br> |
| 516 | - @ <textarea name="comment" cols="80" rows="5" wrap="virtual"></textarea><br> | |
| 519 | + @ <textarea name="comment" cols="80" rows="5" wrap="virtual" | |
| 520 | + @ >%s(zComment)</textarea><br> | |
| 517 | 521 | if( zForumPost ){ |
| 518 | 522 | @ <input type="hidden" name="forumpost" value="%h(zTarget)"> |
| 519 | 523 | }else if( zTkt ){ |
| 520 | 524 | @ <input type="hidden" name="tkt" value="%h(zTkt)"> |
| 521 | 525 | }else if( zTechNote ){ |
| 522 | 526 |
| --- src/attach.c | |
| +++ src/attach.c | |
| @@ -414,13 +414,14 @@ | |
| 414 | const char *zTkt = P("tkt"); |
| 415 | const char *zTechNote = P("technote"); |
| 416 | const char *zFrom = P("from"); |
| 417 | const char *aContent = P("f"); |
| 418 | const char *zName = PD("f:filename","unknown"); |
| 419 | const char *zTarget; |
| 420 | char * zTo = 0; |
| 421 | char *zTargetType; |
| 422 | char *zExtraFree = 0; |
| 423 | int szContent = atoi(PD("f:bytes","0")); |
| 424 | int goodCaptcha = 1; |
| 425 | int szLimit = 0; |
| 426 | |
| @@ -428,15 +429,10 @@ | |
| 428 | if( P("cancel") ) cgi_redirect(zFrom); |
| 429 | if( (!!zPage + !!zTkt + !!zTechNote + !!zForumPost)!=1 ){ |
| 430 | webpage_error("Requires exactly one one: page=X, tkt=X, forumpost=X, or technote=X"); |
| 431 | } |
| 432 | login_check_credentials(); |
| 433 | szLimit = db_get_int("attachment-size-limit", 0); |
| 434 | if( szContent<0 || (szLimit && szContent>szLimit) ){ |
| 435 | webpage_error("Attachment %s is too large. Limit is %d bytes.", zName, |
| 436 | szLimit ? szLimit : 0x7fffffff); |
| 437 | } |
| 438 | if( zForumPost ){ |
| 439 | int fpid; |
| 440 | if( g.perm.AttachForum==0 ){ |
| 441 | login_needed(g.anon.AttachForum); |
| 442 | return; |
| @@ -492,18 +488,25 @@ | |
| 492 | } |
| 493 | zTarget = zTkt; |
| 494 | zTargetType = mprintf("Ticket <a href=\"%R/tktview/%s\">%S</a>", |
| 495 | zTkt, zTkt); |
| 496 | } |
| 497 | if( P("ok") && szContent>0 && (goodCaptcha = captcha_is_correct(0)) ){ |
| 498 | int needModerator = (zForumPost!=0 && forum_need_moderation()) || |
| 499 | (zTkt!=0 && ticket_need_moderation(0)) || |
| 500 | (zPage!=0 && wiki_need_moderation(0)); |
| 501 | const char *zComment = PD("comment", ""); |
| 502 | attach_commit(zName, zTarget, aContent, szContent, needModerator, zComment); |
| 503 | cgi_redirect(zTo ? zTo : zFrom); |
| 504 | } |
| 505 | style_set_current_feature("attach"); |
| 506 | style_header("Add Attachment"); |
| 507 | if( !goodCaptcha ){ |
| 508 | @ <p class="generalError">Error: Incorrect security code.</p> |
| 509 | } |
| @@ -511,11 +514,12 @@ | |
| 511 | form_begin("enctype='multipart/form-data'", "%R/attachadd"); |
| 512 | @ <div> |
| 513 | @ File to Attach: |
| 514 | @ <input type="file" name="f" size="60"><br> |
| 515 | @ Description:<br> |
| 516 | @ <textarea name="comment" cols="80" rows="5" wrap="virtual"></textarea><br> |
| 517 | if( zForumPost ){ |
| 518 | @ <input type="hidden" name="forumpost" value="%h(zTarget)"> |
| 519 | }else if( zTkt ){ |
| 520 | @ <input type="hidden" name="tkt" value="%h(zTkt)"> |
| 521 | }else if( zTechNote ){ |
| 522 |
| --- src/attach.c | |
| +++ src/attach.c | |
| @@ -414,13 +414,14 @@ | |
| 414 | const char *zTkt = P("tkt"); |
| 415 | const char *zTechNote = P("technote"); |
| 416 | const char *zFrom = P("from"); |
| 417 | const char *aContent = P("f"); |
| 418 | const char *zName = PD("f:filename","unknown"); |
| 419 | const char *zComment = PD("comment", ""); |
| 420 | const char *zTarget; |
| 421 | char * zTo = 0; |
| 422 | char *zTargetType = 0; |
| 423 | char *zExtraFree = 0; |
| 424 | int szContent = atoi(PD("f:bytes","0")); |
| 425 | int goodCaptcha = 1; |
| 426 | int szLimit = 0; |
| 427 | |
| @@ -428,15 +429,10 @@ | |
| 429 | if( P("cancel") ) cgi_redirect(zFrom); |
| 430 | if( (!!zPage + !!zTkt + !!zTechNote + !!zForumPost)!=1 ){ |
| 431 | webpage_error("Requires exactly one one: page=X, tkt=X, forumpost=X, or technote=X"); |
| 432 | } |
| 433 | login_check_credentials(); |
| 434 | if( zForumPost ){ |
| 435 | int fpid; |
| 436 | if( g.perm.AttachForum==0 ){ |
| 437 | login_needed(g.anon.AttachForum); |
| 438 | return; |
| @@ -492,18 +488,25 @@ | |
| 488 | } |
| 489 | zTarget = zTkt; |
| 490 | zTargetType = mprintf("Ticket <a href=\"%R/tktview/%s\">%S</a>", |
| 491 | zTkt, zTkt); |
| 492 | } |
| 493 | szLimit = db_get_int("attachment-size-limit", 0); |
| 494 | if( szContent<0 || (szLimit && szContent>szLimit) ){ |
| 495 | /* This check must be done late so that zTargetType is set up. */ |
| 496 | @ <p class="generalError">Attachment %s(zName) is too large. |
| 497 | @ <a href="%R/help/attachment-size-limit">Limit</a> is |
| 498 | @ %d(szLimit ? szLimit : 0x7fffffff) bytes</p> |
| 499 | /* Fall through and render form. */ |
| 500 | }else if( P("ok") && szContent>0 && (goodCaptcha = captcha_is_correct(0)) ){ |
| 501 | int needModerator = (zForumPost!=0 && forum_need_moderation()) || |
| 502 | (zTkt!=0 && ticket_need_moderation(0)) || |
| 503 | (zPage!=0 && wiki_need_moderation(0)); |
| 504 | attach_commit(zName, zTarget, aContent, szContent, needModerator, zComment); |
| 505 | cgi_redirect(zTo ? zTo : zFrom); |
| 506 | } |
| 507 | |
| 508 | style_set_current_feature("attach"); |
| 509 | style_header("Add Attachment"); |
| 510 | if( !goodCaptcha ){ |
| 511 | @ <p class="generalError">Error: Incorrect security code.</p> |
| 512 | } |
| @@ -511,11 +514,12 @@ | |
| 514 | form_begin("enctype='multipart/form-data'", "%R/attachadd"); |
| 515 | @ <div> |
| 516 | @ File to Attach: |
| 517 | @ <input type="file" name="f" size="60"><br> |
| 518 | @ Description:<br> |
| 519 | @ <textarea name="comment" cols="80" rows="5" wrap="virtual" |
| 520 | @ >%s(zComment)</textarea><br> |
| 521 | if( zForumPost ){ |
| 522 | @ <input type="hidden" name="forumpost" value="%h(zTarget)"> |
| 523 | }else if( zTkt ){ |
| 524 | @ <input type="hidden" name="tkt" value="%h(zTkt)"> |
| 525 | }else if( zTechNote ){ |
| 526 |