Fossil SCM
/json/artifact/WIKI_UUID now supports the --format options from /json/wiki/get.
Commit
2cbe686c30ddf66a9775a9bdfffadca48e2d8647
Parent
accd6f3df6918f1…
2 files changed
+5
-3
+30
-10
+5
-3
| --- src/json_artifact.c | ||
| +++ src/json_artifact.c | ||
| @@ -241,13 +241,15 @@ | ||
| 241 | 241 | if( ! g.perm.RdWiki ){ |
| 242 | 242 | json_set_err(FSL_JSON_E_DENIED, |
| 243 | 243 | "Requires 'j' privileges."); |
| 244 | 244 | return NULL; |
| 245 | 245 | }else{ |
| 246 | - char addContent = json_artifact_include_content_flag(); | |
| 247 | - /* todo: support format=(raw|html|none) like /wiki/get does. */ | |
| 248 | - return json_get_wiki_page_by_rid(rid, addContent ? -1 : 0); | |
| 246 | + char contentFormat = json_wiki_get_content_format_flag(-9); | |
| 247 | + if(-9 == contentFormat){ | |
| 248 | + contentFormat = json_artifact_include_content_flag() ? -1 : 0; | |
| 249 | + } | |
| 250 | + return json_get_wiki_page_by_rid(rid, contentFormat); | |
| 249 | 251 | } |
| 250 | 252 | } |
| 251 | 253 | |
| 252 | 254 | cson_value * json_artifact_file(int rid){ |
| 253 | 255 | cson_object * pay = NULL; |
| 254 | 256 |
| --- src/json_artifact.c | |
| +++ src/json_artifact.c | |
| @@ -241,13 +241,15 @@ | |
| 241 | if( ! g.perm.RdWiki ){ |
| 242 | json_set_err(FSL_JSON_E_DENIED, |
| 243 | "Requires 'j' privileges."); |
| 244 | return NULL; |
| 245 | }else{ |
| 246 | char addContent = json_artifact_include_content_flag(); |
| 247 | /* todo: support format=(raw|html|none) like /wiki/get does. */ |
| 248 | return json_get_wiki_page_by_rid(rid, addContent ? -1 : 0); |
| 249 | } |
| 250 | } |
| 251 | |
| 252 | cson_value * json_artifact_file(int rid){ |
| 253 | cson_object * pay = NULL; |
| 254 |
| --- src/json_artifact.c | |
| +++ src/json_artifact.c | |
| @@ -241,13 +241,15 @@ | |
| 241 | if( ! g.perm.RdWiki ){ |
| 242 | json_set_err(FSL_JSON_E_DENIED, |
| 243 | "Requires 'j' privileges."); |
| 244 | return NULL; |
| 245 | }else{ |
| 246 | char contentFormat = json_wiki_get_content_format_flag(-9); |
| 247 | if(-9 == contentFormat){ |
| 248 | contentFormat = json_artifact_include_content_flag() ? -1 : 0; |
| 249 | } |
| 250 | return json_get_wiki_page_by_rid(rid, contentFormat); |
| 251 | } |
| 252 | } |
| 253 | |
| 254 | cson_value * json_artifact_file(int rid){ |
| 255 | cson_object * pay = NULL; |
| 256 |
+30
-10
| --- src/json_wiki.c | ||
| +++ src/json_wiki.c | ||
| @@ -147,10 +147,39 @@ | ||
| 147 | 147 | } |
| 148 | 148 | return json_get_wiki_page_by_rid(rid, contentFormat); |
| 149 | 149 | } |
| 150 | 150 | |
| 151 | 151 | |
| 152 | +/* | |
| 153 | +** Searches json_find_option_ctr("format",NULL,"f") for a flag. | |
| 154 | +** If not found it returns defaultValue else it returns a value | |
| 155 | +** depending on the first character of the format option: | |
| 156 | +** | |
| 157 | +** [h]tml = 1 | |
| 158 | +** [n]one = 0 | |
| 159 | +** [r]aw = -1 | |
| 160 | +** | |
| 161 | +** The return value is intended for use with | |
| 162 | +** json_get_wiki_page_by_rid() and friends. | |
| 163 | +*/ | |
| 164 | +char json_wiki_get_content_format_flag( char defaultValue ){ | |
| 165 | + char contentFormat = defaultValue; | |
| 166 | + char const * zFormat = json_find_option_cstr("format",NULL,"f"); | |
| 167 | + if( !zFormat || !*zFormat ){ | |
| 168 | + return contentFormat; | |
| 169 | + } | |
| 170 | + else if('r'==*zFormat){ | |
| 171 | + contentFormat = -1; | |
| 172 | + } | |
| 173 | + else if('h'==*zFormat){ | |
| 174 | + contentFormat = 1; | |
| 175 | + } | |
| 176 | + else if('n'==*zFormat){ | |
| 177 | + contentFormat = 0; | |
| 178 | + } | |
| 179 | + return contentFormat; | |
| 180 | +} | |
| 152 | 181 | |
| 153 | 182 | /* |
| 154 | 183 | ** Implementation of /json/wiki/get. |
| 155 | 184 | ** |
| 156 | 185 | */ |
| @@ -182,20 +211,11 @@ | ||
| 182 | 211 | json_set_err(FSL_JSON_E_MISSING_ARGS, |
| 183 | 212 | "'name' argument is missing."); |
| 184 | 213 | return NULL; |
| 185 | 214 | } |
| 186 | 215 | |
| 187 | - zFormat = json_find_option_cstr("format",NULL,"f"); | |
| 188 | - if(!zFormat || !*zFormat || ('r'==*zFormat)){ | |
| 189 | - contentFormat = -1; | |
| 190 | - } | |
| 191 | - else if('h'==*zFormat){ | |
| 192 | - contentFormat = 1; | |
| 193 | - } | |
| 194 | - else if('n'==*zFormat){ | |
| 195 | - contentFormat = 0; | |
| 196 | - } | |
| 216 | + contentFormat = json_wiki_get_content_format_flag(contentFormat); | |
| 197 | 217 | return json_get_wiki_page_by_name(zPageName, contentFormat); |
| 198 | 218 | } |
| 199 | 219 | |
| 200 | 220 | /* |
| 201 | 221 | ** Internal impl of /wiki/save and /wiki/create. If createMode is 0 |
| 202 | 222 |
| --- src/json_wiki.c | |
| +++ src/json_wiki.c | |
| @@ -147,10 +147,39 @@ | |
| 147 | } |
| 148 | return json_get_wiki_page_by_rid(rid, contentFormat); |
| 149 | } |
| 150 | |
| 151 | |
| 152 | |
| 153 | /* |
| 154 | ** Implementation of /json/wiki/get. |
| 155 | ** |
| 156 | */ |
| @@ -182,20 +211,11 @@ | |
| 182 | json_set_err(FSL_JSON_E_MISSING_ARGS, |
| 183 | "'name' argument is missing."); |
| 184 | return NULL; |
| 185 | } |
| 186 | |
| 187 | zFormat = json_find_option_cstr("format",NULL,"f"); |
| 188 | if(!zFormat || !*zFormat || ('r'==*zFormat)){ |
| 189 | contentFormat = -1; |
| 190 | } |
| 191 | else if('h'==*zFormat){ |
| 192 | contentFormat = 1; |
| 193 | } |
| 194 | else if('n'==*zFormat){ |
| 195 | contentFormat = 0; |
| 196 | } |
| 197 | return json_get_wiki_page_by_name(zPageName, contentFormat); |
| 198 | } |
| 199 | |
| 200 | /* |
| 201 | ** Internal impl of /wiki/save and /wiki/create. If createMode is 0 |
| 202 |
| --- src/json_wiki.c | |
| +++ src/json_wiki.c | |
| @@ -147,10 +147,39 @@ | |
| 147 | } |
| 148 | return json_get_wiki_page_by_rid(rid, contentFormat); |
| 149 | } |
| 150 | |
| 151 | |
| 152 | /* |
| 153 | ** Searches json_find_option_ctr("format",NULL,"f") for a flag. |
| 154 | ** If not found it returns defaultValue else it returns a value |
| 155 | ** depending on the first character of the format option: |
| 156 | ** |
| 157 | ** [h]tml = 1 |
| 158 | ** [n]one = 0 |
| 159 | ** [r]aw = -1 |
| 160 | ** |
| 161 | ** The return value is intended for use with |
| 162 | ** json_get_wiki_page_by_rid() and friends. |
| 163 | */ |
| 164 | char json_wiki_get_content_format_flag( char defaultValue ){ |
| 165 | char contentFormat = defaultValue; |
| 166 | char const * zFormat = json_find_option_cstr("format",NULL,"f"); |
| 167 | if( !zFormat || !*zFormat ){ |
| 168 | return contentFormat; |
| 169 | } |
| 170 | else if('r'==*zFormat){ |
| 171 | contentFormat = -1; |
| 172 | } |
| 173 | else if('h'==*zFormat){ |
| 174 | contentFormat = 1; |
| 175 | } |
| 176 | else if('n'==*zFormat){ |
| 177 | contentFormat = 0; |
| 178 | } |
| 179 | return contentFormat; |
| 180 | } |
| 181 | |
| 182 | /* |
| 183 | ** Implementation of /json/wiki/get. |
| 184 | ** |
| 185 | */ |
| @@ -182,20 +211,11 @@ | |
| 211 | json_set_err(FSL_JSON_E_MISSING_ARGS, |
| 212 | "'name' argument is missing."); |
| 213 | return NULL; |
| 214 | } |
| 215 | |
| 216 | contentFormat = json_wiki_get_content_format_flag(contentFormat); |
| 217 | return json_get_wiki_page_by_name(zPageName, contentFormat); |
| 218 | } |
| 219 | |
| 220 | /* |
| 221 | ** Internal impl of /wiki/save and /wiki/create. If createMode is 0 |
| 222 |