Fossil SCM
Add ?nojs URL flag check to the new forum JS, /forumnew, and /forumedit. In JS it supresses plugging-in of the JS and in C it suppresses the new-in-this-branch NOSCRIPT tags so that the legacy forms get rendered. We should probably remove the NOSCRIPT tag altogether and have JS remove that form if it exists, which would allow /forumnew and /forumedit to fall back gracefully, even in JS-aware browsers, without the ?nojs URL flag.
Commit
133387b19da24cb03c40ae7824f30e2570000ad1403fa9f8a6a45f6eb0ebc6ce
Parent
a15427ea99555af…
2 files changed
+5
-5
+13
-7
+5
-5
| --- src/forum.c | ||
| +++ src/forum.c | ||
| @@ -2038,11 +2038,11 @@ | ||
| 2038 | 2038 | */ |
| 2039 | 2039 | void forumnew_page(void){ |
| 2040 | 2040 | const char *zTitle = PDT("title",""); |
| 2041 | 2041 | const char *zMimetype = PD("mimetype",DEFAULT_FORUM_MIMETYPE); |
| 2042 | 2042 | const char *zContent = PDT("content",""); |
| 2043 | - const int bLegacy = PB("legacy"); /* True for legacy HTML form */ | |
| 2043 | + const int bNoJs = PB("nojs"); /* True for legacy HTML form */ | |
| 2044 | 2044 | |
| 2045 | 2045 | login_check_credentials(); |
| 2046 | 2046 | if( !g.perm.WrForum ){ |
| 2047 | 2047 | login_needed(g.anon.WrForum); |
| 2048 | 2048 | return; |
| @@ -2056,11 +2056,11 @@ | ||
| 2056 | 2056 | forum_render(zTitle, zMimetype, zContent, "forumEdit", 1); |
| 2057 | 2057 | } |
| 2058 | 2058 | style_set_current_feature("forum"); |
| 2059 | 2059 | style_header("New Forum Thread"); |
| 2060 | 2060 | |
| 2061 | - if( !bLegacy ){ | |
| 2061 | + if( !bNoJs ){ | |
| 2062 | 2062 | @ <noscript> |
| 2063 | 2063 | } |
| 2064 | 2064 | @ <form action="%R/forume1" method="POST"> |
| 2065 | 2065 | @ <h1>New Thread:</h1> |
| 2066 | 2066 | forum_from_line(); |
| @@ -2074,11 +2074,11 @@ | ||
| 2074 | 2074 | } |
| 2075 | 2075 | forum_render_debug_options(); |
| 2076 | 2076 | login_insert_csrf_secret(); |
| 2077 | 2077 | @ </form> |
| 2078 | 2078 | forum_render_attachment_notice(); |
| 2079 | - if( !bLegacy ){ | |
| 2079 | + if( !bNoJs ){ | |
| 2080 | 2080 | @ </noscript> |
| 2081 | 2081 | /* When JS is disabled the block above will work. |
| 2082 | 2082 | When it's enabled, the above won't do anything and |
| 2083 | 2083 | JS will render the editor form in the next element. */ |
| 2084 | 2084 | @ <div hidden id='forumnew-placeholder'> |
| @@ -2106,20 +2106,20 @@ | ||
| 2106 | 2106 | const char *zMimetype = 0; |
| 2107 | 2107 | const char *zContent = 0; |
| 2108 | 2108 | const char *zTitle = 0; |
| 2109 | 2109 | char *zDate = 0; |
| 2110 | 2110 | const char *zFpid = PD("fpid",""); |
| 2111 | - const int bLegacy = 1 ? 1 : PB("legacy"); /* True for legacy HTML form */ | |
| 2111 | + const int bNoJs = PB("nojs"); | |
| 2112 | 2112 | int isCsrfSafe; |
| 2113 | 2113 | int isDelete = 0; |
| 2114 | 2114 | int iClosed = 0; |
| 2115 | 2115 | int bSameUser; /* True if author is also the reader */ |
| 2116 | 2116 | int bPreview; /* True in preview mode. */ |
| 2117 | 2117 | int bPrivate; /* True if post is private (not yet moderated) */ |
| 2118 | 2118 | int bReply; /* True if replying to a post */ |
| 2119 | 2119 | |
| 2120 | - if( !bLegacy ){ | |
| 2120 | + if( !bNoJs ){ | |
| 2121 | 2121 | forumedit_page_v2(); |
| 2122 | 2122 | return; |
| 2123 | 2123 | } |
| 2124 | 2124 | |
| 2125 | 2125 | login_check_credentials(); |
| 2126 | 2126 |
| --- src/forum.c | |
| +++ src/forum.c | |
| @@ -2038,11 +2038,11 @@ | |
| 2038 | */ |
| 2039 | void forumnew_page(void){ |
| 2040 | const char *zTitle = PDT("title",""); |
| 2041 | const char *zMimetype = PD("mimetype",DEFAULT_FORUM_MIMETYPE); |
| 2042 | const char *zContent = PDT("content",""); |
| 2043 | const int bLegacy = PB("legacy"); /* True for legacy HTML form */ |
| 2044 | |
| 2045 | login_check_credentials(); |
| 2046 | if( !g.perm.WrForum ){ |
| 2047 | login_needed(g.anon.WrForum); |
| 2048 | return; |
| @@ -2056,11 +2056,11 @@ | |
| 2056 | forum_render(zTitle, zMimetype, zContent, "forumEdit", 1); |
| 2057 | } |
| 2058 | style_set_current_feature("forum"); |
| 2059 | style_header("New Forum Thread"); |
| 2060 | |
| 2061 | if( !bLegacy ){ |
| 2062 | @ <noscript> |
| 2063 | } |
| 2064 | @ <form action="%R/forume1" method="POST"> |
| 2065 | @ <h1>New Thread:</h1> |
| 2066 | forum_from_line(); |
| @@ -2074,11 +2074,11 @@ | |
| 2074 | } |
| 2075 | forum_render_debug_options(); |
| 2076 | login_insert_csrf_secret(); |
| 2077 | @ </form> |
| 2078 | forum_render_attachment_notice(); |
| 2079 | if( !bLegacy ){ |
| 2080 | @ </noscript> |
| 2081 | /* When JS is disabled the block above will work. |
| 2082 | When it's enabled, the above won't do anything and |
| 2083 | JS will render the editor form in the next element. */ |
| 2084 | @ <div hidden id='forumnew-placeholder'> |
| @@ -2106,20 +2106,20 @@ | |
| 2106 | const char *zMimetype = 0; |
| 2107 | const char *zContent = 0; |
| 2108 | const char *zTitle = 0; |
| 2109 | char *zDate = 0; |
| 2110 | const char *zFpid = PD("fpid",""); |
| 2111 | const int bLegacy = 1 ? 1 : PB("legacy"); /* True for legacy HTML form */ |
| 2112 | int isCsrfSafe; |
| 2113 | int isDelete = 0; |
| 2114 | int iClosed = 0; |
| 2115 | int bSameUser; /* True if author is also the reader */ |
| 2116 | int bPreview; /* True in preview mode. */ |
| 2117 | int bPrivate; /* True if post is private (not yet moderated) */ |
| 2118 | int bReply; /* True if replying to a post */ |
| 2119 | |
| 2120 | if( !bLegacy ){ |
| 2121 | forumedit_page_v2(); |
| 2122 | return; |
| 2123 | } |
| 2124 | |
| 2125 | login_check_credentials(); |
| 2126 |
| --- src/forum.c | |
| +++ src/forum.c | |
| @@ -2038,11 +2038,11 @@ | |
| 2038 | */ |
| 2039 | void forumnew_page(void){ |
| 2040 | const char *zTitle = PDT("title",""); |
| 2041 | const char *zMimetype = PD("mimetype",DEFAULT_FORUM_MIMETYPE); |
| 2042 | const char *zContent = PDT("content",""); |
| 2043 | const int bNoJs = PB("nojs"); /* True for legacy HTML form */ |
| 2044 | |
| 2045 | login_check_credentials(); |
| 2046 | if( !g.perm.WrForum ){ |
| 2047 | login_needed(g.anon.WrForum); |
| 2048 | return; |
| @@ -2056,11 +2056,11 @@ | |
| 2056 | forum_render(zTitle, zMimetype, zContent, "forumEdit", 1); |
| 2057 | } |
| 2058 | style_set_current_feature("forum"); |
| 2059 | style_header("New Forum Thread"); |
| 2060 | |
| 2061 | if( !bNoJs ){ |
| 2062 | @ <noscript> |
| 2063 | } |
| 2064 | @ <form action="%R/forume1" method="POST"> |
| 2065 | @ <h1>New Thread:</h1> |
| 2066 | forum_from_line(); |
| @@ -2074,11 +2074,11 @@ | |
| 2074 | } |
| 2075 | forum_render_debug_options(); |
| 2076 | login_insert_csrf_secret(); |
| 2077 | @ </form> |
| 2078 | forum_render_attachment_notice(); |
| 2079 | if( !bNoJs ){ |
| 2080 | @ </noscript> |
| 2081 | /* When JS is disabled the block above will work. |
| 2082 | When it's enabled, the above won't do anything and |
| 2083 | JS will render the editor form in the next element. */ |
| 2084 | @ <div hidden id='forumnew-placeholder'> |
| @@ -2106,20 +2106,20 @@ | |
| 2106 | const char *zMimetype = 0; |
| 2107 | const char *zContent = 0; |
| 2108 | const char *zTitle = 0; |
| 2109 | char *zDate = 0; |
| 2110 | const char *zFpid = PD("fpid",""); |
| 2111 | const int bNoJs = PB("nojs"); |
| 2112 | int isCsrfSafe; |
| 2113 | int isDelete = 0; |
| 2114 | int iClosed = 0; |
| 2115 | int bSameUser; /* True if author is also the reader */ |
| 2116 | int bPreview; /* True in preview mode. */ |
| 2117 | int bPrivate; /* True if post is private (not yet moderated) */ |
| 2118 | int bReply; /* True if replying to a post */ |
| 2119 | |
| 2120 | if( !bNoJs ){ |
| 2121 | forumedit_page_v2(); |
| 2122 | return; |
| 2123 | } |
| 2124 | |
| 2125 | login_check_credentials(); |
| 2126 |
+13
-7
| --- src/fossil.page.forumpost.js | ||
| +++ src/fossil.page.forumpost.js | ||
| @@ -989,17 +989,22 @@ | ||
| 989 | 989 | inline: 'nearest' |
| 990 | 990 | }); |
| 991 | 991 | }); |
| 992 | 992 | }; |
| 993 | 993 | |
| 994 | + const plugInEditor = | |
| 995 | + (new URL(window.location).searchParams).get('nojs')===null; | |
| 996 | + | |
| 994 | 997 | const eForumNew = ( |
| 995 | - document.body.classList.contains('cpage-forumnew') | |
| 996 | - || document.body.classList.contains('cpage-forume1') | |
| 997 | - ) | |
| 998 | + plugInEditor | |
| 999 | + && ( | |
| 1000 | + document.body.classList.contains('cpage-forumnew') | |
| 1001 | + || document.body.classList.contains('cpage-forume1') | |
| 1002 | + )) | |
| 998 | 1003 | ? document.querySelector('#forumnew-placeholder') |
| 999 | 1004 | : null; |
| 1000 | - if( eForumNew ){ | |
| 1005 | + if( plugInEditor && eForumNew ){ | |
| 1001 | 1006 | /* /forumnew and /forume2 */ |
| 1002 | 1007 | const fpe = new F.ForumPostEditor({ |
| 1003 | 1008 | draftKey: 'draft-forumnew', |
| 1004 | 1009 | hiddenFields: eForumNew.querySelectorAll('input[type=hidden]'), |
| 1005 | 1010 | ondiscard: ()=>{ |
| @@ -1011,12 +1016,13 @@ | ||
| 1011 | 1016 | }); |
| 1012 | 1017 | eForumNew.parentElement.insertBefore(fpe.widget, eForumNew); |
| 1013 | 1018 | eForumNew.remove(); |
| 1014 | 1019 | fossil.page.fpe = fpe /* for testing via the console */; |
| 1015 | 1020 | }/*eForumNew*/ |
| 1016 | - else if( (document.body.classList.contains('cpage-forumpost') | |
| 1017 | - || document.body.classList.contains('cpage-forumthread'))){ | |
| 1021 | + else if( plugInEditor | |
| 1022 | + && (document.body.classList.contains('cpage-forumpost') | |
| 1023 | + || document.body.classList.contains('cpage-forumthread')) ){ | |
| 1018 | 1024 | /* /forumpost and /forumthread. Take over the Edit/Reply buttons |
| 1019 | 1025 | to use a ForumPostEditor. */ |
| 1020 | 1026 | |
| 1021 | 1027 | const fetchPost = async (fpid)=>{ |
| 1022 | 1028 | return window.fetch(F.repoUrl('ajax/artifact.json?uuid='+fpid)) |
| @@ -1205,11 +1211,11 @@ | ||
| 1205 | 1211 | to start hidden so that it does not show up for no-JS |
| 1206 | 1212 | clients. */ |
| 1207 | 1213 | e.classList.remove('initially-hidden'); |
| 1208 | 1214 | }); |
| 1209 | 1215 | |
| 1210 | - if( Date.now() % 17 === 0 ){ | |
| 1216 | + if( plugInEditor && (Date.now() % 17 === 0) ){ | |
| 1211 | 1217 | /* Purge old drafts only every now and then. */ |
| 1212 | 1218 | F.ForumPostEditor.purgeOldDrafts(/^draft-(reply|forumedit)-.*/)/*not purging forumnew*/; |
| 1213 | 1219 | } |
| 1214 | 1220 | })/*F.onPageLoad callback*/; |
| 1215 | 1221 | })(window.fossil); |
| 1216 | 1222 |
| --- src/fossil.page.forumpost.js | |
| +++ src/fossil.page.forumpost.js | |
| @@ -989,17 +989,22 @@ | |
| 989 | inline: 'nearest' |
| 990 | }); |
| 991 | }); |
| 992 | }; |
| 993 | |
| 994 | const eForumNew = ( |
| 995 | document.body.classList.contains('cpage-forumnew') |
| 996 | || document.body.classList.contains('cpage-forume1') |
| 997 | ) |
| 998 | ? document.querySelector('#forumnew-placeholder') |
| 999 | : null; |
| 1000 | if( eForumNew ){ |
| 1001 | /* /forumnew and /forume2 */ |
| 1002 | const fpe = new F.ForumPostEditor({ |
| 1003 | draftKey: 'draft-forumnew', |
| 1004 | hiddenFields: eForumNew.querySelectorAll('input[type=hidden]'), |
| 1005 | ondiscard: ()=>{ |
| @@ -1011,12 +1016,13 @@ | |
| 1011 | }); |
| 1012 | eForumNew.parentElement.insertBefore(fpe.widget, eForumNew); |
| 1013 | eForumNew.remove(); |
| 1014 | fossil.page.fpe = fpe /* for testing via the console */; |
| 1015 | }/*eForumNew*/ |
| 1016 | else if( (document.body.classList.contains('cpage-forumpost') |
| 1017 | || document.body.classList.contains('cpage-forumthread'))){ |
| 1018 | /* /forumpost and /forumthread. Take over the Edit/Reply buttons |
| 1019 | to use a ForumPostEditor. */ |
| 1020 | |
| 1021 | const fetchPost = async (fpid)=>{ |
| 1022 | return window.fetch(F.repoUrl('ajax/artifact.json?uuid='+fpid)) |
| @@ -1205,11 +1211,11 @@ | |
| 1205 | to start hidden so that it does not show up for no-JS |
| 1206 | clients. */ |
| 1207 | e.classList.remove('initially-hidden'); |
| 1208 | }); |
| 1209 | |
| 1210 | if( Date.now() % 17 === 0 ){ |
| 1211 | /* Purge old drafts only every now and then. */ |
| 1212 | F.ForumPostEditor.purgeOldDrafts(/^draft-(reply|forumedit)-.*/)/*not purging forumnew*/; |
| 1213 | } |
| 1214 | })/*F.onPageLoad callback*/; |
| 1215 | })(window.fossil); |
| 1216 |
| --- src/fossil.page.forumpost.js | |
| +++ src/fossil.page.forumpost.js | |
| @@ -989,17 +989,22 @@ | |
| 989 | inline: 'nearest' |
| 990 | }); |
| 991 | }); |
| 992 | }; |
| 993 | |
| 994 | const plugInEditor = |
| 995 | (new URL(window.location).searchParams).get('nojs')===null; |
| 996 | |
| 997 | const eForumNew = ( |
| 998 | plugInEditor |
| 999 | && ( |
| 1000 | document.body.classList.contains('cpage-forumnew') |
| 1001 | || document.body.classList.contains('cpage-forume1') |
| 1002 | )) |
| 1003 | ? document.querySelector('#forumnew-placeholder') |
| 1004 | : null; |
| 1005 | if( plugInEditor && eForumNew ){ |
| 1006 | /* /forumnew and /forume2 */ |
| 1007 | const fpe = new F.ForumPostEditor({ |
| 1008 | draftKey: 'draft-forumnew', |
| 1009 | hiddenFields: eForumNew.querySelectorAll('input[type=hidden]'), |
| 1010 | ondiscard: ()=>{ |
| @@ -1011,12 +1016,13 @@ | |
| 1016 | }); |
| 1017 | eForumNew.parentElement.insertBefore(fpe.widget, eForumNew); |
| 1018 | eForumNew.remove(); |
| 1019 | fossil.page.fpe = fpe /* for testing via the console */; |
| 1020 | }/*eForumNew*/ |
| 1021 | else if( plugInEditor |
| 1022 | && (document.body.classList.contains('cpage-forumpost') |
| 1023 | || document.body.classList.contains('cpage-forumthread')) ){ |
| 1024 | /* /forumpost and /forumthread. Take over the Edit/Reply buttons |
| 1025 | to use a ForumPostEditor. */ |
| 1026 | |
| 1027 | const fetchPost = async (fpid)=>{ |
| 1028 | return window.fetch(F.repoUrl('ajax/artifact.json?uuid='+fpid)) |
| @@ -1205,11 +1211,11 @@ | |
| 1211 | to start hidden so that it does not show up for no-JS |
| 1212 | clients. */ |
| 1213 | e.classList.remove('initially-hidden'); |
| 1214 | }); |
| 1215 | |
| 1216 | if( plugInEditor && (Date.now() % 17 === 0) ){ |
| 1217 | /* Purge old drafts only every now and then. */ |
| 1218 | F.ForumPostEditor.purgeOldDrafts(/^draft-(reply|forumedit)-.*/)/*not purging forumnew*/; |
| 1219 | } |
| 1220 | })/*F.onPageLoad callback*/; |
| 1221 | })(window.fossil); |
| 1222 |