Fossil SCM

Added links to the wiki page's add-attachment and list-attachment pages.

stephan 2020-07-30 23:30 ajax-wiki-editor
Commit 01ab9241554e0700fff089644b2abf58852c924392c319037417ccb8c2c27004
2 files changed +35 -1 +26 -15
--- src/fossil.page.wikiedit.js
+++ src/fossil.page.wikiedit.js
@@ -423,10 +423,11 @@
423423
selectFontSizeWrap: E('#select-font-size'),
424424
// selectDiffWS: E('select[name=diff_ws]'),
425425
cbAutoPreview: E('#cb-preview-autoupdate > input[type=checkbox]'),
426426
previewTarget: E('#wikiedit-tab-preview-wrapper'),
427427
diffTarget: E('#wikiedit-tab-diff-wrapper'),
428
+ attachmentWrapper: E("#wikiedit-attachments"),
428429
tabs:{
429430
pageList: E('#wikiedit-tab-pages'),
430431
content: E('#wikiedit-tab-content'),
431432
preview: E('#wikiedit-tab-preview'),
432433
diff: E('#wikiedit-tab-diff'),
@@ -601,14 +602,15 @@
601602
P.wikiContent(winfo.content || '');
602603
WikiList.e.select.value = winfo.name;
603604
if(!winfo.version && winfo.type!=='sandbox'){
604605
F.error('You are editing a new, unsaved page:',winfo.name);
605606
}
606
- P.updatePageTitle();
607
+ P.updateAttachmentView().updatePageTitle();
607608
},
608609
false
609610
);
611
+ P.updateAttachmentView();
610612
}/*F.onPageLoad()*/);
611613
612614
/**
613615
Returns true if fossil.page.winfo is set, indicating that a page
614616
has been loaded, else it reports an error and returns false.
@@ -641,10 +643,42 @@
641643
title = title.join(' ');
642644
f.titleElement.innerText = title;
643645
f.pageTitleHeader.innerText = title;
644646
return this;
645647
};
648
+
649
+ /** Updates attachment-related links and returns this. */
650
+ P.updateAttachmentView = function(){
651
+ const wrapper = P.e.attachmentWrapper;
652
+ D.clearElement(wrapper);
653
+ const ul = D.ul();
654
+ D.append(wrapper, ul);
655
+ if(!P.winfo){
656
+ D.append(D.li(ul), "No page loaded.");
657
+ return this;
658
+ }else if(!P.winfo.version){
659
+ D.append(D.li(ul), "A new/unsaved page cannot have attachments.");
660
+ return this;
661
+ }
662
+ const wi = P.winfo;
663
+ D.append(
664
+ D.li(ul),
665
+ D.a(F.repoUrl('attachadd',{
666
+ page:wi.name,
667
+ from: F.repoUrl('wikiedit',{
668
+ name: wi.name
669
+ })
670
+ }), "Add attachments.")
671
+ );
672
+ D.append(
673
+ D.li(ul),
674
+ D.a(F.repoUrl('attachlist',{page:wi.name}),
675
+ "List attachments"),
676
+ " (if any)."
677
+ );
678
+ return this;
679
+ };
646680
647681
/**
648682
Getter (if called with no args) or setter (if passed an arg) for
649683
the current file content.
650684
651685
--- src/fossil.page.wikiedit.js
+++ src/fossil.page.wikiedit.js
@@ -423,10 +423,11 @@
423 selectFontSizeWrap: E('#select-font-size'),
424 // selectDiffWS: E('select[name=diff_ws]'),
425 cbAutoPreview: E('#cb-preview-autoupdate > input[type=checkbox]'),
426 previewTarget: E('#wikiedit-tab-preview-wrapper'),
427 diffTarget: E('#wikiedit-tab-diff-wrapper'),
 
428 tabs:{
429 pageList: E('#wikiedit-tab-pages'),
430 content: E('#wikiedit-tab-content'),
431 preview: E('#wikiedit-tab-preview'),
432 diff: E('#wikiedit-tab-diff'),
@@ -601,14 +602,15 @@
601 P.wikiContent(winfo.content || '');
602 WikiList.e.select.value = winfo.name;
603 if(!winfo.version && winfo.type!=='sandbox'){
604 F.error('You are editing a new, unsaved page:',winfo.name);
605 }
606 P.updatePageTitle();
607 },
608 false
609 );
 
610 }/*F.onPageLoad()*/);
611
612 /**
613 Returns true if fossil.page.winfo is set, indicating that a page
614 has been loaded, else it reports an error and returns false.
@@ -641,10 +643,42 @@
641 title = title.join(' ');
642 f.titleElement.innerText = title;
643 f.pageTitleHeader.innerText = title;
644 return this;
645 };
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
646
647 /**
648 Getter (if called with no args) or setter (if passed an arg) for
649 the current file content.
650
651
--- src/fossil.page.wikiedit.js
+++ src/fossil.page.wikiedit.js
@@ -423,10 +423,11 @@
423 selectFontSizeWrap: E('#select-font-size'),
424 // selectDiffWS: E('select[name=diff_ws]'),
425 cbAutoPreview: E('#cb-preview-autoupdate > input[type=checkbox]'),
426 previewTarget: E('#wikiedit-tab-preview-wrapper'),
427 diffTarget: E('#wikiedit-tab-diff-wrapper'),
428 attachmentWrapper: E("#wikiedit-attachments"),
429 tabs:{
430 pageList: E('#wikiedit-tab-pages'),
431 content: E('#wikiedit-tab-content'),
432 preview: E('#wikiedit-tab-preview'),
433 diff: E('#wikiedit-tab-diff'),
@@ -601,14 +602,15 @@
602 P.wikiContent(winfo.content || '');
603 WikiList.e.select.value = winfo.name;
604 if(!winfo.version && winfo.type!=='sandbox'){
605 F.error('You are editing a new, unsaved page:',winfo.name);
606 }
607 P.updateAttachmentView().updatePageTitle();
608 },
609 false
610 );
611 P.updateAttachmentView();
612 }/*F.onPageLoad()*/);
613
614 /**
615 Returns true if fossil.page.winfo is set, indicating that a page
616 has been loaded, else it reports an error and returns false.
@@ -641,10 +643,42 @@
643 title = title.join(' ');
644 f.titleElement.innerText = title;
645 f.pageTitleHeader.innerText = title;
646 return this;
647 };
648
649 /** Updates attachment-related links and returns this. */
650 P.updateAttachmentView = function(){
651 const wrapper = P.e.attachmentWrapper;
652 D.clearElement(wrapper);
653 const ul = D.ul();
654 D.append(wrapper, ul);
655 if(!P.winfo){
656 D.append(D.li(ul), "No page loaded.");
657 return this;
658 }else if(!P.winfo.version){
659 D.append(D.li(ul), "A new/unsaved page cannot have attachments.");
660 return this;
661 }
662 const wi = P.winfo;
663 D.append(
664 D.li(ul),
665 D.a(F.repoUrl('attachadd',{
666 page:wi.name,
667 from: F.repoUrl('wikiedit',{
668 name: wi.name
669 })
670 }), "Add attachments.")
671 );
672 D.append(
673 D.li(ul),
674 D.a(F.repoUrl('attachlist',{page:wi.name}),
675 "List attachments"),
676 " (if any)."
677 );
678 return this;
679 };
680
681 /**
682 Getter (if called with no args) or setter (if passed an arg) for
683 the current file content.
684
685
+26 -15
--- src/wiki.c
+++ src/wiki.c
@@ -803,10 +803,17 @@
803803
** ajax_route_error(). On success, an object in the form documented
804804
** for wiki_ajax_emit_page_object().
805805
**
806806
** The wikiajax API disallows saving of a sandbox pseudo-page, and
807807
** will respond with an error if asked to save one.
808
+**
809
+** Reminder: the original implementation implements sandbox-page
810
+** saving using:
811
+**
812
+** db_set("sandbox",zBody,0);
813
+** db_set("sandbox-mimetype",zMimetype,0);
814
+**
808815
*/
809816
static void wiki_ajax_route_save(void){
810817
const char *zPageName = P("page");
811818
const char *zMimetype = P("mimetype");
812819
const char *zContent = P("content");
@@ -1025,21 +1032,24 @@
10251032
}
10261033
pRoute->xCallback();
10271034
}
10281035
10291036
/*
1030
-** Main front-end for the Ajax-based wiki editor app.
1031
-**
1032
-** Optional URL arguments:
1033
-**
1034
-** name = wiki page name. Note that Ajax-based "v2" APIs use "page"
1035
-** instead because "name" has a special meaning for fossil.
1036
-**
1037
-** mimetype=fossil-standard mimetype. This is typically only passed in
1038
-** via the new-page process.
1037
+** WEBPAGE: wikiedit
1038
+** URL: /wikedit?name=PAGENAME
1039
+**
1040
+** The main front-end for the Ajax-based wiki editor app. Passing
1041
+** in the name of an unknown page will trigger the creation
1042
+** of a new page (which is not actually created in the database
1043
+** until the user explicitly saves it). If passed no page name,
1044
+** the user may select a page from the list on the first UI tab.
1045
+**
1046
+** To create a new page, pass both name=PAGENAME and
1047
+** mimetype=wiki-mime-type (one of text/x-fossil-wiki,
1048
+** text/x-markdown, or text/plain, defauling to the former).
10391049
*/
1040
-static void wikiedit_page_v2(void){
1050
+void wikiedit_page_v2(void){
10411051
const char *zPageName;
10421052
const char * zMimetype = P("mimetype");
10431053
int isSandbox;
10441054
int found = 0;
10451055
@@ -1190,10 +1200,13 @@
11901200
CX("The wiki formatting rules can be found at:");
11911201
CX("<ul>");
11921202
CX("<li><a href='%R/wiki_rules'>Fossil wiki format</a></li>");
11931203
CX("<li><a href='%R/md_rules'>Markdown format</a></li>");
11941204
CX("</ul>");
1205
+ CX("<hr>Attachments:");
1206
+ CX("<div id='wikiedit-attachments'></div>"
1207
+ /* Filled out by JS */);
11951208
CX("</div>");
11961209
}
11971210
11981211
style_emit_script_fossil_bootstrap(0);
11991212
append_diff_javascript(1);
@@ -1236,14 +1249,12 @@
12361249
style_emit_script_tag(1,0);
12371250
style_footer();
12381251
}
12391252
12401253
/*
1241
-** WEBPAGE: wikiedit
1242
-** URL: /wikiedit?name=PAGENAME
1243
-**
1244
-** Edit a wiki page.
1254
+** Legacy /wikiedit implementation, kept around solely for comparison
1255
+** while implementing v2.
12451256
*/
12461257
void wikiedit_page(void){
12471258
char *zTag;
12481259
int rid = 0;
12491260
int isSandbox;
@@ -2060,11 +2071,11 @@
20602071
** -M|--mimetype TEXT-FORMAT The mime type of the update.
20612072
** Defaults to the type used by
20622073
** the previous version of the
20632074
** page, or text/x-fossil-wiki.
20642075
** Valid values are: text/x-fossil-wiki,
2065
-** text/markdown and text/plain. fossil,
2076
+** text/x-markdown and text/plain. fossil,
20662077
** markdown or plain can be specified as
20672078
** synonyms of these values.
20682079
** -t|--technote DATETIME Specifies the timestamp of
20692080
** the technote to be created or
20702081
** updated. When updating a tech note
20712082
--- src/wiki.c
+++ src/wiki.c
@@ -803,10 +803,17 @@
803 ** ajax_route_error(). On success, an object in the form documented
804 ** for wiki_ajax_emit_page_object().
805 **
806 ** The wikiajax API disallows saving of a sandbox pseudo-page, and
807 ** will respond with an error if asked to save one.
 
 
 
 
 
 
 
808 */
809 static void wiki_ajax_route_save(void){
810 const char *zPageName = P("page");
811 const char *zMimetype = P("mimetype");
812 const char *zContent = P("content");
@@ -1025,21 +1032,24 @@
1025 }
1026 pRoute->xCallback();
1027 }
1028
1029 /*
1030 ** Main front-end for the Ajax-based wiki editor app.
1031 **
1032 ** Optional URL arguments:
1033 **
1034 ** name = wiki page name. Note that Ajax-based "v2" APIs use "page"
1035 ** instead because "name" has a special meaning for fossil.
1036 **
1037 ** mimetype=fossil-standard mimetype. This is typically only passed in
1038 ** via the new-page process.
 
 
 
1039 */
1040 static void wikiedit_page_v2(void){
1041 const char *zPageName;
1042 const char * zMimetype = P("mimetype");
1043 int isSandbox;
1044 int found = 0;
1045
@@ -1190,10 +1200,13 @@
1190 CX("The wiki formatting rules can be found at:");
1191 CX("<ul>");
1192 CX("<li><a href='%R/wiki_rules'>Fossil wiki format</a></li>");
1193 CX("<li><a href='%R/md_rules'>Markdown format</a></li>");
1194 CX("</ul>");
 
 
 
1195 CX("</div>");
1196 }
1197
1198 style_emit_script_fossil_bootstrap(0);
1199 append_diff_javascript(1);
@@ -1236,14 +1249,12 @@
1236 style_emit_script_tag(1,0);
1237 style_footer();
1238 }
1239
1240 /*
1241 ** WEBPAGE: wikiedit
1242 ** URL: /wikiedit?name=PAGENAME
1243 **
1244 ** Edit a wiki page.
1245 */
1246 void wikiedit_page(void){
1247 char *zTag;
1248 int rid = 0;
1249 int isSandbox;
@@ -2060,11 +2071,11 @@
2060 ** -M|--mimetype TEXT-FORMAT The mime type of the update.
2061 ** Defaults to the type used by
2062 ** the previous version of the
2063 ** page, or text/x-fossil-wiki.
2064 ** Valid values are: text/x-fossil-wiki,
2065 ** text/markdown and text/plain. fossil,
2066 ** markdown or plain can be specified as
2067 ** synonyms of these values.
2068 ** -t|--technote DATETIME Specifies the timestamp of
2069 ** the technote to be created or
2070 ** updated. When updating a tech note
2071
--- src/wiki.c
+++ src/wiki.c
@@ -803,10 +803,17 @@
803 ** ajax_route_error(). On success, an object in the form documented
804 ** for wiki_ajax_emit_page_object().
805 **
806 ** The wikiajax API disallows saving of a sandbox pseudo-page, and
807 ** will respond with an error if asked to save one.
808 **
809 ** Reminder: the original implementation implements sandbox-page
810 ** saving using:
811 **
812 ** db_set("sandbox",zBody,0);
813 ** db_set("sandbox-mimetype",zMimetype,0);
814 **
815 */
816 static void wiki_ajax_route_save(void){
817 const char *zPageName = P("page");
818 const char *zMimetype = P("mimetype");
819 const char *zContent = P("content");
@@ -1025,21 +1032,24 @@
1032 }
1033 pRoute->xCallback();
1034 }
1035
1036 /*
1037 ** WEBPAGE: wikiedit
1038 ** URL: /wikedit?name=PAGENAME
1039 **
1040 ** The main front-end for the Ajax-based wiki editor app. Passing
1041 ** in the name of an unknown page will trigger the creation
1042 ** of a new page (which is not actually created in the database
1043 ** until the user explicitly saves it). If passed no page name,
1044 ** the user may select a page from the list on the first UI tab.
1045 **
1046 ** To create a new page, pass both name=PAGENAME and
1047 ** mimetype=wiki-mime-type (one of text/x-fossil-wiki,
1048 ** text/x-markdown, or text/plain, defauling to the former).
1049 */
1050 void wikiedit_page_v2(void){
1051 const char *zPageName;
1052 const char * zMimetype = P("mimetype");
1053 int isSandbox;
1054 int found = 0;
1055
@@ -1190,10 +1200,13 @@
1200 CX("The wiki formatting rules can be found at:");
1201 CX("<ul>");
1202 CX("<li><a href='%R/wiki_rules'>Fossil wiki format</a></li>");
1203 CX("<li><a href='%R/md_rules'>Markdown format</a></li>");
1204 CX("</ul>");
1205 CX("<hr>Attachments:");
1206 CX("<div id='wikiedit-attachments'></div>"
1207 /* Filled out by JS */);
1208 CX("</div>");
1209 }
1210
1211 style_emit_script_fossil_bootstrap(0);
1212 append_diff_javascript(1);
@@ -1236,14 +1249,12 @@
1249 style_emit_script_tag(1,0);
1250 style_footer();
1251 }
1252
1253 /*
1254 ** Legacy /wikiedit implementation, kept around solely for comparison
1255 ** while implementing v2.
 
 
1256 */
1257 void wikiedit_page(void){
1258 char *zTag;
1259 int rid = 0;
1260 int isSandbox;
@@ -2060,11 +2071,11 @@
2071 ** -M|--mimetype TEXT-FORMAT The mime type of the update.
2072 ** Defaults to the type used by
2073 ** the previous version of the
2074 ** page, or text/x-fossil-wiki.
2075 ** Valid values are: text/x-fossil-wiki,
2076 ** text/x-markdown and text/plain. fossil,
2077 ** markdown or plain can be specified as
2078 ** synonyms of these values.
2079 ** -t|--technote DATETIME Specifies the timestamp of
2080 ** the technote to be created or
2081 ** updated. When updating a tech note
2082

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button