Fossil SCM

New CX(...) macro for rendering HTTP reply text, as an alternative to the "@ ..." markup provided by translate.c.

drh 2020-05-03 12:21 checkin-without-checkout
Commit 0d160f9fa8bf2e223c5cce71bf6b063a8b098ef4eb68a878b454a29fbf1653a9
2 files changed +11 +65 -68
+11
--- src/cgi.c
+++ src/cgi.c
@@ -64,10 +64,21 @@
6464
#define PDT(x,y) cgi_parameter_trimmed((x),(y))
6565
#define PB(x) cgi_parameter_boolean(x)
6666
#define PCK(x) cgi_parameter_checked(x,1)
6767
#define PIF(x,y) cgi_parameter_checked(x,y)
6868
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
6980
7081
/*
7182
** Destinations for output text.
7283
*/
7384
#define CGI_HEADER 0
7485
--- 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 @@
33663366
** COMMAND: test-ci-mini
33673367
**
33683368
** This is an on-going experiment, subject to change or removal at
33693369
** any time.
33703370
**
3371
-** Usage: %fossil ?OPTIONS? FILENAME
3371
+** Usage: %fossil test-ci-mini ?OPTIONS? FILENAME
33723372
**
33733373
** where FILENAME is a repo-relative name as it would appear in the
33743374
** vfile table.
33753375
**
33763376
** Options:
@@ -3575,13 +3575,13 @@
35753575
return glob_match(pGlobs, zFilename);
35763576
}
35773577
35783578
static void fileedit_emit_script(int phase){
35793579
if(0==phase){
3580
- fossil_print("<script nonce='%s'>", style_nonce());
3580
+ CX("<script nonce='%s'>", style_nonce());
35813581
}else{
3582
- fossil_print("</script>\n");
3582
+ CX("</script>\n");
35833583
}
35843584
}
35853585
35863586
#if 0
35873587
/*
@@ -3588,32 +3588,31 @@
35883588
** This function is for potential TODO features for /fileedit.
35893589
** It's been tested with that code but is not currently used
35903590
** by it.
35913591
*/
35923592
static void fileedit_emit_script_fetch(){
3593
-#define fp fossil_print
35943593
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");
36153614
fileedit_emit_script(1);
36163615
#undef fp
36173616
};
36183617
#endif /* fileedit_emit_script_fetch() */
36193618
@@ -3631,18 +3630,18 @@
36313630
static void style_labeled_checkbox(const char *zFieldName,
36323631
const char * zLabel,
36333632
const char * zValue,
36343633
const char * zTip,
36353634
int isChecked){
3636
- fossil_print("<span class='input-with-label'");
3635
+ CX("<span class='input-with-label'");
36373636
if(zTip && *zTip){
3638
- fossil_print(" title='%h'", zTip);
3637
+ CX(" title='%h'", zTip);
36393638
}
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);
36443643
}
36453644
36463645
/*
36473646
** WEBPAGE: fileedit
36483647
**
@@ -3750,57 +3749,55 @@
37503749
fail((&err,"File appears to be binary. Cannot edit: "
37513750
"<code>%h</code>",zFilename));
37523751
}
37533752
37543753
/* All set. Here we go... */
3755
-#define fp fossil_print
3756
- /* ^^^ Appologies, Richard, but the @ form plays havoc with emacs */
37573754
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>"
37613758
"Checkin Version: <code id='r-label'>%s</code><br>",
37623759
zFilename, cimi.zParentUuid);
3763
- fp("Permalink: <code>"
3760
+ CX("Permalink: <code>"
37643761
"<a id='permalink' href='%R/fileedit?file=%T&r=%!S'>"
37653762
"/fileedit?file=%T&r=%!S</a></code><br>"
37663763
"(Clicking the permalink will reload the page and discard "
37673764
"all edits!)",
37683765
zFilename, cimi.zParentUuid,
37693766
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 "
37723769
"significant bugs. USE AT YOUR OWN RISK, preferably on a test "
37733770
"repo.</p>\n");
37743771
3775
- fp("<form action='%R/fileedit' method='POST' "
3772
+ CX("<form action='%R/fileedit' method='POST' "
37763773
"class='fileedit-form'>\n");
37773774
37783775
/******* Hidden fields *******/
3779
- fp("<input type='hidden' name='r' value='%s'>",
3776
+ CX("<input type='hidden' name='r' value='%s'>",
37803777
cimi.zParentUuid);
3781
- fp("<input type='hidden' name='file' value='%T'>",
3778
+ CX("<input type='hidden' name='file' value='%T'>",
37823779
zFilename);
37833780
37843781
/******* 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'>");
37873784
if(zComment && *zComment){
3788
- fp("%h"/*%h? %s?*/, zComment);
3785
+ CX("%h"/*%h? %s?*/, zComment);
37893786
}
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 "
37923789
"syntax.</div>"/*TODO: radiobuttons for fossil/me/plain text*/);
37933790
37943791
/******* 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' "
37973794
"rows='20' cols='80'>");
3798
- fp("Loading...");
3799
- fp("</textarea>\n");
3795
+ CX("Loading...");
3796
+ CX("</textarea>\n");
38003797
/******* Flags/options *******/
3801
- fp("<fieldset class='fileedit-options'>"
3798
+ CX("<fieldset class='fileedit-options'>"
38023799
"<legend>Options</legend><div>"
38033800
/* Chrome does not sanely lay out multiple
38043801
** fieldset children after the <legend>, so
38053802
** a containing div is necessary. */);
38063803
/*
@@ -3858,37 +3855,37 @@
38583855
switch(eolMode){
38593856
case 1: cimi.flags |= CIMINI_CONVERT_EOL_UNIX; break;
38603857
case 2: cimi.flags |= CIMINI_CONVERT_EOL_WINDOWS; break;
38613858
default: cimi.flags |= CIMINI_CONVERT_EOL_INHERIT; break;
38623859
}
3863
- fp("<select name='eol' "
3860
+ CX("<select name='eol' "
38643861
"title='EOL conversion policy, noting that form-processing "
38653862
"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>",
38673864
(eolMode!=1 && eolMode!=2) ? " selected" : "");
3868
- fp("<option value='1'%s/>Unix EOLs</option>",
3865
+ CX("<option value='1'%s/>Unix EOLs</option>",
38693866
eolMode==1 ? " selected" : "");
3870
- fp("<option value='2'%s>Windows EOLs</option>",
3867
+ CX("<option value='2'%s>Windows EOLs</option>",
38713868
eolMode==2 ? " selected" : "");
3872
- fp("</select>");
3869
+ CX("</select>");
38733870
}
38743871
3875
- fp("</div></fieldset>") /* end of checkboxes */;
3872
+ CX("</div></fieldset>") /* end of checkboxes */;
38763873
38773874
/******* Buttons *******/
3878
- fp("<fieldset class='fileedit-options'>"
3875
+ CX("<fieldset class='fileedit-options'>"
38793876
"<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'>"
38813878
"Save</button>");
3882
- fp("<button type='submit' name='submit' value='2'>"
3879
+ CX("<button type='submit' name='submit' value='2'>"
38833880
"Preview (TODO)</button>");
3884
- fp("<button type='submit' name='submit' value='3'>"
3881
+ CX("<button type='submit' name='submit' value='3'>"
38853882
"Diff (TODO)</button>");
3886
- fp("</div></fieldset>");
3883
+ CX("</div></fieldset>");
38873884
38883885
/******* End of form *******/
3889
- fp("</form>\n");
3886
+ CX("</form>\n");
38903887
38913888
{
38923889
/* Populate the editor...
38933890
**
38943891
** To avoid all escaping-related issues, we have to do this one of
@@ -3929,11 +3926,11 @@
39293926
cimi.zFilename = mprintf("%s",zFilename);
39303927
cimi.pMfOut = &manifest;
39313928
checkin_mini(&cimi, &newVid, &err);
39323929
if(newVid!=0){
39333930
zNewUuid = rid_to_uuid(newVid);
3934
- fp("<h3>Manifest%s: %S</h3><pre>"
3931
+ CX("<h3>Manifest%s: %S</h3><pre>"
39353932
"<code class='fileedit-manifest'>%h</code>"
39363933
"</pre>",
39373934
(cimi.flags & CIMINI_DRY_RUN) ? " (dry run)" : "",
39383935
zNewUuid, blob_str(&manifest));
39393936
if(!(CIMINI_DRY_RUN & cimi.flags)){
@@ -3984,23 +3981,23 @@
39843981
fossil_free(zFileUuid);
39853982
if(stmt.pStmt){
39863983
db_finalize(&stmt);
39873984
}
39883985
if(blob_size(&err)){
3989
- fp("<div class='fileedit-error-report'>%s</div>",
3986
+ CX("<div class='fileedit-error-report'>%s</div>",
39903987
blob_str(&err));
39913988
}
39923989
blob_reset(&err);
39933990
CheckinMiniInfo_cleanup(&cimi);
39943991
if(blob_size(&endScript)>0){
39953992
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",
39983995
&endScript);
3999
- fp("})();");
3996
+ CX("})();");
40003997
fileedit_emit_script(1);
40013998
}
40023999
db_end_transaction(0/*noting that dry-run mode will have already
40034000
** set this to rollback mode. */);
40044001
style_footer();
40054002
#undef fp
40064003
}
40074004
--- 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

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button