Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | Progress toward getting the forum to actually work. This is an incremental check-in. |
---|---|
Downloads: | Tarball | ZIP archive |
Timelines: | family | ancestors | descendants | both | forum-brainstorm-1 |
Files: | files | file ages | folders |
SHA3-256: |
4814c41a9a9be4044fc96f88e9635f28 |
User & Date: | drh 2018-06-16 13:36:39.396 |
Context
2018-06-16
| ||
15:08 | Fix minor issues with Forum editing. ... (check-in: c626d1c0 user: drh tags: forum-brainstorm-1) | |
13:36 | Progress toward getting the forum to actually work. This is an incremental check-in. ... (check-in: 4814c41a user: drh tags: forum-brainstorm-1) | |
2018-06-15
| ||
20:48 | Rough and untested implementation for forum display and reply. Add two new capabilities for posting to the forum not subject to moderation, and for the ability to edit posts from others. ... (check-in: f8927901 user: drh tags: forum-brainstorm-1) | |
Changes
Changes to src/cgi.c.
︙ | ︙ | |||
1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 | */ char *cgi_parameter_trimmed(const char *zName, const char *zDefault){ const char *zIn; char *zOut; int i; zIn = cgi_parameter(zName, 0); if( zIn==0 ) zIn = zDefault; while( fossil_isspace(zIn[0]) ) zIn++; zOut = fossil_strdup(zIn); for(i=0; zOut[i]; i++){} while( i>0 && fossil_isspace(zOut[i-1]) ) zOut[--i] = 0; return zOut; } | > | 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 | */ char *cgi_parameter_trimmed(const char *zName, const char *zDefault){ const char *zIn; char *zOut; int i; zIn = cgi_parameter(zName, 0); if( zIn==0 ) zIn = zDefault; if( zIn==0 ) return 0; while( fossil_isspace(zIn[0]) ) zIn++; zOut = fossil_strdup(zIn); for(i=0; zOut[i]; i++){} while( i>0 && fossil_isspace(zOut[i-1]) ) zOut[--i] = 0; return zOut; } |
︙ | ︙ | |||
1179 1180 1181 1182 1183 1184 1185 | /* ** Print all query parameters on standard output. Format the ** parameters as HTML. This is used for testing and debugging. ** ** Omit the values of the cookies unless showAll is true. */ | | > > > | > | 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 | /* ** Print all query parameters on standard output. Format the ** parameters as HTML. This is used for testing and debugging. ** ** Omit the values of the cookies unless showAll is true. */ void cgi_print_all(int showAll, int onConsole){ int i; cgi_parameter("",""); /* Force the parameters into sorted order */ for(i=0; i<nUsedQP; i++){ const char *zName = aParamQP[i].zName; if( !showAll ){ if( fossil_stricmp("HTTP_COOKIE",zName)==0 ) continue; if( fossil_strnicmp("fossil-",zName,7)==0 ) continue; } if( onConsole ){ fossil_trace("%s = %s\n", zName, aParamQP[i].zValue); }else{ cgi_printf("%h = %h <br />\n", zName, aParamQP[i].zValue); } } } /* ** Export all untagged query parameters (but not cookies or environment ** variables) as hidden values of a form. */ |
︙ | ︙ |
Changes to src/db.c.
︙ | ︙ | |||
270 271 272 273 274 275 276 | va_end(ap); zSql = blob_str(&pStmt->sql); db.nPrepare++; if( flags & DB_PREPARE_PERSISTENT ){ prepFlags = SQLITE_PREPARE_PERSISTENT; } rc = sqlite3_prepare_v3(g.db, zSql, -1, prepFlags, &pStmt->pStmt, 0); | | | 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 | va_end(ap); zSql = blob_str(&pStmt->sql); db.nPrepare++; if( flags & DB_PREPARE_PERSISTENT ){ prepFlags = SQLITE_PREPARE_PERSISTENT; } rc = sqlite3_prepare_v3(g.db, zSql, -1, prepFlags, &pStmt->pStmt, 0); if( rc!=0 && (flags & DB_PREPARE_IGNORE_ERROR)==0 ){ db_err("%s\n%s", sqlite3_errmsg(g.db), zSql); } pStmt->pNext = pStmt->pPrev = 0; pStmt->nStep = 0; pStmt->rc = rc; return rc; } |
︙ | ︙ |
Changes to src/default_css.txt.
︙ | ︙ | |||
629 630 631 632 633 634 635 | display: none; } table.label-value th { vertical-align: top; text-align: right; padding: 0.2ex 1ex; } | > > > > > > > > > > > > > > > > > > > > > > > > | 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 | display: none; } table.label-value th { vertical-align: top; text-align: right; padding: 0.2ex 1ex; } table.forum_post { top-margin: 1ex; bottom-margin: 1ex; left-margin: 0; right-margin: 0; border-spacing: 0; } span.forum_author { color: #888; } span.forum_age { color: #888; font-size: 75%; } span.forum_buttons { font-size: 75%; } span.forum_npost { color: #888; font-size: 75%; } table.forumeditform td { vertical-align: top; } |
Changes to src/forum.c.
︙ | ︙ | |||
74 75 76 77 78 79 80 81 82 83 84 85 86 | login_check_credentials(); if( !g.perm.RdForum ){ login_needed(g.anon.RdForum); return; } forum_verify_schema(); style_header("Forum"); itemId = atoi(PD("item","0")); if( itemId>0 ){ double rNow = db_double(0.0, "SELECT julianday('now')"); /* Show the post given by itemId and all its descendents */ db_prepare(&q, "WITH RECURSIVE" " post(id,uname,mstat,mime,ipaddr,parent,mbody,depth,mtime) AS (" " SELECT mpostid, uname, mstatus, mimetype, ipaddr, inreplyto, mbody," | > > > > > > | | < > | | < | < < | < < > > | < > > > > > | > | | | | | | | 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 | login_check_credentials(); if( !g.perm.RdForum ){ login_needed(g.anon.RdForum); return; } forum_verify_schema(); style_header("Forum"); itemId = atoi(PD("item","0")); if( itemId>0 ){ int iUp; style_submenu_element("Topics", "%R/forum"); iUp = db_int(0, "SELECT inreplyto FROM forumpost WHERE mpostid=%d", itemId); if( iUp ){ style_submenu_element("Parent", "%R/forum?item=%d", iUp); } double rNow = db_double(0.0, "SELECT julianday('now')"); /* Show the post given by itemId and all its descendents */ db_prepare(&q, "WITH RECURSIVE" " post(id,uname,mstat,mime,ipaddr,parent,mbody,depth,mtime) AS (" " SELECT mpostid, uname, mstatus, mimetype, ipaddr, inreplyto, mbody," " 0, mtime FROM forumpost WHERE mpostid=%d" " UNION" " SELECT f.mpostid, f.uname, f.mstatus, f.mimetype, f.ipaddr," " f.inreplyto, f.mbody, p.depth+1 AS xdepth, f.mtime AS xtime" " FROM forumpost AS f, post AS p" " WHERE f.inreplyto=p.id" " ORDER BY xdepth DESC, xtime ASC" ") SELECT * FROM post;", itemId ); while( db_step(&q)==SQLITE_ROW ){ int id = db_column_int(&q, 0); const char *zUser = db_column_text(&q, 1); const char *zStat = db_column_text(&q, 2); const char *zMime = db_column_text(&q, 3); const char *zIp = db_column_text(&q, 4); int iDepth = db_column_int(&q, 7); double rMTime = db_column_double(&q, 8); char *zAge = db_timespan_name(rNow - rMTime); Blob body; @ <!-- Forum post %d(id) --> @ <table class="forum_post"> @ <tr> @ <td class="forum_margin" width="%d(iDepth*25)" rowspan="2"> @ <td><span class="forum_author">%h(zUser)</span> @ <span class="forum_age">%s(zAge) ago</span> sqlite3_free(zAge); if( g.perm.WrForum ){ @ <span class="forum_buttons"> if( g.perm.AdminForum || fossil_strcmp(g.zLogin, zUser)==0 ){ @ <a href='%R/forumedit?item=%d(id)'>Edit</a> } @ <a href='%R/forumedit?replyto=%d(id)'>Reply</a> @ </span> } @ </tr> @ <tr><td><div class="forum_body"> blob_init(&body, db_column_text(&q,6), db_column_bytes(&q,6)); wiki_render_by_mimetype(&body, zMime); blob_reset(&body); @ </div></td></tr> @ </table> } }else{ /* If we reach this point, that means the users wants a list of ** recent threads. */ i = 0; db_prepare(&q, "SELECT a.mtitle, a.npost, b.mpostid" " FROM forumthread AS a, forumpost AS b " " WHERE a.mthreadid=b.mthreadid" " AND b.inreplyto IS NULL" " ORDER BY a.mtime DESC LIMIT 40" ); if( g.perm.WrForum ){ style_submenu_element("New", "%R/forumedit"); } @ <h1>Recent Forum Threads</h1> while( db_step(&q)==SQLITE_ROW ){ int n = db_column_int(&q,1); int itemid = db_column_int(&q,2); const char *zTitle = db_column_text(&q,0); if( (i++)==0 ){ @ <ol> } @ <li><span class="forum_title"> @ %z(href("%R/forum?item=%d",itemid))%h(zTitle)</a></span> @ <span class="forum_npost">%d(n) post%s(n==1?"":"s")</span></li> } if( i ){ @ </ol> } } style_footer(); } |
︙ | ︙ | |||
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 | ** itemId==0 && parentId>0 New reply to parentId ** itemId>0 && parentId==0 Edit existing post itemId */ static int forum_post(int itemId, int parentId, char **pzErr){ const char *zSubject = 0; int threadId; double rNow = db_double(0.0, "SELECT julianday('now')"); if( itemId==0 && parentId==0 ){ /* Start a new thread. Subject required. */ sqlite3_uint64 r1, r2; zSubject = PT("s"); if( zSubject==0 || zSubject[0]==0 ){ *pzErr = "\"Subject\" required to start a new thread"; return 0; } sqlite3_randomness(sizeof(r1), &r1); sqlite3_randomness(sizeof(r2), &r2); db_multi_exec( "INSERT INTO forumthread(mthreadhash, mtitle, mtime, npost)" "VALUES(lower(hex(randomblob(32))),%Q,%!.17g,1)", zSubject, rNow ); threadId = db_last_insert_rowid(); } if( itemId ){ db_multi_exec( "UPDATE forumpost SET" " mtime=%!.17g," " mimetype=%Q," " ipaddr=%Q," " mbody=%Q" " WHERE mpostid=%d", rNow, PT("m"), P("REMOTE_ADDR"), PT("b"), itemId ); }else{ db_multi_exec( "INSERT INTO forumpost(mposthash,mthreadid,uname,mtime," " mstatus,mimetype,ipaddr,inreplyto,mbody) VALUES" | > > > > > > > > > > > | | | | | > > > > > > | > > > > > | > > > > > | > > > > > > > > | > > > > > > > > > > > > > > | 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 | ** itemId==0 && parentId>0 New reply to parentId ** itemId>0 && parentId==0 Edit existing post itemId */ static int forum_post(int itemId, int parentId, char **pzErr){ const char *zSubject = 0; int threadId; double rNow = db_double(0.0, "SELECT julianday('now')"); const char *zMime = wiki_filter_mimetypes(P("m")); if( itemId==0 && parentId==0 ){ /* Start a new thread. Subject required. */ sqlite3_uint64 r1, r2; zSubject = PT("s"); if( zSubject==0 || zSubject[0]==0 ){ *pzErr = "\"Subject\" required to start a new thread"; return 0; } sqlite3_randomness(sizeof(r1), &r1); sqlite3_randomness(sizeof(r2), &r2); db_multi_exec( "INSERT INTO forumthread(mthreadhash, mtitle, mtime, npost)" "VALUES(lower(hex(randomblob(32))),%Q,%!.17g,1)", zSubject, rNow ); threadId = db_last_insert_rowid(); }else{ threadId = db_int(0, "SELECT mthreadid FROM forumpost" " WHERE mpostid=%d", itemId ? itemId : parentId); } if( itemId ){ if( db_int(0, "SELECT inreplyto IS NULL FROM forumpost" " WHERE mpostid=%d", itemId) ){ db_multi_exec( "UPDATE forumthread SET mtitle=%Q WHERE mthreadid=%d", PT("s"), threadId ); } db_multi_exec( "UPDATE forumpost SET" " mtime=%!.17g," " mimetype=%Q," " ipaddr=%Q," " mbody=%Q" " WHERE mpostid=%d", rNow, PT("m"), P("REMOTE_ADDR"), PT("b"), itemId ); }else{ db_multi_exec( "INSERT INTO forumpost(mposthash,mthreadid,uname,mtime," " mstatus,mimetype,ipaddr,inreplyto,mbody) VALUES" " (lower(hex(randomblob(32))),%d,%Q,%!.17g,%Q,%Q,%Q,nullif(%d,0),%Q)", threadId,g.zLogin,rNow,NULL,zMime,P("REMOTE_ADDR"),parentId,P("b")); itemId = db_last_insert_rowid(); } if( zSubject==0 ){ db_multi_exec( "UPDATE forumthread SET mtime=%!.17g, npost=npost+1" " WHERE mthreadid=(SELECT mthreadid FROM forumpost WHERE mpostid=%d)", rNow, itemId ); } return itemId; } /* ** WEBPAGE: forumedit ** ** Query parameters: ** ** replyto=N Enter a reply to forum item N ** item=N Edit item N ** s=SUBJECT Subject. New thread only. Omitted for replies ** b=BODY Body of the post ** m=MIMETYPE Mimetype for the body of the post ** x Submit changes ** p Preview changes */ void forum_edit_page(void){ int itemId; int parentId; char *zErr = 0; login_check_credentials(); const char *zBody; const char *zMime; const char *zSub; if( !g.perm.WrForum ){ login_needed(g.anon.WrForum); return; } forum_verify_schema(); itemId = atoi(PD("item","0")); parentId = atoi(PD("replyto","0")); if( P("cancel")!=0 ){ cgi_redirectf("%R/forum?item=%d", itemId ? itemId : parentId); return; } if( P("x")!=0 && cgi_csrf_safe(1) ){ itemId = forum_post(itemId,parentId,&zErr); if( itemId ){ cgi_redirectf("%R/forum?item=%d",itemId); return; } } zMime = wiki_filter_mimetypes(P("m")); if( itemId>0 ){ style_header("Edit Forum Post"); }else if( parentId>0 ){ style_header("Comment On Forum Post"); }else{ style_header("New Forum Thread"); } @ <form action="%R/forumedit" method="POST"> if( itemId ){ @ <input type="hidden" name="item" value="%d(itemId)"> } if( parentId ){ @ <input type="hidden" name="replyto" value="%d(parentId)"> } if( P("p") ){ Blob x; @ <div class="forumpreview"> if( P("s") ){ @ <h1>%h(PT("s"))</h1> } @ <div class="forumpreviewbody"> blob_init(&x, PT("b"), -1); wiki_render_by_mimetype(&x, PT("m")); blob_reset(&x); @ </div> @ </div> @ <hr> } @ <table border="0" class="forumeditform"> if( zErr ){ @ <tr><td colspan="2"> @ <span class='forumFormErr'>%h(zErr)</span> } if( (itemId==0 && parentId==0) || (itemId && db_int(0, "SELECT inreplyto IS NULL FROM forumpost" " WHERE mpostid=%d", itemId)) ){ zSub = PT("s"); if( zSub==0 && itemId ){ zSub = db_text("", "SELECT mtitle FROM forumthread" " WHERE mthreadid=(SELECT mthreadid FROM forumpost" " WHERE mpostid=%d)", itemId); } @ <tr><td>Subject:</td> @ <td><input type='text' class='forumFormSubject' name='s' value='%h(zSub)'> } @ <tr><td>Markup:</td><td> mimetype_option_menu(zMime); @ <tr><td>Comment:</td><td> @ <textarea name="b" class="wikiedit" cols="80"\ @ rows="20" wrap="virtual">%h(PD("b",""))</textarea></td> @ <tr><td></td><td> @ <input type="submit" name="p" value="Preview"> if( P("p")!=0 ){ @ <input type="submit" name="x" value="Submit"> } @ <input type="submit" name="cancel" value="Cancel"> @ </table> @ </form> style_footer(); } |
Changes to src/main.c.
︙ | ︙ | |||
136 137 138 139 140 141 142 | char *zOpenRevision; /* Check-in version to use during database open */ int localOpen; /* True if the local database is open */ char *zLocalRoot; /* The directory holding the local database */ int minPrefix; /* Number of digits needed for a distinct UUID */ int eHashPolicy; /* Current hash policy. One of HPOLICY_* */ int fSqlTrace; /* True if --sqltrace flag is present */ int fSqlStats; /* True if --sqltrace or --sqlstats are present */ | | > | 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 | char *zOpenRevision; /* Check-in version to use during database open */ int localOpen; /* True if the local database is open */ char *zLocalRoot; /* The directory holding the local database */ int minPrefix; /* Number of digits needed for a distinct UUID */ int eHashPolicy; /* Current hash policy. One of HPOLICY_* */ int fSqlTrace; /* True if --sqltrace flag is present */ int fSqlStats; /* True if --sqltrace or --sqlstats are present */ int fSqlPrint; /* True if --sqlprint flag is present */ int fCgiTrace; /* True if --cgitrace is enabled */ int fQuiet; /* True if -quiet flag is present */ int fJail; /* True if running with a chroot jail */ int fHttpTrace; /* Trace outbound HTTP requests */ int fAnyTrace; /* Any kind of tracing */ char *zHttpAuth; /* HTTP Authorization user:pass information */ int fSystemTrace; /* Trace calls to fossil_system(), --systemtrace */ int fSshTrace; /* Trace the SSH setup traffic */ |
︙ | ︙ | |||
647 648 649 650 651 652 653 654 655 656 657 658 659 660 | g.isHTTP = 0; g.rcvid = 0; g.fQuiet = find_option("quiet", 0, 0)!=0; g.fSqlTrace = find_option("sqltrace", 0, 0)!=0; g.fSqlStats = find_option("sqlstats", 0, 0)!=0; g.fSystemTrace = find_option("systemtrace", 0, 0)!=0; g.fSshTrace = find_option("sshtrace", 0, 0)!=0; g.fSshClient = 0; g.zSshCmd = 0; if( g.fSqlTrace ) g.fSqlStats = 1; g.fHttpTrace = find_option("httptrace", 0, 0)!=0; #ifdef FOSSIL_ENABLE_TH1_HOOKS g.fNoThHook = find_option("no-th-hook", 0, 0)!=0; #endif | > | > | 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 | g.isHTTP = 0; g.rcvid = 0; g.fQuiet = find_option("quiet", 0, 0)!=0; g.fSqlTrace = find_option("sqltrace", 0, 0)!=0; g.fSqlStats = find_option("sqlstats", 0, 0)!=0; g.fSystemTrace = find_option("systemtrace", 0, 0)!=0; g.fSshTrace = find_option("sshtrace", 0, 0)!=0; g.fCgiTrace = find_option("cgitrace", 0, 0)!=0; g.fSshClient = 0; g.zSshCmd = 0; if( g.fSqlTrace ) g.fSqlStats = 1; g.fHttpTrace = find_option("httptrace", 0, 0)!=0; #ifdef FOSSIL_ENABLE_TH1_HOOKS g.fNoThHook = find_option("no-th-hook", 0, 0)!=0; #endif g.fAnyTrace = g.fSqlTrace|g.fSystemTrace|g.fSshTrace| g.fHttpTrace|g.fCgiTrace; g.zHttpAuth = 0; g.zLogin = find_option("user", "U", 1); g.zSSLIdentity = find_option("ssl-identity", 0, 1); g.zErrlog = find_option("errorlog", 0, 1); fossil_init_flags_from_options(); if( find_option("utc",0,0) ) g.fTimeFormat = 1; if( find_option("localtime",0,0) ) g.fTimeFormat = 2; |
︙ | ︙ | |||
1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 | #endif { @ <h1>Server Configuration Error</h1> @ <p>The database schema on the server is out-of-date. Please ask @ the administrator to run <b>fossil rebuild</b>.</p> } }else{ #ifdef FOSSIL_ENABLE_TH1_HOOKS /* ** The TH1 return codes from the hook will be handled as follows: ** ** TH_OK: The xFunc() and the TH1 notification will both be executed. ** ** TH_ERROR: The xFunc() will be skipped, the TH1 notification will be | > > > > | 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 | #endif { @ <h1>Server Configuration Error</h1> @ <p>The database schema on the server is out-of-date. Please ask @ the administrator to run <b>fossil rebuild</b>.</p> } }else{ if( g.fCgiTrace ){ fossil_trace("######## Calling %s #########\n", pCmd->zName); cgi_print_all(1, 1); } #ifdef FOSSIL_ENABLE_TH1_HOOKS /* ** The TH1 return codes from the hook will be handled as follows: ** ** TH_OK: The xFunc() and the TH1 notification will both be executed. ** ** TH_ERROR: The xFunc() will be skipped, the TH1 notification will be |
︙ | ︙ |
Changes to src/style.c.
︙ | ︙ | |||
937 938 939 940 941 942 943 | @ anonymous-adds = %s(zCap)<br /> } @ g.zRepositoryName = %h(g.zRepositoryName)<br /> @ load_average() = %f(load_average())<br /> @ cgi_csrf_safe(0) = %d(cgi_csrf_safe(0))<br /> @ <hr /> P("HTTP_USER_AGENT"); | | | 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 | @ anonymous-adds = %s(zCap)<br /> } @ g.zRepositoryName = %h(g.zRepositoryName)<br /> @ load_average() = %f(load_average())<br /> @ cgi_csrf_safe(0) = %d(cgi_csrf_safe(0))<br /> @ <hr /> P("HTTP_USER_AGENT"); cgi_print_all(showAll, 0); if( showAll && blob_size(&g.httpHeader)>0 ){ @ <hr /> @ <pre> @ %h(blob_str(&g.httpHeader)) @ </pre> } if( g.perm.Setup ){ |
︙ | ︙ |