Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | Further improvements to webpage_error() and webpage_assert(). Fix forum processing so that moderator approval and disapproval work. Add the "Delete" feature to forum that simply nulls out the page using an edit. |
---|---|
Downloads: | Tarball | ZIP archive |
Timelines: | family | ancestors | descendants | both | forum-v2 |
Files: | files | file ages | folders |
SHA3-256: |
32bbb9a9fc6ee546042859c663465093 |
User & Date: | drh 2018-07-25 17:53:13.493 |
Context
2018-07-25
| ||
19:00 | Improved timeline messages for forum events. ... (check-in: e9b13d68 user: drh tags: forum-v2) | |
17:53 | Further improvements to webpage_error() and webpage_assert(). Fix forum processing so that moderator approval and disapproval work. Add the "Delete" feature to forum that simply nulls out the page using an edit. ... (check-in: 32bbb9a9 user: drh tags: forum-v2) | |
16:10 | Add the website_assert() macro. Fixes to forum post editing. ... (check-in: e67efdd7 user: drh tags: forum-v2) | |
Changes
Changes to src/forum.c.
︙ | ︙ | |||
124 125 126 127 128 129 130 | int froot; const char *zName = P("name"); login_check_credentials(); if( !g.perm.RdForum ){ login_needed(g.anon.RdForum); return; } | < | < < | < < < > | < < < > | > > | 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 | int froot; const char *zName = P("name"); login_check_credentials(); if( !g.perm.RdForum ){ login_needed(g.anon.RdForum); return; } if( zName==0 ){ webpage_error("Missing \"name=\" query parameter"); } fpid = symbolic_name_to_rid(zName, "f"); if( fpid<=0 ){ webpage_error("Unknown or ambiguous forum id: \"%s\"", zName); } style_header("Forum"); froot = db_int(0, "SELECT froot FROM forumpost WHERE fpid=%d", fpid); if( froot==0 ){ webpage_error("Not a forum post: \"%s\"", zName); } forum_thread_chronological(froot); style_footer(); } /* ** Return true if a forum post should be moderated. */ static int forum_need_moderation(void){ if( P("domod") ) return 1; if( g.perm.WrTForum ) return 0; if( g.perm.ModForum ) return 0; return 1; } /* ** Add a new Forum Post artifact to the repository. ** ** Return true if a redirect occurs. */ |
︙ | ︙ | |||
233 234 235 236 237 238 239 | blob_init(&formatCheck, 0, 0); blob_init(&errMsg, 0, 0); blob_copy(&formatCheck, &x); pPost = manifest_parse(&formatCheck, 0, &errMsg); if( pPost==0 ){ webpage_error("malformed forum post artifact - %s", blob_str(&errMsg)); } | | < < | 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 | blob_init(&formatCheck, 0, 0); blob_init(&errMsg, 0, 0); blob_copy(&formatCheck, &x); pPost = manifest_parse(&formatCheck, 0, &errMsg); if( pPost==0 ){ webpage_error("malformed forum post artifact - %s", blob_str(&errMsg)); } webpage_assert( pPost->type==CFTYPE_FORUM ); manifest_destroy(pPost); if( P("dryrun") ){ @ <div class='debug'> @ This is the artifact that would have been generated: @ <pre>%h(blob_str(&x))</pre> @ </div> |
︙ | ︙ | |||
328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 | */ void forumedit_page(void){ int fpid; Manifest *pPost; const char *zMimetype = 0; const char *zContent = 0; const char *zTitle = 0; login_check_credentials(); if( !g.perm.WrForum ){ login_needed(g.anon.WrForum); return; } fpid = symbolic_name_to_rid(PD("fpid",""), "f"); if( fpid<=0 || (pPost = manifest_get(fpid, CFTYPE_FORUM, 0))==0 ){ webpage_error("Missing or invalid fpid query parameter"); } | > > > > > > > | < > > | > > | | > > > > > > > > > > > > > > > > | | < > > | > > | | 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 | */ void forumedit_page(void){ int fpid; Manifest *pPost; const char *zMimetype = 0; const char *zContent = 0; const char *zTitle = 0; int isCsrfSafe; int isDelete = 0; login_check_credentials(); if( !g.perm.WrForum ){ login_needed(g.anon.WrForum); return; } fpid = symbolic_name_to_rid(PD("fpid",""), "f"); if( fpid<=0 || (pPost = manifest_get(fpid, CFTYPE_FORUM, 0))==0 ){ webpage_error("Missing or invalid fpid query parameter"); } if( P("cancel") ){ cgi_redirectf("%R/forumthread/%S",P("fpid")); return; } isCsrfSafe = cgi_csrf_safe(1); if( g.perm.ModForum && isCsrfSafe ){ if( P("approve") ){ moderation_approve(fpid); cgi_redirectf("%R/forumthread/%S",P("fpid")); return; } if( P("reject") ){ moderation_disapprove(fpid); cgi_redirectf("%R/forumthread/%S",P("fpid")); return; } } isDelete = P("nullout")!=0; if( P("submit") && isCsrfSafe ){ int done = 1; const char *zMimetype = PD("mimetype","text/x-fossil-wiki"); const char *zContent = PDT("content",""); if( P("reply") ){ done = forum_post(0, fpid, 0, 0, zMimetype, zContent); }else if( P("edit") || isDelete ){ done = forum_post(P("title"), 0, fpid, 0, zMimetype, zContent); }else{ webpage_error("Missing 'reply' query parameter"); } if( done ) return; } if( isDelete ){ zMimetype = "text/x-fossil-wiki"; zContent = "<i>Deleted</i>"; if( pPost->zThreadTitle ) zTitle = "<i>Deleted</i>"; @ <h1>Original Post:</h1> forum_render(pPost->zThreadTitle, pPost->zMimetype, pPost->zWiki); @ <h1>Change Into:</h1> forum_render(zTitle, zMimetype, zContent); @ <form action="%R/forumedit" method="POST"> @ <input type="hidden" name="fpid" value="%h(P("fpid"))"> @ <input type="hidden" name="nullout" value="1"> @ <input type="hidden" name="mimetype" value="%h(zMimetype)"> @ <input type="hidden" name="content" value="%h(zContent)"> if( zTitle ){ @ <input type="hidden" name="title" value="%h(zTitle)"> } }else if( P("edit") ){ /* Provide an edit to the fpid post */ zMimetype = P("mimetype"); zContent = PT("content"); zTitle = P("title"); if( zContent==0 ) zContent = fossil_strdup(pPost->zWiki); if( zMimetype==0 ) zMimetype = fossil_strdup(pPost->zMimetype); if( zTitle==0 && pPost->zThreadTitle!=0 ){ zTitle = fossil_strdup(pPost->zThreadTitle); } style_header("Edit Forum Post"); @ <h1>Original Post:</h1> forum_render(pPost->zThreadTitle, pPost->zMimetype, pPost->zWiki); if( P("preview") ){ @ <h1>Preview Of Editted Post:</h1> forum_render(zTitle, zMimetype, zContent); } @ <h1>Enter A Reply:</h1> @ <form action="%R/forumedit" method="POST"> @ <input type="hidden" name="fpid" value="%h(P("fpid"))"> @ <input type="hidden" name="edit" value="1"> forum_entry_widget(zTitle, zMimetype, zContent); }else{ /* Reply */ zMimetype = PD("mimetype","text/x-fossil-wiki"); zContent = PDT("content",""); style_header("Forum Reply"); @ <h1>Replying To:</h1> forum_render(0, pPost->zMimetype, pPost->zWiki); if( P("preview") ){ @ <h1>Preview:</h1> forum_render(0, zMimetype,zContent); } @ <h1>Enter A Reply:</h1> @ <form action="%R/forumedit" method="POST"> @ <input type="hidden" name="fpid" value="%h(P("fpid"))"> @ <input type="hidden" name="reply" value="1"> forum_entry_widget(0, zMimetype, zContent); } if( !isDelete ){ @ <input type="submit" name="preview" value="Preview"> } @ <input type="submit" name="cancel" value="Cancel"> if( P("preview") || isDelete ){ @ <input type="submit" name="submit" value="Submit"> } if( g.perm.Debug ){ /* For the test-forumnew page add these extra debugging controls */ @ <div class="debug"> @ <label><input type="checkbox" name="dryrun" %s(PCK("dryrun"))> \ @ Dry run</label> |
︙ | ︙ |
Changes to src/main.c.
︙ | ︙ | |||
2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 | ** the administrator only. ** ** case=1 Issue a fossil_warning() while generating the page. ** case=2 Extra db_begin_transaction() ** case=3 Extra db_end_transaction() ** case=4 Error during SQL processing ** case=5 Call the segfault handler */ void test_warning_page(void){ int iCase = atoi(PD("case","0")); int i; login_check_credentials(); if( !g.perm.Setup && !g.perm.Admin ){ login_needed(0); return; } style_header("Warning Test Page"); style_submenu_element("Error Log","%R/errorlog"); if( iCase<1 || iCase>4 ){ @ <p>Generate a message to the <a href="%R/errorlog">error log</a> @ by clicking on one of the following cases: }else{ @ <p>This is the test page for case=%d(iCase). All possible cases: } | > > | | 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 | ** the administrator only. ** ** case=1 Issue a fossil_warning() while generating the page. ** case=2 Extra db_begin_transaction() ** case=3 Extra db_end_transaction() ** case=4 Error during SQL processing ** case=5 Call the segfault handler ** case=6 Call webpage_assert() ** case=7 Call webpage_error() */ void test_warning_page(void){ int iCase = atoi(PD("case","0")); int i; login_check_credentials(); if( !g.perm.Setup && !g.perm.Admin ){ login_needed(0); return; } style_header("Warning Test Page"); style_submenu_element("Error Log","%R/errorlog"); if( iCase<1 || iCase>4 ){ @ <p>Generate a message to the <a href="%R/errorlog">error log</a> @ by clicking on one of the following cases: }else{ @ <p>This is the test page for case=%d(iCase). All possible cases: } for(i=1; i<=7; i++){ @ <a href='./test-warning?case=%d(i)'>[%d(i)]</a> } @ </p> @ <p><ol> @ <li value='1'> Call fossil_warning() if( iCase==1 ){ fossil_warning("Test warning message from /test-warning"); |
︙ | ︙ | |||
2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 | sqlite3_log(SQLITE_ERROR, "Test warning message during SQL"); db_finalize(&q); } @ <li value='5'> simulate segfault handling if( iCase==5 ){ sigsegv_handler(0); } @ </ol> @ <p>End of test</p> style_footer(); } | > > > > > > > > > | 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 | sqlite3_log(SQLITE_ERROR, "Test warning message during SQL"); db_finalize(&q); } @ <li value='5'> simulate segfault handling if( iCase==5 ){ sigsegv_handler(0); } @ <li value='6'> call webpage_assert(0) if( iCase==6 ){ webpage_assert( 5==7 ); } @ <li value='7'> call webpage_error()" if( iCase==7 ){ cgi_reset_content(); webpage_error("Case 7 from /test-warning"); } @ </ol> @ <p>End of test</p> style_footer(); } |
Changes to src/moderate.c.
︙ | ︙ | |||
99 100 101 102 103 104 105 106 107 108 109 110 111 112 | "DELETE FROM delta WHERE rid=%d;" "DELETE FROM event WHERE objid=%d;" "DELETE FROM tagxref WHERE rid=%d;" "DELETE FROM private WHERE rid=%d;" "DELETE FROM attachment WHERE attachid=%d;", rid, rid, rid, rid, rid, rid ); zTktid = db_text(0, "SELECT tktid FROM modreq WHERE objid=%d", rid); if( zTktid && zTktid[0] ){ ticket_rebuild_entry(zTktid); fossil_free(zTktid); } attachRid = db_int(0, "SELECT attachRid FROM modreq WHERE objid=%d", rid); if( rid==objid ){ | > > > | 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 | "DELETE FROM delta WHERE rid=%d;" "DELETE FROM event WHERE objid=%d;" "DELETE FROM tagxref WHERE rid=%d;" "DELETE FROM private WHERE rid=%d;" "DELETE FROM attachment WHERE attachid=%d;", rid, rid, rid, rid, rid, rid ); if( db_table_exists("repository","forumpost") ){ db_multi_exec("DELETE FROM forumpost WHERE fpid=%d", rid); } zTktid = db_text(0, "SELECT tktid FROM modreq WHERE objid=%d", rid); if( zTktid && zTktid[0] ){ ticket_rebuild_entry(zTktid); fossil_free(zTktid); } attachRid = db_int(0, "SELECT attachRid FROM modreq WHERE objid=%d", rid); if( rid==objid ){ |
︙ | ︙ |
Changes to src/style.c.
︙ | ︙ | |||
968 969 970 971 972 973 974 975 976 977 978 979 980 981 | va_list ap; va_start(ap, zFormat); zErr = vmprintf(zFormat, ap); va_end(ap); style_header("Bad Request"); @ <h1>/%h(g.zPath): %h(zErr)</h1> showAll = 0; }else if( !isAuth ){ login_needed(0); return; }else{ style_header("Environment Test"); showAll = PB("showall"); style_submenu_checkbox("showall", "Cookies", 0, 0); | > | 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 | va_list ap; va_start(ap, zFormat); zErr = vmprintf(zFormat, ap); va_end(ap); style_header("Bad Request"); @ <h1>/%h(g.zPath): %h(zErr)</h1> showAll = 0; cgi_set_status(500, "Bad Request"); }else if( !isAuth ){ login_needed(0); return; }else{ style_header("Environment Test"); showAll = PB("showall"); style_submenu_checkbox("showall", "Cookies", 0, 0); |
︙ | ︙ | |||
1014 1015 1016 1017 1018 1019 1020 | @ <pre> @ %h(blob_str(&g.httpHeader)) @ </pre> } } style_footer(); if( zErr ){ | > | > > > > > > > > > | < | 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 | @ <pre> @ %h(blob_str(&g.httpHeader)) @ </pre> } } style_footer(); if( zErr ){ cgi_reply(); fossil_exit(1); } } /* ** Generate a Not Yet Implemented error page. */ void webpage_not_yet_implemented(void){ webpage_error("Not yet implemented"); } /* ** Generate a webpage for a webpage_assert(). */ void webpage_assert_page(const char *zFile, int iLine, const char *zExpr){ fossil_warning("assertion fault at %s:%d - %s", zFile, iLine, zExpr); cgi_reset_content(); webpage_error("assertion fault at %s:%d - %s", zFile, iLine, zExpr); } #if INTERFACE # define webpage_assert(T) if(!(T)){webpage_assert_page(__FILE__,__LINE__,#T);} #endif |