Fossil SCM
Have the forum editor preview use /ajax/preview-text instead of /wikiajax/preview so that it does not require wiki-read permissions to use. Reported in [forum:87f2e5d3356beb10|forum post 2026-06-08T20:14:31Z].
Commit
210435c0d115e7d16c3299cd93adff30a57dc3b3a6cc3a82afa82aa0dde15e4e
Parent
78478f45e91a527…
2 files changed
+5
-1
+11
-6
+5
-1
| --- src/ajax.c | ||
| +++ src/ajax.c | ||
| @@ -459,11 +459,15 @@ | ||
| 459 | 459 | ** |
| 460 | 460 | ** https://fossil-scm.org/forum/forumpost/ed4a762b3a557898 |
| 461 | 461 | ** |
| 462 | 462 | ** This particular route is used by /fileedit and /chat, whereas |
| 463 | 463 | ** /wikiedit uses a simpler wiki-specific route. |
| 464 | - */ } | |
| 464 | + */ | |
| 465 | + /* TODO (2026-06-09): preview.txt, preview.md, preview.wiki as | |
| 466 | + ** shorthand for preview-text?filename=X.(txt|md|wiki), noting that | |
| 467 | + ** the filename is only used for mimetype determination. */ | |
| 468 | + } | |
| 465 | 469 | }; |
| 466 | 470 | |
| 467 | 471 | if(zName==0 || zName[0]==0){ |
| 468 | 472 | ajax_route_error(400,"Missing required [route] 'name' parameter."); |
| 469 | 473 | return; |
| 470 | 474 |
| --- src/ajax.c | |
| +++ src/ajax.c | |
| @@ -459,11 +459,15 @@ | |
| 459 | ** |
| 460 | ** https://fossil-scm.org/forum/forumpost/ed4a762b3a557898 |
| 461 | ** |
| 462 | ** This particular route is used by /fileedit and /chat, whereas |
| 463 | ** /wikiedit uses a simpler wiki-specific route. |
| 464 | */ } |
| 465 | }; |
| 466 | |
| 467 | if(zName==0 || zName[0]==0){ |
| 468 | ajax_route_error(400,"Missing required [route] 'name' parameter."); |
| 469 | return; |
| 470 |
| --- src/ajax.c | |
| +++ src/ajax.c | |
| @@ -459,11 +459,15 @@ | |
| 459 | ** |
| 460 | ** https://fossil-scm.org/forum/forumpost/ed4a762b3a557898 |
| 461 | ** |
| 462 | ** This particular route is used by /fileedit and /chat, whereas |
| 463 | ** /wikiedit uses a simpler wiki-specific route. |
| 464 | */ |
| 465 | /* TODO (2026-06-09): preview.txt, preview.md, preview.wiki as |
| 466 | ** shorthand for preview-text?filename=X.(txt|md|wiki), noting that |
| 467 | ** the filename is only used for mimetype determination. */ |
| 468 | } |
| 469 | }; |
| 470 | |
| 471 | if(zName==0 || zName[0]==0){ |
| 472 | ajax_route_error(400,"Missing required [route] 'name' parameter."); |
| 473 | return; |
| 474 |
+11
-6
| --- src/fossil.page.forumpost.js | ||
| +++ src/fossil.page.forumpost.js | ||
| @@ -521,17 +521,22 @@ | ||
| 521 | 521 | } |
| 522 | 522 | |
| 523 | 523 | async #fetchPreview(content){ |
| 524 | 524 | /* TODO: fetch preview */ |
| 525 | 525 | const e = this.#e; |
| 526 | - const fd = this.#newFormData(content); | |
| 526 | + const fd = /*no: this.#newFormData(content); */ | |
| 527 | + new FormData; | |
| 528 | + let ext; | |
| 529 | + switch(this.mimetype){ | |
| 530 | + case 'text/x-markdown': ext = 'md'; break; | |
| 531 | + case 'text/x-fossil-wiki': ext = 'wiki'; break; | |
| 532 | + default: ext = 'txt'; break; | |
| 533 | + } | |
| 534 | + fd.append('filename', 'x.'+ext/*for mimetype determination*/); | |
| 535 | + fd.append('content', this.editorContent.trim()); | |
| 527 | 536 | return window |
| 528 | - .fetch(F.repoUrl( | |
| 529 | - 'wikiajax/preview' | |
| 530 | - /* ^^^ Maybe change to /ajax/preview-text, but it's | |
| 531 | - ** got a more complicated interface */ | |
| 532 | - ), { | |
| 537 | + .fetch(F.repoUrl('ajax/preview-text'),{ | |
| 533 | 538 | method: 'POST', |
| 534 | 539 | body: fd |
| 535 | 540 | }) |
| 536 | 541 | .then(r=>r.text()) |
| 537 | 542 | .then(t=>{ |
| 538 | 543 |
| --- src/fossil.page.forumpost.js | |
| +++ src/fossil.page.forumpost.js | |
| @@ -521,17 +521,22 @@ | |
| 521 | } |
| 522 | |
| 523 | async #fetchPreview(content){ |
| 524 | /* TODO: fetch preview */ |
| 525 | const e = this.#e; |
| 526 | const fd = this.#newFormData(content); |
| 527 | return window |
| 528 | .fetch(F.repoUrl( |
| 529 | 'wikiajax/preview' |
| 530 | /* ^^^ Maybe change to /ajax/preview-text, but it's |
| 531 | ** got a more complicated interface */ |
| 532 | ), { |
| 533 | method: 'POST', |
| 534 | body: fd |
| 535 | }) |
| 536 | .then(r=>r.text()) |
| 537 | .then(t=>{ |
| 538 |
| --- src/fossil.page.forumpost.js | |
| +++ src/fossil.page.forumpost.js | |
| @@ -521,17 +521,22 @@ | |
| 521 | } |
| 522 | |
| 523 | async #fetchPreview(content){ |
| 524 | /* TODO: fetch preview */ |
| 525 | const e = this.#e; |
| 526 | const fd = /*no: this.#newFormData(content); */ |
| 527 | new FormData; |
| 528 | let ext; |
| 529 | switch(this.mimetype){ |
| 530 | case 'text/x-markdown': ext = 'md'; break; |
| 531 | case 'text/x-fossil-wiki': ext = 'wiki'; break; |
| 532 | default: ext = 'txt'; break; |
| 533 | } |
| 534 | fd.append('filename', 'x.'+ext/*for mimetype determination*/); |
| 535 | fd.append('content', this.editorContent.trim()); |
| 536 | return window |
| 537 | .fetch(F.repoUrl('ajax/preview-text'),{ |
| 538 | method: 'POST', |
| 539 | body: fd |
| 540 | }) |
| 541 | .then(r=>r.text()) |
| 542 | .then(t=>{ |
| 543 |