Fossil SCM

Added --format MIMETYPE flag to (wiki create|commit) and /json/wiki/save.

stephan 2014-05-14 16:39 UTC trunk
Commit 8f2d9e6923ed14ab6bd8a201c8db4da5592045a1
2 files changed +5 -1 +38 -20
+5 -1
--- src/json_wiki.c
+++ src/json_wiki.c
@@ -308,10 +308,11 @@
308308
char const * zPageName; /* cstr form of page name */
309309
cson_value * contentV; /* passed-in content */
310310
cson_value * emptyContent = NULL; /* placeholder for empty content. */
311311
cson_value * payV = NULL; /* payload/return value */
312312
cson_string const * jstr = NULL; /* temp for cson_value-to-cson_string conversions. */
313
+ char const * zMimeType = 0;
313314
unsigned int contentLen = 0;
314315
int rid;
315316
if( (createMode && !g.perm.NewWiki)
316317
|| (!createMode && !g.perm.WrWiki)){
317318
json_set_err(FSL_JSON_E_DENIED,
@@ -371,11 +372,14 @@
371372
jstr = cson_value_get_string(contentV);
372373
contentLen = (int)cson_string_length_bytes(jstr);
373374
if(contentLen){
374375
blob_append(&content, cson_string_cstr(jstr),contentLen);
375376
}
376
- wiki_cmd_commit(zPageName, 0==rid, &content);
377
+
378
+ zMimeType = json_find_option_cstr("format","format","F");
379
+
380
+ wiki_cmd_commit(zPageName, 0==rid, &content, zMimeType);
377381
blob_reset(&content);
378382
/*
379383
Our return value here has a race condition: if this operation
380384
is called concurrently for the same wiki page via two requests,
381385
payV could reflect the results of the other save operation.
382386
--- src/json_wiki.c
+++ src/json_wiki.c
@@ -308,10 +308,11 @@
308 char const * zPageName; /* cstr form of page name */
309 cson_value * contentV; /* passed-in content */
310 cson_value * emptyContent = NULL; /* placeholder for empty content. */
311 cson_value * payV = NULL; /* payload/return value */
312 cson_string const * jstr = NULL; /* temp for cson_value-to-cson_string conversions. */
 
313 unsigned int contentLen = 0;
314 int rid;
315 if( (createMode && !g.perm.NewWiki)
316 || (!createMode && !g.perm.WrWiki)){
317 json_set_err(FSL_JSON_E_DENIED,
@@ -371,11 +372,14 @@
371 jstr = cson_value_get_string(contentV);
372 contentLen = (int)cson_string_length_bytes(jstr);
373 if(contentLen){
374 blob_append(&content, cson_string_cstr(jstr),contentLen);
375 }
376 wiki_cmd_commit(zPageName, 0==rid, &content);
 
 
 
377 blob_reset(&content);
378 /*
379 Our return value here has a race condition: if this operation
380 is called concurrently for the same wiki page via two requests,
381 payV could reflect the results of the other save operation.
382
--- src/json_wiki.c
+++ src/json_wiki.c
@@ -308,10 +308,11 @@
308 char const * zPageName; /* cstr form of page name */
309 cson_value * contentV; /* passed-in content */
310 cson_value * emptyContent = NULL; /* placeholder for empty content. */
311 cson_value * payV = NULL; /* payload/return value */
312 cson_string const * jstr = NULL; /* temp for cson_value-to-cson_string conversions. */
313 char const * zMimeType = 0;
314 unsigned int contentLen = 0;
315 int rid;
316 if( (createMode && !g.perm.NewWiki)
317 || (!createMode && !g.perm.WrWiki)){
318 json_set_err(FSL_JSON_E_DENIED,
@@ -371,11 +372,14 @@
372 jstr = cson_value_get_string(contentV);
373 contentLen = (int)cson_string_length_bytes(jstr);
374 if(contentLen){
375 blob_append(&content, cson_string_cstr(jstr),contentLen);
376 }
377
378 zMimeType = json_find_option_cstr("format","format","F");
379
380 wiki_cmd_commit(zPageName, 0==rid, &content, zMimeType);
381 blob_reset(&content);
382 /*
383 Our return value here has a race condition: if this operation
384 is called concurrently for the same wiki page via two requests,
385 payV could reflect the results of the other save operation.
386
+38 -20
--- src/wiki.c
+++ src/wiki.c
@@ -956,17 +956,18 @@
956956
** a new page. If no previous page with the name zPageName exists
957957
** and isNew is false, then this routine throws an error.
958958
**
959959
** The content of the new page is given by the blob pContent.
960960
*/
961
-int wiki_cmd_commit(char const * zPageName, int isNew, Blob *pContent){
961
+int wiki_cmd_commit(char const * zPageName, int isNew, Blob *pContent,
962
+ char const * zMimeType){
962963
Blob wiki; /* Wiki page content */
963964
Blob cksum; /* wiki checksum */
964965
int rid; /* artifact ID of parent page */
965966
char *zDate; /* timestamp */
966967
char *zUuid; /* uuid for rid */
967
-
968
+
968969
rid = db_int(0,
969970
"SELECT x.rid FROM tag t, tagxref x"
970971
" WHERE x.tagid=t.tagid AND t.tagname='wiki-%q'"
971972
" ORDER BY x.mtime DESC LIMIT 1",
972973
zPageName
@@ -987,10 +988,13 @@
987988
blob_zero(&wiki);
988989
zDate = date_in_standard_format("now");
989990
blob_appendf(&wiki, "D %s\n", zDate);
990991
free(zDate);
991992
blob_appendf(&wiki, "L %F\n", zPageName );
993
+ if( zMimeType && fossil_strcmp(zMimeType,"text/x-fossil-wiki")!=0 ){
994
+ blob_appendf(&wiki, "N %F\n", zMimeType);
995
+ }
992996
if( rid ){
993997
zUuid = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", rid);
994998
blob_appendf(&wiki, "P %s\n", zUuid);
995999
free(zUuid);
9961000
}
@@ -1019,16 +1023,18 @@
10191023
** %fossil wiki export PAGENAME ?FILE?
10201024
**
10211025
** Sends the latest version of the PAGENAME wiki
10221026
** entry to the given file or standard output.
10231027
**
1024
-** %fossil wiki commit PAGENAME ?FILE?
1028
+** %fossil wiki commit PAGENAME ?FILE? [-format TEXT-FORMAT]
10251029
**
10261030
** Commit changes to a wiki page from FILE or from standard
1027
-** input.
1031
+** input. The -format flag specifies the mime type, defaulting
1032
+** to the type used by the previous version of the page or
1033
+** (for new pages) text/x-fossil-wiki.
10281034
**
1029
-** %fossil wiki create PAGENAME ?FILE?
1035
+** %fossil wiki create PAGENAME ?FILE? [-format TEXT-FORMAT]
10301036
**
10311037
** Create a new wiki page with initial content taken from
10321038
** FILE or from standard input.
10331039
**
10341040
** %fossil wiki list
@@ -1054,11 +1060,10 @@
10541060
int rid; /* Artifact ID of the wiki page */
10551061
int i; /* Loop counter */
10561062
char *zBody = 0; /* Wiki page content */
10571063
Blob body; /* Wiki page content */
10581064
Manifest *pWiki = 0; /* Parsed wiki page content */
1059
-
10601065
if( (g.argc!=4) && (g.argc!=5) ){
10611066
usage("export PAGENAME ?FILE?");
10621067
}
10631068
zPageName = g.argv[3];
10641069
rid = db_int(0, "SELECT x.rid FROM tag t, tagxref x"
@@ -1079,40 +1084,54 @@
10791084
blob_append(&body, "\n", 1);
10801085
blob_write_to_file(&body, zFile);
10811086
blob_reset(&body);
10821087
manifest_destroy(pWiki);
10831088
return;
1084
- }else
1085
- if( strncmp(g.argv[2],"commit",n)==0
1086
- || strncmp(g.argv[2],"create",n)==0 ){
1087
- char *zPageName;
1088
- Blob content;
1089
+ }else if( strncmp(g.argv[2],"commit",n)==0
1090
+ || strncmp(g.argv[2],"create",n)==0 ){
1091
+ char const *zPageName; /* page name */
1092
+ Blob content; /* Input content */
1093
+ int rid;
1094
+ Manifest *pWiki = 0; /* Parsed wiki page content */
1095
+ char const * zMimeType = find_option("format", "F", 1);
10891096
if( g.argc!=4 && g.argc!=5 ){
1090
- usage("commit PAGENAME ?FILE?");
1097
+ usage("commit PAGENAME ?FILE? [-format TEXT-FORMAT]");
10911098
}
10921099
zPageName = g.argv[3];
10931100
if( g.argc==4 ){
10941101
blob_read_from_channel(&content, stdin, -1);
10951102
}else{
10961103
blob_read_from_file(&content, g.argv[4]);
1104
+ }
1105
+ if(!zMimeType || !*zMimeType){
1106
+ /* Try to deduce the mime type based on the prior version. */
1107
+ rid = db_int(0, "SELECT x.rid FROM tag t, tagxref x"
1108
+ " WHERE x.tagid=t.tagid AND t.tagname='wiki-%q'"
1109
+ " ORDER BY x.mtime DESC LIMIT 1",
1110
+ zPageName
1111
+ );
1112
+ if(rid>0 && (pWiki = manifest_get(rid, CFTYPE_WIKI, 0))!=0
1113
+ && (pWiki->zMimetype && *pWiki->zMimetype)){
1114
+ zMimeType = pWiki->zMimetype;
1115
+ }
10971116
}
10981117
if( g.argv[2][1]=='r' ){
1099
- wiki_cmd_commit(zPageName, 1, &content);
1118
+ wiki_cmd_commit(zPageName, 1, &content, zMimeType);
11001119
fossil_print("Created new wiki page %s.\n", zPageName);
11011120
}else{
1102
- wiki_cmd_commit(zPageName, 0, &content);
1121
+ wiki_cmd_commit(zPageName, 0, &content, zMimeType);
11031122
fossil_print("Updated wiki page %s.\n", zPageName);
11041123
}
1124
+ manifest_destroy(pWiki);
11051125
blob_reset(&content);
1106
- }else
1107
- if( strncmp(g.argv[2],"delete",n)==0 ){
1126
+ return;
1127
+ }else if( strncmp(g.argv[2],"delete",n)==0 ){
11081128
if( g.argc!=5 ){
11091129
usage("delete PAGENAME");
11101130
}
11111131
fossil_fatal("delete not yet implemented.");
1112
- }else
1113
- if( strncmp(g.argv[2],"list",n)==0 ){
1132
+ }else if( strncmp(g.argv[2],"list",n)==0 ){
11141133
Stmt q;
11151134
db_prepare(&q,
11161135
"SELECT substr(tagname, 6) FROM tag WHERE tagname GLOB 'wiki-*'"
11171136
" ORDER BY lower(tagname) /*sort*/"
11181137
);
@@ -1119,14 +1138,13 @@
11191138
while( db_step(&q)==SQLITE_ROW ){
11201139
const char *zName = db_column_text(&q, 0);
11211140
fossil_print( "%s\n",zName);
11221141
}
11231142
db_finalize(&q);
1124
- }else
1125
- {
1143
+ }else{
11261144
goto wiki_cmd_usage;
11271145
}
11281146
return;
11291147
11301148
wiki_cmd_usage:
11311149
usage("export|create|commit|list ...");
11321150
}
11331151
--- src/wiki.c
+++ src/wiki.c
@@ -956,17 +956,18 @@
956 ** a new page. If no previous page with the name zPageName exists
957 ** and isNew is false, then this routine throws an error.
958 **
959 ** The content of the new page is given by the blob pContent.
960 */
961 int wiki_cmd_commit(char const * zPageName, int isNew, Blob *pContent){
 
962 Blob wiki; /* Wiki page content */
963 Blob cksum; /* wiki checksum */
964 int rid; /* artifact ID of parent page */
965 char *zDate; /* timestamp */
966 char *zUuid; /* uuid for rid */
967
968 rid = db_int(0,
969 "SELECT x.rid FROM tag t, tagxref x"
970 " WHERE x.tagid=t.tagid AND t.tagname='wiki-%q'"
971 " ORDER BY x.mtime DESC LIMIT 1",
972 zPageName
@@ -987,10 +988,13 @@
987 blob_zero(&wiki);
988 zDate = date_in_standard_format("now");
989 blob_appendf(&wiki, "D %s\n", zDate);
990 free(zDate);
991 blob_appendf(&wiki, "L %F\n", zPageName );
 
 
 
992 if( rid ){
993 zUuid = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", rid);
994 blob_appendf(&wiki, "P %s\n", zUuid);
995 free(zUuid);
996 }
@@ -1019,16 +1023,18 @@
1019 ** %fossil wiki export PAGENAME ?FILE?
1020 **
1021 ** Sends the latest version of the PAGENAME wiki
1022 ** entry to the given file or standard output.
1023 **
1024 ** %fossil wiki commit PAGENAME ?FILE?
1025 **
1026 ** Commit changes to a wiki page from FILE or from standard
1027 ** input.
 
 
1028 **
1029 ** %fossil wiki create PAGENAME ?FILE?
1030 **
1031 ** Create a new wiki page with initial content taken from
1032 ** FILE or from standard input.
1033 **
1034 ** %fossil wiki list
@@ -1054,11 +1060,10 @@
1054 int rid; /* Artifact ID of the wiki page */
1055 int i; /* Loop counter */
1056 char *zBody = 0; /* Wiki page content */
1057 Blob body; /* Wiki page content */
1058 Manifest *pWiki = 0; /* Parsed wiki page content */
1059
1060 if( (g.argc!=4) && (g.argc!=5) ){
1061 usage("export PAGENAME ?FILE?");
1062 }
1063 zPageName = g.argv[3];
1064 rid = db_int(0, "SELECT x.rid FROM tag t, tagxref x"
@@ -1079,40 +1084,54 @@
1079 blob_append(&body, "\n", 1);
1080 blob_write_to_file(&body, zFile);
1081 blob_reset(&body);
1082 manifest_destroy(pWiki);
1083 return;
1084 }else
1085 if( strncmp(g.argv[2],"commit",n)==0
1086 || strncmp(g.argv[2],"create",n)==0 ){
1087 char *zPageName;
1088 Blob content;
 
 
1089 if( g.argc!=4 && g.argc!=5 ){
1090 usage("commit PAGENAME ?FILE?");
1091 }
1092 zPageName = g.argv[3];
1093 if( g.argc==4 ){
1094 blob_read_from_channel(&content, stdin, -1);
1095 }else{
1096 blob_read_from_file(&content, g.argv[4]);
 
 
 
 
 
 
 
 
 
 
 
 
1097 }
1098 if( g.argv[2][1]=='r' ){
1099 wiki_cmd_commit(zPageName, 1, &content);
1100 fossil_print("Created new wiki page %s.\n", zPageName);
1101 }else{
1102 wiki_cmd_commit(zPageName, 0, &content);
1103 fossil_print("Updated wiki page %s.\n", zPageName);
1104 }
 
1105 blob_reset(&content);
1106 }else
1107 if( strncmp(g.argv[2],"delete",n)==0 ){
1108 if( g.argc!=5 ){
1109 usage("delete PAGENAME");
1110 }
1111 fossil_fatal("delete not yet implemented.");
1112 }else
1113 if( strncmp(g.argv[2],"list",n)==0 ){
1114 Stmt q;
1115 db_prepare(&q,
1116 "SELECT substr(tagname, 6) FROM tag WHERE tagname GLOB 'wiki-*'"
1117 " ORDER BY lower(tagname) /*sort*/"
1118 );
@@ -1119,14 +1138,13 @@
1119 while( db_step(&q)==SQLITE_ROW ){
1120 const char *zName = db_column_text(&q, 0);
1121 fossil_print( "%s\n",zName);
1122 }
1123 db_finalize(&q);
1124 }else
1125 {
1126 goto wiki_cmd_usage;
1127 }
1128 return;
1129
1130 wiki_cmd_usage:
1131 usage("export|create|commit|list ...");
1132 }
1133
--- src/wiki.c
+++ src/wiki.c
@@ -956,17 +956,18 @@
956 ** a new page. If no previous page with the name zPageName exists
957 ** and isNew is false, then this routine throws an error.
958 **
959 ** The content of the new page is given by the blob pContent.
960 */
961 int wiki_cmd_commit(char const * zPageName, int isNew, Blob *pContent,
962 char const * zMimeType){
963 Blob wiki; /* Wiki page content */
964 Blob cksum; /* wiki checksum */
965 int rid; /* artifact ID of parent page */
966 char *zDate; /* timestamp */
967 char *zUuid; /* uuid for rid */
968
969 rid = db_int(0,
970 "SELECT x.rid FROM tag t, tagxref x"
971 " WHERE x.tagid=t.tagid AND t.tagname='wiki-%q'"
972 " ORDER BY x.mtime DESC LIMIT 1",
973 zPageName
@@ -987,10 +988,13 @@
988 blob_zero(&wiki);
989 zDate = date_in_standard_format("now");
990 blob_appendf(&wiki, "D %s\n", zDate);
991 free(zDate);
992 blob_appendf(&wiki, "L %F\n", zPageName );
993 if( zMimeType && fossil_strcmp(zMimeType,"text/x-fossil-wiki")!=0 ){
994 blob_appendf(&wiki, "N %F\n", zMimeType);
995 }
996 if( rid ){
997 zUuid = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", rid);
998 blob_appendf(&wiki, "P %s\n", zUuid);
999 free(zUuid);
1000 }
@@ -1019,16 +1023,18 @@
1023 ** %fossil wiki export PAGENAME ?FILE?
1024 **
1025 ** Sends the latest version of the PAGENAME wiki
1026 ** entry to the given file or standard output.
1027 **
1028 ** %fossil wiki commit PAGENAME ?FILE? [-format TEXT-FORMAT]
1029 **
1030 ** Commit changes to a wiki page from FILE or from standard
1031 ** input. The -format flag specifies the mime type, defaulting
1032 ** to the type used by the previous version of the page or
1033 ** (for new pages) text/x-fossil-wiki.
1034 **
1035 ** %fossil wiki create PAGENAME ?FILE? [-format TEXT-FORMAT]
1036 **
1037 ** Create a new wiki page with initial content taken from
1038 ** FILE or from standard input.
1039 **
1040 ** %fossil wiki list
@@ -1054,11 +1060,10 @@
1060 int rid; /* Artifact ID of the wiki page */
1061 int i; /* Loop counter */
1062 char *zBody = 0; /* Wiki page content */
1063 Blob body; /* Wiki page content */
1064 Manifest *pWiki = 0; /* Parsed wiki page content */
 
1065 if( (g.argc!=4) && (g.argc!=5) ){
1066 usage("export PAGENAME ?FILE?");
1067 }
1068 zPageName = g.argv[3];
1069 rid = db_int(0, "SELECT x.rid FROM tag t, tagxref x"
@@ -1079,40 +1084,54 @@
1084 blob_append(&body, "\n", 1);
1085 blob_write_to_file(&body, zFile);
1086 blob_reset(&body);
1087 manifest_destroy(pWiki);
1088 return;
1089 }else if( strncmp(g.argv[2],"commit",n)==0
1090 || strncmp(g.argv[2],"create",n)==0 ){
1091 char const *zPageName; /* page name */
1092 Blob content; /* Input content */
1093 int rid;
1094 Manifest *pWiki = 0; /* Parsed wiki page content */
1095 char const * zMimeType = find_option("format", "F", 1);
1096 if( g.argc!=4 && g.argc!=5 ){
1097 usage("commit PAGENAME ?FILE? [-format TEXT-FORMAT]");
1098 }
1099 zPageName = g.argv[3];
1100 if( g.argc==4 ){
1101 blob_read_from_channel(&content, stdin, -1);
1102 }else{
1103 blob_read_from_file(&content, g.argv[4]);
1104 }
1105 if(!zMimeType || !*zMimeType){
1106 /* Try to deduce the mime type based on the prior version. */
1107 rid = db_int(0, "SELECT x.rid FROM tag t, tagxref x"
1108 " WHERE x.tagid=t.tagid AND t.tagname='wiki-%q'"
1109 " ORDER BY x.mtime DESC LIMIT 1",
1110 zPageName
1111 );
1112 if(rid>0 && (pWiki = manifest_get(rid, CFTYPE_WIKI, 0))!=0
1113 && (pWiki->zMimetype && *pWiki->zMimetype)){
1114 zMimeType = pWiki->zMimetype;
1115 }
1116 }
1117 if( g.argv[2][1]=='r' ){
1118 wiki_cmd_commit(zPageName, 1, &content, zMimeType);
1119 fossil_print("Created new wiki page %s.\n", zPageName);
1120 }else{
1121 wiki_cmd_commit(zPageName, 0, &content, zMimeType);
1122 fossil_print("Updated wiki page %s.\n", zPageName);
1123 }
1124 manifest_destroy(pWiki);
1125 blob_reset(&content);
1126 return;
1127 }else if( strncmp(g.argv[2],"delete",n)==0 ){
1128 if( g.argc!=5 ){
1129 usage("delete PAGENAME");
1130 }
1131 fossil_fatal("delete not yet implemented.");
1132 }else if( strncmp(g.argv[2],"list",n)==0 ){
 
1133 Stmt q;
1134 db_prepare(&q,
1135 "SELECT substr(tagname, 6) FROM tag WHERE tagname GLOB 'wiki-*'"
1136 " ORDER BY lower(tagname) /*sort*/"
1137 );
@@ -1119,14 +1138,13 @@
1138 while( db_step(&q)==SQLITE_ROW ){
1139 const char *zName = db_column_text(&q, 0);
1140 fossil_print( "%s\n",zName);
1141 }
1142 db_finalize(&q);
1143 }else{
 
1144 goto wiki_cmd_usage;
1145 }
1146 return;
1147
1148 wiki_cmd_usage:
1149 usage("export|create|commit|list ...");
1150 }
1151

Keyboard Shortcuts

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