Fossil SCM
Added --format MIMETYPE flag to (wiki create|commit) and /json/wiki/save.
Commit
8f2d9e6923ed14ab6bd8a201c8db4da5592045a1
Parent
ec44f61a831e422…
2 files changed
+5
-1
+38
-20
+5
-1
| --- src/json_wiki.c | ||
| +++ src/json_wiki.c | ||
| @@ -308,10 +308,11 @@ | ||
| 308 | 308 | char const * zPageName; /* cstr form of page name */ |
| 309 | 309 | cson_value * contentV; /* passed-in content */ |
| 310 | 310 | cson_value * emptyContent = NULL; /* placeholder for empty content. */ |
| 311 | 311 | cson_value * payV = NULL; /* payload/return value */ |
| 312 | 312 | cson_string const * jstr = NULL; /* temp for cson_value-to-cson_string conversions. */ |
| 313 | + char const * zMimeType = 0; | |
| 313 | 314 | unsigned int contentLen = 0; |
| 314 | 315 | int rid; |
| 315 | 316 | if( (createMode && !g.perm.NewWiki) |
| 316 | 317 | || (!createMode && !g.perm.WrWiki)){ |
| 317 | 318 | json_set_err(FSL_JSON_E_DENIED, |
| @@ -371,11 +372,14 @@ | ||
| 371 | 372 | jstr = cson_value_get_string(contentV); |
| 372 | 373 | contentLen = (int)cson_string_length_bytes(jstr); |
| 373 | 374 | if(contentLen){ |
| 374 | 375 | blob_append(&content, cson_string_cstr(jstr),contentLen); |
| 375 | 376 | } |
| 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); | |
| 377 | 381 | blob_reset(&content); |
| 378 | 382 | /* |
| 379 | 383 | Our return value here has a race condition: if this operation |
| 380 | 384 | is called concurrently for the same wiki page via two requests, |
| 381 | 385 | payV could reflect the results of the other save operation. |
| 382 | 386 |
| --- 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 @@ | ||
| 956 | 956 | ** a new page. If no previous page with the name zPageName exists |
| 957 | 957 | ** and isNew is false, then this routine throws an error. |
| 958 | 958 | ** |
| 959 | 959 | ** The content of the new page is given by the blob pContent. |
| 960 | 960 | */ |
| 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){ | |
| 962 | 963 | Blob wiki; /* Wiki page content */ |
| 963 | 964 | Blob cksum; /* wiki checksum */ |
| 964 | 965 | int rid; /* artifact ID of parent page */ |
| 965 | 966 | char *zDate; /* timestamp */ |
| 966 | 967 | char *zUuid; /* uuid for rid */ |
| 967 | - | |
| 968 | + | |
| 968 | 969 | rid = db_int(0, |
| 969 | 970 | "SELECT x.rid FROM tag t, tagxref x" |
| 970 | 971 | " WHERE x.tagid=t.tagid AND t.tagname='wiki-%q'" |
| 971 | 972 | " ORDER BY x.mtime DESC LIMIT 1", |
| 972 | 973 | zPageName |
| @@ -987,10 +988,13 @@ | ||
| 987 | 988 | blob_zero(&wiki); |
| 988 | 989 | zDate = date_in_standard_format("now"); |
| 989 | 990 | blob_appendf(&wiki, "D %s\n", zDate); |
| 990 | 991 | free(zDate); |
| 991 | 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 | + } | |
| 992 | 996 | if( rid ){ |
| 993 | 997 | zUuid = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", rid); |
| 994 | 998 | blob_appendf(&wiki, "P %s\n", zUuid); |
| 995 | 999 | free(zUuid); |
| 996 | 1000 | } |
| @@ -1019,16 +1023,18 @@ | ||
| 1019 | 1023 | ** %fossil wiki export PAGENAME ?FILE? |
| 1020 | 1024 | ** |
| 1021 | 1025 | ** Sends the latest version of the PAGENAME wiki |
| 1022 | 1026 | ** entry to the given file or standard output. |
| 1023 | 1027 | ** |
| 1024 | -** %fossil wiki commit PAGENAME ?FILE? | |
| 1028 | +** %fossil wiki commit PAGENAME ?FILE? [-format TEXT-FORMAT] | |
| 1025 | 1029 | ** |
| 1026 | 1030 | ** 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. | |
| 1028 | 1034 | ** |
| 1029 | -** %fossil wiki create PAGENAME ?FILE? | |
| 1035 | +** %fossil wiki create PAGENAME ?FILE? [-format TEXT-FORMAT] | |
| 1030 | 1036 | ** |
| 1031 | 1037 | ** Create a new wiki page with initial content taken from |
| 1032 | 1038 | ** FILE or from standard input. |
| 1033 | 1039 | ** |
| 1034 | 1040 | ** %fossil wiki list |
| @@ -1054,11 +1060,10 @@ | ||
| 1054 | 1060 | int rid; /* Artifact ID of the wiki page */ |
| 1055 | 1061 | int i; /* Loop counter */ |
| 1056 | 1062 | char *zBody = 0; /* Wiki page content */ |
| 1057 | 1063 | Blob body; /* Wiki page content */ |
| 1058 | 1064 | Manifest *pWiki = 0; /* Parsed wiki page content */ |
| 1059 | - | |
| 1060 | 1065 | if( (g.argc!=4) && (g.argc!=5) ){ |
| 1061 | 1066 | usage("export PAGENAME ?FILE?"); |
| 1062 | 1067 | } |
| 1063 | 1068 | zPageName = g.argv[3]; |
| 1064 | 1069 | rid = db_int(0, "SELECT x.rid FROM tag t, tagxref x" |
| @@ -1079,40 +1084,54 @@ | ||
| 1079 | 1084 | blob_append(&body, "\n", 1); |
| 1080 | 1085 | blob_write_to_file(&body, zFile); |
| 1081 | 1086 | blob_reset(&body); |
| 1082 | 1087 | manifest_destroy(pWiki); |
| 1083 | 1088 | 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); | |
| 1089 | 1096 | if( g.argc!=4 && g.argc!=5 ){ |
| 1090 | - usage("commit PAGENAME ?FILE?"); | |
| 1097 | + usage("commit PAGENAME ?FILE? [-format TEXT-FORMAT]"); | |
| 1091 | 1098 | } |
| 1092 | 1099 | zPageName = g.argv[3]; |
| 1093 | 1100 | if( g.argc==4 ){ |
| 1094 | 1101 | blob_read_from_channel(&content, stdin, -1); |
| 1095 | 1102 | }else{ |
| 1096 | 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 | + } | |
| 1097 | 1116 | } |
| 1098 | 1117 | if( g.argv[2][1]=='r' ){ |
| 1099 | - wiki_cmd_commit(zPageName, 1, &content); | |
| 1118 | + wiki_cmd_commit(zPageName, 1, &content, zMimeType); | |
| 1100 | 1119 | fossil_print("Created new wiki page %s.\n", zPageName); |
| 1101 | 1120 | }else{ |
| 1102 | - wiki_cmd_commit(zPageName, 0, &content); | |
| 1121 | + wiki_cmd_commit(zPageName, 0, &content, zMimeType); | |
| 1103 | 1122 | fossil_print("Updated wiki page %s.\n", zPageName); |
| 1104 | 1123 | } |
| 1124 | + manifest_destroy(pWiki); | |
| 1105 | 1125 | 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 ){ | |
| 1108 | 1128 | if( g.argc!=5 ){ |
| 1109 | 1129 | usage("delete PAGENAME"); |
| 1110 | 1130 | } |
| 1111 | 1131 | 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 ){ | |
| 1114 | 1133 | Stmt q; |
| 1115 | 1134 | db_prepare(&q, |
| 1116 | 1135 | "SELECT substr(tagname, 6) FROM tag WHERE tagname GLOB 'wiki-*'" |
| 1117 | 1136 | " ORDER BY lower(tagname) /*sort*/" |
| 1118 | 1137 | ); |
| @@ -1119,14 +1138,13 @@ | ||
| 1119 | 1138 | while( db_step(&q)==SQLITE_ROW ){ |
| 1120 | 1139 | const char *zName = db_column_text(&q, 0); |
| 1121 | 1140 | fossil_print( "%s\n",zName); |
| 1122 | 1141 | } |
| 1123 | 1142 | db_finalize(&q); |
| 1124 | - }else | |
| 1125 | - { | |
| 1143 | + }else{ | |
| 1126 | 1144 | goto wiki_cmd_usage; |
| 1127 | 1145 | } |
| 1128 | 1146 | return; |
| 1129 | 1147 | |
| 1130 | 1148 | wiki_cmd_usage: |
| 1131 | 1149 | usage("export|create|commit|list ..."); |
| 1132 | 1150 | } |
| 1133 | 1151 |
| --- 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 |