Fossil SCM
[c541b6e734] Add -technote option to wiki command
Commit
467e493e89d20a10cb01d899ad2f11ae38b38cd3
Parent
5906ebc75590584…
2 files changed
+168
-81
+126
-62
+168
-81
| --- src/event.c | ||
| +++ src/event.c | ||
| @@ -219,10 +219,118 @@ | ||
| 219 | 219 | @ </pre> |
| 220 | 220 | } |
| 221 | 221 | style_footer(); |
| 222 | 222 | manifest_destroy(pTNote); |
| 223 | 223 | } |
| 224 | + | |
| 225 | +/* | |
| 226 | +** Add or update a new tech note to the repository. rid is id of | |
| 227 | +** the prior version of this technote, if any. | |
| 228 | +** | |
| 229 | +** zId specifies the uuid of the tech note | |
| 230 | +** zBody specifies the content of the tech note | |
| 231 | +** zETime specifies the timestamp of the tech note | |
| 232 | +** zMimeType specifies the N-card for the wiki page. If it is 0, | |
| 233 | +** empty, or "text/x-fossil-wiki" (the default format) then it is | |
| 234 | +** ignored. | |
| 235 | +** zComment is the comment shown on the timeline. | |
| 236 | +** zTags are the tags for the tech note. | |
| 237 | +** zClr is the background color used for the tech note on the timeline. | |
| 238 | +** | |
| 239 | +** returns 1 if the tech note was added or updated, 0 if the | |
| 240 | +** update failed making an invalid artifact | |
| 241 | +*/ | |
| 242 | +int event_commit_common(int rid, const char *zId, const char *zBody, char *zETime, | |
| 243 | + const char *zMimetype, const char *zComment, | |
| 244 | + const char *zTags, const char *zClr){ | |
| 245 | + Blob event; | |
| 246 | + char *zDate; | |
| 247 | + Blob cksum; | |
| 248 | + int nrid, n; | |
| 249 | + | |
| 250 | + blob_init(&event, 0, 0); | |
| 251 | + db_begin_transaction(); | |
| 252 | + while( fossil_isspace(zComment[0]) ) zComment++; | |
| 253 | + n = strlen(zComment); | |
| 254 | + while( n>0 && fossil_isspace(zComment[n-1]) ){ n--; } | |
| 255 | + if( n>0 ){ | |
| 256 | + blob_appendf(&event, "C %#F\n", n, zComment); | |
| 257 | + } | |
| 258 | + zDate = date_in_standard_format("now"); | |
| 259 | + blob_appendf(&event, "D %s\n", zDate); | |
| 260 | + free(zDate); | |
| 261 | + | |
| 262 | + zETime[10] = 'T'; | |
| 263 | + blob_appendf(&event, "E %s %s\n", zETime, zId); | |
| 264 | + zETime[10] = ' '; | |
| 265 | + if( rid ){ | |
| 266 | + char *zUuid = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", rid); | |
| 267 | + blob_appendf(&event, "P %s\n", zUuid); | |
| 268 | + free(zUuid); | |
| 269 | + } | |
| 270 | + if( zMimetype && zMimetype[0] ){ | |
| 271 | + blob_appendf(&event, "N %s\n", zMimetype); | |
| 272 | + } | |
| 273 | + if( zClr && zClr[0] ){ | |
| 274 | + blob_appendf(&event, "T +bgcolor * %F\n", zClr); | |
| 275 | + } | |
| 276 | + if( zTags && zTags[0] ){ | |
| 277 | + Blob tags, one; | |
| 278 | + int i, j; | |
| 279 | + Stmt q; | |
| 280 | + char *zBlob; | |
| 281 | + | |
| 282 | + /* Load the tags string into a blob */ | |
| 283 | + blob_zero(&tags); | |
| 284 | + blob_append(&tags, zTags, -1); | |
| 285 | + | |
| 286 | + /* Collapse all sequences of whitespace and "," characters into | |
| 287 | + ** a single space character */ | |
| 288 | + zBlob = blob_str(&tags); | |
| 289 | + for(i=j=0; zBlob[i]; i++, j++){ | |
| 290 | + if( fossil_isspace(zBlob[i]) || zBlob[i]==',' ){ | |
| 291 | + while( fossil_isspace(zBlob[i+1]) ){ i++; } | |
| 292 | + zBlob[j] = ' '; | |
| 293 | + }else{ | |
| 294 | + zBlob[j] = zBlob[i]; | |
| 295 | + } | |
| 296 | + } | |
| 297 | + blob_resize(&tags, j); | |
| 298 | + | |
| 299 | + /* Parse out each tag and load it into a temporary table for sorting */ | |
| 300 | + db_multi_exec("CREATE TEMP TABLE newtags(x);"); | |
| 301 | + while( blob_token(&tags, &one) ){ | |
| 302 | + db_multi_exec("INSERT INTO newtags VALUES(%B)", &one); | |
| 303 | + } | |
| 304 | + blob_reset(&tags); | |
| 305 | + | |
| 306 | + /* Extract the tags in sorted order and make an entry in the | |
| 307 | + ** artifact for each. */ | |
| 308 | + db_prepare(&q, "SELECT x FROM newtags ORDER BY x"); | |
| 309 | + while( db_step(&q)==SQLITE_ROW ){ | |
| 310 | + blob_appendf(&event, "T +sym-%F *\n", db_column_text(&q, 0)); | |
| 311 | + } | |
| 312 | + db_finalize(&q); | |
| 313 | + } | |
| 314 | + if( !login_is_nobody() ){ | |
| 315 | + blob_appendf(&event, "U %F\n", login_name()); | |
| 316 | + } | |
| 317 | + blob_appendf(&event, "W %d\n%s\n", strlen(zBody), zBody); | |
| 318 | + md5sum_blob(&event, &cksum); | |
| 319 | + blob_appendf(&event, "Z %b\n", &cksum); | |
| 320 | + blob_reset(&cksum); | |
| 321 | + nrid = content_put(&event); | |
| 322 | + db_multi_exec("INSERT OR IGNORE INTO unsent VALUES(%d)", nrid); | |
| 323 | + if( manifest_crosslink(nrid, &event, MC_NONE)==0 ){ | |
| 324 | + db_end_transaction(1); | |
| 325 | + return 0; | |
| 326 | + } | |
| 327 | + assert( blob_is_reset(&event) ); | |
| 328 | + content_deltify(rid, nrid, 0); | |
| 329 | + db_end_transaction(0); | |
| 330 | + return 1; | |
| 331 | +} | |
| 224 | 332 | |
| 225 | 333 | /* |
| 226 | 334 | ** WEBPAGE: technoteedit |
| 227 | 335 | ** WEBPAGE: eventedit |
| 228 | 336 | ** |
| @@ -323,97 +431,18 @@ | ||
| 323 | 431 | ); |
| 324 | 432 | } |
| 325 | 433 | } |
| 326 | 434 | zETime = db_text(0, "SELECT coalesce(datetime(%Q),datetime('now'))", zETime); |
| 327 | 435 | if( P("submit")!=0 && (zBody!=0 && zComment!=0) ){ |
| 328 | - char *zDate; | |
| 329 | - Blob cksum; | |
| 330 | - int nrid, n; | |
| 331 | - blob_init(&event, 0, 0); | |
| 332 | - db_begin_transaction(); | |
| 333 | 436 | login_verify_csrf_secret(); |
| 334 | - while( fossil_isspace(zComment[0]) ) zComment++; | |
| 335 | - n = strlen(zComment); | |
| 336 | - while( n>0 && fossil_isspace(zComment[n-1]) ){ n--; } | |
| 337 | - if( n>0 ){ | |
| 338 | - blob_appendf(&event, "C %#F\n", n, zComment); | |
| 339 | - } | |
| 340 | - zDate = date_in_standard_format("now"); | |
| 341 | - blob_appendf(&event, "D %s\n", zDate); | |
| 342 | - free(zDate); | |
| 343 | - zETime[10] = 'T'; | |
| 344 | - blob_appendf(&event, "E %s %s\n", zETime, zId); | |
| 345 | - zETime[10] = ' '; | |
| 346 | - if( rid ){ | |
| 347 | - char *zUuid = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", rid); | |
| 348 | - blob_appendf(&event, "P %s\n", zUuid); | |
| 349 | - free(zUuid); | |
| 350 | - } | |
| 351 | - if( zMimetype && zMimetype[0] ){ | |
| 352 | - blob_appendf(&event, "N %s\n", zMimetype); | |
| 353 | - } | |
| 354 | - if( zClr && zClr[0] ){ | |
| 355 | - blob_appendf(&event, "T +bgcolor * %F\n", zClr); | |
| 356 | - } | |
| 357 | - if( zTags && zTags[0] ){ | |
| 358 | - Blob tags, one; | |
| 359 | - int i, j; | |
| 360 | - Stmt q; | |
| 361 | - char *zBlob; | |
| 362 | - | |
| 363 | - /* Load the tags string into a blob */ | |
| 364 | - blob_zero(&tags); | |
| 365 | - blob_append(&tags, zTags, -1); | |
| 366 | - | |
| 367 | - /* Collapse all sequences of whitespace and "," characters into | |
| 368 | - ** a single space character */ | |
| 369 | - zBlob = blob_str(&tags); | |
| 370 | - for(i=j=0; zBlob[i]; i++, j++){ | |
| 371 | - if( fossil_isspace(zBlob[i]) || zBlob[i]==',' ){ | |
| 372 | - while( fossil_isspace(zBlob[i+1]) ){ i++; } | |
| 373 | - zBlob[j] = ' '; | |
| 374 | - }else{ | |
| 375 | - zBlob[j] = zBlob[i]; | |
| 376 | - } | |
| 377 | - } | |
| 378 | - blob_resize(&tags, j); | |
| 379 | - | |
| 380 | - /* Parse out each tag and load it into a temporary table for sorting */ | |
| 381 | - db_multi_exec("CREATE TEMP TABLE newtags(x);"); | |
| 382 | - while( blob_token(&tags, &one) ){ | |
| 383 | - db_multi_exec("INSERT INTO newtags VALUES(%B)", &one); | |
| 384 | - } | |
| 385 | - blob_reset(&tags); | |
| 386 | - | |
| 387 | - /* Extract the tags in sorted order and make an entry in the | |
| 388 | - ** artifact for each. */ | |
| 389 | - db_prepare(&q, "SELECT x FROM newtags ORDER BY x"); | |
| 390 | - while( db_step(&q)==SQLITE_ROW ){ | |
| 391 | - blob_appendf(&event, "T +sym-%F *\n", db_column_text(&q, 0)); | |
| 392 | - } | |
| 393 | - db_finalize(&q); | |
| 394 | - } | |
| 395 | - if( !login_is_nobody() ){ | |
| 396 | - blob_appendf(&event, "U %F\n", login_name()); | |
| 397 | - } | |
| 398 | - blob_appendf(&event, "W %d\n%s\n", strlen(zBody), zBody); | |
| 399 | - md5sum_blob(&event, &cksum); | |
| 400 | - blob_appendf(&event, "Z %b\n", &cksum); | |
| 401 | - blob_reset(&cksum); | |
| 402 | - nrid = content_put(&event); | |
| 403 | - db_multi_exec("INSERT OR IGNORE INTO unsent VALUES(%d)", nrid); | |
| 404 | - if( manifest_crosslink(nrid, &event, MC_NONE)==0 ){ | |
| 405 | - db_end_transaction(1); | |
| 437 | + if ( !event_commit_common(rid, zId, zBody, zETime, zMimetype, zComment, zTags, zClr) ){ | |
| 406 | 438 | style_header("Error"); |
| 407 | 439 | @ Internal error: Fossil tried to make an invalid artifact for |
| 408 | - @ the edited technode. | |
| 440 | + @ the edited technote. | |
| 409 | 441 | style_footer(); |
| 410 | 442 | return; |
| 411 | 443 | } |
| 412 | - assert( blob_is_reset(&event) ); | |
| 413 | - content_deltify(rid, nrid, 0); | |
| 414 | - db_end_transaction(0); | |
| 415 | 444 | cgi_redirectf("technote?name=%T", zId); |
| 416 | 445 | } |
| 417 | 446 | if( P("cancel")!=0 ){ |
| 418 | 447 | cgi_redirectf("technote?name=%T", zId); |
| 419 | 448 | return; |
| @@ -497,5 +526,63 @@ | ||
| 497 | 526 | @ <input type="submit" name="cancel" value="Cancel" /> |
| 498 | 527 | @ </td></tr></table> |
| 499 | 528 | @ </div></form> |
| 500 | 529 | style_footer(); |
| 501 | 530 | } |
| 531 | + | |
| 532 | +/* | |
| 533 | +** Add a new tech note to the repository. The timestamp is | |
| 534 | +** given by the zETime parameter. isNew must be true to create | |
| 535 | +** a new page. If no previous page with the name zPageName exists | |
| 536 | +** and isNew is false, then this routine throws an error. | |
| 537 | +** | |
| 538 | +** The content of the new page is given by the blob pContent. | |
| 539 | +** | |
| 540 | +** zMimeType specifies the N-card for the wiki page. If it is 0, | |
| 541 | +** empty, or "text/x-fossil-wiki" (the default format) then it is | |
| 542 | +** ignored. | |
| 543 | +** zComment is the comment that will appear on the timeline for | |
| 544 | +** this technote | |
| 545 | +** zTags is a list of the tags for this technote | |
| 546 | +** zCLr is the background color for this technote | |
| 547 | +*/ | |
| 548 | +int event_cmd_commit(char *zETime, int isNew, Blob *pContent, | |
| 549 | + const char *zMimeType, const char *zComment, | |
| 550 | + const char *zTags, const char *zClr){ | |
| 551 | + int rid; /* Artifact id of the tech note */ | |
| 552 | + const char *zId; /* id of the tech note */ | |
| 553 | + rid = db_int(0, "SELECT objid FROM event" | |
| 554 | + " WHERE datetime(mtime)=datetime('%q') AND type = 'e'" | |
| 555 | + " LIMIT 1", | |
| 556 | + zETime | |
| 557 | + ); | |
| 558 | + if( rid==0 && !isNew ){ | |
| 559 | +#ifdef FOSSIL_ENABLE_JSON | |
| 560 | + g.json.resultCode = FSL_JSON_E_RESOURCE_NOT_FOUND; | |
| 561 | +#endif | |
| 562 | + fossil_fatal("no such tech note: %s", zETime); | |
| 563 | + } | |
| 564 | + if( rid!=0 && isNew ){ | |
| 565 | +#ifdef FOSSIL_ENABLE_JSON | |
| 566 | + g.json.resultCode = FSL_JSON_E_RESOURCE_ALREADY_EXISTS; | |
| 567 | +#endif | |
| 568 | + fossil_fatal("tech note %s already exists", zETime); | |
| 569 | + } | |
| 570 | + | |
| 571 | + if ( isNew ){ | |
| 572 | + zId = db_text(0, "SELECT lower(hex(randomblob(20)))"); | |
| 573 | + }else{ | |
| 574 | + zId = db_text(0, | |
| 575 | + "SELECT substr(tagname,7) FROM tag WHERE tagid=(SELECT tagid FROM event WHERE objid='%d')", | |
| 576 | + rid | |
| 577 | + ); | |
| 578 | + } | |
| 579 | + | |
| 580 | + user_select(); | |
| 581 | + if (event_commit_common(rid, zId, blob_str(pContent), zETime, | |
| 582 | + zMimeType, zComment, zTags, zClr)==0 ){ | |
| 583 | +#ifdef FOSSIL_ENABLE_JSON | |
| 584 | + g.json.resultCode = FSL_JSON_E_ASSERT; | |
| 585 | +#endif | |
| 586 | + fossil_fatal("Internal error: Fossil tried to make an invalid artifact for the technote.\n"); | |
| 587 | + } | |
| 588 | +} | |
| 502 | 589 |
| --- src/event.c | |
| +++ src/event.c | |
| @@ -219,10 +219,118 @@ | |
| 219 | @ </pre> |
| 220 | } |
| 221 | style_footer(); |
| 222 | manifest_destroy(pTNote); |
| 223 | } |
| 224 | |
| 225 | /* |
| 226 | ** WEBPAGE: technoteedit |
| 227 | ** WEBPAGE: eventedit |
| 228 | ** |
| @@ -323,97 +431,18 @@ | |
| 323 | ); |
| 324 | } |
| 325 | } |
| 326 | zETime = db_text(0, "SELECT coalesce(datetime(%Q),datetime('now'))", zETime); |
| 327 | if( P("submit")!=0 && (zBody!=0 && zComment!=0) ){ |
| 328 | char *zDate; |
| 329 | Blob cksum; |
| 330 | int nrid, n; |
| 331 | blob_init(&event, 0, 0); |
| 332 | db_begin_transaction(); |
| 333 | login_verify_csrf_secret(); |
| 334 | while( fossil_isspace(zComment[0]) ) zComment++; |
| 335 | n = strlen(zComment); |
| 336 | while( n>0 && fossil_isspace(zComment[n-1]) ){ n--; } |
| 337 | if( n>0 ){ |
| 338 | blob_appendf(&event, "C %#F\n", n, zComment); |
| 339 | } |
| 340 | zDate = date_in_standard_format("now"); |
| 341 | blob_appendf(&event, "D %s\n", zDate); |
| 342 | free(zDate); |
| 343 | zETime[10] = 'T'; |
| 344 | blob_appendf(&event, "E %s %s\n", zETime, zId); |
| 345 | zETime[10] = ' '; |
| 346 | if( rid ){ |
| 347 | char *zUuid = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", rid); |
| 348 | blob_appendf(&event, "P %s\n", zUuid); |
| 349 | free(zUuid); |
| 350 | } |
| 351 | if( zMimetype && zMimetype[0] ){ |
| 352 | blob_appendf(&event, "N %s\n", zMimetype); |
| 353 | } |
| 354 | if( zClr && zClr[0] ){ |
| 355 | blob_appendf(&event, "T +bgcolor * %F\n", zClr); |
| 356 | } |
| 357 | if( zTags && zTags[0] ){ |
| 358 | Blob tags, one; |
| 359 | int i, j; |
| 360 | Stmt q; |
| 361 | char *zBlob; |
| 362 | |
| 363 | /* Load the tags string into a blob */ |
| 364 | blob_zero(&tags); |
| 365 | blob_append(&tags, zTags, -1); |
| 366 | |
| 367 | /* Collapse all sequences of whitespace and "," characters into |
| 368 | ** a single space character */ |
| 369 | zBlob = blob_str(&tags); |
| 370 | for(i=j=0; zBlob[i]; i++, j++){ |
| 371 | if( fossil_isspace(zBlob[i]) || zBlob[i]==',' ){ |
| 372 | while( fossil_isspace(zBlob[i+1]) ){ i++; } |
| 373 | zBlob[j] = ' '; |
| 374 | }else{ |
| 375 | zBlob[j] = zBlob[i]; |
| 376 | } |
| 377 | } |
| 378 | blob_resize(&tags, j); |
| 379 | |
| 380 | /* Parse out each tag and load it into a temporary table for sorting */ |
| 381 | db_multi_exec("CREATE TEMP TABLE newtags(x);"); |
| 382 | while( blob_token(&tags, &one) ){ |
| 383 | db_multi_exec("INSERT INTO newtags VALUES(%B)", &one); |
| 384 | } |
| 385 | blob_reset(&tags); |
| 386 | |
| 387 | /* Extract the tags in sorted order and make an entry in the |
| 388 | ** artifact for each. */ |
| 389 | db_prepare(&q, "SELECT x FROM newtags ORDER BY x"); |
| 390 | while( db_step(&q)==SQLITE_ROW ){ |
| 391 | blob_appendf(&event, "T +sym-%F *\n", db_column_text(&q, 0)); |
| 392 | } |
| 393 | db_finalize(&q); |
| 394 | } |
| 395 | if( !login_is_nobody() ){ |
| 396 | blob_appendf(&event, "U %F\n", login_name()); |
| 397 | } |
| 398 | blob_appendf(&event, "W %d\n%s\n", strlen(zBody), zBody); |
| 399 | md5sum_blob(&event, &cksum); |
| 400 | blob_appendf(&event, "Z %b\n", &cksum); |
| 401 | blob_reset(&cksum); |
| 402 | nrid = content_put(&event); |
| 403 | db_multi_exec("INSERT OR IGNORE INTO unsent VALUES(%d)", nrid); |
| 404 | if( manifest_crosslink(nrid, &event, MC_NONE)==0 ){ |
| 405 | db_end_transaction(1); |
| 406 | style_header("Error"); |
| 407 | @ Internal error: Fossil tried to make an invalid artifact for |
| 408 | @ the edited technode. |
| 409 | style_footer(); |
| 410 | return; |
| 411 | } |
| 412 | assert( blob_is_reset(&event) ); |
| 413 | content_deltify(rid, nrid, 0); |
| 414 | db_end_transaction(0); |
| 415 | cgi_redirectf("technote?name=%T", zId); |
| 416 | } |
| 417 | if( P("cancel")!=0 ){ |
| 418 | cgi_redirectf("technote?name=%T", zId); |
| 419 | return; |
| @@ -497,5 +526,63 @@ | |
| 497 | @ <input type="submit" name="cancel" value="Cancel" /> |
| 498 | @ </td></tr></table> |
| 499 | @ </div></form> |
| 500 | style_footer(); |
| 501 | } |
| 502 |
| --- src/event.c | |
| +++ src/event.c | |
| @@ -219,10 +219,118 @@ | |
| 219 | @ </pre> |
| 220 | } |
| 221 | style_footer(); |
| 222 | manifest_destroy(pTNote); |
| 223 | } |
| 224 | |
| 225 | /* |
| 226 | ** Add or update a new tech note to the repository. rid is id of |
| 227 | ** the prior version of this technote, if any. |
| 228 | ** |
| 229 | ** zId specifies the uuid of the tech note |
| 230 | ** zBody specifies the content of the tech note |
| 231 | ** zETime specifies the timestamp of the tech note |
| 232 | ** zMimeType specifies the N-card for the wiki page. If it is 0, |
| 233 | ** empty, or "text/x-fossil-wiki" (the default format) then it is |
| 234 | ** ignored. |
| 235 | ** zComment is the comment shown on the timeline. |
| 236 | ** zTags are the tags for the tech note. |
| 237 | ** zClr is the background color used for the tech note on the timeline. |
| 238 | ** |
| 239 | ** returns 1 if the tech note was added or updated, 0 if the |
| 240 | ** update failed making an invalid artifact |
| 241 | */ |
| 242 | int event_commit_common(int rid, const char *zId, const char *zBody, char *zETime, |
| 243 | const char *zMimetype, const char *zComment, |
| 244 | const char *zTags, const char *zClr){ |
| 245 | Blob event; |
| 246 | char *zDate; |
| 247 | Blob cksum; |
| 248 | int nrid, n; |
| 249 | |
| 250 | blob_init(&event, 0, 0); |
| 251 | db_begin_transaction(); |
| 252 | while( fossil_isspace(zComment[0]) ) zComment++; |
| 253 | n = strlen(zComment); |
| 254 | while( n>0 && fossil_isspace(zComment[n-1]) ){ n--; } |
| 255 | if( n>0 ){ |
| 256 | blob_appendf(&event, "C %#F\n", n, zComment); |
| 257 | } |
| 258 | zDate = date_in_standard_format("now"); |
| 259 | blob_appendf(&event, "D %s\n", zDate); |
| 260 | free(zDate); |
| 261 | |
| 262 | zETime[10] = 'T'; |
| 263 | blob_appendf(&event, "E %s %s\n", zETime, zId); |
| 264 | zETime[10] = ' '; |
| 265 | if( rid ){ |
| 266 | char *zUuid = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", rid); |
| 267 | blob_appendf(&event, "P %s\n", zUuid); |
| 268 | free(zUuid); |
| 269 | } |
| 270 | if( zMimetype && zMimetype[0] ){ |
| 271 | blob_appendf(&event, "N %s\n", zMimetype); |
| 272 | } |
| 273 | if( zClr && zClr[0] ){ |
| 274 | blob_appendf(&event, "T +bgcolor * %F\n", zClr); |
| 275 | } |
| 276 | if( zTags && zTags[0] ){ |
| 277 | Blob tags, one; |
| 278 | int i, j; |
| 279 | Stmt q; |
| 280 | char *zBlob; |
| 281 | |
| 282 | /* Load the tags string into a blob */ |
| 283 | blob_zero(&tags); |
| 284 | blob_append(&tags, zTags, -1); |
| 285 | |
| 286 | /* Collapse all sequences of whitespace and "," characters into |
| 287 | ** a single space character */ |
| 288 | zBlob = blob_str(&tags); |
| 289 | for(i=j=0; zBlob[i]; i++, j++){ |
| 290 | if( fossil_isspace(zBlob[i]) || zBlob[i]==',' ){ |
| 291 | while( fossil_isspace(zBlob[i+1]) ){ i++; } |
| 292 | zBlob[j] = ' '; |
| 293 | }else{ |
| 294 | zBlob[j] = zBlob[i]; |
| 295 | } |
| 296 | } |
| 297 | blob_resize(&tags, j); |
| 298 | |
| 299 | /* Parse out each tag and load it into a temporary table for sorting */ |
| 300 | db_multi_exec("CREATE TEMP TABLE newtags(x);"); |
| 301 | while( blob_token(&tags, &one) ){ |
| 302 | db_multi_exec("INSERT INTO newtags VALUES(%B)", &one); |
| 303 | } |
| 304 | blob_reset(&tags); |
| 305 | |
| 306 | /* Extract the tags in sorted order and make an entry in the |
| 307 | ** artifact for each. */ |
| 308 | db_prepare(&q, "SELECT x FROM newtags ORDER BY x"); |
| 309 | while( db_step(&q)==SQLITE_ROW ){ |
| 310 | blob_appendf(&event, "T +sym-%F *\n", db_column_text(&q, 0)); |
| 311 | } |
| 312 | db_finalize(&q); |
| 313 | } |
| 314 | if( !login_is_nobody() ){ |
| 315 | blob_appendf(&event, "U %F\n", login_name()); |
| 316 | } |
| 317 | blob_appendf(&event, "W %d\n%s\n", strlen(zBody), zBody); |
| 318 | md5sum_blob(&event, &cksum); |
| 319 | blob_appendf(&event, "Z %b\n", &cksum); |
| 320 | blob_reset(&cksum); |
| 321 | nrid = content_put(&event); |
| 322 | db_multi_exec("INSERT OR IGNORE INTO unsent VALUES(%d)", nrid); |
| 323 | if( manifest_crosslink(nrid, &event, MC_NONE)==0 ){ |
| 324 | db_end_transaction(1); |
| 325 | return 0; |
| 326 | } |
| 327 | assert( blob_is_reset(&event) ); |
| 328 | content_deltify(rid, nrid, 0); |
| 329 | db_end_transaction(0); |
| 330 | return 1; |
| 331 | } |
| 332 | |
| 333 | /* |
| 334 | ** WEBPAGE: technoteedit |
| 335 | ** WEBPAGE: eventedit |
| 336 | ** |
| @@ -323,97 +431,18 @@ | |
| 431 | ); |
| 432 | } |
| 433 | } |
| 434 | zETime = db_text(0, "SELECT coalesce(datetime(%Q),datetime('now'))", zETime); |
| 435 | if( P("submit")!=0 && (zBody!=0 && zComment!=0) ){ |
| 436 | login_verify_csrf_secret(); |
| 437 | if ( !event_commit_common(rid, zId, zBody, zETime, zMimetype, zComment, zTags, zClr) ){ |
| 438 | style_header("Error"); |
| 439 | @ Internal error: Fossil tried to make an invalid artifact for |
| 440 | @ the edited technote. |
| 441 | style_footer(); |
| 442 | return; |
| 443 | } |
| 444 | cgi_redirectf("technote?name=%T", zId); |
| 445 | } |
| 446 | if( P("cancel")!=0 ){ |
| 447 | cgi_redirectf("technote?name=%T", zId); |
| 448 | return; |
| @@ -497,5 +526,63 @@ | |
| 526 | @ <input type="submit" name="cancel" value="Cancel" /> |
| 527 | @ </td></tr></table> |
| 528 | @ </div></form> |
| 529 | style_footer(); |
| 530 | } |
| 531 | |
| 532 | /* |
| 533 | ** Add a new tech note to the repository. The timestamp is |
| 534 | ** given by the zETime parameter. isNew must be true to create |
| 535 | ** a new page. If no previous page with the name zPageName exists |
| 536 | ** and isNew is false, then this routine throws an error. |
| 537 | ** |
| 538 | ** The content of the new page is given by the blob pContent. |
| 539 | ** |
| 540 | ** zMimeType specifies the N-card for the wiki page. If it is 0, |
| 541 | ** empty, or "text/x-fossil-wiki" (the default format) then it is |
| 542 | ** ignored. |
| 543 | ** zComment is the comment that will appear on the timeline for |
| 544 | ** this technote |
| 545 | ** zTags is a list of the tags for this technote |
| 546 | ** zCLr is the background color for this technote |
| 547 | */ |
| 548 | int event_cmd_commit(char *zETime, int isNew, Blob *pContent, |
| 549 | const char *zMimeType, const char *zComment, |
| 550 | const char *zTags, const char *zClr){ |
| 551 | int rid; /* Artifact id of the tech note */ |
| 552 | const char *zId; /* id of the tech note */ |
| 553 | rid = db_int(0, "SELECT objid FROM event" |
| 554 | " WHERE datetime(mtime)=datetime('%q') AND type = 'e'" |
| 555 | " LIMIT 1", |
| 556 | zETime |
| 557 | ); |
| 558 | if( rid==0 && !isNew ){ |
| 559 | #ifdef FOSSIL_ENABLE_JSON |
| 560 | g.json.resultCode = FSL_JSON_E_RESOURCE_NOT_FOUND; |
| 561 | #endif |
| 562 | fossil_fatal("no such tech note: %s", zETime); |
| 563 | } |
| 564 | if( rid!=0 && isNew ){ |
| 565 | #ifdef FOSSIL_ENABLE_JSON |
| 566 | g.json.resultCode = FSL_JSON_E_RESOURCE_ALREADY_EXISTS; |
| 567 | #endif |
| 568 | fossil_fatal("tech note %s already exists", zETime); |
| 569 | } |
| 570 | |
| 571 | if ( isNew ){ |
| 572 | zId = db_text(0, "SELECT lower(hex(randomblob(20)))"); |
| 573 | }else{ |
| 574 | zId = db_text(0, |
| 575 | "SELECT substr(tagname,7) FROM tag WHERE tagid=(SELECT tagid FROM event WHERE objid='%d')", |
| 576 | rid |
| 577 | ); |
| 578 | } |
| 579 | |
| 580 | user_select(); |
| 581 | if (event_commit_common(rid, zId, blob_str(pContent), zETime, |
| 582 | zMimeType, zComment, zTags, zClr)==0 ){ |
| 583 | #ifdef FOSSIL_ENABLE_JSON |
| 584 | g.json.resultCode = FSL_JSON_E_ASSERT; |
| 585 | #endif |
| 586 | fossil_fatal("Internal error: Fossil tried to make an invalid artifact for the technote.\n"); |
| 587 | } |
| 588 | } |
| 589 |
+126
-62
| --- src/wiki.c | ||
| +++ src/wiki.c | ||
| @@ -1137,36 +1137,44 @@ | ||
| 1137 | 1137 | } |
| 1138 | 1138 | |
| 1139 | 1139 | /* |
| 1140 | 1140 | ** COMMAND: wiki* |
| 1141 | 1141 | ** |
| 1142 | -** Usage: %fossil wiki (export|create|commit|list) WikiName | |
| 1143 | -** | |
| 1144 | -** Run various subcommands to work with wiki entries. | |
| 1145 | -** | |
| 1146 | -** %fossil wiki export PAGENAME ?FILE? | |
| 1147 | -** | |
| 1148 | -** Sends the latest version of the PAGENAME wiki | |
| 1149 | -** entry to the given file or standard output. | |
| 1150 | -** | |
| 1151 | -** %fossil wiki commit PAGENAME ?FILE? [-mimetype TEXT-FORMAT] | |
| 1152 | -** | |
| 1153 | -** Commit changes to a wiki page from FILE or from standard | |
| 1154 | -** input. The -mimetype (-M) flag specifies the mime type, | |
| 1155 | -** defaulting to the type used by the previous version of | |
| 1156 | -** the page or (for new pages) text/x-fossil-wiki. | |
| 1157 | -** | |
| 1158 | -** %fossil wiki create PAGENAME ?FILE? [-mimetype TEXT-FORMAT] | |
| 1159 | -** | |
| 1160 | -** Create a new wiki page with initial content taken from | |
| 1161 | -** FILE or from standard input. | |
| 1162 | -** | |
| 1163 | -** %fossil wiki list | |
| 1164 | -** %fossil wiki ls | |
| 1165 | -** | |
| 1166 | -** Lists all wiki entries, one per line, ordered | |
| 1167 | -** case-insensitively by name. | |
| 1142 | +** Usage: ../fossil wiki (export|create|commit|list) WikiName | |
| 1143 | +** | |
| 1144 | +** Run various subcommands to work with wiki entries or tech notes. | |
| 1145 | +** | |
| 1146 | +** ../fossil wiki export ?PAGENAME? ?FILE? [-t|--technote DATETIME ] | |
| 1147 | +** | |
| 1148 | +** Sends the latest version of either the PAGENAME wiki entry | |
| 1149 | +** or the DATETIME tech note to the given file or standard | |
| 1150 | +** output. One of PAGENAME or DATETIME must be specified. | |
| 1151 | +** | |
| 1152 | +** ../fossil wiki (create|commit) PAGENAME ?FILE? ?OPTIONS? | |
| 1153 | +** | |
| 1154 | +** Create a new or commit changes to an existing wiki page or | |
| 1155 | +** technote from FILE or from standard input. | |
| 1156 | +** | |
| 1157 | +** Options: | |
| 1158 | +** -M|--mimetype TEXT-FORMAT The mime type of the update defaulting | |
| 1159 | +** defaulting to the type used by the | |
| 1160 | +** previous version of the page or (for | |
| 1161 | +** new pages) text/x-fossil-wiki. | |
| 1162 | +** -t|--technote DATETIME Specifies the timestamp of the technote | |
| 1163 | +** to be created or updated. | |
| 1164 | +** --technote-tags TAGS The set of tags for a technote. | |
| 1165 | +** --technote-bgcolor COLOR The color used for the technote on the | |
| 1166 | +** timeline. | |
| 1167 | +** | |
| 1168 | +** ../fossil wiki list ?-technote? | |
| 1169 | +** ../fossil wiki ls ?-technote? | |
| 1170 | +** | |
| 1171 | +** Lists all wiki entries, one per line, ordered | |
| 1172 | +** case-insensitively by name. The -technote flag | |
| 1173 | +** specifies that technotes will be listed instead of | |
| 1174 | +** the wiki entries, which will be listed in order | |
| 1175 | +** timestamp. | |
| 1168 | 1176 | ** |
| 1169 | 1177 | */ |
| 1170 | 1178 | void wiki_cmd(void){ |
| 1171 | 1179 | int n; |
| 1172 | 1180 | db_find_and_open_repository(0, 0); |
| @@ -1179,33 +1187,54 @@ | ||
| 1179 | 1187 | } |
| 1180 | 1188 | |
| 1181 | 1189 | if( strncmp(g.argv[2],"export",n)==0 ){ |
| 1182 | 1190 | const char *zPageName; /* Name of the wiki page to export */ |
| 1183 | 1191 | const char *zFile; /* Name of the output file (0=stdout) */ |
| 1192 | + const char *zETime; /* The name of the technote to export */ | |
| 1184 | 1193 | int rid; /* Artifact ID of the wiki page */ |
| 1185 | 1194 | int i; /* Loop counter */ |
| 1186 | 1195 | char *zBody = 0; /* Wiki page content */ |
| 1187 | 1196 | Blob body; /* Wiki page content */ |
| 1188 | 1197 | Manifest *pWiki = 0; /* Parsed wiki page content */ |
| 1189 | - if( (g.argc!=4) && (g.argc!=5) ){ | |
| 1190 | - usage("export PAGENAME ?FILE?"); | |
| 1191 | - } | |
| 1192 | - zPageName = g.argv[3]; | |
| 1193 | - rid = db_int(0, "SELECT x.rid FROM tag t, tagxref x" | |
| 1194 | - " WHERE x.tagid=t.tagid AND t.tagname='wiki-%q'" | |
| 1195 | - " ORDER BY x.mtime DESC LIMIT 1", | |
| 1196 | - zPageName | |
| 1197 | - ); | |
| 1198 | - if( (pWiki = manifest_get(rid, CFTYPE_WIKI, 0))!=0 ){ | |
| 1199 | - zBody = pWiki->zWiki; | |
| 1200 | - } | |
| 1201 | - if( zBody==0 ){ | |
| 1202 | - fossil_fatal("wiki page [%s] not found",zPageName); | |
| 1198 | +int iii; | |
| 1199 | + zETime = find_option("technote","t",1); | |
| 1200 | + if( !zETime ){ | |
| 1201 | + if( (g.argc!=4) && (g.argc!=5) ){ | |
| 1202 | + usage("export PAGENAME ?FILE?"); | |
| 1203 | + } | |
| 1204 | + zPageName = g.argv[3]; | |
| 1205 | + rid = db_int(0, "SELECT x.rid FROM tag t, tagxref x" | |
| 1206 | + " WHERE x.tagid=t.tagid AND t.tagname='wiki-%q'" | |
| 1207 | + " ORDER BY x.mtime DESC LIMIT 1", | |
| 1208 | + zPageName | |
| 1209 | + ); | |
| 1210 | + if( (pWiki = manifest_get(rid, CFTYPE_WIKI, 0))!=0 ){ | |
| 1211 | + zBody = pWiki->zWiki; | |
| 1212 | + } | |
| 1213 | + if( zBody==0 ){ | |
| 1214 | + fossil_fatal("wiki page [%s] not found",zPageName); | |
| 1215 | + } | |
| 1216 | + zFile = (g.argc==4) ? "-" : g.argv[4]; | |
| 1217 | + }else{ | |
| 1218 | + if( (g.argc!=3) && (g.argc!=4) ){ | |
| 1219 | + usage("export ?FILE? --technote DATETIME"); | |
| 1220 | + } | |
| 1221 | + rid = db_int(0, "SELECT objid FROM event" | |
| 1222 | + " WHERE datetime(mtime)=datetime('%q') AND type='e'" | |
| 1223 | + " ORDER BY mtime DESC LIMIT 1", | |
| 1224 | + zETime | |
| 1225 | + ); | |
| 1226 | + if( (pWiki = manifest_get(rid, CFTYPE_EVENT, 0))!=0 ){ | |
| 1227 | + zBody = pWiki->zWiki; | |
| 1228 | + } | |
| 1229 | + if( zBody==0 ){ | |
| 1230 | + fossil_fatal("technote [%s] not found",zPageName); | |
| 1231 | + } | |
| 1232 | + zFile = (g.argc==3) ? "-" : g.argv[3]; | |
| 1203 | 1233 | } |
| 1204 | 1234 | for(i=strlen(zBody); i>0 && fossil_isspace(zBody[i-1]); i--){} |
| 1205 | 1235 | zBody[i] = 0; |
| 1206 | - zFile = (g.argc==4) ? "-" : g.argv[4]; | |
| 1207 | 1236 | blob_init(&body, zBody, -1); |
| 1208 | 1237 | blob_append(&body, "\n", 1); |
| 1209 | 1238 | blob_write_to_file(&body, zFile); |
| 1210 | 1239 | blob_reset(&body); |
| 1211 | 1240 | manifest_destroy(pWiki); |
| @@ -1215,37 +1244,65 @@ | ||
| 1215 | 1244 | const char *zPageName; /* page name */ |
| 1216 | 1245 | Blob content; /* Input content */ |
| 1217 | 1246 | int rid; |
| 1218 | 1247 | Manifest *pWiki = 0; /* Parsed wiki page content */ |
| 1219 | 1248 | const char *zMimeType = find_option("mimetype", "M", 1); |
| 1249 | + const char *zETime = find_option("technote", "t", 1); | |
| 1250 | + const char *zTags = find_option("technote-tags", NULL, 1); | |
| 1251 | + const char *zClr = find_option("technote-bgcolor", NULL, 1); | |
| 1220 | 1252 | if( g.argc!=4 && g.argc!=5 ){ |
| 1221 | - usage("commit|create PAGENAME ?FILE? [-mimetype TEXT-FORMAT]"); | |
| 1253 | + usage("commit|create PAGENAME ?FILE? [--mimetype TEXT-FORMAT] [--technote DATETIME] [--technote-tags TAGS] [--technote-bgcolor COLOR]"); | |
| 1222 | 1254 | } |
| 1223 | 1255 | zPageName = g.argv[3]; |
| 1224 | 1256 | if( g.argc==4 ){ |
| 1225 | 1257 | blob_read_from_channel(&content, stdin, -1); |
| 1226 | 1258 | }else{ |
| 1227 | 1259 | blob_read_from_file(&content, g.argv[4]); |
| 1228 | 1260 | } |
| 1229 | 1261 | if(!zMimeType || !*zMimeType){ |
| 1230 | 1262 | /* Try to deduce the mime type based on the prior version. */ |
| 1231 | - rid = db_int(0, "SELECT x.rid FROM tag t, tagxref x" | |
| 1232 | - " WHERE x.tagid=t.tagid AND t.tagname='wiki-%q'" | |
| 1233 | - " ORDER BY x.mtime DESC LIMIT 1", | |
| 1234 | - zPageName | |
| 1235 | - ); | |
| 1236 | - if(rid>0 && (pWiki = manifest_get(rid, CFTYPE_WIKI, 0))!=0 | |
| 1237 | - && (pWiki->zMimetype && *pWiki->zMimetype)){ | |
| 1238 | - zMimeType = pWiki->zMimetype; | |
| 1239 | - } | |
| 1240 | - } | |
| 1241 | - if( g.argv[2][1]=='r' ){ | |
| 1242 | - wiki_cmd_commit(zPageName, 1, &content, zMimeType, 1); | |
| 1243 | - fossil_print("Created new wiki page %s.\n", zPageName); | |
| 1244 | - }else{ | |
| 1245 | - wiki_cmd_commit(zPageName, 0, &content, zMimeType, 1); | |
| 1246 | - fossil_print("Updated wiki page %s.\n", zPageName); | |
| 1263 | + if ( !zETime ){ | |
| 1264 | + rid = db_int(0, "SELECT x.rid FROM tag t, tagxref x" | |
| 1265 | + " WHERE x.tagid=t.tagid AND t.tagname='wiki-%q'" | |
| 1266 | + " ORDER BY x.mtime DESC LIMIT 1", | |
| 1267 | + zPageName | |
| 1268 | + ); | |
| 1269 | + if(rid>0 && (pWiki = manifest_get(rid, CFTYPE_WIKI, 0))!=0 | |
| 1270 | + && (pWiki->zMimetype && *pWiki->zMimetype)){ | |
| 1271 | + zMimeType = pWiki->zMimetype; | |
| 1272 | + } | |
| 1273 | + }else{ | |
| 1274 | + rid = db_int(0, "SELECT objid FROM event" | |
| 1275 | + " WHERE datetime(mtime)=datetime('%q') AND type='e'" | |
| 1276 | + " ORDER BY mtime DESC LIMIT 1", | |
| 1277 | + zPageName | |
| 1278 | + ); | |
| 1279 | + if(rid>0 && (pWiki = manifest_get(rid, CFTYPE_EVENT, 0))!=0 | |
| 1280 | + && (pWiki->zMimetype && *pWiki->zMimetype)){ | |
| 1281 | + zMimeType = pWiki->zMimetype; | |
| 1282 | + } | |
| 1283 | + } | |
| 1284 | + } | |
| 1285 | + if( !zETime ){ | |
| 1286 | + if( g.argv[2][1]=='r' ){ | |
| 1287 | + wiki_cmd_commit(zPageName, 1, &content, zMimeType, 1); | |
| 1288 | + fossil_print("Created new wiki page %s.\n", zPageName); | |
| 1289 | + }else{ | |
| 1290 | + wiki_cmd_commit(zPageName, 0, &content, zMimeType, 1); | |
| 1291 | + fossil_print("Updated wiki page %s.\n", zPageName); | |
| 1292 | + } | |
| 1293 | + }else{ | |
| 1294 | + char *zMETime; /* Normalized, mutable version of zETime */ | |
| 1295 | + zMETime = db_text(0, "SELECT coalesce(datetime(%Q),datetime('now'))", zETime); | |
| 1296 | + if( g.argv[2][1]=='r' ){ | |
| 1297 | + event_cmd_commit(zMETime, 1, &content, zMimeType, zPageName, zTags, zClr); | |
| 1298 | + fossil_print("Created new tech note %s.\n", zMETime); | |
| 1299 | + }else{ | |
| 1300 | + event_cmd_commit(zMETime, 0, &content, zMimeType, zPageName, zTags, zClr); | |
| 1301 | + fossil_print("Updated tech note %s.\n", zMETime); | |
| 1302 | + } | |
| 1303 | + free(zMETime); | |
| 1247 | 1304 | } |
| 1248 | 1305 | manifest_destroy(pWiki); |
| 1249 | 1306 | blob_reset(&content); |
| 1250 | 1307 | }else if( strncmp(g.argv[2],"delete",n)==0 ){ |
| 1251 | 1308 | if( g.argc!=5 ){ |
| @@ -1253,14 +1310,21 @@ | ||
| 1253 | 1310 | } |
| 1254 | 1311 | fossil_fatal("delete not yet implemented."); |
| 1255 | 1312 | }else if(( strncmp(g.argv[2],"list",n)==0 ) |
| 1256 | 1313 | || ( strncmp(g.argv[2],"ls",n)==0 )){ |
| 1257 | 1314 | Stmt q; |
| 1258 | - db_prepare(&q, | |
| 1259 | - "SELECT substr(tagname, 6) FROM tag WHERE tagname GLOB 'wiki-*'" | |
| 1260 | - " ORDER BY lower(tagname) /*sort*/" | |
| 1261 | - ); | |
| 1315 | + if ( !find_option("technote","t",0) ){ | |
| 1316 | + db_prepare(&q, | |
| 1317 | + "SELECT substr(tagname, 6) FROM tag WHERE tagname GLOB 'wiki-*'" | |
| 1318 | + " ORDER BY lower(tagname) /*sort*/" | |
| 1319 | + ); | |
| 1320 | + }else{ | |
| 1321 | + db_prepare(&q, | |
| 1322 | + "SELECT datetime(mtime) FROM event WHERE type='e'" | |
| 1323 | + " ORDER BY mtime /*sort*/" | |
| 1324 | + ); | |
| 1325 | + } | |
| 1262 | 1326 | while( db_step(&q)==SQLITE_ROW ){ |
| 1263 | 1327 | const char *zName = db_column_text(&q, 0); |
| 1264 | 1328 | fossil_print( "%s\n",zName); |
| 1265 | 1329 | } |
| 1266 | 1330 | db_finalize(&q); |
| 1267 | 1331 |
| --- src/wiki.c | |
| +++ src/wiki.c | |
| @@ -1137,36 +1137,44 @@ | |
| 1137 | } |
| 1138 | |
| 1139 | /* |
| 1140 | ** COMMAND: wiki* |
| 1141 | ** |
| 1142 | ** Usage: %fossil wiki (export|create|commit|list) WikiName |
| 1143 | ** |
| 1144 | ** Run various subcommands to work with wiki entries. |
| 1145 | ** |
| 1146 | ** %fossil wiki export PAGENAME ?FILE? |
| 1147 | ** |
| 1148 | ** Sends the latest version of the PAGENAME wiki |
| 1149 | ** entry to the given file or standard output. |
| 1150 | ** |
| 1151 | ** %fossil wiki commit PAGENAME ?FILE? [-mimetype TEXT-FORMAT] |
| 1152 | ** |
| 1153 | ** Commit changes to a wiki page from FILE or from standard |
| 1154 | ** input. The -mimetype (-M) flag specifies the mime type, |
| 1155 | ** defaulting to the type used by the previous version of |
| 1156 | ** the page or (for new pages) text/x-fossil-wiki. |
| 1157 | ** |
| 1158 | ** %fossil wiki create PAGENAME ?FILE? [-mimetype TEXT-FORMAT] |
| 1159 | ** |
| 1160 | ** Create a new wiki page with initial content taken from |
| 1161 | ** FILE or from standard input. |
| 1162 | ** |
| 1163 | ** %fossil wiki list |
| 1164 | ** %fossil wiki ls |
| 1165 | ** |
| 1166 | ** Lists all wiki entries, one per line, ordered |
| 1167 | ** case-insensitively by name. |
| 1168 | ** |
| 1169 | */ |
| 1170 | void wiki_cmd(void){ |
| 1171 | int n; |
| 1172 | db_find_and_open_repository(0, 0); |
| @@ -1179,33 +1187,54 @@ | |
| 1179 | } |
| 1180 | |
| 1181 | if( strncmp(g.argv[2],"export",n)==0 ){ |
| 1182 | const char *zPageName; /* Name of the wiki page to export */ |
| 1183 | const char *zFile; /* Name of the output file (0=stdout) */ |
| 1184 | int rid; /* Artifact ID of the wiki page */ |
| 1185 | int i; /* Loop counter */ |
| 1186 | char *zBody = 0; /* Wiki page content */ |
| 1187 | Blob body; /* Wiki page content */ |
| 1188 | Manifest *pWiki = 0; /* Parsed wiki page content */ |
| 1189 | if( (g.argc!=4) && (g.argc!=5) ){ |
| 1190 | usage("export PAGENAME ?FILE?"); |
| 1191 | } |
| 1192 | zPageName = g.argv[3]; |
| 1193 | rid = db_int(0, "SELECT x.rid FROM tag t, tagxref x" |
| 1194 | " WHERE x.tagid=t.tagid AND t.tagname='wiki-%q'" |
| 1195 | " ORDER BY x.mtime DESC LIMIT 1", |
| 1196 | zPageName |
| 1197 | ); |
| 1198 | if( (pWiki = manifest_get(rid, CFTYPE_WIKI, 0))!=0 ){ |
| 1199 | zBody = pWiki->zWiki; |
| 1200 | } |
| 1201 | if( zBody==0 ){ |
| 1202 | fossil_fatal("wiki page [%s] not found",zPageName); |
| 1203 | } |
| 1204 | for(i=strlen(zBody); i>0 && fossil_isspace(zBody[i-1]); i--){} |
| 1205 | zBody[i] = 0; |
| 1206 | zFile = (g.argc==4) ? "-" : g.argv[4]; |
| 1207 | blob_init(&body, zBody, -1); |
| 1208 | blob_append(&body, "\n", 1); |
| 1209 | blob_write_to_file(&body, zFile); |
| 1210 | blob_reset(&body); |
| 1211 | manifest_destroy(pWiki); |
| @@ -1215,37 +1244,65 @@ | |
| 1215 | const char *zPageName; /* page name */ |
| 1216 | Blob content; /* Input content */ |
| 1217 | int rid; |
| 1218 | Manifest *pWiki = 0; /* Parsed wiki page content */ |
| 1219 | const char *zMimeType = find_option("mimetype", "M", 1); |
| 1220 | if( g.argc!=4 && g.argc!=5 ){ |
| 1221 | usage("commit|create PAGENAME ?FILE? [-mimetype TEXT-FORMAT]"); |
| 1222 | } |
| 1223 | zPageName = g.argv[3]; |
| 1224 | if( g.argc==4 ){ |
| 1225 | blob_read_from_channel(&content, stdin, -1); |
| 1226 | }else{ |
| 1227 | blob_read_from_file(&content, g.argv[4]); |
| 1228 | } |
| 1229 | if(!zMimeType || !*zMimeType){ |
| 1230 | /* Try to deduce the mime type based on the prior version. */ |
| 1231 | rid = db_int(0, "SELECT x.rid FROM tag t, tagxref x" |
| 1232 | " WHERE x.tagid=t.tagid AND t.tagname='wiki-%q'" |
| 1233 | " ORDER BY x.mtime DESC LIMIT 1", |
| 1234 | zPageName |
| 1235 | ); |
| 1236 | if(rid>0 && (pWiki = manifest_get(rid, CFTYPE_WIKI, 0))!=0 |
| 1237 | && (pWiki->zMimetype && *pWiki->zMimetype)){ |
| 1238 | zMimeType = pWiki->zMimetype; |
| 1239 | } |
| 1240 | } |
| 1241 | if( g.argv[2][1]=='r' ){ |
| 1242 | wiki_cmd_commit(zPageName, 1, &content, zMimeType, 1); |
| 1243 | fossil_print("Created new wiki page %s.\n", zPageName); |
| 1244 | }else{ |
| 1245 | wiki_cmd_commit(zPageName, 0, &content, zMimeType, 1); |
| 1246 | fossil_print("Updated wiki page %s.\n", zPageName); |
| 1247 | } |
| 1248 | manifest_destroy(pWiki); |
| 1249 | blob_reset(&content); |
| 1250 | }else if( strncmp(g.argv[2],"delete",n)==0 ){ |
| 1251 | if( g.argc!=5 ){ |
| @@ -1253,14 +1310,21 @@ | |
| 1253 | } |
| 1254 | fossil_fatal("delete not yet implemented."); |
| 1255 | }else if(( strncmp(g.argv[2],"list",n)==0 ) |
| 1256 | || ( strncmp(g.argv[2],"ls",n)==0 )){ |
| 1257 | Stmt q; |
| 1258 | db_prepare(&q, |
| 1259 | "SELECT substr(tagname, 6) FROM tag WHERE tagname GLOB 'wiki-*'" |
| 1260 | " ORDER BY lower(tagname) /*sort*/" |
| 1261 | ); |
| 1262 | while( db_step(&q)==SQLITE_ROW ){ |
| 1263 | const char *zName = db_column_text(&q, 0); |
| 1264 | fossil_print( "%s\n",zName); |
| 1265 | } |
| 1266 | db_finalize(&q); |
| 1267 |
| --- src/wiki.c | |
| +++ src/wiki.c | |
| @@ -1137,36 +1137,44 @@ | |
| 1137 | } |
| 1138 | |
| 1139 | /* |
| 1140 | ** COMMAND: wiki* |
| 1141 | ** |
| 1142 | ** Usage: ../fossil wiki (export|create|commit|list) WikiName |
| 1143 | ** |
| 1144 | ** Run various subcommands to work with wiki entries or tech notes. |
| 1145 | ** |
| 1146 | ** ../fossil wiki export ?PAGENAME? ?FILE? [-t|--technote DATETIME ] |
| 1147 | ** |
| 1148 | ** Sends the latest version of either the PAGENAME wiki entry |
| 1149 | ** or the DATETIME tech note to the given file or standard |
| 1150 | ** output. One of PAGENAME or DATETIME must be specified. |
| 1151 | ** |
| 1152 | ** ../fossil wiki (create|commit) PAGENAME ?FILE? ?OPTIONS? |
| 1153 | ** |
| 1154 | ** Create a new or commit changes to an existing wiki page or |
| 1155 | ** technote from FILE or from standard input. |
| 1156 | ** |
| 1157 | ** Options: |
| 1158 | ** -M|--mimetype TEXT-FORMAT The mime type of the update defaulting |
| 1159 | ** defaulting to the type used by the |
| 1160 | ** previous version of the page or (for |
| 1161 | ** new pages) text/x-fossil-wiki. |
| 1162 | ** -t|--technote DATETIME Specifies the timestamp of the technote |
| 1163 | ** to be created or updated. |
| 1164 | ** --technote-tags TAGS The set of tags for a technote. |
| 1165 | ** --technote-bgcolor COLOR The color used for the technote on the |
| 1166 | ** timeline. |
| 1167 | ** |
| 1168 | ** ../fossil wiki list ?-technote? |
| 1169 | ** ../fossil wiki ls ?-technote? |
| 1170 | ** |
| 1171 | ** Lists all wiki entries, one per line, ordered |
| 1172 | ** case-insensitively by name. The -technote flag |
| 1173 | ** specifies that technotes will be listed instead of |
| 1174 | ** the wiki entries, which will be listed in order |
| 1175 | ** timestamp. |
| 1176 | ** |
| 1177 | */ |
| 1178 | void wiki_cmd(void){ |
| 1179 | int n; |
| 1180 | db_find_and_open_repository(0, 0); |
| @@ -1179,33 +1187,54 @@ | |
| 1187 | } |
| 1188 | |
| 1189 | if( strncmp(g.argv[2],"export",n)==0 ){ |
| 1190 | const char *zPageName; /* Name of the wiki page to export */ |
| 1191 | const char *zFile; /* Name of the output file (0=stdout) */ |
| 1192 | const char *zETime; /* The name of the technote to export */ |
| 1193 | int rid; /* Artifact ID of the wiki page */ |
| 1194 | int i; /* Loop counter */ |
| 1195 | char *zBody = 0; /* Wiki page content */ |
| 1196 | Blob body; /* Wiki page content */ |
| 1197 | Manifest *pWiki = 0; /* Parsed wiki page content */ |
| 1198 | int iii; |
| 1199 | zETime = find_option("technote","t",1); |
| 1200 | if( !zETime ){ |
| 1201 | if( (g.argc!=4) && (g.argc!=5) ){ |
| 1202 | usage("export PAGENAME ?FILE?"); |
| 1203 | } |
| 1204 | zPageName = g.argv[3]; |
| 1205 | rid = db_int(0, "SELECT x.rid FROM tag t, tagxref x" |
| 1206 | " WHERE x.tagid=t.tagid AND t.tagname='wiki-%q'" |
| 1207 | " ORDER BY x.mtime DESC LIMIT 1", |
| 1208 | zPageName |
| 1209 | ); |
| 1210 | if( (pWiki = manifest_get(rid, CFTYPE_WIKI, 0))!=0 ){ |
| 1211 | zBody = pWiki->zWiki; |
| 1212 | } |
| 1213 | if( zBody==0 ){ |
| 1214 | fossil_fatal("wiki page [%s] not found",zPageName); |
| 1215 | } |
| 1216 | zFile = (g.argc==4) ? "-" : g.argv[4]; |
| 1217 | }else{ |
| 1218 | if( (g.argc!=3) && (g.argc!=4) ){ |
| 1219 | usage("export ?FILE? --technote DATETIME"); |
| 1220 | } |
| 1221 | rid = db_int(0, "SELECT objid FROM event" |
| 1222 | " WHERE datetime(mtime)=datetime('%q') AND type='e'" |
| 1223 | " ORDER BY mtime DESC LIMIT 1", |
| 1224 | zETime |
| 1225 | ); |
| 1226 | if( (pWiki = manifest_get(rid, CFTYPE_EVENT, 0))!=0 ){ |
| 1227 | zBody = pWiki->zWiki; |
| 1228 | } |
| 1229 | if( zBody==0 ){ |
| 1230 | fossil_fatal("technote [%s] not found",zPageName); |
| 1231 | } |
| 1232 | zFile = (g.argc==3) ? "-" : g.argv[3]; |
| 1233 | } |
| 1234 | for(i=strlen(zBody); i>0 && fossil_isspace(zBody[i-1]); i--){} |
| 1235 | zBody[i] = 0; |
| 1236 | blob_init(&body, zBody, -1); |
| 1237 | blob_append(&body, "\n", 1); |
| 1238 | blob_write_to_file(&body, zFile); |
| 1239 | blob_reset(&body); |
| 1240 | manifest_destroy(pWiki); |
| @@ -1215,37 +1244,65 @@ | |
| 1244 | const char *zPageName; /* page name */ |
| 1245 | Blob content; /* Input content */ |
| 1246 | int rid; |
| 1247 | Manifest *pWiki = 0; /* Parsed wiki page content */ |
| 1248 | const char *zMimeType = find_option("mimetype", "M", 1); |
| 1249 | const char *zETime = find_option("technote", "t", 1); |
| 1250 | const char *zTags = find_option("technote-tags", NULL, 1); |
| 1251 | const char *zClr = find_option("technote-bgcolor", NULL, 1); |
| 1252 | if( g.argc!=4 && g.argc!=5 ){ |
| 1253 | usage("commit|create PAGENAME ?FILE? [--mimetype TEXT-FORMAT] [--technote DATETIME] [--technote-tags TAGS] [--technote-bgcolor COLOR]"); |
| 1254 | } |
| 1255 | zPageName = g.argv[3]; |
| 1256 | if( g.argc==4 ){ |
| 1257 | blob_read_from_channel(&content, stdin, -1); |
| 1258 | }else{ |
| 1259 | blob_read_from_file(&content, g.argv[4]); |
| 1260 | } |
| 1261 | if(!zMimeType || !*zMimeType){ |
| 1262 | /* Try to deduce the mime type based on the prior version. */ |
| 1263 | if ( !zETime ){ |
| 1264 | rid = db_int(0, "SELECT x.rid FROM tag t, tagxref x" |
| 1265 | " WHERE x.tagid=t.tagid AND t.tagname='wiki-%q'" |
| 1266 | " ORDER BY x.mtime DESC LIMIT 1", |
| 1267 | zPageName |
| 1268 | ); |
| 1269 | if(rid>0 && (pWiki = manifest_get(rid, CFTYPE_WIKI, 0))!=0 |
| 1270 | && (pWiki->zMimetype && *pWiki->zMimetype)){ |
| 1271 | zMimeType = pWiki->zMimetype; |
| 1272 | } |
| 1273 | }else{ |
| 1274 | rid = db_int(0, "SELECT objid FROM event" |
| 1275 | " WHERE datetime(mtime)=datetime('%q') AND type='e'" |
| 1276 | " ORDER BY mtime DESC LIMIT 1", |
| 1277 | zPageName |
| 1278 | ); |
| 1279 | if(rid>0 && (pWiki = manifest_get(rid, CFTYPE_EVENT, 0))!=0 |
| 1280 | && (pWiki->zMimetype && *pWiki->zMimetype)){ |
| 1281 | zMimeType = pWiki->zMimetype; |
| 1282 | } |
| 1283 | } |
| 1284 | } |
| 1285 | if( !zETime ){ |
| 1286 | if( g.argv[2][1]=='r' ){ |
| 1287 | wiki_cmd_commit(zPageName, 1, &content, zMimeType, 1); |
| 1288 | fossil_print("Created new wiki page %s.\n", zPageName); |
| 1289 | }else{ |
| 1290 | wiki_cmd_commit(zPageName, 0, &content, zMimeType, 1); |
| 1291 | fossil_print("Updated wiki page %s.\n", zPageName); |
| 1292 | } |
| 1293 | }else{ |
| 1294 | char *zMETime; /* Normalized, mutable version of zETime */ |
| 1295 | zMETime = db_text(0, "SELECT coalesce(datetime(%Q),datetime('now'))", zETime); |
| 1296 | if( g.argv[2][1]=='r' ){ |
| 1297 | event_cmd_commit(zMETime, 1, &content, zMimeType, zPageName, zTags, zClr); |
| 1298 | fossil_print("Created new tech note %s.\n", zMETime); |
| 1299 | }else{ |
| 1300 | event_cmd_commit(zMETime, 0, &content, zMimeType, zPageName, zTags, zClr); |
| 1301 | fossil_print("Updated tech note %s.\n", zMETime); |
| 1302 | } |
| 1303 | free(zMETime); |
| 1304 | } |
| 1305 | manifest_destroy(pWiki); |
| 1306 | blob_reset(&content); |
| 1307 | }else if( strncmp(g.argv[2],"delete",n)==0 ){ |
| 1308 | if( g.argc!=5 ){ |
| @@ -1253,14 +1310,21 @@ | |
| 1310 | } |
| 1311 | fossil_fatal("delete not yet implemented."); |
| 1312 | }else if(( strncmp(g.argv[2],"list",n)==0 ) |
| 1313 | || ( strncmp(g.argv[2],"ls",n)==0 )){ |
| 1314 | Stmt q; |
| 1315 | if ( !find_option("technote","t",0) ){ |
| 1316 | db_prepare(&q, |
| 1317 | "SELECT substr(tagname, 6) FROM tag WHERE tagname GLOB 'wiki-*'" |
| 1318 | " ORDER BY lower(tagname) /*sort*/" |
| 1319 | ); |
| 1320 | }else{ |
| 1321 | db_prepare(&q, |
| 1322 | "SELECT datetime(mtime) FROM event WHERE type='e'" |
| 1323 | " ORDER BY mtime /*sort*/" |
| 1324 | ); |
| 1325 | } |
| 1326 | while( db_step(&q)==SQLITE_ROW ){ |
| 1327 | const char *zName = db_column_text(&q, 0); |
| 1328 | fossil_print( "%s\n",zName); |
| 1329 | } |
| 1330 | db_finalize(&q); |
| 1331 |