| ︙ | | |
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
+
|
*******************************************************************************
**
** This file contains code for the /fileedit page and related code.
*/
#include "config.h"
#include "fileedit.h"
#include <assert.h>
#include <stdarg.h>
/*
** State for the "mini-checkin" infrastructure, which enables the
** ability to commit changes to a single file without a checkout
** db, e.g. for use via an HTTP request.
**
** Use CheckinMiniInfo_init() to cleanly initialize one to a known
|
| ︙ | | |
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
-
+
|
char *zParentUuid; /* Full UUID of pParent */
char *zFilename; /* Name of single file to commit. Must be
relative to the top of the repo. */
Blob fileContent; /* Content of file referred to by zFilename. */
Blob fileHash; /* Hash of this->fileContent, using the repo's
preferred hash method. */
Blob comment; /* Check-in comment text */
char *zMimetype; /* Mimetype of comment. May be NULL */
char *zCommentMimetype; /* Mimetype of comment. May be NULL */
char *zUser; /* User name */
char *zDate; /* Optionally force this date string (anything
supported by date_in_standard_format()).
Maybe be NULL. */
Blob *pMfOut; /* If not NULL, checkin_mini() will write a
copy of the generated manifest here. This
memory is NOT owned by CheckinMiniInfo. */
|
| ︙ | | |
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
|
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
|
-
+
|
blob_reset(&p->fileHash);
if(p->pParent){
manifest_destroy(p->pParent);
}
fossil_free(p->zFilename);
fossil_free(p->zDate);
fossil_free(p->zParentUuid);
fossil_free(p->zMimetype);
fossil_free(p->zCommentMimetype);
fossil_free(p->zUser);
CheckinMiniInfo_init(p);
}
/*
** Internal helper which returns an F-card perms string suitable for
** writing into a manifest.
|
| ︙ | | |
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
|
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
|
-
-
+
+
|
}else{
blob_append(pOut, "C (no\\scomment)\n", 16);
}
blob_appendf(pOut, "D %s\n", pCI->zDate);
if(create_manifest_mini_fcards(pOut,pCI,asDelta,pErr)==0){
return 0;
}
if(pCI->zMimetype!=0 && pCI->zMimetype[0]!=0){
blob_appendf(pOut, "N %F\n", pCI->zMimetype);
if(pCI->zCommentMimetype!=0 && pCI->zCommentMimetype[0]!=0){
blob_appendf(pOut, "N %F\n", pCI->zCommentMimetype);
}
blob_appendf(pOut, "P %s\n", pCI->zParentUuid);
blob_appendf(pOut, "U %F\n", pCI->zUser);
md5sum_blob(pOut, &zCard);
blob_appendf(pOut, "Z %b\n", &zCard);
blob_reset(&zCard);
return 1;
|
| ︙ | | |
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
|
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
|
-
+
-
+
|
** zFieldName, zLabel, and zValue are required. zTip is optional.
*/
static void style_labeled_checkbox(const char *zFieldName,
const char * zLabel,
const char * zValue,
const char * zTip,
int isChecked){
CX("<span class='input-with-label'");
CX("<div class='input-with-label'");
if(zTip && *zTip){
CX(" title='%h'", zTip);
}
CX("><input type='checkbox' name='%s' value='%T'%s/>",
zFieldName,
zValue ? zValue : "", isChecked ? " checked" : "");
CX("<span>%h</span></span>", zLabel);
CX("<span>%h</span></div>", zLabel);
}
enum fileedit_render_preview_flags {
FE_PREVIEW_LINE_NUMBERS = 1
};
enum fileedit_render_modes {
FE_RENDER_GUESS = 0,
|
| ︙ | | |
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
|
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
|
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
|
CX("<pre>%h</pre>", zExt+1, zContent);
}
break;
}
}
CX("</div><!--.fileedit-preview-->\n");
}
/*
** Outputs a SELECT list from a compile-time list of integers.
** The vargs must be a list of (const char *, int) pairs, terminated
** with a single NULL. Each pair is interpreted as...
**
** If the (const char *) is NULL, it is the end of the list, else
** a new OPTION entry is created. If the string is empty, the
** label and value of the OPTION is the integer part of the pair.
** If the string is not empty, it becomes the label and the integer
** the value. If that value == selectedValue then that OPTION
** element gets the 'selected' attribute.
**
** Note that the pairs are not in (int, const char *) order because
** there is no well-known integer value which we can definitively use
** as a list terminator.
**
** zFieldName is the value of the form element's name attribute.
**
** zLabel is an optional string to use as a "label" for the element
** (see below).
**
** zTooltip is an optional value for the SELECT's title attribute.
**
** The structure of the emited HTML is:
**
** <div class='input-with-label'>
** <span>{{zLabel}}</span>
** <select>...</select>
** </div>
**
*/
static void style_select_list_int_v(const char *zFieldName,
const char * zLabel,
const char * zToolTip,
int selectedVal, va_list vargs){
CX("<div class='input-with-label'");
if(zToolTip && *zToolTip){
CX(" title='%h'",zToolTip);
}
CX(">");
if(zLabel && *zLabel){
CX("<span>%h</span>", zLabel);
}
CX("<select name='%s'>",zFieldName);
while(1){
const char * zOption = va_arg(vargs,char *);
int v;
if(NULL==zOption){
break;
}
v = va_arg(vargs,int);
CX("<option value='%d'%s>",
v, v==selectedVal ? " selected" : "");
if(*zOption){
CX("%s", zOption);
}else{
CX("%d",v);
}
CX("</option>\n");
}
CX("</select>\n");
if(zLabel && *zLabel){
CX("</div>\n");
}
}
/*
** The ellipsis-args counterpart of style_select_list_int_v().
*/
void style_select_list_int(const char *zFieldName,
const char * zLabel,
const char * zToolTip,
int selectedVal, ... ){
va_list vargs;
va_start(vargs,selectedVal);
style_select_list_int_v(zFieldName, zLabel, zToolTip,
selectedVal, vargs);
va_end(vargs);
}
/*
** WEBPAGE: fileedit
**
** EXPERIMENTAL and subject to change and removal at any time. The goal
** is to allow online edits of files.
**
|
| ︙ | | |
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
|
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
|
-
+
|
CheckinMiniInfo_init(&cimi);
submitMode = atoi(PD("submit","0"));
if(submitMode < SUBMIT_NONE || submitMode > SUBMIT_DIFF){
submitMode = 0;
}
zFlagCheck = P("comment_mimetype");
if(zFlagCheck){
cimi.zMimetype = mprintf("%s",zFlagCheck);
cimi.zCommentMimetype = mprintf("%s",zFlagCheck);
zFlagCheck = 0;
}
cimi.zUser = mprintf("%s",g.zLogin);
style_header("File Editor");
/* As of this point, don't use return or fossil_fatal(), use
** fail((&err,...)) instead so that we can be sure to do any
|
| ︙ | | |
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
|
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
|
-
+
-
-
-
-
-
-
-
-
-
-
|
zFilename, cimi.zParentUuid);
CX("</p>");
CX("<p>This page is <em>far from complete</em> and may still have "
"significant bugs. USE AT YOUR OWN RISK, preferably on a test "
"repo.</p>\n");
CX("<form action='%R/fileedit#options' method='POST' "
"class='fileedit-form'>\n");
"class='fileedit'>\n");
/******* Hidden fields *******/
CX("<input type='hidden' name='r' value='%s'>",
cimi.zParentUuid);
CX("<input type='hidden' name='file' value='%T'>",
zFilename);
/******* Comment *******/
CX("<h3>Checkin Comment</h3>\n");
CX("<textarea name='comment' rows='3' cols='80'>");
if(zComment && *zComment){
CX("%h"/*%h? %s?*/, zComment);
}
CX("</textarea>\n");
CX("<div class='fileedit-hint'>Comments use the Fossil wiki markup "
"syntax.</div>"/*TODO: radiobuttons for fossil/me/plain text*/);
/******* Content *******/
CX("<h3>File Content</h3>\n");
CX("<textarea name='content' id='fileedit-content' "
"rows='20' cols='80'>");
if(0==loadMode){
CX("%h",blob_str(&cimi.fileContent));
}else{
|
| ︙ | | |
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
|
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
|
-
-
-
-
+
+
+
+
+
+
-
-
+
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
+
+
+
+
-
-
+
-
-
-
+
-
-
-
+
-
-
-
+
-
-
+
-
-
-
-
+
+
+
+
-
-
-
-
-
+
-
-
+
+
+
+
+
|
const int eolMode = submitMode==SUBMIT_NONE
? 0 : atoi(PD("eol","0"));
switch(eolMode){
case 1: cimi.flags |= CIMINI_CONVERT_EOL_UNIX; break;
case 2: cimi.flags |= CIMINI_CONVERT_EOL_WINDOWS; break;
default: cimi.flags |= CIMINI_CONVERT_EOL_INHERIT; break;
}
CX("<select name='eol' "
"title='EOL conversion policy, noting that form-processing "
"may implicitly change the line endings of the input.'>");
CX("<option value='0'%s>Inherit EOLs</option>",
style_select_list_int("eol", "EOL Style",
"EOL conversion policy, noting that "
"form-processing may implicitly change the "
"line endings of the input.",
eolMode==1||eolMode==2 ? eolMode : 0,
"Inherit", 0,
(eolMode!=1 && eolMode!=2) ? " selected" : "");
CX("<option value='1'%s/>Unix EOLs</option>",
"Unix", 1,
eolMode==1 ? " selected" : "");
CX("<option value='2'%s>Windows EOLs</option>",
eolMode==2 ? " selected" : "");
CX("</select>");
}
CX("</div></fieldset>") /* end of checkboxes */;
"Windows", 2,
NULL);
}
CX("</div></fieldset>") /* end of checkboxes */;
/******* Comment *******/
CX("<a id='comment'></a>");
CX("<fieldset><legend>Commit message</legend><div>");
CX("<textarea name='comment' rows='3' cols='80'>");
/* ^^^ adding the 'required' attribute means we cannot even submit
** for PREVIEW mode if it's empty :/. */
if(zComment && *zComment){
CX("%h"/*%h? %s?*/, zComment);
}
CX("</textarea>\n");
CX("<div class='fileedit-hint'>Comments use the Fossil wiki markup "
"syntax.</div>\n"/*TODO: select for fossil/md/plain text*/);
CX("</div></fieldset>\n");
/******* Buttons *******/
CX("<a id='buttons'></a>");
CX("<fieldset class='fileedit-options'>"
"<legend>Tell the server to...</legend><div>");
CX("<button type='submit' name='submit' value='1'>"
"Save</button>");
CX("<button type='submit' name='submit' value='2'>"
"Preview</button>");
CX("<button type='submit' name='submit' value='3'>"
"Diff (TODO)</button>");
{
/* Preview rendering mode selection... */
previewRenderMode = atoi(PD("preview_render_mode","0"));
if(0==previewRenderMode){
previewRenderMode = fileedit_render_mode_for_mimetype(zFileMime);
}
CX("<br>");
CX("<select name='preview_render_mode'>\n");
CX("<option value='%d' disabled>Preview Mode</option>",
FE_RENDER_GUESS);
style_select_list_int("preview_render_mode",
"Preview Mode",
"Preview mode format.",
previewRenderMode,
CX("<option value='%d'%s>Guess</option>",
FE_RENDER_GUESS,
"Guess", FE_RENDER_GUESS,
FE_RENDER_GUESS==previewRenderMode ? " selected" : "");
CX("<option value='%d'%s>Wiki/Markdown</option>",
FE_RENDER_WIKI,
"Wiki/Markdown", FE_RENDER_WIKI,
FE_RENDER_WIKI==previewRenderMode ? " selected" : "");
CX("<option value='%d'%s>HTML (iframe)</option>",
FE_RENDER_HTML,
"HTML (iframe)", FE_RENDER_HTML,
FE_RENDER_HTML==previewRenderMode ? " selected" : "");
CX("<option value='%d'%s>Plain Text</option>",
FE_RENDER_PLAIN_TEXT,
"Plain Text", FE_RENDER_PLAIN_TEXT,
FE_RENDER_PLAIN_TEXT==previewRenderMode ? " selected" : "");
CX("</select>\n");
NULL);
if(FE_RENDER_HTML==previewRenderMode){
/* HTML preview mode iframe height... */
int i;
if(submitMode==SUBMIT_PREVIEW){
previewHtmlHeight = atoi(PD("preview_html_ems","0"));
}else{
previewHtmlHeight = 40;
}
/* Allow selection of HTML preview iframe height */
CX("<select name='preview_html_ems' "
"title='Height (in EMs) of the iframe used for HTML "
"preview.'>\n");
style_select_list_int("preview_html_ems",
"Preview IFrame Height (EMs)",
"Height (in EMs) of the iframe used for "
"HTML preview",
CX("<option disabled value='40'>HTML Preview Height (EMs)"
"</option>\n");
for( i = 20; i <= 100; i+=20 ){
CX("<option value='%d'%s>%d</option>\n",
i, (previewHtmlHeight==i) ? " selected" : "", i);
previewHtmlHeight,
}
CX("</select>\n");
"", 20, "", 40,
"", 60, "", 80,
"", 100, NULL);
}
else if(FE_RENDER_PLAIN_TEXT==previewRenderMode){
style_labeled_checkbox("preview_ln",
"Add line numbers to plain-text previews?",
"1",
"If on, plain-text files (only) will get "
"line numbers added to the preview.",
previewLn);
}
}
CX("<button type='submit' name='submit' value='3'>"
"Diff (TODO)</button>");
CX("</div></fieldset>");
/******* End of form *******/
CX("</form>\n");
/* Dynamically populate the editor... */
if(1==loadMode || (2==loadMode && submitMode>SUBMIT_NONE)){
|
| ︙ | | |