Fossil SCM

integrated wiki-keep-mimetype branch.

stephan 2014-05-30 18:12 trunk merge
Commit 52d242a73be2d7d68f8cf5693481a95976995faf
--- src/json_artifact.c
+++ src/json_artifact.c
@@ -245,29 +245,29 @@
245245
** If the "format" (CLI: -f) flag is set function returns the same as
246246
** json_wiki_get_content_format_flag(), else it returns true (non-0)
247247
** if either the includeContent (HTTP) or -content|-c boolean flags
248248
** (CLI) are set.
249249
*/
250
-static char json_artifact_get_content_format_flag(){
250
+static int json_artifact_get_content_format_flag(){
251251
enum { MagicValue = -9 };
252
- char contentFormat = json_wiki_get_content_format_flag(MagicValue);
252
+ int contentFormat = json_wiki_get_content_format_flag(MagicValue);
253253
if(MagicValue == contentFormat){
254254
contentFormat = json_find_option_bool("includeContent","content","c",0) /* deprecated */ ? -1 : 0;
255255
}
256256
return contentFormat;
257257
}
258258
259
-extern char json_wiki_get_content_format_flag( char defaultValue ) /* json_wiki.c */;
259
+extern int json_wiki_get_content_format_flag( int defaultValue ) /* json_wiki.c */;
260260
261261
cson_value * json_artifact_wiki(cson_object * zParent, int rid){
262262
if( ! g.perm.RdWiki ){
263263
json_set_err(FSL_JSON_E_DENIED,
264264
"Requires 'j' privileges.");
265265
return NULL;
266266
}else{
267267
enum { MagicValue = -9 };
268
- char const contentFormat = json_artifact_get_content_format_flag();
268
+ int const contentFormat = json_artifact_get_content_format_flag();
269269
return json_get_wiki_page_by_rid(rid, contentFormat);
270270
}
271271
}
272272
273273
/*
@@ -289,11 +289,11 @@
289289
290290
cson_value * json_artifact_file(cson_object * zParent, int rid){
291291
cson_object * pay = NULL;
292292
Stmt q = empty_Stmt;
293293
cson_array * checkin_arr = NULL;
294
- char contentFormat;
294
+ int contentFormat;
295295
i64 contentSize = -1;
296296
char * parentUuid;
297297
if( ! g.perm.Read ){
298298
json_set_err(FSL_JSON_E_DENIED,
299299
"Requires 'o' privileges.");
300300
--- src/json_artifact.c
+++ src/json_artifact.c
@@ -245,29 +245,29 @@
245 ** If the "format" (CLI: -f) flag is set function returns the same as
246 ** json_wiki_get_content_format_flag(), else it returns true (non-0)
247 ** if either the includeContent (HTTP) or -content|-c boolean flags
248 ** (CLI) are set.
249 */
250 static char json_artifact_get_content_format_flag(){
251 enum { MagicValue = -9 };
252 char contentFormat = json_wiki_get_content_format_flag(MagicValue);
253 if(MagicValue == contentFormat){
254 contentFormat = json_find_option_bool("includeContent","content","c",0) /* deprecated */ ? -1 : 0;
255 }
256 return contentFormat;
257 }
258
259 extern char json_wiki_get_content_format_flag( char defaultValue ) /* json_wiki.c */;
260
261 cson_value * json_artifact_wiki(cson_object * zParent, int rid){
262 if( ! g.perm.RdWiki ){
263 json_set_err(FSL_JSON_E_DENIED,
264 "Requires 'j' privileges.");
265 return NULL;
266 }else{
267 enum { MagicValue = -9 };
268 char const contentFormat = json_artifact_get_content_format_flag();
269 return json_get_wiki_page_by_rid(rid, contentFormat);
270 }
271 }
272
273 /*
@@ -289,11 +289,11 @@
289
290 cson_value * json_artifact_file(cson_object * zParent, int rid){
291 cson_object * pay = NULL;
292 Stmt q = empty_Stmt;
293 cson_array * checkin_arr = NULL;
294 char contentFormat;
295 i64 contentSize = -1;
296 char * parentUuid;
297 if( ! g.perm.Read ){
298 json_set_err(FSL_JSON_E_DENIED,
299 "Requires 'o' privileges.");
300
--- src/json_artifact.c
+++ src/json_artifact.c
@@ -245,29 +245,29 @@
245 ** If the "format" (CLI: -f) flag is set function returns the same as
246 ** json_wiki_get_content_format_flag(), else it returns true (non-0)
247 ** if either the includeContent (HTTP) or -content|-c boolean flags
248 ** (CLI) are set.
249 */
250 static int json_artifact_get_content_format_flag(){
251 enum { MagicValue = -9 };
252 int contentFormat = json_wiki_get_content_format_flag(MagicValue);
253 if(MagicValue == contentFormat){
254 contentFormat = json_find_option_bool("includeContent","content","c",0) /* deprecated */ ? -1 : 0;
255 }
256 return contentFormat;
257 }
258
259 extern int json_wiki_get_content_format_flag( int defaultValue ) /* json_wiki.c */;
260
261 cson_value * json_artifact_wiki(cson_object * zParent, int rid){
262 if( ! g.perm.RdWiki ){
263 json_set_err(FSL_JSON_E_DENIED,
264 "Requires 'j' privileges.");
265 return NULL;
266 }else{
267 enum { MagicValue = -9 };
268 int const contentFormat = json_artifact_get_content_format_flag();
269 return json_get_wiki_page_by_rid(rid, contentFormat);
270 }
271 }
272
273 /*
@@ -289,11 +289,11 @@
289
290 cson_value * json_artifact_file(cson_object * zParent, int rid){
291 cson_object * pay = NULL;
292 Stmt q = empty_Stmt;
293 cson_array * checkin_arr = NULL;
294 int contentFormat;
295 i64 contentSize = -1;
296 char * parentUuid;
297 if( ! g.perm.Read ){
298 json_set_err(FSL_JSON_E_DENIED,
299 "Requires 'o' privileges.");
300
+11 -7
--- src/json_wiki.c
+++ src/json_wiki.c
@@ -80,11 +80,11 @@
8080
** the page.
8181
**
8282
** The returned value, if not NULL, is-a JSON Object owned by the
8383
** caller. If it returns NULL then it may set g.json's error state.
8484
*/
85
-cson_value * json_get_wiki_page_by_rid(int rid, char contentFormat){
85
+cson_value * json_get_wiki_page_by_rid(int rid, int contentFormat){
8686
Manifest * pWiki = NULL;
8787
if( NULL == (pWiki = manifest_get(rid, CFTYPE_WIKI, 0)) ){
8888
json_set_err( FSL_JSON_E_UNKNOWN,
8989
"Error reading wiki page from manifest (rid=%d).",
9090
rid );
@@ -145,11 +145,11 @@
145145
/*
146146
** Searches for the latest version of a wiki page with the given
147147
** name. If found it behaves like json_get_wiki_page_by_rid(theRid,
148148
** contentFormat), else it returns NULL.
149149
*/
150
-cson_value * json_get_wiki_page_by_name(char const * zPageName, char contentFormat){
150
+cson_value * json_get_wiki_page_by_name(char const * zPageName, int contentFormat){
151151
int rid;
152152
rid = db_int(0,
153153
"SELECT x.rid FROM tag t, tagxref x, blob b"
154154
" WHERE x.tagid=t.tagid AND t.tagname='wiki-%q' "
155155
" AND b.rid=x.rid"
@@ -175,12 +175,12 @@
175175
** [r]aw = -1
176176
**
177177
** The return value is intended for use with
178178
** json_get_wiki_page_by_rid() and friends.
179179
*/
180
-char json_wiki_get_content_format_flag( char defaultValue ){
181
- char contentFormat = defaultValue;
180
+int json_wiki_get_content_format_flag( int defaultValue ){
181
+ int contentFormat = defaultValue;
182182
char const * zFormat = json_find_option_cstr("format",NULL,"f");
183183
if( !zFormat || !*zFormat ){
184184
return contentFormat;
185185
}
186186
else if('r'==*zFormat){
@@ -203,11 +203,11 @@
203203
** json_get_wiki_page_by_name() will be returned (owned by the
204204
** caller). On error g.json's error state is set and NULL is returned.
205205
*/
206206
static cson_value * json_wiki_get_by_name_or_symname(char const * zPageName,
207207
char const * zSymname,
208
- char contentFormat ){
208
+ int contentFormat ){
209209
if(!zSymname || !*zSymname){
210210
return json_get_wiki_page_by_name(zPageName, contentFormat);
211211
}else{
212212
int rid = symbolic_name_to_rid( zSymname ? zSymname : zPageName, "w" );
213213
if(rid<0){
@@ -229,11 +229,11 @@
229229
**
230230
*/
231231
static cson_value * json_wiki_get(){
232232
char const * zPageName;
233233
char const * zSymName = NULL;
234
- char contentFormat = -1;
234
+ int contentFormat = -1;
235235
if( !g.perm.RdWiki && !g.perm.Read ){
236236
json_set_err(FSL_JSON_E_DENIED,
237237
"Requires 'o' or 'j' access.");
238238
return NULL;
239239
}
@@ -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("mimetype","mimetype","M");
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
@@ -80,11 +80,11 @@
80 ** the page.
81 **
82 ** The returned value, if not NULL, is-a JSON Object owned by the
83 ** caller. If it returns NULL then it may set g.json's error state.
84 */
85 cson_value * json_get_wiki_page_by_rid(int rid, char contentFormat){
86 Manifest * pWiki = NULL;
87 if( NULL == (pWiki = manifest_get(rid, CFTYPE_WIKI, 0)) ){
88 json_set_err( FSL_JSON_E_UNKNOWN,
89 "Error reading wiki page from manifest (rid=%d).",
90 rid );
@@ -145,11 +145,11 @@
145 /*
146 ** Searches for the latest version of a wiki page with the given
147 ** name. If found it behaves like json_get_wiki_page_by_rid(theRid,
148 ** contentFormat), else it returns NULL.
149 */
150 cson_value * json_get_wiki_page_by_name(char const * zPageName, char contentFormat){
151 int rid;
152 rid = db_int(0,
153 "SELECT x.rid FROM tag t, tagxref x, blob b"
154 " WHERE x.tagid=t.tagid AND t.tagname='wiki-%q' "
155 " AND b.rid=x.rid"
@@ -175,12 +175,12 @@
175 ** [r]aw = -1
176 **
177 ** The return value is intended for use with
178 ** json_get_wiki_page_by_rid() and friends.
179 */
180 char json_wiki_get_content_format_flag( char defaultValue ){
181 char contentFormat = defaultValue;
182 char const * zFormat = json_find_option_cstr("format",NULL,"f");
183 if( !zFormat || !*zFormat ){
184 return contentFormat;
185 }
186 else if('r'==*zFormat){
@@ -203,11 +203,11 @@
203 ** json_get_wiki_page_by_name() will be returned (owned by the
204 ** caller). On error g.json's error state is set and NULL is returned.
205 */
206 static cson_value * json_wiki_get_by_name_or_symname(char const * zPageName,
207 char const * zSymname,
208 char contentFormat ){
209 if(!zSymname || !*zSymname){
210 return json_get_wiki_page_by_name(zPageName, contentFormat);
211 }else{
212 int rid = symbolic_name_to_rid( zSymname ? zSymname : zPageName, "w" );
213 if(rid<0){
@@ -229,11 +229,11 @@
229 **
230 */
231 static cson_value * json_wiki_get(){
232 char const * zPageName;
233 char const * zSymName = NULL;
234 char contentFormat = -1;
235 if( !g.perm.RdWiki && !g.perm.Read ){
236 json_set_err(FSL_JSON_E_DENIED,
237 "Requires 'o' or 'j' access.");
238 return NULL;
239 }
@@ -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
@@ -80,11 +80,11 @@
80 ** the page.
81 **
82 ** The returned value, if not NULL, is-a JSON Object owned by the
83 ** caller. If it returns NULL then it may set g.json's error state.
84 */
85 cson_value * json_get_wiki_page_by_rid(int rid, int contentFormat){
86 Manifest * pWiki = NULL;
87 if( NULL == (pWiki = manifest_get(rid, CFTYPE_WIKI, 0)) ){
88 json_set_err( FSL_JSON_E_UNKNOWN,
89 "Error reading wiki page from manifest (rid=%d).",
90 rid );
@@ -145,11 +145,11 @@
145 /*
146 ** Searches for the latest version of a wiki page with the given
147 ** name. If found it behaves like json_get_wiki_page_by_rid(theRid,
148 ** contentFormat), else it returns NULL.
149 */
150 cson_value * json_get_wiki_page_by_name(char const * zPageName, int contentFormat){
151 int rid;
152 rid = db_int(0,
153 "SELECT x.rid FROM tag t, tagxref x, blob b"
154 " WHERE x.tagid=t.tagid AND t.tagname='wiki-%q' "
155 " AND b.rid=x.rid"
@@ -175,12 +175,12 @@
175 ** [r]aw = -1
176 **
177 ** The return value is intended for use with
178 ** json_get_wiki_page_by_rid() and friends.
179 */
180 int json_wiki_get_content_format_flag( int defaultValue ){
181 int contentFormat = defaultValue;
182 char const * zFormat = json_find_option_cstr("format",NULL,"f");
183 if( !zFormat || !*zFormat ){
184 return contentFormat;
185 }
186 else if('r'==*zFormat){
@@ -203,11 +203,11 @@
203 ** json_get_wiki_page_by_name() will be returned (owned by the
204 ** caller). On error g.json's error state is set and NULL is returned.
205 */
206 static cson_value * json_wiki_get_by_name_or_symname(char const * zPageName,
207 char const * zSymname,
208 int contentFormat ){
209 if(!zSymname || !*zSymname){
210 return json_get_wiki_page_by_name(zPageName, contentFormat);
211 }else{
212 int rid = symbolic_name_to_rid( zSymname ? zSymname : zPageName, "w" );
213 if(rid<0){
@@ -229,11 +229,11 @@
229 **
230 */
231 static cson_value * json_wiki_get(){
232 char const * zPageName;
233 char const * zSymName = NULL;
234 int contentFormat = -1;
235 if( !g.perm.RdWiki && !g.perm.Read ){
236 json_set_err(FSL_JSON_E_DENIED,
237 "Requires 'o' or 'j' access.");
238 return NULL;
239 }
@@ -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("mimetype","mimetype","M");
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
+42 -20
--- src/wiki.c
+++ src/wiki.c
@@ -955,18 +955,23 @@
955955
** given by the zPageName parameter. isNew must be true to create
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.
960
+**
961
+** zMimeType specifies the N-card for the wiki page. If it is 0,
962
+** empty, or "text/x-fossil-wiki" (the default format) then it is
963
+** ignored.
960964
*/
961
-int wiki_cmd_commit(char const * zPageName, int isNew, Blob *pContent){
965
+int wiki_cmd_commit(char const * zPageName, int isNew, Blob *pContent,
966
+ char const * zMimeType){
962967
Blob wiki; /* Wiki page content */
963968
Blob cksum; /* wiki checksum */
964969
int rid; /* artifact ID of parent page */
965970
char *zDate; /* timestamp */
966971
char *zUuid; /* uuid for rid */
967
-
972
+
968973
rid = db_int(0,
969974
"SELECT x.rid FROM tag t, tagxref x"
970975
" WHERE x.tagid=t.tagid AND t.tagname='wiki-%q'"
971976
" ORDER BY x.mtime DESC LIMIT 1",
972977
zPageName
@@ -987,10 +992,14 @@
987992
blob_zero(&wiki);
988993
zDate = date_in_standard_format("now");
989994
blob_appendf(&wiki, "D %s\n", zDate);
990995
free(zDate);
991996
blob_appendf(&wiki, "L %F\n", zPageName );
997
+ if( zMimeType && *zMimeType
998
+ && 0!=fossil_strcmp(zMimeType,"text/x-fossil-wiki") ){
999
+ blob_appendf(&wiki, "N %F\n", zMimeType);
1000
+ }
9921001
if( rid ){
9931002
zUuid = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", rid);
9941003
blob_appendf(&wiki, "P %s\n", zUuid);
9951004
free(zUuid);
9961005
}
@@ -1019,16 +1028,18 @@
10191028
** %fossil wiki export PAGENAME ?FILE?
10201029
**
10211030
** Sends the latest version of the PAGENAME wiki
10221031
** entry to the given file or standard output.
10231032
**
1024
-** %fossil wiki commit PAGENAME ?FILE?
1033
+** %fossil wiki commit PAGENAME ?FILE? [-mimetype TEXT-FORMAT]
10251034
**
10261035
** Commit changes to a wiki page from FILE or from standard
1027
-** input.
1036
+** input. The -mimetype (-M) flag specifies the mime type,
1037
+** defaulting to the type used by the previous version of
1038
+** the page or (for new pages) text/x-fossil-wiki.
10281039
**
1029
-** %fossil wiki create PAGENAME ?FILE?
1040
+** %fossil wiki create PAGENAME ?FILE? [-mimetype TEXT-FORMAT]
10301041
**
10311042
** Create a new wiki page with initial content taken from
10321043
** FILE or from standard input.
10331044
**
10341045
** %fossil wiki list
@@ -1054,11 +1065,10 @@
10541065
int rid; /* Artifact ID of the wiki page */
10551066
int i; /* Loop counter */
10561067
char *zBody = 0; /* Wiki page content */
10571068
Blob body; /* Wiki page content */
10581069
Manifest *pWiki = 0; /* Parsed wiki page content */
1059
-
10601070
if( (g.argc!=4) && (g.argc!=5) ){
10611071
usage("export PAGENAME ?FILE?");
10621072
}
10631073
zPageName = g.argv[3];
10641074
rid = db_int(0, "SELECT x.rid FROM tag t, tagxref x"
@@ -1079,40 +1089,53 @@
10791089
blob_append(&body, "\n", 1);
10801090
blob_write_to_file(&body, zFile);
10811091
blob_reset(&body);
10821092
manifest_destroy(pWiki);
10831093
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;
1094
+ }else if( strncmp(g.argv[2],"commit",n)==0
1095
+ || strncmp(g.argv[2],"create",n)==0 ){
1096
+ char const *zPageName; /* page name */
1097
+ Blob content; /* Input content */
1098
+ int rid;
1099
+ Manifest *pWiki = 0; /* Parsed wiki page content */
1100
+ char const * zMimeType = find_option("mimetype", "M", 1);
10891101
if( g.argc!=4 && g.argc!=5 ){
1090
- usage("commit PAGENAME ?FILE?");
1102
+ usage("commit|create PAGENAME ?FILE? [-mimetype TEXT-FORMAT]");
10911103
}
10921104
zPageName = g.argv[3];
10931105
if( g.argc==4 ){
10941106
blob_read_from_channel(&content, stdin, -1);
10951107
}else{
10961108
blob_read_from_file(&content, g.argv[4]);
1109
+ }
1110
+ if(!zMimeType || !*zMimeType){
1111
+ /* Try to deduce the mime type based on the prior version. */
1112
+ rid = db_int(0, "SELECT x.rid FROM tag t, tagxref x"
1113
+ " WHERE x.tagid=t.tagid AND t.tagname='wiki-%q'"
1114
+ " ORDER BY x.mtime DESC LIMIT 1",
1115
+ zPageName
1116
+ );
1117
+ if(rid>0 && (pWiki = manifest_get(rid, CFTYPE_WIKI, 0))!=0
1118
+ && (pWiki->zMimetype && *pWiki->zMimetype)){
1119
+ zMimeType = pWiki->zMimetype;
1120
+ }
10971121
}
10981122
if( g.argv[2][1]=='r' ){
1099
- wiki_cmd_commit(zPageName, 1, &content);
1123
+ wiki_cmd_commit(zPageName, 1, &content, zMimeType);
11001124
fossil_print("Created new wiki page %s.\n", zPageName);
11011125
}else{
1102
- wiki_cmd_commit(zPageName, 0, &content);
1126
+ wiki_cmd_commit(zPageName, 0, &content, zMimeType);
11031127
fossil_print("Updated wiki page %s.\n", zPageName);
11041128
}
1129
+ manifest_destroy(pWiki);
11051130
blob_reset(&content);
1106
- }else
1107
- if( strncmp(g.argv[2],"delete",n)==0 ){
1131
+ }else if( strncmp(g.argv[2],"delete",n)==0 ){
11081132
if( g.argc!=5 ){
11091133
usage("delete PAGENAME");
11101134
}
11111135
fossil_fatal("delete not yet implemented.");
1112
- }else
1113
- if( strncmp(g.argv[2],"list",n)==0 ){
1136
+ }else if( strncmp(g.argv[2],"list",n)==0 ){
11141137
Stmt q;
11151138
db_prepare(&q,
11161139
"SELECT substr(tagname, 6) FROM tag WHERE tagname GLOB 'wiki-*'"
11171140
" ORDER BY lower(tagname) /*sort*/"
11181141
);
@@ -1119,14 +1142,13 @@
11191142
while( db_step(&q)==SQLITE_ROW ){
11201143
const char *zName = db_column_text(&q, 0);
11211144
fossil_print( "%s\n",zName);
11221145
}
11231146
db_finalize(&q);
1124
- }else
1125
- {
1147
+ }else{
11261148
goto wiki_cmd_usage;
11271149
}
11281150
return;
11291151
11301152
wiki_cmd_usage:
11311153
usage("export|create|commit|list ...");
11321154
}
11331155
--- src/wiki.c
+++ src/wiki.c
@@ -955,18 +955,23 @@
955 ** given by the zPageName parameter. isNew must be true to create
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 +992,14 @@
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 +1028,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 +1065,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 +1089,53 @@
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 +1142,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
@@ -955,18 +955,23 @@
955 ** given by the zPageName parameter. isNew must be true to create
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 ** zMimeType specifies the N-card for the wiki page. If it is 0,
962 ** empty, or "text/x-fossil-wiki" (the default format) then it is
963 ** ignored.
964 */
965 int wiki_cmd_commit(char const * zPageName, int isNew, Blob *pContent,
966 char const * zMimeType){
967 Blob wiki; /* Wiki page content */
968 Blob cksum; /* wiki checksum */
969 int rid; /* artifact ID of parent page */
970 char *zDate; /* timestamp */
971 char *zUuid; /* uuid for rid */
972
973 rid = db_int(0,
974 "SELECT x.rid FROM tag t, tagxref x"
975 " WHERE x.tagid=t.tagid AND t.tagname='wiki-%q'"
976 " ORDER BY x.mtime DESC LIMIT 1",
977 zPageName
@@ -987,10 +992,14 @@
992 blob_zero(&wiki);
993 zDate = date_in_standard_format("now");
994 blob_appendf(&wiki, "D %s\n", zDate);
995 free(zDate);
996 blob_appendf(&wiki, "L %F\n", zPageName );
997 if( zMimeType && *zMimeType
998 && 0!=fossil_strcmp(zMimeType,"text/x-fossil-wiki") ){
999 blob_appendf(&wiki, "N %F\n", zMimeType);
1000 }
1001 if( rid ){
1002 zUuid = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", rid);
1003 blob_appendf(&wiki, "P %s\n", zUuid);
1004 free(zUuid);
1005 }
@@ -1019,16 +1028,18 @@
1028 ** %fossil wiki export PAGENAME ?FILE?
1029 **
1030 ** Sends the latest version of the PAGENAME wiki
1031 ** entry to the given file or standard output.
1032 **
1033 ** %fossil wiki commit PAGENAME ?FILE? [-mimetype TEXT-FORMAT]
1034 **
1035 ** Commit changes to a wiki page from FILE or from standard
1036 ** input. The -mimetype (-M) flag specifies the mime type,
1037 ** defaulting to the type used by the previous version of
1038 ** the page or (for new pages) text/x-fossil-wiki.
1039 **
1040 ** %fossil wiki create PAGENAME ?FILE? [-mimetype TEXT-FORMAT]
1041 **
1042 ** Create a new wiki page with initial content taken from
1043 ** FILE or from standard input.
1044 **
1045 ** %fossil wiki list
@@ -1054,11 +1065,10 @@
1065 int rid; /* Artifact ID of the wiki page */
1066 int i; /* Loop counter */
1067 char *zBody = 0; /* Wiki page content */
1068 Blob body; /* Wiki page content */
1069 Manifest *pWiki = 0; /* Parsed wiki page content */
 
1070 if( (g.argc!=4) && (g.argc!=5) ){
1071 usage("export PAGENAME ?FILE?");
1072 }
1073 zPageName = g.argv[3];
1074 rid = db_int(0, "SELECT x.rid FROM tag t, tagxref x"
@@ -1079,40 +1089,53 @@
1089 blob_append(&body, "\n", 1);
1090 blob_write_to_file(&body, zFile);
1091 blob_reset(&body);
1092 manifest_destroy(pWiki);
1093 return;
1094 }else if( strncmp(g.argv[2],"commit",n)==0
1095 || strncmp(g.argv[2],"create",n)==0 ){
1096 char const *zPageName; /* page name */
1097 Blob content; /* Input content */
1098 int rid;
1099 Manifest *pWiki = 0; /* Parsed wiki page content */
1100 char const * zMimeType = find_option("mimetype", "M", 1);
1101 if( g.argc!=4 && g.argc!=5 ){
1102 usage("commit|create PAGENAME ?FILE? [-mimetype TEXT-FORMAT]");
1103 }
1104 zPageName = g.argv[3];
1105 if( g.argc==4 ){
1106 blob_read_from_channel(&content, stdin, -1);
1107 }else{
1108 blob_read_from_file(&content, g.argv[4]);
1109 }
1110 if(!zMimeType || !*zMimeType){
1111 /* Try to deduce the mime type based on the prior version. */
1112 rid = db_int(0, "SELECT x.rid FROM tag t, tagxref x"
1113 " WHERE x.tagid=t.tagid AND t.tagname='wiki-%q'"
1114 " ORDER BY x.mtime DESC LIMIT 1",
1115 zPageName
1116 );
1117 if(rid>0 && (pWiki = manifest_get(rid, CFTYPE_WIKI, 0))!=0
1118 && (pWiki->zMimetype && *pWiki->zMimetype)){
1119 zMimeType = pWiki->zMimetype;
1120 }
1121 }
1122 if( g.argv[2][1]=='r' ){
1123 wiki_cmd_commit(zPageName, 1, &content, zMimeType);
1124 fossil_print("Created new wiki page %s.\n", zPageName);
1125 }else{
1126 wiki_cmd_commit(zPageName, 0, &content, zMimeType);
1127 fossil_print("Updated wiki page %s.\n", zPageName);
1128 }
1129 manifest_destroy(pWiki);
1130 blob_reset(&content);
1131 }else if( strncmp(g.argv[2],"delete",n)==0 ){
 
1132 if( g.argc!=5 ){
1133 usage("delete PAGENAME");
1134 }
1135 fossil_fatal("delete not yet implemented.");
1136 }else if( strncmp(g.argv[2],"list",n)==0 ){
 
1137 Stmt q;
1138 db_prepare(&q,
1139 "SELECT substr(tagname, 6) FROM tag WHERE tagname GLOB 'wiki-*'"
1140 " ORDER BY lower(tagname) /*sort*/"
1141 );
@@ -1119,14 +1142,13 @@
1142 while( db_step(&q)==SQLITE_ROW ){
1143 const char *zName = db_column_text(&q, 0);
1144 fossil_print( "%s\n",zName);
1145 }
1146 db_finalize(&q);
1147 }else{
 
1148 goto wiki_cmd_usage;
1149 }
1150 return;
1151
1152 wiki_cmd_usage:
1153 usage("export|create|commit|list ...");
1154 }
1155
+42 -20
--- src/wiki.c
+++ src/wiki.c
@@ -955,18 +955,23 @@
955955
** given by the zPageName parameter. isNew must be true to create
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.
960
+**
961
+** zMimeType specifies the N-card for the wiki page. If it is 0,
962
+** empty, or "text/x-fossil-wiki" (the default format) then it is
963
+** ignored.
960964
*/
961
-int wiki_cmd_commit(char const * zPageName, int isNew, Blob *pContent){
965
+int wiki_cmd_commit(char const * zPageName, int isNew, Blob *pContent,
966
+ char const * zMimeType){
962967
Blob wiki; /* Wiki page content */
963968
Blob cksum; /* wiki checksum */
964969
int rid; /* artifact ID of parent page */
965970
char *zDate; /* timestamp */
966971
char *zUuid; /* uuid for rid */
967
-
972
+
968973
rid = db_int(0,
969974
"SELECT x.rid FROM tag t, tagxref x"
970975
" WHERE x.tagid=t.tagid AND t.tagname='wiki-%q'"
971976
" ORDER BY x.mtime DESC LIMIT 1",
972977
zPageName
@@ -987,10 +992,14 @@
987992
blob_zero(&wiki);
988993
zDate = date_in_standard_format("now");
989994
blob_appendf(&wiki, "D %s\n", zDate);
990995
free(zDate);
991996
blob_appendf(&wiki, "L %F\n", zPageName );
997
+ if( zMimeType && *zMimeType
998
+ && 0!=fossil_strcmp(zMimeType,"text/x-fossil-wiki") ){
999
+ blob_appendf(&wiki, "N %F\n", zMimeType);
1000
+ }
9921001
if( rid ){
9931002
zUuid = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", rid);
9941003
blob_appendf(&wiki, "P %s\n", zUuid);
9951004
free(zUuid);
9961005
}
@@ -1019,16 +1028,18 @@
10191028
** %fossil wiki export PAGENAME ?FILE?
10201029
**
10211030
** Sends the latest version of the PAGENAME wiki
10221031
** entry to the given file or standard output.
10231032
**
1024
-** %fossil wiki commit PAGENAME ?FILE?
1033
+** %fossil wiki commit PAGENAME ?FILE? [-mimetype TEXT-FORMAT]
10251034
**
10261035
** Commit changes to a wiki page from FILE or from standard
1027
-** input.
1036
+** input. The -mimetype (-M) flag specifies the mime type,
1037
+** defaulting to the type used by the previous version of
1038
+** the page or (for new pages) text/x-fossil-wiki.
10281039
**
1029
-** %fossil wiki create PAGENAME ?FILE?
1040
+** %fossil wiki create PAGENAME ?FILE? [-mimetype TEXT-FORMAT]
10301041
**
10311042
** Create a new wiki page with initial content taken from
10321043
** FILE or from standard input.
10331044
**
10341045
** %fossil wiki list
@@ -1054,11 +1065,10 @@
10541065
int rid; /* Artifact ID of the wiki page */
10551066
int i; /* Loop counter */
10561067
char *zBody = 0; /* Wiki page content */
10571068
Blob body; /* Wiki page content */
10581069
Manifest *pWiki = 0; /* Parsed wiki page content */
1059
-
10601070
if( (g.argc!=4) && (g.argc!=5) ){
10611071
usage("export PAGENAME ?FILE?");
10621072
}
10631073
zPageName = g.argv[3];
10641074
rid = db_int(0, "SELECT x.rid FROM tag t, tagxref x"
@@ -1079,40 +1089,53 @@
10791089
blob_append(&body, "\n", 1);
10801090
blob_write_to_file(&body, zFile);
10811091
blob_reset(&body);
10821092
manifest_destroy(pWiki);
10831093
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;
1094
+ }else if( strncmp(g.argv[2],"commit",n)==0
1095
+ || strncmp(g.argv[2],"create",n)==0 ){
1096
+ char const *zPageName; /* page name */
1097
+ Blob content; /* Input content */
1098
+ int rid;
1099
+ Manifest *pWiki = 0; /* Parsed wiki page content */
1100
+ char const * zMimeType = find_option("mimetype", "M", 1);
10891101
if( g.argc!=4 && g.argc!=5 ){
1090
- usage("commit PAGENAME ?FILE?");
1102
+ usage("commit|create PAGENAME ?FILE? [-mimetype TEXT-FORMAT]");
10911103
}
10921104
zPageName = g.argv[3];
10931105
if( g.argc==4 ){
10941106
blob_read_from_channel(&content, stdin, -1);
10951107
}else{
10961108
blob_read_from_file(&content, g.argv[4]);
1109
+ }
1110
+ if(!zMimeType || !*zMimeType){
1111
+ /* Try to deduce the mime type based on the prior version. */
1112
+ rid = db_int(0, "SELECT x.rid FROM tag t, tagxref x"
1113
+ " WHERE x.tagid=t.tagid AND t.tagname='wiki-%q'"
1114
+ " ORDER BY x.mtime DESC LIMIT 1",
1115
+ zPageName
1116
+ );
1117
+ if(rid>0 && (pWiki = manifest_get(rid, CFTYPE_WIKI, 0))!=0
1118
+ && (pWiki->zMimetype && *pWiki->zMimetype)){
1119
+ zMimeType = pWiki->zMimetype;
1120
+ }
10971121
}
10981122
if( g.argv[2][1]=='r' ){
1099
- wiki_cmd_commit(zPageName, 1, &content);
1123
+ wiki_cmd_commit(zPageName, 1, &content, zMimeType);
11001124
fossil_print("Created new wiki page %s.\n", zPageName);
11011125
}else{
1102
- wiki_cmd_commit(zPageName, 0, &content);
1126
+ wiki_cmd_commit(zPageName, 0, &content, zMimeType);
11031127
fossil_print("Updated wiki page %s.\n", zPageName);
11041128
}
1129
+ manifest_destroy(pWiki);
11051130
blob_reset(&content);
1106
- }else
1107
- if( strncmp(g.argv[2],"delete",n)==0 ){
1131
+ }else if( strncmp(g.argv[2],"delete",n)==0 ){
11081132
if( g.argc!=5 ){
11091133
usage("delete PAGENAME");
11101134
}
11111135
fossil_fatal("delete not yet implemented.");
1112
- }else
1113
- if( strncmp(g.argv[2],"list",n)==0 ){
1136
+ }else if( strncmp(g.argv[2],"list",n)==0 ){
11141137
Stmt q;
11151138
db_prepare(&q,
11161139
"SELECT substr(tagname, 6) FROM tag WHERE tagname GLOB 'wiki-*'"
11171140
" ORDER BY lower(tagname) /*sort*/"
11181141
);
@@ -1119,14 +1142,13 @@
11191142
while( db_step(&q)==SQLITE_ROW ){
11201143
const char *zName = db_column_text(&q, 0);
11211144
fossil_print( "%s\n",zName);
11221145
}
11231146
db_finalize(&q);
1124
- }else
1125
- {
1147
+ }else{
11261148
goto wiki_cmd_usage;
11271149
}
11281150
return;
11291151
11301152
wiki_cmd_usage:
11311153
usage("export|create|commit|list ...");
11321154
}
11331155
--- src/wiki.c
+++ src/wiki.c
@@ -955,18 +955,23 @@
955 ** given by the zPageName parameter. isNew must be true to create
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 +992,14 @@
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 +1028,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 +1065,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 +1089,53 @@
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 +1142,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
@@ -955,18 +955,23 @@
955 ** given by the zPageName parameter. isNew must be true to create
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 ** zMimeType specifies the N-card for the wiki page. If it is 0,
962 ** empty, or "text/x-fossil-wiki" (the default format) then it is
963 ** ignored.
964 */
965 int wiki_cmd_commit(char const * zPageName, int isNew, Blob *pContent,
966 char const * zMimeType){
967 Blob wiki; /* Wiki page content */
968 Blob cksum; /* wiki checksum */
969 int rid; /* artifact ID of parent page */
970 char *zDate; /* timestamp */
971 char *zUuid; /* uuid for rid */
972
973 rid = db_int(0,
974 "SELECT x.rid FROM tag t, tagxref x"
975 " WHERE x.tagid=t.tagid AND t.tagname='wiki-%q'"
976 " ORDER BY x.mtime DESC LIMIT 1",
977 zPageName
@@ -987,10 +992,14 @@
992 blob_zero(&wiki);
993 zDate = date_in_standard_format("now");
994 blob_appendf(&wiki, "D %s\n", zDate);
995 free(zDate);
996 blob_appendf(&wiki, "L %F\n", zPageName );
997 if( zMimeType && *zMimeType
998 && 0!=fossil_strcmp(zMimeType,"text/x-fossil-wiki") ){
999 blob_appendf(&wiki, "N %F\n", zMimeType);
1000 }
1001 if( rid ){
1002 zUuid = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", rid);
1003 blob_appendf(&wiki, "P %s\n", zUuid);
1004 free(zUuid);
1005 }
@@ -1019,16 +1028,18 @@
1028 ** %fossil wiki export PAGENAME ?FILE?
1029 **
1030 ** Sends the latest version of the PAGENAME wiki
1031 ** entry to the given file or standard output.
1032 **
1033 ** %fossil wiki commit PAGENAME ?FILE? [-mimetype TEXT-FORMAT]
1034 **
1035 ** Commit changes to a wiki page from FILE or from standard
1036 ** input. The -mimetype (-M) flag specifies the mime type,
1037 ** defaulting to the type used by the previous version of
1038 ** the page or (for new pages) text/x-fossil-wiki.
1039 **
1040 ** %fossil wiki create PAGENAME ?FILE? [-mimetype TEXT-FORMAT]
1041 **
1042 ** Create a new wiki page with initial content taken from
1043 ** FILE or from standard input.
1044 **
1045 ** %fossil wiki list
@@ -1054,11 +1065,10 @@
1065 int rid; /* Artifact ID of the wiki page */
1066 int i; /* Loop counter */
1067 char *zBody = 0; /* Wiki page content */
1068 Blob body; /* Wiki page content */
1069 Manifest *pWiki = 0; /* Parsed wiki page content */
 
1070 if( (g.argc!=4) && (g.argc!=5) ){
1071 usage("export PAGENAME ?FILE?");
1072 }
1073 zPageName = g.argv[3];
1074 rid = db_int(0, "SELECT x.rid FROM tag t, tagxref x"
@@ -1079,40 +1089,53 @@
1089 blob_append(&body, "\n", 1);
1090 blob_write_to_file(&body, zFile);
1091 blob_reset(&body);
1092 manifest_destroy(pWiki);
1093 return;
1094 }else if( strncmp(g.argv[2],"commit",n)==0
1095 || strncmp(g.argv[2],"create",n)==0 ){
1096 char const *zPageName; /* page name */
1097 Blob content; /* Input content */
1098 int rid;
1099 Manifest *pWiki = 0; /* Parsed wiki page content */
1100 char const * zMimeType = find_option("mimetype", "M", 1);
1101 if( g.argc!=4 && g.argc!=5 ){
1102 usage("commit|create PAGENAME ?FILE? [-mimetype TEXT-FORMAT]");
1103 }
1104 zPageName = g.argv[3];
1105 if( g.argc==4 ){
1106 blob_read_from_channel(&content, stdin, -1);
1107 }else{
1108 blob_read_from_file(&content, g.argv[4]);
1109 }
1110 if(!zMimeType || !*zMimeType){
1111 /* Try to deduce the mime type based on the prior version. */
1112 rid = db_int(0, "SELECT x.rid FROM tag t, tagxref x"
1113 " WHERE x.tagid=t.tagid AND t.tagname='wiki-%q'"
1114 " ORDER BY x.mtime DESC LIMIT 1",
1115 zPageName
1116 );
1117 if(rid>0 && (pWiki = manifest_get(rid, CFTYPE_WIKI, 0))!=0
1118 && (pWiki->zMimetype && *pWiki->zMimetype)){
1119 zMimeType = pWiki->zMimetype;
1120 }
1121 }
1122 if( g.argv[2][1]=='r' ){
1123 wiki_cmd_commit(zPageName, 1, &content, zMimeType);
1124 fossil_print("Created new wiki page %s.\n", zPageName);
1125 }else{
1126 wiki_cmd_commit(zPageName, 0, &content, zMimeType);
1127 fossil_print("Updated wiki page %s.\n", zPageName);
1128 }
1129 manifest_destroy(pWiki);
1130 blob_reset(&content);
1131 }else if( strncmp(g.argv[2],"delete",n)==0 ){
 
1132 if( g.argc!=5 ){
1133 usage("delete PAGENAME");
1134 }
1135 fossil_fatal("delete not yet implemented.");
1136 }else if( strncmp(g.argv[2],"list",n)==0 ){
 
1137 Stmt q;
1138 db_prepare(&q,
1139 "SELECT substr(tagname, 6) FROM tag WHERE tagname GLOB 'wiki-*'"
1140 " ORDER BY lower(tagname) /*sort*/"
1141 );
@@ -1119,14 +1142,13 @@
1142 while( db_step(&q)==SQLITE_ROW ){
1143 const char *zName = db_column_text(&q, 0);
1144 fossil_print( "%s\n",zName);
1145 }
1146 db_finalize(&q);
1147 }else{
 
1148 goto wiki_cmd_usage;
1149 }
1150 return;
1151
1152 wiki_cmd_usage:
1153 usage("export|create|commit|list ...");
1154 }
1155

Keyboard Shortcuts

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