Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
| Comment: | Initial bits for the ajax-powered wiki editor. There's still much to do here, but most of the basics are in place. |
|---|---|
| Downloads: | Tarball | ZIP archive |
| Timelines: | family | ancestors | descendants | both | ajax-wiki-editor |
| Files: | files | file ages | folders |
| SHA3-256: |
20636c936f865945083ba344d68c02ba |
| User & Date: | stephan 2020-07-29 20:19:50.174 |
Context
|
2020-07-30
| ||
| 00:05 | All major features except saving are implemented. ... (check-in: 5d61cec568 user: stephan tags: ajax-wiki-editor) | |
|
2020-07-29
| ||
| 20:19 | Initial bits for the ajax-powered wiki editor. There's still much to do here, but most of the basics are in place. ... (check-in: 20636c936f user: stephan tags: ajax-wiki-editor) | |
| 20:08 | Fixed %j encoding to backslash-escape double-quotes. It was accounting for them in its allocation but not actually escaping them. ... (check-in: caa51decb8 user: stephan tags: trunk) | |
Changes
Changes to src/ajax.c.
| ︙ | ︙ | |||
321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 |
assert(!"cannot happen");
}
if(zRenderMode!=0){
cgi_printf_header("x-ajax-render-mode: %s\r\n", zRenderMode);
}
}
/*
** Internal mapping of ajax sub-route names to various metadata.
*/
struct AjaxRoute {
const char *zName; /* Name part of the route after "ajax/" */
void (*xCallback)(); /* Impl function for the route. */
int bWriteMode; /* True if requires write mode */
int bPost; /* True if requires POST (i.e. CSRF
** verification) */
};
typedef struct AjaxRoute AjaxRoute;
/*
** Comparison function for bsearch() for searching an AjaxRoute
** list for a matching name.
*/
| > > | | 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 |
assert(!"cannot happen");
}
if(zRenderMode!=0){
cgi_printf_header("x-ajax-render-mode: %s\r\n", zRenderMode);
}
}
#if INTERFACE
/*
** Internal mapping of ajax sub-route names to various metadata.
*/
struct AjaxRoute {
const char *zName; /* Name part of the route after "ajax/" */
void (*xCallback)(); /* Impl function for the route. */
int bWriteMode; /* True if requires write mode */
int bPost; /* True if requires POST (i.e. CSRF
** verification) */
};
typedef struct AjaxRoute AjaxRoute;
#endif /*INTERFACE*/
/*
** Comparison function for bsearch() for searching an AjaxRoute
** list for a matching name.
*/
int cmp_ajax_route_name(const void *a, const void *b){
const AjaxRoute * rA = (const AjaxRoute*)a;
const AjaxRoute * rB = (const AjaxRoute*)b;
return fossil_strcmp(rA->zName, rB->zName);
}
/*
** WEBPAGE: ajax
|
| ︙ | ︙ |
Changes to src/default.css.
| ︙ | ︙ | |||
917 918 919 920 921 922 923 |
textarea {
max-width: 95%;
}
img {
max-width: 100%;
height: auto;
}
| > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 |
textarea {
max-width: 95%;
}
img {
max-width: 100%;
height: auto;
}
/**
.tab-xxx: styles for fossil.tabs.js.
*/
.tab-container {
width: 100%;
display: flex;
flex-direction: column;
align-items: stretch;
}
.tab-container > #fossil-status-bar {
margin-top: 0;
}
.tab-container > .tabs {
padding: 0.25em;
margin: 0;
display: flex;
flex-direction: column;
border-width: 1px;
border-style: outset;
border-color: inherit;
}
.tab-container > .tabs > .tab-panel {
align-self: stretch;
flex: 10 1 auto;
display: block;
}
.tab-container > .tab-bar {
display: flex;
flex-direction: row;
flex: 1 10 auto;
align-self: stretch;
flex-wrap: wrap;
}
.tab-container > .tab-bar > .tab-button {
display: inline-block;
border-radius: 0.5em 0.5em 0 0;
margin: 0 0.1em;
padding: 0.25em 0.75em;
align-self: baseline;
border-color: inherit;
border-width: 1px;
border-bottom: none;
border-top-style: inset;
border-left-style: inset;
border-right-style: inset;
cursor: pointer;
opacity: 0.6;
}
.tab-container > .tab-bar > .tab-button.selected {
text-decoration: underline;
opacity: 1.0;
border-top-style: outset;
border-left-style: outset;
border-right-style: outset;
}
/**
The flex-xxx classes can be used to create basic flexbox layouts
through the application of classes to the containing/contained
objects.
*/
.flex-container {
display: flex;
}
.flex-container.flex-row {
flex-direction: row;
flex-wrap: wrap;
justify-content: center;
align-items: center;
}
.flex-container .flex-grow {
flex-grow: 10;
flex-shrink: 0;
}
.flex-container .flex-shrink {
flex-grow: 0;
flex-shrink: 10;
}
.flex-container.flex-row.stretch {
flex-wrap: wrap;
align-items: baseline;
justify-content: stretch;
margin: 0;
}
.flex-container.flex-column {
flex-direction: column;
flex-wrap: wrap;
justify-content: center;
align-items: center;
}
.flex-container.flex-column.stretch {
align-items: stretch;
margin: 0;
}
.flex-container.child-gap-small > * {
margin: 0.25em;
}
#fossil-status-bar {
display: block;
font-family: monospace;
border-width: 1px;
border-style: inset;
border-color: inherit;
min-height: 1.5em;
font-size: 1.2em;
padding: 0.2em;
margin: 0.25em 0;
flex: 0 0 auto;
}
.font-size-100 {
font-size: 100%;
}
.font-size-125 {
font-size: 125%;
}
.font-size-150 {
font-size: 150%;
}
.font-size-175 {
font-size: 175%;
}
.font-size-200 {
font-size: 200%;
}
/**
.input-with-label is intended to be a wrapper element which
contain both a LABEL tag and an INPUT or SELECT control.
The wrapper is "necessary", as opposed to placing the INPUT
in the LABEL, so that we can include multiple INPUT
elements (e.g. a set of radio buttons).
*/
.input-with-label {
border: 1px inset #808080;
border-radius: 0.5em;
padding: 0.25em 0.4em;
margin: 0 0.5em;
display: inline-block;
cursor: default;
}
.input-with-label > * {
vertical-align: middle;
}
.input-with-label > label {
display: inline; /* some skins set label display to block! */
}
.input-with-label > input {
margin: 0;
}
.input-with-label > button {
margin: 0;
}
.input-with-label > select {
margin: 0;
}
.input-with-label > input[type=text] {
margin: 0;
}
.input-with-label > textarea {
margin: 0;
}
.input-with-label > input[type=checkbox] {
vertical-align: sub;
}
.input-with-label > input[type=radio] {
vertical-align: sub;
}
.input-with-label > label {
font-weight: initial;
margin: 0 0.25em 0 0.25em;
vertical-align: middle;
}
|
Changes to src/fossil.page.fileedit.js.
| ︙ | ︙ | |||
147 148 149 150 151 152 153 |
by prepending P.name to suffix. */
contentKey: function(suffix){return P.name+'/'+suffix},
/** Returns the index object, fetching it from the stash or creating
it anew on the first call. */
getIndex: function(){
if(!this.index){
this.index = F.storage.getJSON(
| | < < < < < < < < < < < < < < < | 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
by prepending P.name to suffix. */
contentKey: function(suffix){return P.name+'/'+suffix},
/** Returns the index object, fetching it from the stash or creating
it anew on the first call. */
getIndex: function(){
if(!this.index){
this.index = F.storage.getJSON(
this.keys.index, {}
);
}
return this.index;
},
_fireStashEvent: function(){
if(this._disableNextEvent) delete this._disableNextEvent;
else F.page.dispatchEvent('fileedit-stash-updated', this);
},
|
| ︙ | ︙ |
Added src/fossil.page.wikiedit.js.
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 |
(function(F/*the fossil object*/){
"use strict";
/**
Client-side implementation of the /wikiedit app. Requires that
the fossil JS bootstrapping is complete and that several fossil
JS APIs have been installed: fossil.fetch, fossil.dom,
fossil.tabs, fossil.storage, fossil.confirmer.
Custom events which can be listened for via
fossil.page.addEventListener():
- Event 'wiki-loaded': passes on information when it
loads a wiki (whether from the network or its internal local-edit
cache), in the form of an "winfo" object:
{
name: string,
mimetype: mimetype string,
content: string
version: UUID string // POTENTIAL TODO. Currently edit only the latest version.
}
The internal docs and code frequently use the term "winfo", and such
references refer to an object with that form.
The fossil.page.wikiContent() method gets or sets the current
file content for the page.
- Event 'wiki-saved': is fired when a commit completes,
passing on the same info as fileedit-file-loaded.
- Event 'wiki-content-replaced': when the editor's content is
replaced, as opposed to it being edited via user
interaction. This normally happens via selecting a file to
load. The event detail is the fossil.page object, not the current
file content.
- Event 'wiki-preview-updated': when the preview is refreshed
from the server, this event passes on information about the preview
change in the form of an object:
{
element: the DOM element which contains the content preview.
mimetype: the page's mimetype.
}
Here's an example which can be used with the highlightjs code
highlighter to update the highlighting when the preview is
refreshed in "wiki" mode (which includes fossil-native wiki and
markdown):
fossil.page.addEventListener(
'wiki-preview-updated',
(ev)=>{
if(ev.detail.mimetype!=='text/plain'){
ev.detail.element.querySelectorAll(
'code[class^=language-]'
).forEach((e)=>hljs.highlightBlock(e));
}
}
);
*/
const E = (s)=>document.querySelector(s),
D = F.dom,
P = F.page;
P.config = {};
/**
$stash is an internal-use-only object for managing "stashed"
local edits, to help avoid that users accidentally lose content
by switching tabs or following links or some such. The basic
theory of operation is...
All "stashed" state is stored using fossil.storage.
- When the current wiki content is modified by the user, the
current state of the page is stashed.
- When saving, the stashed entry for the previous version is
removed from the stash.
- When "loading", we use any stashed state for the given
checkin/file combination. When forcing a re-load of content,
any stashed entry for that combination is removed from the
stash.
- Every time P.stashContentChange() updates the stash, it is
pruned to $stash.prune.defaultMaxCount most-recently-updated
entries.
- This API often refers to "winfo objects." Those are objects
with a minimum of {page,mimetype} properties (which must be
valid), and the page name is used as basis for the stash keys
for any given page.
The structure of the stash is a bit convoluted for efficiency's
sake: we store a map of file info (winfo) objects separately from
those files' contents because otherwise we would be required to
JSONize/de-JSONize the file content when stashing/restoring it,
and that would be horribly inefficient (meaning "battery-consuming"
on mobile devices).
*/
const $stash = {
keys: {
index: F.page.name+'/index'
},
/**
index: {
"PAGE_NAME": {wiki page info w/o content}
...
}
In F.storage we...
- Store this.index under the key this.keys.index.
- Store each page's content under the key
(P.name+'/PAGE_NAME'). These are stored separately from the
index entries to avoid having to JSONize/de-JSONize the
content. The assumption/hope is that the browser can store
those records "directly," without any intermediary
encoding/decoding going on.
*/
indexKey: function(winfo){return winfo.name},
/** Returns the key for storing content for the given key suffix,
by prepending P.name to suffix. */
contentKey: function(suffix){return P.name+'/'+suffix},
/** Returns the index object, fetching it from the stash or creating
it anew on the first call. */
getIndex: function(){
if(!this.index){
this.index = F.storage.getJSON(
this.keys.index, {}
);
}
return this.index;
},
_fireStashEvent: function(){
if(this._disableNextEvent) delete this._disableNextEvent;
else F.page.dispatchEvent('wikiedit-stash-updated', this);
},
/**
Returns the stashed version, if any, for the given winfo object.
*/
getWinfo: function(winfo){
const ndx = this.getIndex();
return ndx[this.indexKey(winfo)];
},
/** Serializes this object's index to F.storage. Returns this. */
storeIndex: function(){
if(this.index) F.storage.setJSON(this.keys.index,this.index);
return this;
},
/** Updates the stash record for the given winfo
and (optionally) content. If passed 1 arg, only
the winfo stash is updated, else both the winfo
and its contents are (re-)stashed. Returns this.
*/
updateWinfo: function(winfo,content){
const ndx = this.getIndex(),
key = this.indexKey(winfo),
old = ndx[key];
const record = old || (ndx[key]={
name: winfo.name,
mimetype: winfo.mimetype,
isSandbox: !!winfo.isSandbox
});
record.stashTime = new Date().getTime();
this.storeIndex();
if(arguments.length>1){
F.storage.set(this.contentKey(key), content);
}
this._fireStashEvent();
return this;
},
/**
Returns the stashed content, if any, for the given winfo
object.
*/
stashedContent: function(winfo){
return F.storage.get(this.contentKey(this.indexKey(winfo)));
},
/** Returns true if we have stashed content for the given winfo
record. */
hasStashedContent: function(winfo){
return F.storage.contains(this.contentKey(this.indexKey(winfo)));
},
/** Unstashes the given winfo record and its content.
Returns this. */
unstash: function(winfo){
const ndx = this.getIndex(),
key = this.indexKey(winfo);
delete winfo.stashTime;
delete ndx[key];
F.storage.remove(this.contentKey(key));
this.storeIndex();
this._fireStashEvent();
return this;
},
/**
Clears all $stash entries from F.storage. Returns this.
*/
clear: function(){
const ndx = this.getIndex(),
self = this;
let count = 0;
Object.keys(ndx).forEach(function(k){
++count;
const e = ndx[k];
delete ndx[k];
F.storage.remove(self.contentKey(k));
});
F.storage.remove(this.keys.index);
delete this.index;
if(count) this._fireStashEvent();
return this;
},
/**
Removes all but the maxCount most-recently-updated stash
entries, where maxCount defaults to this.prune.defaultMaxCount.
*/
prune: function f(maxCount){
const ndx = this.getIndex();
const li = [];
if(!maxCount || maxCount<0) maxCount = f.defaultMaxCount;
Object.keys(ndx).forEach((k)=>li.push(ndx[k]));
li.sort((l,r)=>l.stashTime - r.stashTime);
let n = 0;
while(li.length>maxCount){
++n;
const e = li.shift();
this._disableNextEvent = true;
this.unstash(e);
console.warn("Pruned oldest local file edit entry:",e);
}
if(n) this._fireStashEvent();
}
};
$stash.prune.defaultMaxCount = P.config.defaultMaxStashSize;
/**
Internal workaround to select the current preview mode
and fire a change event if the value actually changes
or if forceEvent is truthy.
*/
P.selectMimetype = function(modeValue, forceEvent){
const s = this.e.selectMimetype;
if(!modeValue) modeValue = s.value;
else if(s.value != modeValue){
s.value = modeValue;
forceEvent = true;
}
if(forceEvent){
// Force UI update
s.dispatchEvent(new Event('change',{target:s}));
}
};
/**
Keep track of how many in-flight AJAX requests there are so we
can disable input elements while any are pending. For
simplicity's sake we simply disable ALL OF IT while any AJAX is
pending, rather than disabling operation-specific UI elements,
which would be a huge maintenance hassle.
Noting, however, that this global on/off is not *quite*
pedantically correct. Pedantically speaking. If an element is
disabled before an XHR starts, this code "should" notice that and
not include it in the to-re-enable list. That would be annoying
to do, and becomes impossible to do properly once multiple XHRs
are in transit and an element is disabled seprately between two
of those in-transit requests (that would be an unlikely, but
possible, corner case).
*/
const ajaxState = {
count: 0 /* in-flight F.fetch() requests */,
toDisable: undefined /* elements to disable during ajax activity */
};
F.fetch.beforesend = function f(){
if(!ajaxState.toDisable){
ajaxState.toDisable = document.querySelectorAll(
'button, input, select, textarea'
);
}
if(1===++ajaxState.count){
D.addClass(document.body, 'waiting');
D.disable(ajaxState.toDisable);
}
};
F.fetch.aftersend = function(){
if(0===--ajaxState.count){
D.removeClass(document.body, 'waiting');
D.enable(ajaxState.toDisable);
}
};
F.onPageLoad(function() {
document.body.classList.add('wikiedit');
P.base = {tag: E('base'), wikiUrl: F.repoUrl('wiki')};
P.base.originalHref = P.base.tag.href;
P.tabs = new fossil.TabManager('#wikiedit-tabs');
P.e = { /* various DOM elements we work with... */
taEditor: E('#wikiedit-content-editor'),
// btnCommit: E("#wikiedit-btn-commit"),
btnReload: E("#wikiedit-tab-content button.wikiedit-content-reload"),
selectMimetype: E('#select-mimetype select'),
selectFontSizeWrap: E('#select-font-size'),
// selectDiffWS: E('select[name=diff_ws]'),
cbAutoPreview: E('#cb-preview-autoupdate > input[type=checkbox]'),
previewTarget: E('#wikiedit-tab-preview-wrapper'),
diffTarget: E('#wikiedit-tab-diff-wrapper'),
tabs:{
content: E('#wikiedit-tab-content'),
preview: E('#wikiedit-tab-preview'),
diff: E('#wikiedit-tab-diff')
//commit: E('#wikiedit-tab-commit')
}
};
P.tabs.e.container.insertBefore(
/* Move the status bar between the tab buttons and
tab panels. Seems to be the best fit in terms of
functionality and visibility. */
E('#fossil-status-bar'), P.tabs.e.tabs
);
P.tabs.addEventListener(
/* Set up auto-refresh of the preview tab... */
'before-switch-to', function(ev){
if(ev.detail===P.e.tabs.preview){
P.baseHrefForWiki();
if(P.e.cbAutoPreview.checked) P.preview();
}else if(ev.detail===P.e.tabs.diff){
/* Work around a weird bug where the page gets wider than
the window when the diff tab is NOT in view and the
current SBS diff widget is wider than the window. When
the diff IS in view then CSS overflow magically reduces
the page size again. Weird. Maybe FF-specific. Note that
this weirdness happens even though P.e.diffTarget's parent
is hidden (and therefore P.e.diffTarget is also hidden).
*/
D.removeClass(P.e.diffTarget, 'hidden');
}
}
);
P.tabs.addEventListener(
/* Set up auto-refresh of the preview tab... */
'before-switch-from', function(ev){
if(ev.detail===P.e.tabs.preview){
P.baseHrefRestore();
}else if(ev.detail===P.e.tabs.diff){
/* See notes in the before-switch-to handler. */
D.addClass(P.e.diffTarget, 'hidden');
}
}
);
F.connectPagePreviewers(
P.e.tabs.preview.querySelector(
'#btn-preview-refresh'
)
);
const diffButtons = E('#wikiedit-tab-diff-buttons');
diffButtons.querySelector('button.sbs').addEventListener(
"click",(e)=>P.diff(true), false
);
diffButtons.querySelector('button.unified').addEventListener(
"click",(e)=>P.diff(false), false
);
if(0) P.e.btnCommit.addEventListener(
"click",(e)=>P.commit(), false
);
F.confirmer(P.e.btnReload, {
confirmText: "Really reload, losing edits?",
onconfirm: (e)=>P.unstashContent().loadPage(),
ticks: 3
});
P.e.taEditor.addEventListener(
'change', ()=>P.stashContentChange(), false
);
P.selectMimetype(false, true);
const selectFontSize = E('select[name=editor_font_size]');
if(selectFontSize){
selectFontSize.addEventListener(
"change",function(e){
const ed = P.e.taEditor;
ed.className = ed.className.replace(
/\bfont-size-\d+/g, '' );
ed.classList.add('font-size-'+e.target.value);
}, false
);
selectFontSize.dispatchEvent(
// Force UI update
new Event('change',{target:selectFontSize})
);
}
P.addEventListener(
// Clear certain views when new content is loaded/set
'wikiedit-content-replaced',
()=>D.clearElement(P.e.diffTarget, P.e.previewTarget)
);
P.addEventListener(
// Clear certain views after a non-dry-run commit
'wikiedit-saved',
(e)=>{
if(!e.detail.dryRun){
D.clearElement(P.e.diffTarget, P.e.previewTarget);
}
}
);
}/*F.onPageLoad()*/);
/**
Returns true if fossil.page.winfo is set, indicating that a page
has been loaded, else it reports an error and returns false.
If passed a truthy value any error message about not having
a wiki page loaded is suppressed.
*/
const affirmPageLoaded = function(quiet){
if(!P.winfo && !quiet) F.error("No wiki page is loaded.");
return !!P.winfo;
};
/**
Getter (if called with no args) or setter (if passed an arg) for
the current file content.
The setter form sets the content, dispatches a
'wikiedit-content-replaced' event, and returns this object.
*/
P.wikiContent = function f(){
if(0===arguments.length){
return f.get();
}else{
f.set(arguments[0] || '');
this.dispatchEvent('wikiedit-content-replaced', this);
return this;
}
};
/* Default get/set impls for file content */
P.wikiContent.get = function(){return P.e.taEditor.value};
P.wikiContent.set = function(content){P.e.taEditor.value = content};
/**
For use when installing a custom editor widget. Pass it the
getter and setter callbacks to fetch resp. set the content of the
custom widget. They will be triggered via
P.wikiContent(). Returns this object.
*/
P.setFileContentMethods = function(getter, setter){
this.wikiContent.get = getter;
this.wikiContent.set = setter;
return this;
};
/**
Removes the default editor widget (and any dependent elements)
from the DOM, adds the given element in its place, removes this
method from this object, and returns this object.
*/
P.replaceEditorElement = function(newEditor){
P.e.taEditor.parentNode.insertBefore(newEditor, P.e.taEditor);
P.e.taEditor.remove();
P.e.selectFontSizeWrap.remove();
delete this.replaceEditorElement;
return P;
};
/**
Sets the current page's base.href to {g.zTop}/wiki.
*/
P.baseHrefForWiki = function f(){
this.base.tag.href = this.base.wikiUrl;
return this;
};
/**
Sets the document's base.href value to its page-load-time
setting.
*/
P.baseHrefRestore = function(){
this.base.tag.href = this.base.originalHref;
};
/**
loadPage() loads the given wiki page and updates the relevant
UI elements to reflect the loaded state. If passed no arguments
then it re-uses the values from the currently-loaded page, reloading
it (emitting an error message if no file is loaded).
Returns this object, noting that the load is async. After loading
it triggers a 'wikiedit-file-loaded' event, passing it
this.winfo.
If a locally-edited copy of the given file/rev is found, that
copy is used instead of one fetched from the server, but it is
still treated as a load event.
Alternate call forms:
- no arguments: re-loads from this.winfo.
- 1 non-string argument: assumed to be an winfo-style
object. Must have at least the {name} property, but need not have
other winfo state.
*/
P.loadPage = function(name){
if(0===arguments.length){
/* Reload from this.winfo */
if(!affirmPageLoaded()) return this;
name = this.winfo.name;
}else if(1===arguments.length && 'string' !== typeof name){
/* Assume winfo-like object */
const arg = arguments[0];
name = arg.name;
}
const self = this;
const onload = (r)=>{
delete self.winfo;
self.winfo = {
name: r.name,
mimetype: r.mimetype,
type: !!r.type
};
self.e.selectMimetype.value = r.mimetype;
self.tabs.switchToTab(self.e.tabs.content);
self.wikiContent(r.content);
self.dispatchEvent('wiki-loaded', r);
};
const semiWinfo = {name: name};
const stashWinfo = this.getStashedWinfo(semiWinfo);
if(stashWinfo){ // fake a response from the stash...
this.winfo = stashWinfo;
onload({
name: stashWinfo.name,
mimetype: stashWinfo.mimetype,
type: stashWinfo.type,
content: this.contentFromStash()
});
F.message("Fetched from the local-edit storage:",
stashWinfo.name);
return this;
}
F.message(
"Loading content..."
).fetch('wikiajax/fetch',{
urlParams: {
page: name
},
responseType: 'json',
onload:(r)=>{
onload(r);
F.message('Loaded page ['+r.name+'].');
}
});
return this;
};
/**
Fetches the page preview based on the contents and settings of
this page's input fields, and updates the UI with with the
preview.
Returns this object, noting that the operation is async.
*/
P.preview = function f(switchToTab){
if(!affirmPageLoaded()) return this;
const target = this.e.previewTarget,
self = this;
const updateView = function(c){
D.clearElement(target);
if('string'===typeof c) target.innerHTML = c;
if(switchToTab) self.tabs.switchToTab(self.e.tabs.preview);
};
return this._postPreview(this.wikiContent(), updateView);
};
/**
Callback for use with F.connectPagePreviewers()
*/
P._postPreview = function(content,callback){
if(!affirmPageLoaded()) return this;
if(!content){
callback(content);
return this;
}
const fd = new FormData();
const mimetype = this.e.selectMimetype.value;
fd.append('mimetype',mimetype);
fd.append('content',content || '');
F.message(
"Fetching preview..."
).fetch('wikiajax/preview',{
payload: fd,
onload: (r,header)=>{
callback(r);
F.message('Updated preview.');
P.dispatchEvent('wikiedit-preview-updated',{
mimetype: mimetype,
element: P.e.previewTarget
});
},
onerror: (e)=>{
fossil.fetch.onerror(e);
callback("Error fetching preview: "+e);
}
});
return this;
};
/**
Undo some of the SBS diff-rendering bits which hurt us more than
they help...
*/
P.tweakSbsDiffs2 = function(){
if(1){
const dt = this.e.diffTarget;
dt.querySelectorAll('.sbsdiffcols .difftxtcol').forEach(
(dtc)=>{
const pre = dtc.querySelector('pre');
pre.style.width = 'initial';
//pre.removeAttribute('style');
//console.debug("pre width =",pre.style.width);
}
);
}
this.tweakSbsDiffs();
};
/**
Fetches the content diff based on the contents and settings of
this page's input fields, and updates the UI with the diff view.
Returns this object, noting that the operation is async.
*/
P.diff = function f(sbs){
if(!affirmPageLoaded()) return this;
const content = this.wikiContent(),
self = this,
target = this.e.diffTarget;
const fd = new FormData();
fd.append('filename',this.winfo.filename);
fd.append('checkin', this.winfo.checkin);
fd.append('sbs', sbs ? 1 : 0);
fd.append('content',content);
if(this.e.selectDiffWS) fd.append('ws',this.e.selectDiffWS.value);
F.message(
"Fetching diff..."
).fetch('ajax/wiki-diff',{
payload: fd,
onload: function(c){
target.innerHTML = [
"<div>Diff <code>[",
self.winfo.checkin,
"]</code> → Local Edits</div>",
c||'No changes.'
].join('');
if(sbs) P.tweakSbsDiffs2();
F.message('Updated diff.');
self.tabs.switchToTab(self.e.tabs.diff);
}
});
return this;
};
/**
Updates P.winfo for certain state and stashes P.winfo, with the
current content fetched via P.wikiContent().
If passed truthy AND the stash already has stashed content for
the current page, only the stashed winfo record is updated, else
both the winfo and content are updated.
*/
P.stashContentChange = function(onlyWinfo){
if(affirmPageLoaded(true)){
const wi = this.winfo;
if(onlyWinfo && $stash.hasStashedContent(wi)){
$stash.updateWinfo(wi);
}else{
$stash.updateWinfo(wi, P.wikiContent());
}
F.message("Stashed page ["+wi.name+"].");
$stash.prune();
}
return this;
};
/**
Removes any stashed state for the current P.winfo (if set) from
F.storage. Returns this.
*/
P.unstashContent = function(){
const winfo = arguments[0] || this.winfo;
if(winfo){
$stash.unstash(winfo);
//console.debug("Unstashed",winfo);
F.message("Unstashed page ["+winfo.name+"].");
}
return this;
};
/**
Clears all stashed file state from F.storage. Returns this.
*/
P.clearStash = function(){
$stash.clear();
return this;
};
/**
If stashed content for P.winfo exists, it is returned, else
undefined is returned.
*/
P.contentFromStash = function(){
return affirmPageLoaded(true) ? $stash.stashedContent(this.winfo) : undefined;
};
/**
If a stashed version of the given winfo object exists (same
filename/checkin values), return it, else return undefined.
*/
P.getStashedWinfo = function(winfo){
return $stash.getWinfo(winfo);
};
P.$stash = $stash /* only for development/debugging */;
})(window.fossil);
|
Changes to src/main.mk.
| ︙ | ︙ | |||
226 227 228 229 230 231 232 233 234 235 236 237 238 239 | $(SRCDIR)/forum.js \ $(SRCDIR)/fossil.bootstrap.js \ $(SRCDIR)/fossil.confirmer.js \ $(SRCDIR)/fossil.dom.js \ $(SRCDIR)/fossil.fetch.js \ $(SRCDIR)/fossil.page.fileedit.js \ $(SRCDIR)/fossil.page.forumpost.js \ $(SRCDIR)/fossil.storage.js \ $(SRCDIR)/fossil.tabs.js \ $(SRCDIR)/graph.js \ $(SRCDIR)/href.js \ $(SRCDIR)/login.js \ $(SRCDIR)/markdown.md \ $(SRCDIR)/menu.js \ | > | 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 | $(SRCDIR)/forum.js \ $(SRCDIR)/fossil.bootstrap.js \ $(SRCDIR)/fossil.confirmer.js \ $(SRCDIR)/fossil.dom.js \ $(SRCDIR)/fossil.fetch.js \ $(SRCDIR)/fossil.page.fileedit.js \ $(SRCDIR)/fossil.page.forumpost.js \ $(SRCDIR)/fossil.page.wikiedit.js \ $(SRCDIR)/fossil.storage.js \ $(SRCDIR)/fossil.tabs.js \ $(SRCDIR)/graph.js \ $(SRCDIR)/href.js \ $(SRCDIR)/login.js \ $(SRCDIR)/markdown.md \ $(SRCDIR)/menu.js \ |
| ︙ | ︙ | |||
255 256 257 258 259 260 261 262 263 264 265 266 267 268 | $(SRCDIR)/sounds/b.wav \ $(SRCDIR)/sounds/c.wav \ $(SRCDIR)/sounds/d.wav \ $(SRCDIR)/sounds/e.wav \ $(SRCDIR)/sounds/f.wav \ $(SRCDIR)/style.admin_log.css \ $(SRCDIR)/style.fileedit.css \ $(SRCDIR)/tree.js \ $(SRCDIR)/useredit.js \ $(SRCDIR)/wiki.wiki TRANS_SRC = \ $(OBJDIR)/add_.c \ $(OBJDIR)/ajax_.c \ | > | 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 | $(SRCDIR)/sounds/b.wav \ $(SRCDIR)/sounds/c.wav \ $(SRCDIR)/sounds/d.wav \ $(SRCDIR)/sounds/e.wav \ $(SRCDIR)/sounds/f.wav \ $(SRCDIR)/style.admin_log.css \ $(SRCDIR)/style.fileedit.css \ $(SRCDIR)/style.wikiedit.css \ $(SRCDIR)/tree.js \ $(SRCDIR)/useredit.js \ $(SRCDIR)/wiki.wiki TRANS_SRC = \ $(OBJDIR)/add_.c \ $(OBJDIR)/ajax_.c \ |
| ︙ | ︙ |
Changes to src/style.fileedit.css.
| ︙ | ︙ | |||
181 182 183 184 185 186 187 |
flex-direction: column;
align-items: stretch;
width: initial;
}
body.fileedit .sbsdiffcols div.difftxtcol pre {
max-width: 44em;
}
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | 181 182 183 184 185 186 187 |
flex-direction: column;
align-items: stretch;
width: initial;
}
body.fileedit .sbsdiffcols div.difftxtcol pre {
max-width: 44em;
}
|
Added src/style.wikiedit.css.
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
body.wikieedit.waiting * {
/* Triggered during AJAX requests. */
cursor: wait;
}
body.wikiedit textarea:focus,
body.wikiedit input:focus{
/* The sudden appearance of a border (as in the Ardoise skin)
shifts the layout in unsightly ways */
border: initial;
}
body.wikiedit div.wikiedit-preview {
margin: 0;
padding: 0;
}
body.wikiedit #wikiedit-tabs {
margin: 1em 0 0 0;
}
body.wikiedit #wikiedit-tab-preview-wrapper {
overflow: auto;
}
body.wikiedit .tab-container > .tabs > .tab-panel > .wikiedit-options {
margin-top: 0;
border: none;
border-radius: 0;
border-bottom-width: 1px;
border-bottom-style: dotted;
}
body.wikiedit .tab-container > .tabs > .tab-panel > .wikiedit-options > button {
vertical-align: middle;
margin: 0.5em;
}
body.wikiedit .tab-container > .tabs > .tab-panel > .wikiedit-options > input {
vertical-align: middle;
margin: 0.5em;
}
body.wikiedit .tab-container > .tabs > .tab-panel > .wikiedit-options > .input-with-label {
vertical-align: middle;
margin: 0.5em;
}
body.wikiedit .wikiedit-options > div > * {
margin: 0.25em;
}
body.wikiedit .wikiedit-options.flex-container.flex-row {
align-items: first baseline;
}
|
Changes to src/wiki.c.
| ︙ | ︙ | |||
396 397 398 399 400 401 402 403 404 405 406 407 408 409 |
return WIKITYPE_BRANCH;
}else
if( sqlite3_strglob("tag/*", zPageName)==0 ){
return WIKITYPE_TAG;
}
return WIKITYPE_NORMAL;
}
/*
** Add an appropriate style_header() for either the /wiki or /wikiedit page
** for zPageName. zExtra is an empty string for /wiki but has the text
** "Edit: " for /wikiedit.
**
** If the page is /wiki and the page is one of the special times (check-in,
| > > > > > > > > > > > > > > | 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 |
return WIKITYPE_BRANCH;
}else
if( sqlite3_strglob("tag/*", zPageName)==0 ){
return WIKITYPE_TAG;
}
return WIKITYPE_NORMAL;
}
/*
** Returns a JSON-friendly string form of the integer value returned
** by wiki_page_type(zPageName).
*/
const char * wiki_page_type_name(const char *zPageName){
switch(wiki_page_type(zPageName)){
case WIKITYPE_CHECKIN: return "checkin";
case WIKITYPE_BRANCH: return "branch";
case WIKITYPE_TAG: return "tag";
case WIKITYPE_NORMAL:
default: return "normal";
}
}
/*
** Add an appropriate style_header() for either the /wiki or /wikiedit page
** for zPageName. zExtra is an empty string for /wiki but has the text
** "Edit: " for /wikiedit.
**
** If the page is /wiki and the page is one of the special times (check-in,
|
| ︙ | ︙ | |||
618 619 620 621 622 623 624 625 626 627 628 629 630 631 |
for(i=4; i>=2; i-=2){
if( zMimetype && fossil_strcmp(zMimetype, azStyles[i])==0 ){
return azStyles[i+1];
}
}
return azStyles[1];
}
/*
** WEBPAGE: wikiedit
** URL: /wikiedit?name=PAGENAME
**
** Edit a wiki page.
*/
| > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 |
for(i=4; i>=2; i-=2){
if( zMimetype && fossil_strcmp(zMimetype, azStyles[i])==0 ){
return azStyles[i+1];
}
}
return azStyles[1];
}
/*
** Tries to fetch a wiki page for the given name. If found, it
** returns true, else false. If pRid is not NULL then if found *pRid is
** set to its RID. If ppWiki is not NULL then if found *ppWiki is set
** to the loaded wiki object, which the caller is responsible for
** passing to manifest_destroy().
*/
int wiki_fetch_by_name( const char *zPageName, int * pRid,
Manifest **ppWiki ){
Manifest *pWiki = 0;
char *zTag = mprintf("wiki-%s", zPageName);
const int rid = db_int(0,
"SELECT rid FROM tagxref"
" WHERE tagid=(SELECT tagid FROM tag WHERE tagname=%Q)"
" ORDER BY mtime DESC", zTag
);
fossil_free(zTag);
if( rid == 0 ){
return 0;
}
else if(pRid){
*pRid = rid;
}
if(ppWiki){
pWiki = manifest_get(rid, CFTYPE_WIKI, 0);
if( pWiki==0 ){
/* "Cannot happen." */
return 0;
}
*ppWiki = pWiki;
}
return 1;
}
/*
** Ajax route handler for /wikiajax/fetch.
**
** URL params:
**
** page = the wiki page name
**
** Responds with JSON. On error, an object in the form documented by
** ajax_route_error(). On success, an object in this form:
**
** { name: "page name",
** type: "normal" | "tag" | "checkin" | "branch" | "sandbox",
** mimetype: "mime type",
** content: "page content"
** }
*/
static void wiki_ajax_route_fetch(){
const char * zPageName = P("page");
int isSandbox;
if( zPageName==0 || zPageName[0]==0 ){
ajax_route_error(400,"Missing page name.");
return;
}
cgi_set_content_type("application/json");
isSandbox = is_sandbox(zPageName);
if( isSandbox ){
char * zMimetype =
db_get("sandbox-mimetype","text/x-fossil-wiki");
CX("{\"name\": %!j, \"type\": \"sandbox\", "
"\"mimetype\": %!j, \"content\": ""}",
zPageName, zMimetype);
fossil_free(zMimetype);
}else{
Manifest * pWiki = 0;
if( !wiki_fetch_by_name(zPageName, 0, &pWiki) ){
ajax_route_error(404, "Wiki page not found.");
return;
}
CX("{\"name\": %!j, \"type\": %!j, "
"\"mimetype\": %!j, \"content\": %!j}",
pWiki->zWikiTitle,
wiki_page_type_name(pWiki->zWikiTitle),
pWiki->zMimetype ? pWiki->zMimetype : "text/x-fossil-wiki",
pWiki->zWiki);
manifest_destroy(pWiki);
}
}
/*
** Ajax route handler for /wikiajax/preview.
**
** URL params:
**
** mimetype = the wiki page mimetype (determines rendering style)
** content = the wiki page content
*/
static void wiki_ajax_route_preview(){
Blob content = empty_blob;
const char * zMimetype = PD("mimetype","text/x-fossil-wiki");
const char * zContent = P("content");
if( zContent==0 ){
ajax_route_error(400,"Missing content to preview.");
return;
}
blob_init(&content, zContent, -1);
cgi_set_content_type("text/html");
wiki_render_by_mimetype(&content, zMimetype);
blob_reset(&content);
}
/*
** WEBPAGE: wikiajax
**
** An internal dispatcher for wiki AJAX operations. Not for direct
** client use.
*/
void wiki_ajax_page(void){
const char * zName = P("name");
AjaxRoute routeName = {0,0,0,0};
const AjaxRoute * pRoute = 0;
const AjaxRoute routes[] = {
/* Keep these sorted by zName (for bsearch()) */
{"fetch", wiki_ajax_route_fetch, 0, 0},
{"preview", wiki_ajax_route_preview, 1, 1}
/* /preview access mode: whether or not wiki-write mode is
needed really depends on multiple factors. e.g. the sandbox
page does not normally require more than anonymous access.
TODO: set its write-mode to false and do the check manually
in that route's handler.
*/
};
if(zName==0 || zName[0]==0){
ajax_route_error(400,"Missing required [route] 'name' parameter.");
return;
}
routeName.zName = zName;
pRoute = (const AjaxRoute *)bsearch(&routeName, routes,
count(routes), sizeof routes[0],
cmp_ajax_route_name);
if(pRoute==0){
ajax_route_error(404,"Ajax route not found.");
return;
}
login_check_credentials();
if( pRoute->bWriteMode!=0 && g.perm.WrWiki==0 ){
ajax_route_error(403,"Write permissions required.");
return;
}else if(0==cgi_csrf_safe(pRoute->bPost)){
ajax_route_error(403,
"CSRF violation (make sure sending of HTTP "
"Referer headers is enabled for XHR "
"connections).");
return;
}
pRoute->xCallback();
}
/*
** Main front-end for the Ajax-based wiki editor app.
*/
static void wikiedit_page_v2(void){
const char *zPageName;
Blob endScript = empty_blob; /* end-of-page JS code */;
int isSandbox;
login_check_credentials();
zPageName = PD("name","");
/* TODO: not require a page name, and instead offer a list
of pages. */
/*TODO: check name only for case of new page:
if( check_name(zPageName) ) return;*/
isSandbox = is_sandbox(zPageName);
if( isSandbox ){
if( !g.perm.WrWiki ){
login_needed(g.anon.WrWiki);
return;
}
}else if( zPageName!=0 ){
int rid = 0;
int found = 0;
if( !wiki_special_permission(zPageName) ){
login_needed(0);
return;
}
found = wiki_fetch_by_name(zPageName, &rid, 0);
if( !found ){
/* TODO: set up for a new page */
}
if( (rid && !g.perm.WrWiki) || (!rid && !g.perm.NewWiki) ){
login_needed(rid ? g.anon.WrWiki : g.anon.NewWiki);
return;
}
}
style_header("Wiki Editor");
/* Status bar */
CX("<div id='fossil-status-bar' "
"title='Status message area. Double-click to clear them.'>"
"Status messages will go here.</div>\n"
/* will be moved into the tab container via JS */);
/* Main tab container... */
CX("<div id='wikiedit-tabs' class='tab-container'></div>");
/******* Page list *******/
{
CX("<div id='wikiedit-tab-pages' "
"data-tab-parent='wikiedit-tabs' "
"data-tab-label='Page List'"
">");
CX("<div class='flex-container flex-row child-gap-small'>");
CX("TODO: page selection list.");
CX("</div>");
CX("</div>"/*#tab-file-content*/);
}
/******* Content tab *******/
{
CX("<div id='wikiedit-tab-content' "
"data-tab-parent='wikiedit-tabs' "
"data-tab-label='Page Editor' "
"data-tab-select='1'"
">");
CX("<div class='flex-container flex-row child-gap-small'>");
style_select_list_str("select-mimetype",
"mimetype",
"Mimetype", 0,
"text/x-fossil-wiki",
"Fossil wiki", "text/x-fossil-wiki",
"Markdown", "text/x-markdown",
"Plain text", "text/plain",
NULL);
CX("<button class='wikiedit-content-reload confirmer' "
"title='Reload the file from the server, discarding "
"any local edits. To help avoid accidental loss of "
"edits, it requires confirmation (a second click) within "
"a few seconds or it will not reload.'"
">Discard & Reload</button>");
style_select_list_int("select-font-size",
"editor_font_size", "Editor font size",
NULL/*tooltip*/,
100,
"100%", 100, "125%", 125,
"150%", 150, "175%", 175,
"200%", 200, NULL);
CX("</div>");
CX("<div class='flex-container flex-column stretch'>");
CX("<textarea name='content' id='wikiedit-content-editor' "
"class='wikiedit' "
"rows='20' cols='80'>");
CX("</textarea>");
CX("</div>"/*textarea wrapper*/);
CX("</div>"/*#tab-file-content*/);
}
/****** Preview tab ******/
{
CX("<div id='wikiedit-tab-preview' "
"data-tab-parent='wikiedit-tabs' "
"data-tab-label='Preview'"
">");
CX("<div class='wikiedit-options flex-container flex-row'>");
CX("<button id='btn-preview-refresh' "
"data-f-preview-from='wikiContent' "
/* ^^^ fossil.page[methodName]() OR text source elem ID,
** but we need a method in order to support clients swapping out
** the text editor with their own. */
"data-f-preview-via='_postPreview' "
/* ^^^ fossil.page[methodName](content, callback) */
"data-f-preview-to='#wikiedit-tab-preview-wrapper' "
/* ^^^ dest elem ID */
">Refresh</button>");
/* Toggle auto-update of preview when the Preview tab is selected. */
style_labeled_checkbox("cb-preview-autoupdate",
NULL,
"Auto-refresh?",
"1", 1,
"If on, the preview will automatically "
"refresh when this tab is selected.");
CX("</div>"/*.wikiedit-options*/);
CX("<div id='wikiedit-tab-preview-wrapper'></div>");
CX("</div>"/*#wikiedit-tab-preview*/);
}
/****** Diff tab ******/
{
CX("<div id='wikiedit-tab-diff' "
"data-tab-parent='wikiedit-tabs' "
"data-tab-label='Diff'"
">");
CX("<div class='wikiedit-options flex-container flex-row' "
"id='wikiedit-tab-diff-buttons'>");
CX("<button class='sbs'>Side-by-side</button>"
"<button class='unified'>Unified</button>");
if(0){
/* For the time being let's just ignore all whitespace
** changes, as files with Windows-style EOLs always show
** more diffs than we want then they're submitted to
** ?ajax=diff because JS normalizes them to Unix EOLs.
** We can revisit this decision later. */
style_select_list_int("diff-ws-policy",
"diff_ws", "Whitespace",
"Whitespace handling policy.",
2,
"Diff all whitespace", 0,
"Ignore EOL whitespace", 1,
"Ignore all whitespace", 2,
NULL);
}
CX("</div>");
CX("<div id='wikiedit-tab-diff-wrapper'>"
"Diffs will be shown here."
"</div>");
CX("</div>"/*#wikiedit-tab-diff*/);
}
if(zPageName && *zPageName){
/* Dynamically populate the editor... */
blob_appendf(&endScript, "fossil.onPageLoad(function(){");
blob_appendf(&endScript, "fossil.page.loadPage(%!j);",
zPageName);
blob_appendf(&endScript, "});\n");
}
style_emit_script_fossil_bootstrap(0);
append_diff_javascript(1);
style_emit_script_fetch(0);
style_emit_script_tabs(0)/*also emits fossil.dom*/;
style_emit_script_confirmer(0);
style_emit_script_builtin(0, "fossil.storage.js");
style_emit_script_builtin(0, "fossil.page.wikiedit.js");
if(blob_size(&endScript)>0){
style_emit_script_tag(0,0);
CX("\n(function(){\n");
CX("try{\n%b}\n"
"catch(e){"
"fossil.error(e); console.error('Exception:',e);"
"}\n",
&endScript);
CX("})();");
style_emit_script_tag(1,0);
}
blob_reset(&endScript);
style_footer();
}
/*
** WEBPAGE: wikiedit
** URL: /wikiedit?name=PAGENAME
**
** Edit a wiki page.
*/
|
| ︙ | ︙ | |||
641 642 643 644 645 646 647 648 649 650 651 652 653 654 |
char *zBody = (char*)P("w");
const char *zMimetype = wiki_filter_mimetypes(P("mimetype"));
int isWysiwyg = P("wysiwyg")!=0;
int goodCaptcha = 1;
int eType = WIKITYPE_UNKNOWN;
int havePreview = 0;
if( P("edit-wysiwyg")!=0 ){ isWysiwyg = 1; zBody = 0; }
if( P("edit-markup")!=0 ){ isWysiwyg = 0; zBody = 0; }
if( zBody ){
if( isWysiwyg ){
Blob body;
blob_zero(&body);
htmlTidy(zBody, &body);
| > > > > > | 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 |
char *zBody = (char*)P("w");
const char *zMimetype = wiki_filter_mimetypes(P("mimetype"));
int isWysiwyg = P("wysiwyg")!=0;
int goodCaptcha = 1;
int eType = WIKITYPE_UNKNOWN;
int havePreview = 0;
if(1){
wikiedit_page_v2();
return;
}
if( P("edit-wysiwyg")!=0 ){ isWysiwyg = 1; zBody = 0; }
if( P("edit-markup")!=0 ){ isWysiwyg = 0; zBody = 0; }
if( zBody ){
if( isWysiwyg ){
Blob body;
blob_zero(&body);
htmlTidy(zBody, &body);
|
| ︙ | ︙ |
Changes to win/Makefile.mingw.
| ︙ | ︙ | |||
638 639 640 641 642 643 644 645 646 647 648 649 650 651 | $(SRCDIR)/forum.js \ $(SRCDIR)/fossil.bootstrap.js \ $(SRCDIR)/fossil.confirmer.js \ $(SRCDIR)/fossil.dom.js \ $(SRCDIR)/fossil.fetch.js \ $(SRCDIR)/fossil.page.fileedit.js \ $(SRCDIR)/fossil.page.forumpost.js \ $(SRCDIR)/fossil.storage.js \ $(SRCDIR)/fossil.tabs.js \ $(SRCDIR)/graph.js \ $(SRCDIR)/href.js \ $(SRCDIR)/login.js \ $(SRCDIR)/markdown.md \ $(SRCDIR)/menu.js \ | > | 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 | $(SRCDIR)/forum.js \ $(SRCDIR)/fossil.bootstrap.js \ $(SRCDIR)/fossil.confirmer.js \ $(SRCDIR)/fossil.dom.js \ $(SRCDIR)/fossil.fetch.js \ $(SRCDIR)/fossil.page.fileedit.js \ $(SRCDIR)/fossil.page.forumpost.js \ $(SRCDIR)/fossil.page.wikiedit.js \ $(SRCDIR)/fossil.storage.js \ $(SRCDIR)/fossil.tabs.js \ $(SRCDIR)/graph.js \ $(SRCDIR)/href.js \ $(SRCDIR)/login.js \ $(SRCDIR)/markdown.md \ $(SRCDIR)/menu.js \ |
| ︙ | ︙ | |||
667 668 669 670 671 672 673 674 675 676 677 678 679 680 | $(SRCDIR)/sounds/b.wav \ $(SRCDIR)/sounds/c.wav \ $(SRCDIR)/sounds/d.wav \ $(SRCDIR)/sounds/e.wav \ $(SRCDIR)/sounds/f.wav \ $(SRCDIR)/style.admin_log.css \ $(SRCDIR)/style.fileedit.css \ $(SRCDIR)/tree.js \ $(SRCDIR)/useredit.js \ $(SRCDIR)/wiki.wiki TRANS_SRC = \ $(OBJDIR)/add_.c \ $(OBJDIR)/ajax_.c \ | > | 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 | $(SRCDIR)/sounds/b.wav \ $(SRCDIR)/sounds/c.wav \ $(SRCDIR)/sounds/d.wav \ $(SRCDIR)/sounds/e.wav \ $(SRCDIR)/sounds/f.wav \ $(SRCDIR)/style.admin_log.css \ $(SRCDIR)/style.fileedit.css \ $(SRCDIR)/style.wikiedit.css \ $(SRCDIR)/tree.js \ $(SRCDIR)/useredit.js \ $(SRCDIR)/wiki.wiki TRANS_SRC = \ $(OBJDIR)/add_.c \ $(OBJDIR)/ajax_.c \ |
| ︙ | ︙ |
Changes to win/Makefile.msc.
| ︙ | ︙ | |||
559 560 561 562 563 564 565 566 567 568 569 570 571 572 |
"$(SRCDIR)\forum.js" \
"$(SRCDIR)\fossil.bootstrap.js" \
"$(SRCDIR)\fossil.confirmer.js" \
"$(SRCDIR)\fossil.dom.js" \
"$(SRCDIR)\fossil.fetch.js" \
"$(SRCDIR)\fossil.page.fileedit.js" \
"$(SRCDIR)\fossil.page.forumpost.js" \
"$(SRCDIR)\fossil.storage.js" \
"$(SRCDIR)\fossil.tabs.js" \
"$(SRCDIR)\graph.js" \
"$(SRCDIR)\href.js" \
"$(SRCDIR)\login.js" \
"$(SRCDIR)\markdown.md" \
"$(SRCDIR)\menu.js" \
| > | 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 |
"$(SRCDIR)\forum.js" \
"$(SRCDIR)\fossil.bootstrap.js" \
"$(SRCDIR)\fossil.confirmer.js" \
"$(SRCDIR)\fossil.dom.js" \
"$(SRCDIR)\fossil.fetch.js" \
"$(SRCDIR)\fossil.page.fileedit.js" \
"$(SRCDIR)\fossil.page.forumpost.js" \
"$(SRCDIR)\fossil.page.wikiedit.js" \
"$(SRCDIR)\fossil.storage.js" \
"$(SRCDIR)\fossil.tabs.js" \
"$(SRCDIR)\graph.js" \
"$(SRCDIR)\href.js" \
"$(SRCDIR)\login.js" \
"$(SRCDIR)\markdown.md" \
"$(SRCDIR)\menu.js" \
|
| ︙ | ︙ | |||
588 589 590 591 592 593 594 595 596 597 598 599 600 601 |
"$(SRCDIR)\sounds\b.wav" \
"$(SRCDIR)\sounds\c.wav" \
"$(SRCDIR)\sounds\d.wav" \
"$(SRCDIR)\sounds\e.wav" \
"$(SRCDIR)\sounds\f.wav" \
"$(SRCDIR)\style.admin_log.css" \
"$(SRCDIR)\style.fileedit.css" \
"$(SRCDIR)\tree.js" \
"$(SRCDIR)\useredit.js" \
"$(SRCDIR)\wiki.wiki"
OBJ = "$(OX)\add$O" \
"$(OX)\ajax$O" \
"$(OX)\alerts$O" \
| > | 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 |
"$(SRCDIR)\sounds\b.wav" \
"$(SRCDIR)\sounds\c.wav" \
"$(SRCDIR)\sounds\d.wav" \
"$(SRCDIR)\sounds\e.wav" \
"$(SRCDIR)\sounds\f.wav" \
"$(SRCDIR)\style.admin_log.css" \
"$(SRCDIR)\style.fileedit.css" \
"$(SRCDIR)\style.wikiedit.css" \
"$(SRCDIR)\tree.js" \
"$(SRCDIR)\useredit.js" \
"$(SRCDIR)\wiki.wiki"
OBJ = "$(OX)\add$O" \
"$(OX)\ajax$O" \
"$(OX)\alerts$O" \
|
| ︙ | ︙ | |||
1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 | echo "$(SRCDIR)\forum.js" >> $@ echo "$(SRCDIR)\fossil.bootstrap.js" >> $@ echo "$(SRCDIR)\fossil.confirmer.js" >> $@ echo "$(SRCDIR)\fossil.dom.js" >> $@ echo "$(SRCDIR)\fossil.fetch.js" >> $@ echo "$(SRCDIR)\fossil.page.fileedit.js" >> $@ echo "$(SRCDIR)\fossil.page.forumpost.js" >> $@ echo "$(SRCDIR)\fossil.storage.js" >> $@ echo "$(SRCDIR)\fossil.tabs.js" >> $@ echo "$(SRCDIR)\graph.js" >> $@ echo "$(SRCDIR)\href.js" >> $@ echo "$(SRCDIR)\login.js" >> $@ echo "$(SRCDIR)\markdown.md" >> $@ echo "$(SRCDIR)\menu.js" >> $@ | > | 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 | echo "$(SRCDIR)\forum.js" >> $@ echo "$(SRCDIR)\fossil.bootstrap.js" >> $@ echo "$(SRCDIR)\fossil.confirmer.js" >> $@ echo "$(SRCDIR)\fossil.dom.js" >> $@ echo "$(SRCDIR)\fossil.fetch.js" >> $@ echo "$(SRCDIR)\fossil.page.fileedit.js" >> $@ echo "$(SRCDIR)\fossil.page.forumpost.js" >> $@ echo "$(SRCDIR)\fossil.page.wikiedit.js" >> $@ echo "$(SRCDIR)\fossil.storage.js" >> $@ echo "$(SRCDIR)\fossil.tabs.js" >> $@ echo "$(SRCDIR)\graph.js" >> $@ echo "$(SRCDIR)\href.js" >> $@ echo "$(SRCDIR)\login.js" >> $@ echo "$(SRCDIR)\markdown.md" >> $@ echo "$(SRCDIR)\menu.js" >> $@ |
| ︙ | ︙ | |||
1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 | echo "$(SRCDIR)\sounds/b.wav" >> $@ echo "$(SRCDIR)\sounds/c.wav" >> $@ echo "$(SRCDIR)\sounds/d.wav" >> $@ echo "$(SRCDIR)\sounds/e.wav" >> $@ echo "$(SRCDIR)\sounds/f.wav" >> $@ echo "$(SRCDIR)\style.admin_log.css" >> $@ echo "$(SRCDIR)\style.fileedit.css" >> $@ echo "$(SRCDIR)\tree.js" >> $@ echo "$(SRCDIR)\useredit.js" >> $@ echo "$(SRCDIR)\wiki.wiki" >> $@ "$(OX)\add$O" : "$(OX)\add_.c" "$(OX)\add.h" $(TCC) /Fo$@ /Fd$(@D)\ -c "$(OX)\add_.c" | > | 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 | echo "$(SRCDIR)\sounds/b.wav" >> $@ echo "$(SRCDIR)\sounds/c.wav" >> $@ echo "$(SRCDIR)\sounds/d.wav" >> $@ echo "$(SRCDIR)\sounds/e.wav" >> $@ echo "$(SRCDIR)\sounds/f.wav" >> $@ echo "$(SRCDIR)\style.admin_log.css" >> $@ echo "$(SRCDIR)\style.fileedit.css" >> $@ echo "$(SRCDIR)\style.wikiedit.css" >> $@ echo "$(SRCDIR)\tree.js" >> $@ echo "$(SRCDIR)\useredit.js" >> $@ echo "$(SRCDIR)\wiki.wiki" >> $@ "$(OX)\add$O" : "$(OX)\add_.c" "$(OX)\add.h" $(TCC) /Fo$@ /Fd$(@D)\ -c "$(OX)\add_.c" |
| ︙ | ︙ |