Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
| Comment: | /fileedit now accepts 'fn' and 'ci' as undocumented aliases for 'filename' resp. 'checkin', for consistency with some other pages. style_emit_script_builtin() now includes a cache-buster on URLs (a prefix of the builtin content's MD5 hash). |
|---|---|
| Downloads: | Tarball | ZIP archive |
| Timelines: | family | ancestors | descendants | both | fileedit-ajaxify |
| Files: | files | file ages | folders |
| SHA3-256: |
3733293a0125a4dac7c4b2188789fd6b |
| User & Date: | stephan 2020-05-08 12:39:20.304 |
Context
|
2020-05-08
| ||
| 14:00 | Delay the initial filepage loadFile() until a windows.load event. This seems to eliminate what appears to have been a race between that call and the filepage init code. ... (check-in: 07d0bcc598 user: stephan tags: fileedit-ajaxify) | |
| 12:39 | /fileedit now accepts 'fn' and 'ci' as undocumented aliases for 'filename' resp. 'checkin', for consistency with some other pages. style_emit_script_builtin() now includes a cache-buster on URLs (a prefix of the builtin content's MD5 hash). ... (check-in: 3733293a01 user: stephan tags: fileedit-ajaxify) | |
|
2020-05-07
| ||
| 12:52 | Normalized the various input-with-label elements to use SPAN wrappers instead of DIV. ... (check-in: 53b31b0814 user: stephan tags: fileedit-ajaxify) | |
Changes
Changes to src/fileedit.c.
| ︙ | ︙ | |||
1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 |
fileedit_ajax_error(403, "File is disallowed by the "
"fileedit-glob setting.");
return 0;
}
return 1;
}
/*
** Passed the values of the "checkin" and "filename" request
** properties, this function verifies that they are valid and
** populates:
**
** - *zRevUuid = the fully-expanded value of zRev (owned by the
** caller). zRevUuid may be NULL.
| > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 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 |
fileedit_ajax_error(403, "File is disallowed by the "
"fileedit-glob setting.");
return 0;
}
return 1;
}
/*
** If zFn is not NULL, it is assigned the value of the first one of
** the "filename" or "fn" CGI parameters which is set.
**
** If zCi is not NULL, it is assigned the value of the first one of
** the "checkin" or "ci" CGI parameters which is set.
**
** If a parameter is not NULL, it will be assigned NULL if the
** corresponding parameter is not set.
**
** Returns the number of non-NULL values it assigns to arguments. Thus
** if passed (&x, NULL), it returns 1 if it assigns non-NULL to *x and
** 0 if it assigns NULL to *x.
*/
static int fileedit_get_fnci_args( const char **zFn, const char **zCi ){
int rc = 0;
if(zCi!=0){
*zCi = PD("checkin",P("ci"));
if( *zCi ) ++rc;
}
if(zFn!=0){
*zFn = PD("filename",P("fn"));
if (*zFn) ++rc;
}
return rc;
}
/*
** Passed the values of the "checkin" and "filename" request
** properties, this function verifies that they are valid and
** populates:
**
** - *zRevUuid = the fully-expanded value of zRev (owned by the
** caller). zRevUuid may be NULL.
|
| ︙ | ︙ | |||
1093 1094 1095 1096 1097 1098 1099 |
static int fileedit_ajax_setup_filerev(const char * zRev,
char ** zRevUuid,
int * vid,
const char * zFilename,
int * frid){
char * zCi = 0; /* fully-resolved checkin UUID */
char * zFileUuid; /* file UUID */
| | | 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 |
static int fileedit_ajax_setup_filerev(const char * zRev,
char ** zRevUuid,
int * vid,
const char * zFilename,
int * frid){
char * zCi = 0; /* fully-resolved checkin UUID */
char * zFileUuid; /* file UUID */
if(!fileedit_ajax_check_filename(zFilename)){
return 0;
}
*vid = symbolic_name_to_rid(zRev, "ci");
if(0==*vid){
fileedit_ajax_error(404,"Cannot resolve name as a checkin: %s",
zRev);
|
| ︙ | ︙ | |||
1137 1138 1139 1140 1141 1142 1143 |
**
** User must have Write access to use this page.
**
** Responds with the raw content of the given page. On error it
** produces a JSON response as documented for fileedit_ajax_error().
*/
void fileedit_ajax_content(){
| | | > | 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 |
**
** User must have Write access to use this page.
**
** Responds with the raw content of the given page. On error it
** produces a JSON response as documented for fileedit_ajax_error().
*/
void fileedit_ajax_content(){
const char * zFilename = 0;
const char * zRev = 0;
int vid, frid;
Blob content = empty_blob;
const char * zMime;
fileedit_get_fnci_args( &zFilename, &zRev );
if(!fileedit_ajax_boostrap()
|| !fileedit_ajax_setup_filerev(zRev, 0, &vid,
zFilename, &frid)){
return;
}
zMime = mimetype_from_name(zFilename);
content_get(frid, &content);
|
| ︙ | ︙ | |||
1185 1186 1187 1188 1189 1190 1191 |
**
** User must have Write access to use this page.
**
** Responds with the HTML content of the preview. On error it produces
** a JSON response as documented for fileedit_ajax_error().
*/
void fileedit_ajax_preview(){
| | > | 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 |
**
** User must have Write access to use this page.
**
** Responds with the HTML content of the preview. On error it produces
** a JSON response as documented for fileedit_ajax_error().
*/
void fileedit_ajax_preview(){
const char * zFilename = 0;
const char * zContent = P("content");
int renderMode = atoi(PD("render_mode","0"));
int ln = atoi(PD("ln","0"));
int iframeHeight = atoi(PD("iframe_height","40"));
Blob content = empty_blob;
fileedit_get_fnci_args( &zFilename, 0 );
if(!fileedit_ajax_boostrap()
|| !fileedit_ajax_check_filename(zFilename)){
return;
}
cgi_set_content_type("text/html");
blob_init(&content, zContent, -1);
fileedit_render_preview(&content, zFilename,
|
| ︙ | ︙ | |||
1228 1229 1230 1231 1232 1233 1234 |
void fileedit_ajax_diff(){
/*
** Reminder: we only need the filename to perform valdiation
** against fileedit_is_editable(), else this route could be
** abused to get diffs against content disallowed by the
** whitelist.
*/
| | | > | 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 |
void fileedit_ajax_diff(){
/*
** Reminder: we only need the filename to perform valdiation
** against fileedit_is_editable(), else this route could be
** abused to get diffs against content disallowed by the
** whitelist.
*/
const char * zFilename = 0;
const char * zRev = 0;
const char * zContent = P("content");
char * zRevUuid = 0;
int isSbs = atoi(PD("sbs","0"));
int vid, frid;
Blob content = empty_blob;
fileedit_get_fnci_args( &zFilename, &zRev );
if(!fileedit_ajax_boostrap()
|| !fileedit_ajax_setup_filerev(zRev, &zRevUuid, &vid,
zFilename, &frid)){
return;
}
if(!zContent){
zContent = "";
|
| ︙ | ︙ | |||
1271 1272 1273 1274 1275 1276 1277 |
*/
static int fileedit_setup_cimi_from_p(CheckinMiniInfo * p, Blob * pErr){
char * zFileUuid = 0; /* UUID of file content */
const char * zFlag; /* generic flag */
int rc = 0, vid = 0, frid = 0; /* result code, checkin/file rids */
#define fail(EXPR) blob_appendf EXPR; goto end_fail
| | | | | | 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 |
*/
static int fileedit_setup_cimi_from_p(CheckinMiniInfo * p, Blob * pErr){
char * zFileUuid = 0; /* UUID of file content */
const char * zFlag; /* generic flag */
int rc = 0, vid = 0, frid = 0; /* result code, checkin/file rids */
#define fail(EXPR) blob_appendf EXPR; goto end_fail
zFlag = PD("filename",P("fn"));
if(zFlag==0 || !*zFlag){
rc = 400;
fail((pErr,"Missing required 'filename' parameter."));
}
p->zFilename = mprintf("%s",zFlag);
if(0==fileedit_is_editable(p->zFilename)){
rc = 403;
fail((pErr,"Filename [%h] is disallowed "
"by the [fileedit-glob] repository "
"setting.",
p->zFilename));
}
zFlag = PD("checkin",P("ci"));
if(!zFlag){
rc = 400;
fail((pErr,"Missing required 'checkin' parameter."));
}
vid = symbolic_name_to_rid(zFlag, "ci");
if(0==vid){
rc = 404;
fail((pErr,"Could not resolve checkin version."));
}else if(vid<0){
rc = 400;
|
| ︙ | ︙ | |||
1418 1419 1420 1421 1422 1423 1424 |
char * zNewUuid = 0; /* newVid's UUID */
if(!fileedit_ajax_boostrap()){
goto end_cleanup;
}
db_begin_transaction();
CheckinMiniInfo_init(&cimi);
| | | 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 |
char * zNewUuid = 0; /* newVid's UUID */
if(!fileedit_ajax_boostrap()){
goto end_cleanup;
}
db_begin_transaction();
CheckinMiniInfo_init(&cimi);
rc = fileedit_setup_cimi_from_p(&cimi, &err);
if(0!=rc){
fileedit_ajax_error(rc,"%b",&err);
goto end_cleanup;
}
if(blob_size(&cimi.comment)==0){
fileedit_ajax_error(400,"Empty checkin comment is not permitted.");
goto end_cleanup;
|
| ︙ | ︙ |
Changes to src/style.c.
| ︙ | ︙ | |||
1468 1469 1470 1471 1472 1473 1474 |
/* The remaining fossil object bootstrap code is not dependent on
** C-runtime state... */
if(asInline){
CX("%s\n", builtin_text("fossil.bootstrap.js"));
}
style_emit_script_tag(1,0);
if(asInline==0){
| | | 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 |
/* The remaining fossil object bootstrap code is not dependent on
** C-runtime state... */
if(asInline){
CX("%s\n", builtin_text("fossil.bootstrap.js"));
}
style_emit_script_tag(1,0);
if(asInline==0){
style_emit_script_builtin("fossil.bootstrap.js", 0);
}
}
}
/*
** If passed 0 as its first argument, it emits a script opener tag
** with this request's nonce. If passed non-0 it emits a script
|
| ︙ | ︙ | |||
1508 1509 1510 1511 1512 1513 1514 | } } /* ** Emits a script tag which uses content from a builtin script file. ** ** If asInline is true, it is emitted directly as an opening tag, the | | > | > > > > > > > > > | > | 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 |
}
}
/*
** Emits a script tag which uses content from a builtin script file.
**
** If asInline is true, it is emitted directly as an opening tag, the
** content of the zName builtin file, and a closing tag.
**
** If it is false, a script tag loading it via
** src=builtin/{{zName}}?cache=XYZ is emitted, where XYZ is a prefix
** of the builtin content's md5 hash.
*/
void style_emit_script_builtin(char const * zName, int asInline){
if(asInline){
style_emit_script_tag(0,0);
CX("%s", builtin_text(zName));
style_emit_script_tag(1,0);
}else{
char * zFull = mprintf("builtin/%s",zName);
const char * zBuiltin = builtin_text(zName);
const char * zHash = 0;
if(zBuiltin!=0){
md5sum_init();
md5sum_step_text(zBuiltin,-1);
zHash = md5sum_finish(0);
}
CX("<script src='%R/%T?cache=%.8s'></script>\n",zFull,
zHash ? zHash : "MISSING");
fossil_free(zFull);
}
}
/*
** The first time this is called it emits the JS code from the
** built-in file fossil.fossil.js. Subsequent calls are no-ops.
|
| ︙ | ︙ |