Fossil SCM
New CX(...) macro for rendering HTTP reply text, as an alternative to the "@ ..." markup provided by translate.c.
Commit
0d160f9fa8bf2e223c5cce71bf6b063a8b098ef4eb68a878b454a29fbf1653a9
Parent
7243aea14a7cde8…
2 files changed
+11
+65
-68
+11
| --- src/cgi.c | ||
| +++ src/cgi.c | ||
| @@ -64,10 +64,21 @@ | ||
| 64 | 64 | #define PDT(x,y) cgi_parameter_trimmed((x),(y)) |
| 65 | 65 | #define PB(x) cgi_parameter_boolean(x) |
| 66 | 66 | #define PCK(x) cgi_parameter_checked(x,1) |
| 67 | 67 | #define PIF(x,y) cgi_parameter_checked(x,y) |
| 68 | 68 | |
| 69 | +/* | |
| 70 | +** Shortcut for the cgi_printf() routine. Instead of using the | |
| 71 | +** | |
| 72 | +** @ ... | |
| 73 | +** | |
| 74 | +** notation provided by the translate.c utility, you can also | |
| 75 | +** optionally use: | |
| 76 | +** | |
| 77 | +** CX(...) | |
| 78 | +*/ | |
| 79 | +#define CX cgi_printf | |
| 69 | 80 | |
| 70 | 81 | /* |
| 71 | 82 | ** Destinations for output text. |
| 72 | 83 | */ |
| 73 | 84 | #define CGI_HEADER 0 |
| 74 | 85 |
| --- src/cgi.c | |
| +++ src/cgi.c | |
| @@ -64,10 +64,21 @@ | |
| 64 | #define PDT(x,y) cgi_parameter_trimmed((x),(y)) |
| 65 | #define PB(x) cgi_parameter_boolean(x) |
| 66 | #define PCK(x) cgi_parameter_checked(x,1) |
| 67 | #define PIF(x,y) cgi_parameter_checked(x,y) |
| 68 | |
| 69 | |
| 70 | /* |
| 71 | ** Destinations for output text. |
| 72 | */ |
| 73 | #define CGI_HEADER 0 |
| 74 |
| --- src/cgi.c | |
| +++ src/cgi.c | |
| @@ -64,10 +64,21 @@ | |
| 64 | #define PDT(x,y) cgi_parameter_trimmed((x),(y)) |
| 65 | #define PB(x) cgi_parameter_boolean(x) |
| 66 | #define PCK(x) cgi_parameter_checked(x,1) |
| 67 | #define PIF(x,y) cgi_parameter_checked(x,y) |
| 68 | |
| 69 | /* |
| 70 | ** Shortcut for the cgi_printf() routine. Instead of using the |
| 71 | ** |
| 72 | ** @ ... |
| 73 | ** |
| 74 | ** notation provided by the translate.c utility, you can also |
| 75 | ** optionally use: |
| 76 | ** |
| 77 | ** CX(...) |
| 78 | */ |
| 79 | #define CX cgi_printf |
| 80 | |
| 81 | /* |
| 82 | ** Destinations for output text. |
| 83 | */ |
| 84 | #define CGI_HEADER 0 |
| 85 |
+65
-68
| --- src/checkin.c | ||
| +++ src/checkin.c | ||
| @@ -3366,11 +3366,11 @@ | ||
| 3366 | 3366 | ** COMMAND: test-ci-mini |
| 3367 | 3367 | ** |
| 3368 | 3368 | ** This is an on-going experiment, subject to change or removal at |
| 3369 | 3369 | ** any time. |
| 3370 | 3370 | ** |
| 3371 | -** Usage: %fossil ?OPTIONS? FILENAME | |
| 3371 | +** Usage: %fossil test-ci-mini ?OPTIONS? FILENAME | |
| 3372 | 3372 | ** |
| 3373 | 3373 | ** where FILENAME is a repo-relative name as it would appear in the |
| 3374 | 3374 | ** vfile table. |
| 3375 | 3375 | ** |
| 3376 | 3376 | ** Options: |
| @@ -3575,13 +3575,13 @@ | ||
| 3575 | 3575 | return glob_match(pGlobs, zFilename); |
| 3576 | 3576 | } |
| 3577 | 3577 | |
| 3578 | 3578 | static void fileedit_emit_script(int phase){ |
| 3579 | 3579 | if(0==phase){ |
| 3580 | - fossil_print("<script nonce='%s'>", style_nonce()); | |
| 3580 | + CX("<script nonce='%s'>", style_nonce()); | |
| 3581 | 3581 | }else{ |
| 3582 | - fossil_print("</script>\n"); | |
| 3582 | + CX("</script>\n"); | |
| 3583 | 3583 | } |
| 3584 | 3584 | } |
| 3585 | 3585 | |
| 3586 | 3586 | #if 0 |
| 3587 | 3587 | /* |
| @@ -3588,32 +3588,31 @@ | ||
| 3588 | 3588 | ** This function is for potential TODO features for /fileedit. |
| 3589 | 3589 | ** It's been tested with that code but is not currently used |
| 3590 | 3590 | ** by it. |
| 3591 | 3591 | */ |
| 3592 | 3592 | static void fileedit_emit_script_fetch(){ |
| 3593 | -#define fp fossil_print | |
| 3594 | 3593 | fileedit_emit_script(0); |
| 3595 | - fp("window.fossilFetch = function(path,opt){\n"); | |
| 3596 | - fp(" if('function'===typeof opt){\n"); | |
| 3597 | - fp(" opt={onload:opt};\n"); | |
| 3598 | - fp(" }else{\n"); | |
| 3599 | - fp(" opt=opt||{onload:function(r){console.debug('response:',r)}}\n"); | |
| 3600 | - fp(" }\n"); | |
| 3601 | - fp(" const url='%R/'+path, x=new XMLHttpRequest();\n"); | |
| 3602 | - fp(" x.open(opt.method||'GET', url, true);\n"); | |
| 3603 | - fp(" x.responseType=opt.responseType||'text';\n"); | |
| 3604 | - fp(" if(opt.onload){\n"); | |
| 3605 | - fp(" x.onload = function(e){\n"); | |
| 3606 | - fp(" if(200!==this.status){\n"); | |
| 3607 | - fp(" if(opt.onerror) opt.onerror(e);\n"); | |
| 3608 | - fp(" return;\n"); | |
| 3609 | - fp(" }\n"); | |
| 3610 | - fp(" opt.onload(this.response);\n"); | |
| 3611 | - fp(" }\n"); | |
| 3612 | - fp(" }\n"); | |
| 3613 | - fp(" x.send();"); | |
| 3614 | - fp("};\n"); | |
| 3594 | + CX("window.fossilFetch = function(path,opt){\n"); | |
| 3595 | + CX(" if('function'===typeof opt){\n"); | |
| 3596 | + CX(" opt={onload:opt};\n"); | |
| 3597 | + CX(" }else{\n"); | |
| 3598 | + CX(" opt=opt||{onload:function(r){console.debug('response:',r)}}\n"); | |
| 3599 | + CX(" }\n"); | |
| 3600 | + CX(" const url='%R/'+path, x=new XMLHttpRequest();\n"); | |
| 3601 | + CX(" x.open(opt.method||'GET', url, true);\n"); | |
| 3602 | + CX(" x.responseType=opt.responseType||'text';\n"); | |
| 3603 | + CX(" if(opt.onload){\n"); | |
| 3604 | + CX(" x.onload = function(e){\n"); | |
| 3605 | + CX(" if(200!==this.status){\n"); | |
| 3606 | + CX(" if(opt.onerror) opt.onerror(e);\n"); | |
| 3607 | + CX(" return;\n"); | |
| 3608 | + CX(" }\n"); | |
| 3609 | + CX(" opt.onload(this.response);\n"); | |
| 3610 | + CX(" }\n"); | |
| 3611 | + CX(" }\n"); | |
| 3612 | + CX(" x.send();"); | |
| 3613 | + CX("};\n"); | |
| 3615 | 3614 | fileedit_emit_script(1); |
| 3616 | 3615 | #undef fp |
| 3617 | 3616 | }; |
| 3618 | 3617 | #endif /* fileedit_emit_script_fetch() */ |
| 3619 | 3618 | |
| @@ -3631,18 +3630,18 @@ | ||
| 3631 | 3630 | static void style_labeled_checkbox(const char *zFieldName, |
| 3632 | 3631 | const char * zLabel, |
| 3633 | 3632 | const char * zValue, |
| 3634 | 3633 | const char * zTip, |
| 3635 | 3634 | int isChecked){ |
| 3636 | - fossil_print("<span class='input-with-label'"); | |
| 3635 | + CX("<span class='input-with-label'"); | |
| 3637 | 3636 | if(zTip && *zTip){ |
| 3638 | - fossil_print(" title='%h'", zTip); | |
| 3637 | + CX(" title='%h'", zTip); | |
| 3639 | 3638 | } |
| 3640 | - fossil_print("><input type='checkbox' name='%s' value='%T'%s/>", | |
| 3641 | - zFieldName, | |
| 3642 | - zValue ? zValue : "", isChecked ? " checked" : ""); | |
| 3643 | - fossil_print("<span>%h</span></span>", zLabel); | |
| 3639 | + CX("><input type='checkbox' name='%s' value='%T'%s/>", | |
| 3640 | + zFieldName, | |
| 3641 | + zValue ? zValue : "", isChecked ? " checked" : ""); | |
| 3642 | + CX("<span>%h</span></span>", zLabel); | |
| 3644 | 3643 | } |
| 3645 | 3644 | |
| 3646 | 3645 | /* |
| 3647 | 3646 | ** WEBPAGE: fileedit |
| 3648 | 3647 | ** |
| @@ -3750,57 +3749,55 @@ | ||
| 3750 | 3749 | fail((&err,"File appears to be binary. Cannot edit: " |
| 3751 | 3750 | "<code>%h</code>",zFilename)); |
| 3752 | 3751 | } |
| 3753 | 3752 | |
| 3754 | 3753 | /* All set. Here we go... */ |
| 3755 | -#define fp fossil_print | |
| 3756 | - /* ^^^ Appologies, Richard, but the @ form plays havoc with emacs */ | |
| 3757 | 3754 | |
| 3758 | - fp("<h1>Editing:</h1>"); | |
| 3759 | - fp("<p class='fileedit-hint'>"); | |
| 3760 | - fp("File: <code>%h</code><br>" | |
| 3755 | + CX("<h1>Editing:</h1>"); | |
| 3756 | + CX("<p class='fileedit-hint'>"); | |
| 3757 | + CX("File: <code>%h</code><br>" | |
| 3761 | 3758 | "Checkin Version: <code id='r-label'>%s</code><br>", |
| 3762 | 3759 | zFilename, cimi.zParentUuid); |
| 3763 | - fp("Permalink: <code>" | |
| 3760 | + CX("Permalink: <code>" | |
| 3764 | 3761 | "<a id='permalink' href='%R/fileedit?file=%T&r=%!S'>" |
| 3765 | 3762 | "/fileedit?file=%T&r=%!S</a></code><br>" |
| 3766 | 3763 | "(Clicking the permalink will reload the page and discard " |
| 3767 | 3764 | "all edits!)", |
| 3768 | 3765 | zFilename, cimi.zParentUuid, |
| 3769 | 3766 | zFilename, cimi.zParentUuid); |
| 3770 | - fp("</p>"); | |
| 3771 | - fp("<p>This page is <em>far from complete</em> and may still have " | |
| 3767 | + CX("</p>"); | |
| 3768 | + CX("<p>This page is <em>far from complete</em> and may still have " | |
| 3772 | 3769 | "significant bugs. USE AT YOUR OWN RISK, preferably on a test " |
| 3773 | 3770 | "repo.</p>\n"); |
| 3774 | 3771 | |
| 3775 | - fp("<form action='%R/fileedit' method='POST' " | |
| 3772 | + CX("<form action='%R/fileedit' method='POST' " | |
| 3776 | 3773 | "class='fileedit-form'>\n"); |
| 3777 | 3774 | |
| 3778 | 3775 | /******* Hidden fields *******/ |
| 3779 | - fp("<input type='hidden' name='r' value='%s'>", | |
| 3776 | + CX("<input type='hidden' name='r' value='%s'>", | |
| 3780 | 3777 | cimi.zParentUuid); |
| 3781 | - fp("<input type='hidden' name='file' value='%T'>", | |
| 3778 | + CX("<input type='hidden' name='file' value='%T'>", | |
| 3782 | 3779 | zFilename); |
| 3783 | 3780 | |
| 3784 | 3781 | /******* Comment *******/ |
| 3785 | - fp("<h3>Checkin Comment</h3>\n"); | |
| 3786 | - fp("<textarea name='comment' rows='3' cols='80'>"); | |
| 3782 | + CX("<h3>Checkin Comment</h3>\n"); | |
| 3783 | + CX("<textarea name='comment' rows='3' cols='80'>"); | |
| 3787 | 3784 | if(zComment && *zComment){ |
| 3788 | - fp("%h"/*%h? %s?*/, zComment); | |
| 3785 | + CX("%h"/*%h? %s?*/, zComment); | |
| 3789 | 3786 | } |
| 3790 | - fp("</textarea>\n"); | |
| 3791 | - fp("<div class='fileedit-hint'>Comments use the Fossil wiki markup " | |
| 3787 | + CX("</textarea>\n"); | |
| 3788 | + CX("<div class='fileedit-hint'>Comments use the Fossil wiki markup " | |
| 3792 | 3789 | "syntax.</div>"/*TODO: radiobuttons for fossil/me/plain text*/); |
| 3793 | 3790 | |
| 3794 | 3791 | /******* Content *******/ |
| 3795 | - fp("<h3>File Content</h3>\n"); | |
| 3796 | - fp("<textarea name='content' id='fileedit-content' " | |
| 3792 | + CX("<h3>File Content</h3>\n"); | |
| 3793 | + CX("<textarea name='content' id='fileedit-content' " | |
| 3797 | 3794 | "rows='20' cols='80'>"); |
| 3798 | - fp("Loading..."); | |
| 3799 | - fp("</textarea>\n"); | |
| 3795 | + CX("Loading..."); | |
| 3796 | + CX("</textarea>\n"); | |
| 3800 | 3797 | /******* Flags/options *******/ |
| 3801 | - fp("<fieldset class='fileedit-options'>" | |
| 3798 | + CX("<fieldset class='fileedit-options'>" | |
| 3802 | 3799 | "<legend>Options</legend><div>" |
| 3803 | 3800 | /* Chrome does not sanely lay out multiple |
| 3804 | 3801 | ** fieldset children after the <legend>, so |
| 3805 | 3802 | ** a containing div is necessary. */); |
| 3806 | 3803 | /* |
| @@ -3858,37 +3855,37 @@ | ||
| 3858 | 3855 | switch(eolMode){ |
| 3859 | 3856 | case 1: cimi.flags |= CIMINI_CONVERT_EOL_UNIX; break; |
| 3860 | 3857 | case 2: cimi.flags |= CIMINI_CONVERT_EOL_WINDOWS; break; |
| 3861 | 3858 | default: cimi.flags |= CIMINI_CONVERT_EOL_INHERIT; break; |
| 3862 | 3859 | } |
| 3863 | - fp("<select name='eol' " | |
| 3860 | + CX("<select name='eol' " | |
| 3864 | 3861 | "title='EOL conversion policy, noting that form-processing " |
| 3865 | 3862 | "may implicitly change the line endings of the input.'>"); |
| 3866 | - fp("<option value='0'%s>Inherit EOLs</option>", | |
| 3863 | + CX("<option value='0'%s>Inherit EOLs</option>", | |
| 3867 | 3864 | (eolMode!=1 && eolMode!=2) ? " selected" : ""); |
| 3868 | - fp("<option value='1'%s/>Unix EOLs</option>", | |
| 3865 | + CX("<option value='1'%s/>Unix EOLs</option>", | |
| 3869 | 3866 | eolMode==1 ? " selected" : ""); |
| 3870 | - fp("<option value='2'%s>Windows EOLs</option>", | |
| 3867 | + CX("<option value='2'%s>Windows EOLs</option>", | |
| 3871 | 3868 | eolMode==2 ? " selected" : ""); |
| 3872 | - fp("</select>"); | |
| 3869 | + CX("</select>"); | |
| 3873 | 3870 | } |
| 3874 | 3871 | |
| 3875 | - fp("</div></fieldset>") /* end of checkboxes */; | |
| 3872 | + CX("</div></fieldset>") /* end of checkboxes */; | |
| 3876 | 3873 | |
| 3877 | 3874 | /******* Buttons *******/ |
| 3878 | - fp("<fieldset class='fileedit-options'>" | |
| 3875 | + CX("<fieldset class='fileedit-options'>" | |
| 3879 | 3876 | "<legend>Tell the server to...</legend><div>"); |
| 3880 | - fp("<button type='submit' name='submit' value='1'>" | |
| 3877 | + CX("<button type='submit' name='submit' value='1'>" | |
| 3881 | 3878 | "Save</button>"); |
| 3882 | - fp("<button type='submit' name='submit' value='2'>" | |
| 3879 | + CX("<button type='submit' name='submit' value='2'>" | |
| 3883 | 3880 | "Preview (TODO)</button>"); |
| 3884 | - fp("<button type='submit' name='submit' value='3'>" | |
| 3881 | + CX("<button type='submit' name='submit' value='3'>" | |
| 3885 | 3882 | "Diff (TODO)</button>"); |
| 3886 | - fp("</div></fieldset>"); | |
| 3883 | + CX("</div></fieldset>"); | |
| 3887 | 3884 | |
| 3888 | 3885 | /******* End of form *******/ |
| 3889 | - fp("</form>\n"); | |
| 3886 | + CX("</form>\n"); | |
| 3890 | 3887 | |
| 3891 | 3888 | { |
| 3892 | 3889 | /* Populate the editor... |
| 3893 | 3890 | ** |
| 3894 | 3891 | ** To avoid all escaping-related issues, we have to do this one of |
| @@ -3929,11 +3926,11 @@ | ||
| 3929 | 3926 | cimi.zFilename = mprintf("%s",zFilename); |
| 3930 | 3927 | cimi.pMfOut = &manifest; |
| 3931 | 3928 | checkin_mini(&cimi, &newVid, &err); |
| 3932 | 3929 | if(newVid!=0){ |
| 3933 | 3930 | zNewUuid = rid_to_uuid(newVid); |
| 3934 | - fp("<h3>Manifest%s: %S</h3><pre>" | |
| 3931 | + CX("<h3>Manifest%s: %S</h3><pre>" | |
| 3935 | 3932 | "<code class='fileedit-manifest'>%h</code>" |
| 3936 | 3933 | "</pre>", |
| 3937 | 3934 | (cimi.flags & CIMINI_DRY_RUN) ? " (dry run)" : "", |
| 3938 | 3935 | zNewUuid, blob_str(&manifest)); |
| 3939 | 3936 | if(!(CIMINI_DRY_RUN & cimi.flags)){ |
| @@ -3984,23 +3981,23 @@ | ||
| 3984 | 3981 | fossil_free(zFileUuid); |
| 3985 | 3982 | if(stmt.pStmt){ |
| 3986 | 3983 | db_finalize(&stmt); |
| 3987 | 3984 | } |
| 3988 | 3985 | if(blob_size(&err)){ |
| 3989 | - fp("<div class='fileedit-error-report'>%s</div>", | |
| 3986 | + CX("<div class='fileedit-error-report'>%s</div>", | |
| 3990 | 3987 | blob_str(&err)); |
| 3991 | 3988 | } |
| 3992 | 3989 | blob_reset(&err); |
| 3993 | 3990 | CheckinMiniInfo_cleanup(&cimi); |
| 3994 | 3991 | if(blob_size(&endScript)>0){ |
| 3995 | 3992 | fileedit_emit_script(0); |
| 3996 | - fp("(function(){\n"); | |
| 3997 | - fp("try{\n%b\n}catch(e){console.error('Exception:',e)}\n", | |
| 3993 | + CX("(function(){\n"); | |
| 3994 | + CX("try{\n%b\n}catch(e){console.error('Exception:',e)}\n", | |
| 3998 | 3995 | &endScript); |
| 3999 | - fp("})();"); | |
| 3996 | + CX("})();"); | |
| 4000 | 3997 | fileedit_emit_script(1); |
| 4001 | 3998 | } |
| 4002 | 3999 | db_end_transaction(0/*noting that dry-run mode will have already |
| 4003 | 4000 | ** set this to rollback mode. */); |
| 4004 | 4001 | style_footer(); |
| 4005 | 4002 | #undef fp |
| 4006 | 4003 | } |
| 4007 | 4004 |
| --- src/checkin.c | |
| +++ src/checkin.c | |
| @@ -3366,11 +3366,11 @@ | |
| 3366 | ** COMMAND: test-ci-mini |
| 3367 | ** |
| 3368 | ** This is an on-going experiment, subject to change or removal at |
| 3369 | ** any time. |
| 3370 | ** |
| 3371 | ** Usage: %fossil ?OPTIONS? FILENAME |
| 3372 | ** |
| 3373 | ** where FILENAME is a repo-relative name as it would appear in the |
| 3374 | ** vfile table. |
| 3375 | ** |
| 3376 | ** Options: |
| @@ -3575,13 +3575,13 @@ | |
| 3575 | return glob_match(pGlobs, zFilename); |
| 3576 | } |
| 3577 | |
| 3578 | static void fileedit_emit_script(int phase){ |
| 3579 | if(0==phase){ |
| 3580 | fossil_print("<script nonce='%s'>", style_nonce()); |
| 3581 | }else{ |
| 3582 | fossil_print("</script>\n"); |
| 3583 | } |
| 3584 | } |
| 3585 | |
| 3586 | #if 0 |
| 3587 | /* |
| @@ -3588,32 +3588,31 @@ | |
| 3588 | ** This function is for potential TODO features for /fileedit. |
| 3589 | ** It's been tested with that code but is not currently used |
| 3590 | ** by it. |
| 3591 | */ |
| 3592 | static void fileedit_emit_script_fetch(){ |
| 3593 | #define fp fossil_print |
| 3594 | fileedit_emit_script(0); |
| 3595 | fp("window.fossilFetch = function(path,opt){\n"); |
| 3596 | fp(" if('function'===typeof opt){\n"); |
| 3597 | fp(" opt={onload:opt};\n"); |
| 3598 | fp(" }else{\n"); |
| 3599 | fp(" opt=opt||{onload:function(r){console.debug('response:',r)}}\n"); |
| 3600 | fp(" }\n"); |
| 3601 | fp(" const url='%R/'+path, x=new XMLHttpRequest();\n"); |
| 3602 | fp(" x.open(opt.method||'GET', url, true);\n"); |
| 3603 | fp(" x.responseType=opt.responseType||'text';\n"); |
| 3604 | fp(" if(opt.onload){\n"); |
| 3605 | fp(" x.onload = function(e){\n"); |
| 3606 | fp(" if(200!==this.status){\n"); |
| 3607 | fp(" if(opt.onerror) opt.onerror(e);\n"); |
| 3608 | fp(" return;\n"); |
| 3609 | fp(" }\n"); |
| 3610 | fp(" opt.onload(this.response);\n"); |
| 3611 | fp(" }\n"); |
| 3612 | fp(" }\n"); |
| 3613 | fp(" x.send();"); |
| 3614 | fp("};\n"); |
| 3615 | fileedit_emit_script(1); |
| 3616 | #undef fp |
| 3617 | }; |
| 3618 | #endif /* fileedit_emit_script_fetch() */ |
| 3619 | |
| @@ -3631,18 +3630,18 @@ | |
| 3631 | static void style_labeled_checkbox(const char *zFieldName, |
| 3632 | const char * zLabel, |
| 3633 | const char * zValue, |
| 3634 | const char * zTip, |
| 3635 | int isChecked){ |
| 3636 | fossil_print("<span class='input-with-label'"); |
| 3637 | if(zTip && *zTip){ |
| 3638 | fossil_print(" title='%h'", zTip); |
| 3639 | } |
| 3640 | fossil_print("><input type='checkbox' name='%s' value='%T'%s/>", |
| 3641 | zFieldName, |
| 3642 | zValue ? zValue : "", isChecked ? " checked" : ""); |
| 3643 | fossil_print("<span>%h</span></span>", zLabel); |
| 3644 | } |
| 3645 | |
| 3646 | /* |
| 3647 | ** WEBPAGE: fileedit |
| 3648 | ** |
| @@ -3750,57 +3749,55 @@ | |
| 3750 | fail((&err,"File appears to be binary. Cannot edit: " |
| 3751 | "<code>%h</code>",zFilename)); |
| 3752 | } |
| 3753 | |
| 3754 | /* All set. Here we go... */ |
| 3755 | #define fp fossil_print |
| 3756 | /* ^^^ Appologies, Richard, but the @ form plays havoc with emacs */ |
| 3757 | |
| 3758 | fp("<h1>Editing:</h1>"); |
| 3759 | fp("<p class='fileedit-hint'>"); |
| 3760 | fp("File: <code>%h</code><br>" |
| 3761 | "Checkin Version: <code id='r-label'>%s</code><br>", |
| 3762 | zFilename, cimi.zParentUuid); |
| 3763 | fp("Permalink: <code>" |
| 3764 | "<a id='permalink' href='%R/fileedit?file=%T&r=%!S'>" |
| 3765 | "/fileedit?file=%T&r=%!S</a></code><br>" |
| 3766 | "(Clicking the permalink will reload the page and discard " |
| 3767 | "all edits!)", |
| 3768 | zFilename, cimi.zParentUuid, |
| 3769 | zFilename, cimi.zParentUuid); |
| 3770 | fp("</p>"); |
| 3771 | fp("<p>This page is <em>far from complete</em> and may still have " |
| 3772 | "significant bugs. USE AT YOUR OWN RISK, preferably on a test " |
| 3773 | "repo.</p>\n"); |
| 3774 | |
| 3775 | fp("<form action='%R/fileedit' method='POST' " |
| 3776 | "class='fileedit-form'>\n"); |
| 3777 | |
| 3778 | /******* Hidden fields *******/ |
| 3779 | fp("<input type='hidden' name='r' value='%s'>", |
| 3780 | cimi.zParentUuid); |
| 3781 | fp("<input type='hidden' name='file' value='%T'>", |
| 3782 | zFilename); |
| 3783 | |
| 3784 | /******* Comment *******/ |
| 3785 | fp("<h3>Checkin Comment</h3>\n"); |
| 3786 | fp("<textarea name='comment' rows='3' cols='80'>"); |
| 3787 | if(zComment && *zComment){ |
| 3788 | fp("%h"/*%h? %s?*/, zComment); |
| 3789 | } |
| 3790 | fp("</textarea>\n"); |
| 3791 | fp("<div class='fileedit-hint'>Comments use the Fossil wiki markup " |
| 3792 | "syntax.</div>"/*TODO: radiobuttons for fossil/me/plain text*/); |
| 3793 | |
| 3794 | /******* Content *******/ |
| 3795 | fp("<h3>File Content</h3>\n"); |
| 3796 | fp("<textarea name='content' id='fileedit-content' " |
| 3797 | "rows='20' cols='80'>"); |
| 3798 | fp("Loading..."); |
| 3799 | fp("</textarea>\n"); |
| 3800 | /******* Flags/options *******/ |
| 3801 | fp("<fieldset class='fileedit-options'>" |
| 3802 | "<legend>Options</legend><div>" |
| 3803 | /* Chrome does not sanely lay out multiple |
| 3804 | ** fieldset children after the <legend>, so |
| 3805 | ** a containing div is necessary. */); |
| 3806 | /* |
| @@ -3858,37 +3855,37 @@ | |
| 3858 | switch(eolMode){ |
| 3859 | case 1: cimi.flags |= CIMINI_CONVERT_EOL_UNIX; break; |
| 3860 | case 2: cimi.flags |= CIMINI_CONVERT_EOL_WINDOWS; break; |
| 3861 | default: cimi.flags |= CIMINI_CONVERT_EOL_INHERIT; break; |
| 3862 | } |
| 3863 | fp("<select name='eol' " |
| 3864 | "title='EOL conversion policy, noting that form-processing " |
| 3865 | "may implicitly change the line endings of the input.'>"); |
| 3866 | fp("<option value='0'%s>Inherit EOLs</option>", |
| 3867 | (eolMode!=1 && eolMode!=2) ? " selected" : ""); |
| 3868 | fp("<option value='1'%s/>Unix EOLs</option>", |
| 3869 | eolMode==1 ? " selected" : ""); |
| 3870 | fp("<option value='2'%s>Windows EOLs</option>", |
| 3871 | eolMode==2 ? " selected" : ""); |
| 3872 | fp("</select>"); |
| 3873 | } |
| 3874 | |
| 3875 | fp("</div></fieldset>") /* end of checkboxes */; |
| 3876 | |
| 3877 | /******* Buttons *******/ |
| 3878 | fp("<fieldset class='fileedit-options'>" |
| 3879 | "<legend>Tell the server to...</legend><div>"); |
| 3880 | fp("<button type='submit' name='submit' value='1'>" |
| 3881 | "Save</button>"); |
| 3882 | fp("<button type='submit' name='submit' value='2'>" |
| 3883 | "Preview (TODO)</button>"); |
| 3884 | fp("<button type='submit' name='submit' value='3'>" |
| 3885 | "Diff (TODO)</button>"); |
| 3886 | fp("</div></fieldset>"); |
| 3887 | |
| 3888 | /******* End of form *******/ |
| 3889 | fp("</form>\n"); |
| 3890 | |
| 3891 | { |
| 3892 | /* Populate the editor... |
| 3893 | ** |
| 3894 | ** To avoid all escaping-related issues, we have to do this one of |
| @@ -3929,11 +3926,11 @@ | |
| 3929 | cimi.zFilename = mprintf("%s",zFilename); |
| 3930 | cimi.pMfOut = &manifest; |
| 3931 | checkin_mini(&cimi, &newVid, &err); |
| 3932 | if(newVid!=0){ |
| 3933 | zNewUuid = rid_to_uuid(newVid); |
| 3934 | fp("<h3>Manifest%s: %S</h3><pre>" |
| 3935 | "<code class='fileedit-manifest'>%h</code>" |
| 3936 | "</pre>", |
| 3937 | (cimi.flags & CIMINI_DRY_RUN) ? " (dry run)" : "", |
| 3938 | zNewUuid, blob_str(&manifest)); |
| 3939 | if(!(CIMINI_DRY_RUN & cimi.flags)){ |
| @@ -3984,23 +3981,23 @@ | |
| 3984 | fossil_free(zFileUuid); |
| 3985 | if(stmt.pStmt){ |
| 3986 | db_finalize(&stmt); |
| 3987 | } |
| 3988 | if(blob_size(&err)){ |
| 3989 | fp("<div class='fileedit-error-report'>%s</div>", |
| 3990 | blob_str(&err)); |
| 3991 | } |
| 3992 | blob_reset(&err); |
| 3993 | CheckinMiniInfo_cleanup(&cimi); |
| 3994 | if(blob_size(&endScript)>0){ |
| 3995 | fileedit_emit_script(0); |
| 3996 | fp("(function(){\n"); |
| 3997 | fp("try{\n%b\n}catch(e){console.error('Exception:',e)}\n", |
| 3998 | &endScript); |
| 3999 | fp("})();"); |
| 4000 | fileedit_emit_script(1); |
| 4001 | } |
| 4002 | db_end_transaction(0/*noting that dry-run mode will have already |
| 4003 | ** set this to rollback mode. */); |
| 4004 | style_footer(); |
| 4005 | #undef fp |
| 4006 | } |
| 4007 |
| --- src/checkin.c | |
| +++ src/checkin.c | |
| @@ -3366,11 +3366,11 @@ | |
| 3366 | ** COMMAND: test-ci-mini |
| 3367 | ** |
| 3368 | ** This is an on-going experiment, subject to change or removal at |
| 3369 | ** any time. |
| 3370 | ** |
| 3371 | ** Usage: %fossil test-ci-mini ?OPTIONS? FILENAME |
| 3372 | ** |
| 3373 | ** where FILENAME is a repo-relative name as it would appear in the |
| 3374 | ** vfile table. |
| 3375 | ** |
| 3376 | ** Options: |
| @@ -3575,13 +3575,13 @@ | |
| 3575 | return glob_match(pGlobs, zFilename); |
| 3576 | } |
| 3577 | |
| 3578 | static void fileedit_emit_script(int phase){ |
| 3579 | if(0==phase){ |
| 3580 | CX("<script nonce='%s'>", style_nonce()); |
| 3581 | }else{ |
| 3582 | CX("</script>\n"); |
| 3583 | } |
| 3584 | } |
| 3585 | |
| 3586 | #if 0 |
| 3587 | /* |
| @@ -3588,32 +3588,31 @@ | |
| 3588 | ** This function is for potential TODO features for /fileedit. |
| 3589 | ** It's been tested with that code but is not currently used |
| 3590 | ** by it. |
| 3591 | */ |
| 3592 | static void fileedit_emit_script_fetch(){ |
| 3593 | fileedit_emit_script(0); |
| 3594 | CX("window.fossilFetch = function(path,opt){\n"); |
| 3595 | CX(" if('function'===typeof opt){\n"); |
| 3596 | CX(" opt={onload:opt};\n"); |
| 3597 | CX(" }else{\n"); |
| 3598 | CX(" opt=opt||{onload:function(r){console.debug('response:',r)}}\n"); |
| 3599 | CX(" }\n"); |
| 3600 | CX(" const url='%R/'+path, x=new XMLHttpRequest();\n"); |
| 3601 | CX(" x.open(opt.method||'GET', url, true);\n"); |
| 3602 | CX(" x.responseType=opt.responseType||'text';\n"); |
| 3603 | CX(" if(opt.onload){\n"); |
| 3604 | CX(" x.onload = function(e){\n"); |
| 3605 | CX(" if(200!==this.status){\n"); |
| 3606 | CX(" if(opt.onerror) opt.onerror(e);\n"); |
| 3607 | CX(" return;\n"); |
| 3608 | CX(" }\n"); |
| 3609 | CX(" opt.onload(this.response);\n"); |
| 3610 | CX(" }\n"); |
| 3611 | CX(" }\n"); |
| 3612 | CX(" x.send();"); |
| 3613 | CX("};\n"); |
| 3614 | fileedit_emit_script(1); |
| 3615 | #undef fp |
| 3616 | }; |
| 3617 | #endif /* fileedit_emit_script_fetch() */ |
| 3618 | |
| @@ -3631,18 +3630,18 @@ | |
| 3630 | static void style_labeled_checkbox(const char *zFieldName, |
| 3631 | const char * zLabel, |
| 3632 | const char * zValue, |
| 3633 | const char * zTip, |
| 3634 | int isChecked){ |
| 3635 | CX("<span class='input-with-label'"); |
| 3636 | if(zTip && *zTip){ |
| 3637 | CX(" title='%h'", zTip); |
| 3638 | } |
| 3639 | CX("><input type='checkbox' name='%s' value='%T'%s/>", |
| 3640 | zFieldName, |
| 3641 | zValue ? zValue : "", isChecked ? " checked" : ""); |
| 3642 | CX("<span>%h</span></span>", zLabel); |
| 3643 | } |
| 3644 | |
| 3645 | /* |
| 3646 | ** WEBPAGE: fileedit |
| 3647 | ** |
| @@ -3750,57 +3749,55 @@ | |
| 3749 | fail((&err,"File appears to be binary. Cannot edit: " |
| 3750 | "<code>%h</code>",zFilename)); |
| 3751 | } |
| 3752 | |
| 3753 | /* All set. Here we go... */ |
| 3754 | |
| 3755 | CX("<h1>Editing:</h1>"); |
| 3756 | CX("<p class='fileedit-hint'>"); |
| 3757 | CX("File: <code>%h</code><br>" |
| 3758 | "Checkin Version: <code id='r-label'>%s</code><br>", |
| 3759 | zFilename, cimi.zParentUuid); |
| 3760 | CX("Permalink: <code>" |
| 3761 | "<a id='permalink' href='%R/fileedit?file=%T&r=%!S'>" |
| 3762 | "/fileedit?file=%T&r=%!S</a></code><br>" |
| 3763 | "(Clicking the permalink will reload the page and discard " |
| 3764 | "all edits!)", |
| 3765 | zFilename, cimi.zParentUuid, |
| 3766 | zFilename, cimi.zParentUuid); |
| 3767 | CX("</p>"); |
| 3768 | CX("<p>This page is <em>far from complete</em> and may still have " |
| 3769 | "significant bugs. USE AT YOUR OWN RISK, preferably on a test " |
| 3770 | "repo.</p>\n"); |
| 3771 | |
| 3772 | CX("<form action='%R/fileedit' method='POST' " |
| 3773 | "class='fileedit-form'>\n"); |
| 3774 | |
| 3775 | /******* Hidden fields *******/ |
| 3776 | CX("<input type='hidden' name='r' value='%s'>", |
| 3777 | cimi.zParentUuid); |
| 3778 | CX("<input type='hidden' name='file' value='%T'>", |
| 3779 | zFilename); |
| 3780 | |
| 3781 | /******* Comment *******/ |
| 3782 | CX("<h3>Checkin Comment</h3>\n"); |
| 3783 | CX("<textarea name='comment' rows='3' cols='80'>"); |
| 3784 | if(zComment && *zComment){ |
| 3785 | CX("%h"/*%h? %s?*/, zComment); |
| 3786 | } |
| 3787 | CX("</textarea>\n"); |
| 3788 | CX("<div class='fileedit-hint'>Comments use the Fossil wiki markup " |
| 3789 | "syntax.</div>"/*TODO: radiobuttons for fossil/me/plain text*/); |
| 3790 | |
| 3791 | /******* Content *******/ |
| 3792 | CX("<h3>File Content</h3>\n"); |
| 3793 | CX("<textarea name='content' id='fileedit-content' " |
| 3794 | "rows='20' cols='80'>"); |
| 3795 | CX("Loading..."); |
| 3796 | CX("</textarea>\n"); |
| 3797 | /******* Flags/options *******/ |
| 3798 | CX("<fieldset class='fileedit-options'>" |
| 3799 | "<legend>Options</legend><div>" |
| 3800 | /* Chrome does not sanely lay out multiple |
| 3801 | ** fieldset children after the <legend>, so |
| 3802 | ** a containing div is necessary. */); |
| 3803 | /* |
| @@ -3858,37 +3855,37 @@ | |
| 3855 | switch(eolMode){ |
| 3856 | case 1: cimi.flags |= CIMINI_CONVERT_EOL_UNIX; break; |
| 3857 | case 2: cimi.flags |= CIMINI_CONVERT_EOL_WINDOWS; break; |
| 3858 | default: cimi.flags |= CIMINI_CONVERT_EOL_INHERIT; break; |
| 3859 | } |
| 3860 | CX("<select name='eol' " |
| 3861 | "title='EOL conversion policy, noting that form-processing " |
| 3862 | "may implicitly change the line endings of the input.'>"); |
| 3863 | CX("<option value='0'%s>Inherit EOLs</option>", |
| 3864 | (eolMode!=1 && eolMode!=2) ? " selected" : ""); |
| 3865 | CX("<option value='1'%s/>Unix EOLs</option>", |
| 3866 | eolMode==1 ? " selected" : ""); |
| 3867 | CX("<option value='2'%s>Windows EOLs</option>", |
| 3868 | eolMode==2 ? " selected" : ""); |
| 3869 | CX("</select>"); |
| 3870 | } |
| 3871 | |
| 3872 | CX("</div></fieldset>") /* end of checkboxes */; |
| 3873 | |
| 3874 | /******* Buttons *******/ |
| 3875 | CX("<fieldset class='fileedit-options'>" |
| 3876 | "<legend>Tell the server to...</legend><div>"); |
| 3877 | CX("<button type='submit' name='submit' value='1'>" |
| 3878 | "Save</button>"); |
| 3879 | CX("<button type='submit' name='submit' value='2'>" |
| 3880 | "Preview (TODO)</button>"); |
| 3881 | CX("<button type='submit' name='submit' value='3'>" |
| 3882 | "Diff (TODO)</button>"); |
| 3883 | CX("</div></fieldset>"); |
| 3884 | |
| 3885 | /******* End of form *******/ |
| 3886 | CX("</form>\n"); |
| 3887 | |
| 3888 | { |
| 3889 | /* Populate the editor... |
| 3890 | ** |
| 3891 | ** To avoid all escaping-related issues, we have to do this one of |
| @@ -3929,11 +3926,11 @@ | |
| 3926 | cimi.zFilename = mprintf("%s",zFilename); |
| 3927 | cimi.pMfOut = &manifest; |
| 3928 | checkin_mini(&cimi, &newVid, &err); |
| 3929 | if(newVid!=0){ |
| 3930 | zNewUuid = rid_to_uuid(newVid); |
| 3931 | CX("<h3>Manifest%s: %S</h3><pre>" |
| 3932 | "<code class='fileedit-manifest'>%h</code>" |
| 3933 | "</pre>", |
| 3934 | (cimi.flags & CIMINI_DRY_RUN) ? " (dry run)" : "", |
| 3935 | zNewUuid, blob_str(&manifest)); |
| 3936 | if(!(CIMINI_DRY_RUN & cimi.flags)){ |
| @@ -3984,23 +3981,23 @@ | |
| 3981 | fossil_free(zFileUuid); |
| 3982 | if(stmt.pStmt){ |
| 3983 | db_finalize(&stmt); |
| 3984 | } |
| 3985 | if(blob_size(&err)){ |
| 3986 | CX("<div class='fileedit-error-report'>%s</div>", |
| 3987 | blob_str(&err)); |
| 3988 | } |
| 3989 | blob_reset(&err); |
| 3990 | CheckinMiniInfo_cleanup(&cimi); |
| 3991 | if(blob_size(&endScript)>0){ |
| 3992 | fileedit_emit_script(0); |
| 3993 | CX("(function(){\n"); |
| 3994 | CX("try{\n%b\n}catch(e){console.error('Exception:',e)}\n", |
| 3995 | &endScript); |
| 3996 | CX("})();"); |
| 3997 | fileedit_emit_script(1); |
| 3998 | } |
| 3999 | db_end_transaction(0/*noting that dry-run mode will have already |
| 4000 | ** set this to rollback mode. */); |
| 4001 | style_footer(); |
| 4002 | #undef fp |
| 4003 | } |
| 4004 |