Fossil SCM
Add the ability to view diffs of wiki changes.
Commit
8e3b7fab9f76ffc44eac1ea2bd1f6d7d7f6785c3
Parent
a9a27f8aaab2a7a…
1 file changed
+68
-1
+68
-1
| --- src/wiki.c | ||
| +++ src/wiki.c | ||
| @@ -458,10 +458,23 @@ | ||
| 458 | 458 | @ <input type="submit" name="submit" value="Append Your Changes"> |
| 459 | 459 | @ <input type="submit" name="cancel" value="Cancel"> |
| 460 | 460 | @ </form> |
| 461 | 461 | style_footer(); |
| 462 | 462 | } |
| 463 | + | |
| 464 | +/* | |
| 465 | +** Name of the wiki history page being generated | |
| 466 | +*/ | |
| 467 | +static const char *zWikiPageName; | |
| 468 | + | |
| 469 | +/* | |
| 470 | +** Function called to output extra text at the end of each line in | |
| 471 | +** a wiki history listing. | |
| 472 | +*/ | |
| 473 | +static void wiki_history_extra(int rid){ | |
| 474 | + @ <a href="%s(g.zTop)/wdiff?name=%h(zWikiPageName)&a=%d(rid)">[diff]</a> | |
| 475 | +} | |
| 463 | 476 | |
| 464 | 477 | /* |
| 465 | 478 | ** WEBPAGE: whistory |
| 466 | 479 | ** URL: /whistory?name=PAGENAME |
| 467 | 480 | ** |
| @@ -484,14 +497,68 @@ | ||
| 484 | 497 | "(SELECT tagid FROM tag WHERE tagname='wiki-%q'))" |
| 485 | 498 | "ORDER BY mtime DESC", |
| 486 | 499 | timeline_query_for_www(), zPageName); |
| 487 | 500 | db_prepare(&q, zSQL); |
| 488 | 501 | free(zSQL); |
| 489 | - www_print_timeline(&q, TIMELINE_ARTID, 0); | |
| 502 | + zWikiPageName = zPageName; | |
| 503 | + www_print_timeline(&q, TIMELINE_ARTID, wiki_history_extra); | |
| 490 | 504 | db_finalize(&q); |
| 491 | 505 | style_footer(); |
| 492 | 506 | } |
| 507 | + | |
| 508 | +/* | |
| 509 | +** WEBPAGE: wdiff | |
| 510 | +** URL: /whistory?name=PAGENAME&a=RID1&b=RID2 | |
| 511 | +** | |
| 512 | +** Show the difference between two wiki pages. | |
| 513 | +*/ | |
| 514 | +void wdiff_page(void){ | |
| 515 | + char *zTitle; | |
| 516 | + int rid1, rid2; | |
| 517 | + const char *zPageName; | |
| 518 | + Blob content1, content2; | |
| 519 | + Manifest m1, m2; | |
| 520 | + Blob w1, w2, d; | |
| 521 | + | |
| 522 | + login_check_credentials(); | |
| 523 | + rid1 = atoi(PD("a","0")); | |
| 524 | + if( !g.okHistory ){ login_needed(); return; } | |
| 525 | + if( rid1==0 ) fossil_redirect_home(); | |
| 526 | + rid2 = atoi(PD("b","0")); | |
| 527 | + zPageName = PD("name",""); | |
| 528 | + zTitle = mprintf("Changes To %h", zPageName); | |
| 529 | + style_header(zTitle); | |
| 530 | + free(zTitle); | |
| 531 | + | |
| 532 | + if( rid2==0 ){ | |
| 533 | + rid2 = db_int(0, | |
| 534 | + "SELECT objid FROM event JOIN tagxref ON objid=rid AND tagid=" | |
| 535 | + "(SELECT tagid FROM tag WHERE tagname='wiki-%q')" | |
| 536 | + " WHERE event.mtime<(SELECT mtime FROM event WHERE objid=%d)" | |
| 537 | + " ORDER BY event.mtime DESC LIMIT 1", | |
| 538 | + zPageName, rid1 | |
| 539 | + ); | |
| 540 | + } | |
| 541 | + content_get(rid1, &content1); | |
| 542 | + manifest_parse(&m1, &content1); | |
| 543 | + if( m1.type!=CFTYPE_WIKI ) fossil_redirect_home(); | |
| 544 | + blob_init(&w1, m1.zWiki, -1); | |
| 545 | + blob_zero(&w2); | |
| 546 | + if( rid2 ){ | |
| 547 | + content_get(rid2, &content2); | |
| 548 | + manifest_parse(&m2, &content2); | |
| 549 | + if( m2.type==CFTYPE_WIKI ){ | |
| 550 | + blob_init(&w2, m2.zWiki, -1); | |
| 551 | + } | |
| 552 | + } | |
| 553 | + blob_zero(&d); | |
| 554 | + text_diff(&w2, &w1, &d, 5); | |
| 555 | + @ <pre> | |
| 556 | + @ %h(blob_str(&d)) | |
| 557 | + @ </pre> | |
| 558 | + style_footer(); | |
| 559 | +} | |
| 493 | 560 | |
| 494 | 561 | /* |
| 495 | 562 | ** WEBPAGE: wcontent |
| 496 | 563 | ** |
| 497 | 564 | ** List all available wiki pages with date created and last modified. |
| 498 | 565 |
| --- src/wiki.c | |
| +++ src/wiki.c | |
| @@ -458,10 +458,23 @@ | |
| 458 | @ <input type="submit" name="submit" value="Append Your Changes"> |
| 459 | @ <input type="submit" name="cancel" value="Cancel"> |
| 460 | @ </form> |
| 461 | style_footer(); |
| 462 | } |
| 463 | |
| 464 | /* |
| 465 | ** WEBPAGE: whistory |
| 466 | ** URL: /whistory?name=PAGENAME |
| 467 | ** |
| @@ -484,14 +497,68 @@ | |
| 484 | "(SELECT tagid FROM tag WHERE tagname='wiki-%q'))" |
| 485 | "ORDER BY mtime DESC", |
| 486 | timeline_query_for_www(), zPageName); |
| 487 | db_prepare(&q, zSQL); |
| 488 | free(zSQL); |
| 489 | www_print_timeline(&q, TIMELINE_ARTID, 0); |
| 490 | db_finalize(&q); |
| 491 | style_footer(); |
| 492 | } |
| 493 | |
| 494 | /* |
| 495 | ** WEBPAGE: wcontent |
| 496 | ** |
| 497 | ** List all available wiki pages with date created and last modified. |
| 498 |
| --- src/wiki.c | |
| +++ src/wiki.c | |
| @@ -458,10 +458,23 @@ | |
| 458 | @ <input type="submit" name="submit" value="Append Your Changes"> |
| 459 | @ <input type="submit" name="cancel" value="Cancel"> |
| 460 | @ </form> |
| 461 | style_footer(); |
| 462 | } |
| 463 | |
| 464 | /* |
| 465 | ** Name of the wiki history page being generated |
| 466 | */ |
| 467 | static const char *zWikiPageName; |
| 468 | |
| 469 | /* |
| 470 | ** Function called to output extra text at the end of each line in |
| 471 | ** a wiki history listing. |
| 472 | */ |
| 473 | static void wiki_history_extra(int rid){ |
| 474 | @ <a href="%s(g.zTop)/wdiff?name=%h(zWikiPageName)&a=%d(rid)">[diff]</a> |
| 475 | } |
| 476 | |
| 477 | /* |
| 478 | ** WEBPAGE: whistory |
| 479 | ** URL: /whistory?name=PAGENAME |
| 480 | ** |
| @@ -484,14 +497,68 @@ | |
| 497 | "(SELECT tagid FROM tag WHERE tagname='wiki-%q'))" |
| 498 | "ORDER BY mtime DESC", |
| 499 | timeline_query_for_www(), zPageName); |
| 500 | db_prepare(&q, zSQL); |
| 501 | free(zSQL); |
| 502 | zWikiPageName = zPageName; |
| 503 | www_print_timeline(&q, TIMELINE_ARTID, wiki_history_extra); |
| 504 | db_finalize(&q); |
| 505 | style_footer(); |
| 506 | } |
| 507 | |
| 508 | /* |
| 509 | ** WEBPAGE: wdiff |
| 510 | ** URL: /whistory?name=PAGENAME&a=RID1&b=RID2 |
| 511 | ** |
| 512 | ** Show the difference between two wiki pages. |
| 513 | */ |
| 514 | void wdiff_page(void){ |
| 515 | char *zTitle; |
| 516 | int rid1, rid2; |
| 517 | const char *zPageName; |
| 518 | Blob content1, content2; |
| 519 | Manifest m1, m2; |
| 520 | Blob w1, w2, d; |
| 521 | |
| 522 | login_check_credentials(); |
| 523 | rid1 = atoi(PD("a","0")); |
| 524 | if( !g.okHistory ){ login_needed(); return; } |
| 525 | if( rid1==0 ) fossil_redirect_home(); |
| 526 | rid2 = atoi(PD("b","0")); |
| 527 | zPageName = PD("name",""); |
| 528 | zTitle = mprintf("Changes To %h", zPageName); |
| 529 | style_header(zTitle); |
| 530 | free(zTitle); |
| 531 | |
| 532 | if( rid2==0 ){ |
| 533 | rid2 = db_int(0, |
| 534 | "SELECT objid FROM event JOIN tagxref ON objid=rid AND tagid=" |
| 535 | "(SELECT tagid FROM tag WHERE tagname='wiki-%q')" |
| 536 | " WHERE event.mtime<(SELECT mtime FROM event WHERE objid=%d)" |
| 537 | " ORDER BY event.mtime DESC LIMIT 1", |
| 538 | zPageName, rid1 |
| 539 | ); |
| 540 | } |
| 541 | content_get(rid1, &content1); |
| 542 | manifest_parse(&m1, &content1); |
| 543 | if( m1.type!=CFTYPE_WIKI ) fossil_redirect_home(); |
| 544 | blob_init(&w1, m1.zWiki, -1); |
| 545 | blob_zero(&w2); |
| 546 | if( rid2 ){ |
| 547 | content_get(rid2, &content2); |
| 548 | manifest_parse(&m2, &content2); |
| 549 | if( m2.type==CFTYPE_WIKI ){ |
| 550 | blob_init(&w2, m2.zWiki, -1); |
| 551 | } |
| 552 | } |
| 553 | blob_zero(&d); |
| 554 | text_diff(&w2, &w1, &d, 5); |
| 555 | @ <pre> |
| 556 | @ %h(blob_str(&d)) |
| 557 | @ </pre> |
| 558 | style_footer(); |
| 559 | } |
| 560 | |
| 561 | /* |
| 562 | ** WEBPAGE: wcontent |
| 563 | ** |
| 564 | ** List all available wiki pages with date created and last modified. |
| 565 |