Fossil SCM
Internally rename "entry" to "post" for more consistent terminology
Commit
adefa86c5e1fe13ae5dd0208425da7e5801830ef0dde458be867c8d7ce6cdeca
Parent
dd47b8c311ab476…
1 file changed
+72
-72
+72
-72
| --- src/forum.c | ||
| +++ src/forum.c | ||
| @@ -30,41 +30,41 @@ | ||
| 30 | 30 | /* |
| 31 | 31 | ** Each instance of the following object represents a single message - |
| 32 | 32 | ** either the initial post, an edit to a post, a reply, or an edit to |
| 33 | 33 | ** a reply. |
| 34 | 34 | */ |
| 35 | -struct ForumEntry { | |
| 36 | - int fpid; /* rid for this entry */ | |
| 35 | +struct ForumPost { | |
| 36 | + int fpid; /* rid for this post */ | |
| 37 | 37 | int sid; /* Serial ID number */ |
| 38 | 38 | int rev; /* Revision number */ |
| 39 | 39 | char *zUuid; /* Artifact hash */ |
| 40 | - ForumEntry *pIrt; /* This entry replies to pIrt */ | |
| 41 | - ForumEntry *pEditHead; /* Original, unedited entry */ | |
| 42 | - ForumEntry *pEditTail; /* Most recent edit for this entry */ | |
| 43 | - ForumEntry *pEditNext; /* This entry is edited by pEditNext */ | |
| 44 | - ForumEntry *pEditPrev; /* This entry is an edit of pEditPrev */ | |
| 45 | - ForumEntry *pNext; /* Next in chronological order */ | |
| 46 | - ForumEntry *pPrev; /* Previous in chronological order */ | |
| 47 | - ForumEntry *pDisplay; /* Next in display order */ | |
| 48 | - int nEdit; /* Number of edits to this entry */ | |
| 49 | - int nIndent; /* Number of levels of indentation for this entry */ | |
| 40 | + ForumPost *pIrt; /* This post replies to pIrt */ | |
| 41 | + ForumPost *pEditHead; /* Original, unedited post */ | |
| 42 | + ForumPost *pEditTail; /* Most recent edit for this post */ | |
| 43 | + ForumPost *pEditNext; /* This post is edited by pEditNext */ | |
| 44 | + ForumPost *pEditPrev; /* This post is an edit of pEditPrev */ | |
| 45 | + ForumPost *pNext; /* Next in chronological order */ | |
| 46 | + ForumPost *pPrev; /* Previous in chronological order */ | |
| 47 | + ForumPost *pDisplay; /* Next in display order */ | |
| 48 | + int nEdit; /* Number of edits to this post */ | |
| 49 | + int nIndent; /* Number of levels of indentation for this post */ | |
| 50 | 50 | }; |
| 51 | 51 | |
| 52 | 52 | /* |
| 53 | 53 | ** A single instance of the following tracks all entries for a thread. |
| 54 | 54 | */ |
| 55 | 55 | struct ForumThread { |
| 56 | - ForumEntry *pFirst; /* First entry in chronological order */ | |
| 57 | - ForumEntry *pLast; /* Last entry in chronological order */ | |
| 58 | - ForumEntry *pDisplay; /* Entries in display order */ | |
| 59 | - ForumEntry *pTail; /* Last on the display list */ | |
| 56 | + ForumPost *pFirst; /* First post in chronological order */ | |
| 57 | + ForumPost *pLast; /* Last post in chronological order */ | |
| 58 | + ForumPost *pDisplay; /* Entries in display order */ | |
| 59 | + ForumPost *pTail; /* Last on the display list */ | |
| 60 | 60 | int mxIndent; /* Maximum indentation level */ |
| 61 | 61 | }; |
| 62 | 62 | #endif /* INTERFACE */ |
| 63 | 63 | |
| 64 | 64 | /* |
| 65 | -** Return true if the forum entry with the given rid has been | |
| 65 | +** Return true if the forum post with the given rid has been | |
| 66 | 66 | ** subsequently edited. |
| 67 | 67 | */ |
| 68 | 68 | int forum_rid_has_been_edited(int rid){ |
| 69 | 69 | static Stmt q; |
| 70 | 70 | int res; |
| @@ -80,41 +80,41 @@ | ||
| 80 | 80 | |
| 81 | 81 | /* |
| 82 | 82 | ** Delete a complete ForumThread and all its entries. |
| 83 | 83 | */ |
| 84 | 84 | static void forumthread_delete(ForumThread *pThread){ |
| 85 | - ForumEntry *pEntry, *pNext; | |
| 86 | - for(pEntry=pThread->pFirst; pEntry; pEntry = pNext){ | |
| 87 | - pNext = pEntry->pNext; | |
| 88 | - fossil_free(pEntry->zUuid); | |
| 89 | - fossil_free(pEntry); | |
| 85 | + ForumPost *pPost, *pNext; | |
| 86 | + for(pPost=pThread->pFirst; pPost; pPost = pNext){ | |
| 87 | + pNext = pPost->pNext; | |
| 88 | + fossil_free(pPost->zUuid); | |
| 89 | + fossil_free(pPost); | |
| 90 | 90 | } |
| 91 | 91 | fossil_free(pThread); |
| 92 | 92 | } |
| 93 | 93 | |
| 94 | 94 | #if 0 /* not used */ |
| 95 | 95 | /* |
| 96 | -** Search a ForumEntry list forwards looking for the entry with fpid | |
| 96 | +** Search a ForumPost list forwards looking for the post with fpid | |
| 97 | 97 | */ |
| 98 | -static ForumEntry *forumentry_forward(ForumEntry *p, int fpid){ | |
| 98 | +static ForumPost *forumpost_forward(ForumPost *p, int fpid){ | |
| 99 | 99 | while( p && p->fpid!=fpid ) p = p->pNext; |
| 100 | 100 | return p; |
| 101 | 101 | } |
| 102 | 102 | #endif |
| 103 | 103 | |
| 104 | 104 | /* |
| 105 | -** Search backwards for a ForumEntry | |
| 105 | +** Search backwards for a ForumPost | |
| 106 | 106 | */ |
| 107 | -static ForumEntry *forumentry_backward(ForumEntry *p, int fpid){ | |
| 107 | +static ForumPost *forumpost_backward(ForumPost *p, int fpid){ | |
| 108 | 108 | while( p && p->fpid!=fpid ) p = p->pPrev; |
| 109 | 109 | return p; |
| 110 | 110 | } |
| 111 | 111 | |
| 112 | 112 | /* |
| 113 | -** Add an entry to the display list | |
| 113 | +** Add a post to the display list | |
| 114 | 114 | */ |
| 115 | -static void forumentry_add_to_display(ForumThread *pThread, ForumEntry *p){ | |
| 115 | +static void forumpost_add_to_display(ForumThread *pThread, ForumPost *p){ | |
| 116 | 116 | if( pThread->pDisplay==0 ){ |
| 117 | 117 | pThread->pDisplay = p; |
| 118 | 118 | }else{ |
| 119 | 119 | pThread->pTail->pDisplay = p; |
| 120 | 120 | } |
| @@ -121,48 +121,48 @@ | ||
| 121 | 121 | pThread->pTail = p; |
| 122 | 122 | } |
| 123 | 123 | |
| 124 | 124 | /* |
| 125 | 125 | ** Extend the display list for pThread by adding all entries that |
| 126 | -** reference fpid. The first such entry will be no earlier then | |
| 127 | -** entry "p". | |
| 126 | +** reference fpid. The first such post will be no earlier then | |
| 127 | +** post "p". | |
| 128 | 128 | */ |
| 129 | 129 | static void forumthread_display_order( |
| 130 | 130 | ForumThread *pThread, /* The complete thread */ |
| 131 | - ForumEntry *pBase /* Add replies to this entry */ | |
| 131 | + ForumPost *pBase /* Add replies to this post */ | |
| 132 | 132 | ){ |
| 133 | - ForumEntry *p; | |
| 134 | - ForumEntry *pPrev = 0; | |
| 135 | - ForumEntry *pBaseIrt; | |
| 133 | + ForumPost *p; | |
| 134 | + ForumPost *pPrev = 0; | |
| 135 | + ForumPost *pBaseIrt; | |
| 136 | 136 | for(p=pBase->pNext; p; p=p->pNext){ |
| 137 | 137 | if( !p->pEditPrev && p->pIrt ){ |
| 138 | 138 | pBaseIrt = p->pIrt->pEditHead ? p->pIrt->pEditHead : p->pIrt; |
| 139 | 139 | if( pBaseIrt==pBase ){ |
| 140 | 140 | if( pPrev ){ |
| 141 | 141 | pPrev->nIndent = pBase->nIndent + 1; |
| 142 | - forumentry_add_to_display(pThread, pPrev); | |
| 142 | + forumpost_add_to_display(pThread, pPrev); | |
| 143 | 143 | forumthread_display_order(pThread, pPrev); |
| 144 | 144 | } |
| 145 | 145 | pPrev = p; |
| 146 | 146 | } |
| 147 | 147 | } |
| 148 | 148 | } |
| 149 | 149 | if( pPrev ){ |
| 150 | 150 | pPrev->nIndent = pBase->nIndent + 1; |
| 151 | 151 | if( pPrev->nIndent>pThread->mxIndent ) pThread->mxIndent = pPrev->nIndent; |
| 152 | - forumentry_add_to_display(pThread, pPrev); | |
| 152 | + forumpost_add_to_display(pThread, pPrev); | |
| 153 | 153 | forumthread_display_order(pThread, pPrev); |
| 154 | 154 | } |
| 155 | 155 | } |
| 156 | 156 | |
| 157 | 157 | /* |
| 158 | 158 | ** Construct a ForumThread object given the root record id. |
| 159 | 159 | */ |
| 160 | 160 | static ForumThread *forumthread_create(int froot, int computeHierarchy){ |
| 161 | 161 | ForumThread *pThread; |
| 162 | - ForumEntry *pEntry; | |
| 163 | - ForumEntry *p; | |
| 162 | + ForumPost *pPost; | |
| 163 | + ForumPost *p; | |
| 164 | 164 | Stmt q; |
| 165 | 165 | int sid = 1; |
| 166 | 166 | int firt, fprev; |
| 167 | 167 | pThread = fossil_malloc( sizeof(*pThread) ); |
| 168 | 168 | memset(pThread, 0, sizeof(*pThread)); |
| @@ -171,62 +171,62 @@ | ||
| 171 | 171 | " FROM forumpost" |
| 172 | 172 | " WHERE froot=%d ORDER BY fmtime", |
| 173 | 173 | froot |
| 174 | 174 | ); |
| 175 | 175 | while( db_step(&q)==SQLITE_ROW ){ |
| 176 | - pEntry = fossil_malloc( sizeof(*pEntry) ); | |
| 177 | - memset(pEntry, 0, sizeof(*pEntry)); | |
| 178 | - pEntry->fpid = db_column_int(&q, 0); | |
| 176 | + pPost = fossil_malloc( sizeof(*pPost) ); | |
| 177 | + memset(pPost, 0, sizeof(*pPost)); | |
| 178 | + pPost->fpid = db_column_int(&q, 0); | |
| 179 | 179 | firt = db_column_int(&q, 1); |
| 180 | 180 | fprev = db_column_int(&q, 2); |
| 181 | - pEntry->zUuid = fossil_strdup(db_column_text(&q,3)); | |
| 182 | - if( !fprev ) pEntry->sid = sid++; | |
| 183 | - pEntry->pPrev = pThread->pLast; | |
| 184 | - pEntry->pNext = 0; | |
| 181 | + pPost->zUuid = fossil_strdup(db_column_text(&q,3)); | |
| 182 | + if( !fprev ) pPost->sid = sid++; | |
| 183 | + pPost->pPrev = pThread->pLast; | |
| 184 | + pPost->pNext = 0; | |
| 185 | 185 | if( pThread->pLast==0 ){ |
| 186 | - pThread->pFirst = pEntry; | |
| 186 | + pThread->pFirst = pPost; | |
| 187 | 187 | }else{ |
| 188 | - pThread->pLast->pNext = pEntry; | |
| 188 | + pThread->pLast->pNext = pPost; | |
| 189 | 189 | } |
| 190 | - pThread->pLast = pEntry; | |
| 190 | + pThread->pLast = pPost; | |
| 191 | 191 | |
| 192 | 192 | /* Find the in-reply-to post. Default to the topic post if the replied-to |
| 193 | 193 | ** post cannot be found. */ |
| 194 | 194 | if( firt ){ |
| 195 | - pEntry->pIrt = pThread->pFirst; | |
| 195 | + pPost->pIrt = pThread->pFirst; | |
| 196 | 196 | for(p=pThread->pFirst; p; p=p->pNext){ |
| 197 | 197 | if( p->fpid==firt ){ |
| 198 | - pEntry->pIrt = p; | |
| 198 | + pPost->pIrt = p; | |
| 199 | 199 | break; |
| 200 | 200 | } |
| 201 | 201 | } |
| 202 | 202 | } |
| 203 | 203 | |
| 204 | 204 | /* Maintain the linked list of post edits. */ |
| 205 | 205 | if( fprev ){ |
| 206 | - p = forumentry_backward(pEntry->pPrev, fprev); | |
| 207 | - p->pEditNext = pEntry; | |
| 208 | - pEntry->sid = p->sid; | |
| 209 | - pEntry->rev = p->rev+1; | |
| 210 | - pEntry->nEdit = p->nEdit+1; | |
| 211 | - pEntry->pEditPrev = p; | |
| 212 | - pEntry->pEditHead = p->pEditHead ? p->pEditHead : p; | |
| 206 | + p = forumpost_backward(pPost->pPrev, fprev); | |
| 207 | + p->pEditNext = pPost; | |
| 208 | + pPost->sid = p->sid; | |
| 209 | + pPost->rev = p->rev+1; | |
| 210 | + pPost->nEdit = p->nEdit+1; | |
| 211 | + pPost->pEditPrev = p; | |
| 212 | + pPost->pEditHead = p->pEditHead ? p->pEditHead : p; | |
| 213 | 213 | for(; p; p=p->pEditPrev ){ |
| 214 | - p->nEdit = pEntry->nEdit; | |
| 215 | - p->pEditTail = pEntry; | |
| 214 | + p->nEdit = pPost->nEdit; | |
| 215 | + p->pEditTail = pPost; | |
| 216 | 216 | } |
| 217 | 217 | } |
| 218 | 218 | } |
| 219 | 219 | db_finalize(&q); |
| 220 | 220 | |
| 221 | 221 | if( computeHierarchy ){ |
| 222 | 222 | /* Compute the hierarchical display order */ |
| 223 | - pEntry = pThread->pFirst; | |
| 224 | - pEntry->nIndent = 1; | |
| 223 | + pPost = pThread->pFirst; | |
| 224 | + pPost->nIndent = 1; | |
| 225 | 225 | pThread->mxIndent = 1; |
| 226 | - forumentry_add_to_display(pThread, pEntry); | |
| 227 | - forumthread_display_order(pThread, pEntry); | |
| 226 | + forumpost_add_to_display(pThread, pPost); | |
| 227 | + forumthread_display_order(pThread, pPost); | |
| 228 | 228 | } |
| 229 | 229 | |
| 230 | 230 | /* Return the result */ |
| 231 | 231 | return pThread; |
| 232 | 232 | } |
| @@ -270,11 +270,11 @@ | ||
| 270 | 270 | void forumthread_cmd(void){ |
| 271 | 271 | int fpid; |
| 272 | 272 | int froot; |
| 273 | 273 | const char *zName; |
| 274 | 274 | ForumThread *pThread; |
| 275 | - ForumEntry *p; | |
| 275 | + ForumPost *p; | |
| 276 | 276 | |
| 277 | 277 | db_find_and_open_repository(0,0); |
| 278 | 278 | verify_all_options(); |
| 279 | 279 | if( g.argc==2 ){ |
| 280 | 280 | forum_thread_list(); |
| @@ -413,11 +413,11 @@ | ||
| 413 | 413 | /* |
| 414 | 414 | ** Display all posts in a forum thread in chronological order |
| 415 | 415 | */ |
| 416 | 416 | static void forum_display_chronological(int froot, int target, int bRawMode){ |
| 417 | 417 | ForumThread *pThread = forumthread_create(froot, 0); |
| 418 | - ForumEntry *p; | |
| 418 | + ForumPost *p; | |
| 419 | 419 | int notAnon = login_is_individual(); |
| 420 | 420 | char cMode = bRawMode ? 'r' : 'c'; |
| 421 | 421 | for(p=pThread->pFirst; p; p=p->pNext){ |
| 422 | 422 | char *zDate; |
| 423 | 423 | Manifest *pPost; |
| @@ -548,14 +548,14 @@ | ||
| 548 | 548 | /* |
| 549 | 549 | ** Display all the edit history of post "target". |
| 550 | 550 | */ |
| 551 | 551 | static void forum_display_history(int froot, int target, int bRawMode){ |
| 552 | 552 | ForumThread *pThread = forumthread_create(froot, 0); |
| 553 | - ForumEntry *p; | |
| 553 | + ForumPost *p; | |
| 554 | 554 | int notAnon = login_is_individual(); |
| 555 | 555 | char cMode = bRawMode ? 'r' : 'c'; |
| 556 | - ForumEntry *pEditTail = 0; | |
| 556 | + ForumPost *pEditTail = 0; | |
| 557 | 557 | int cnt = 0; |
| 558 | 558 | for(p=pThread->pFirst; p; p=p->pNext){ |
| 559 | 559 | if( p->fpid==target ){ |
| 560 | 560 | pEditTail = p->pEditTail ? p->pEditTail : p; |
| 561 | 561 | break; |
| @@ -644,11 +644,11 @@ | ||
| 644 | 644 | /* |
| 645 | 645 | ** Display all messages in a forumthread with indentation. |
| 646 | 646 | */ |
| 647 | 647 | static int forum_display_hierarchical(int froot, int target){ |
| 648 | 648 | ForumThread *pThread; |
| 649 | - ForumEntry *p; | |
| 649 | + ForumPost *p; | |
| 650 | 650 | Manifest *pPost, *pOPost; |
| 651 | 651 | int fpid; |
| 652 | 652 | const char *zUuid; |
| 653 | 653 | char *zDate; |
| 654 | 654 | const char *zSel; |
| @@ -1031,11 +1031,11 @@ | ||
| 1031 | 1031 | } |
| 1032 | 1032 | |
| 1033 | 1033 | /* |
| 1034 | 1034 | ** Paint the form elements for entering a Forum post |
| 1035 | 1035 | */ |
| 1036 | -static void forum_entry_widget( | |
| 1036 | +static void forum_post_widget( | |
| 1037 | 1037 | const char *zTitle, |
| 1038 | 1038 | const char *zMimetype, |
| 1039 | 1039 | const char *zContent |
| 1040 | 1040 | ){ |
| 1041 | 1041 | if( zTitle ){ |
| @@ -1140,11 +1140,11 @@ | ||
| 1140 | 1140 | } |
| 1141 | 1141 | style_header("New Forum Thread"); |
| 1142 | 1142 | @ <form action="%R/forume1" method="POST"> |
| 1143 | 1143 | @ <h1>New Thread:</h1> |
| 1144 | 1144 | forum_from_line(); |
| 1145 | - forum_entry_widget(zTitle, zMimetype, zContent); | |
| 1145 | + forum_post_widget(zTitle, zMimetype, zContent); | |
| 1146 | 1146 | @ <input type="submit" name="preview" value="Preview"> |
| 1147 | 1147 | if( P("preview") && !whitespace_only(zContent) ){ |
| 1148 | 1148 | @ <input type="submit" name="submit" value="Submit"> |
| 1149 | 1149 | }else{ |
| 1150 | 1150 | @ <input type="submit" name="submit" value="Submit" disabled> |
| @@ -1290,11 +1290,11 @@ | ||
| 1290 | 1290 | @ <h2>Revised Message:</h2> |
| 1291 | 1291 | @ <form action="%R/forume2" method="POST"> |
| 1292 | 1292 | @ <input type="hidden" name="fpid" value="%h(P("fpid"))"> |
| 1293 | 1293 | @ <input type="hidden" name="edit" value="1"> |
| 1294 | 1294 | forum_from_line(); |
| 1295 | - forum_entry_widget(zTitle, zMimetype, zContent); | |
| 1295 | + forum_post_widget(zTitle, zMimetype, zContent); | |
| 1296 | 1296 | }else{ |
| 1297 | 1297 | /* Reply */ |
| 1298 | 1298 | char *zDisplayName; |
| 1299 | 1299 | zMimetype = PD("mimetype",DEFAULT_FORUM_MIMETYPE); |
| 1300 | 1300 | zContent = PDT("content",""); |
| @@ -1316,11 +1316,11 @@ | ||
| 1316 | 1316 | @ <h2>Enter Reply:</h2> |
| 1317 | 1317 | @ <form action="%R/forume2" method="POST"> |
| 1318 | 1318 | @ <input type="hidden" name="fpid" value="%h(P("fpid"))"> |
| 1319 | 1319 | @ <input type="hidden" name="reply" value="1"> |
| 1320 | 1320 | forum_from_line(); |
| 1321 | - forum_entry_widget(0, zMimetype, zContent); | |
| 1321 | + forum_post_widget(0, zMimetype, zContent); | |
| 1322 | 1322 | } |
| 1323 | 1323 | if( !isDelete ){ |
| 1324 | 1324 | @ <input type="submit" name="preview" value="Preview"> |
| 1325 | 1325 | } |
| 1326 | 1326 | @ <input type="submit" name="cancel" value="Cancel"> |
| 1327 | 1327 |
| --- src/forum.c | |
| +++ src/forum.c | |
| @@ -30,41 +30,41 @@ | |
| 30 | /* |
| 31 | ** Each instance of the following object represents a single message - |
| 32 | ** either the initial post, an edit to a post, a reply, or an edit to |
| 33 | ** a reply. |
| 34 | */ |
| 35 | struct ForumEntry { |
| 36 | int fpid; /* rid for this entry */ |
| 37 | int sid; /* Serial ID number */ |
| 38 | int rev; /* Revision number */ |
| 39 | char *zUuid; /* Artifact hash */ |
| 40 | ForumEntry *pIrt; /* This entry replies to pIrt */ |
| 41 | ForumEntry *pEditHead; /* Original, unedited entry */ |
| 42 | ForumEntry *pEditTail; /* Most recent edit for this entry */ |
| 43 | ForumEntry *pEditNext; /* This entry is edited by pEditNext */ |
| 44 | ForumEntry *pEditPrev; /* This entry is an edit of pEditPrev */ |
| 45 | ForumEntry *pNext; /* Next in chronological order */ |
| 46 | ForumEntry *pPrev; /* Previous in chronological order */ |
| 47 | ForumEntry *pDisplay; /* Next in display order */ |
| 48 | int nEdit; /* Number of edits to this entry */ |
| 49 | int nIndent; /* Number of levels of indentation for this entry */ |
| 50 | }; |
| 51 | |
| 52 | /* |
| 53 | ** A single instance of the following tracks all entries for a thread. |
| 54 | */ |
| 55 | struct ForumThread { |
| 56 | ForumEntry *pFirst; /* First entry in chronological order */ |
| 57 | ForumEntry *pLast; /* Last entry in chronological order */ |
| 58 | ForumEntry *pDisplay; /* Entries in display order */ |
| 59 | ForumEntry *pTail; /* Last on the display list */ |
| 60 | int mxIndent; /* Maximum indentation level */ |
| 61 | }; |
| 62 | #endif /* INTERFACE */ |
| 63 | |
| 64 | /* |
| 65 | ** Return true if the forum entry with the given rid has been |
| 66 | ** subsequently edited. |
| 67 | */ |
| 68 | int forum_rid_has_been_edited(int rid){ |
| 69 | static Stmt q; |
| 70 | int res; |
| @@ -80,41 +80,41 @@ | |
| 80 | |
| 81 | /* |
| 82 | ** Delete a complete ForumThread and all its entries. |
| 83 | */ |
| 84 | static void forumthread_delete(ForumThread *pThread){ |
| 85 | ForumEntry *pEntry, *pNext; |
| 86 | for(pEntry=pThread->pFirst; pEntry; pEntry = pNext){ |
| 87 | pNext = pEntry->pNext; |
| 88 | fossil_free(pEntry->zUuid); |
| 89 | fossil_free(pEntry); |
| 90 | } |
| 91 | fossil_free(pThread); |
| 92 | } |
| 93 | |
| 94 | #if 0 /* not used */ |
| 95 | /* |
| 96 | ** Search a ForumEntry list forwards looking for the entry with fpid |
| 97 | */ |
| 98 | static ForumEntry *forumentry_forward(ForumEntry *p, int fpid){ |
| 99 | while( p && p->fpid!=fpid ) p = p->pNext; |
| 100 | return p; |
| 101 | } |
| 102 | #endif |
| 103 | |
| 104 | /* |
| 105 | ** Search backwards for a ForumEntry |
| 106 | */ |
| 107 | static ForumEntry *forumentry_backward(ForumEntry *p, int fpid){ |
| 108 | while( p && p->fpid!=fpid ) p = p->pPrev; |
| 109 | return p; |
| 110 | } |
| 111 | |
| 112 | /* |
| 113 | ** Add an entry to the display list |
| 114 | */ |
| 115 | static void forumentry_add_to_display(ForumThread *pThread, ForumEntry *p){ |
| 116 | if( pThread->pDisplay==0 ){ |
| 117 | pThread->pDisplay = p; |
| 118 | }else{ |
| 119 | pThread->pTail->pDisplay = p; |
| 120 | } |
| @@ -121,48 +121,48 @@ | |
| 121 | pThread->pTail = p; |
| 122 | } |
| 123 | |
| 124 | /* |
| 125 | ** Extend the display list for pThread by adding all entries that |
| 126 | ** reference fpid. The first such entry will be no earlier then |
| 127 | ** entry "p". |
| 128 | */ |
| 129 | static void forumthread_display_order( |
| 130 | ForumThread *pThread, /* The complete thread */ |
| 131 | ForumEntry *pBase /* Add replies to this entry */ |
| 132 | ){ |
| 133 | ForumEntry *p; |
| 134 | ForumEntry *pPrev = 0; |
| 135 | ForumEntry *pBaseIrt; |
| 136 | for(p=pBase->pNext; p; p=p->pNext){ |
| 137 | if( !p->pEditPrev && p->pIrt ){ |
| 138 | pBaseIrt = p->pIrt->pEditHead ? p->pIrt->pEditHead : p->pIrt; |
| 139 | if( pBaseIrt==pBase ){ |
| 140 | if( pPrev ){ |
| 141 | pPrev->nIndent = pBase->nIndent + 1; |
| 142 | forumentry_add_to_display(pThread, pPrev); |
| 143 | forumthread_display_order(pThread, pPrev); |
| 144 | } |
| 145 | pPrev = p; |
| 146 | } |
| 147 | } |
| 148 | } |
| 149 | if( pPrev ){ |
| 150 | pPrev->nIndent = pBase->nIndent + 1; |
| 151 | if( pPrev->nIndent>pThread->mxIndent ) pThread->mxIndent = pPrev->nIndent; |
| 152 | forumentry_add_to_display(pThread, pPrev); |
| 153 | forumthread_display_order(pThread, pPrev); |
| 154 | } |
| 155 | } |
| 156 | |
| 157 | /* |
| 158 | ** Construct a ForumThread object given the root record id. |
| 159 | */ |
| 160 | static ForumThread *forumthread_create(int froot, int computeHierarchy){ |
| 161 | ForumThread *pThread; |
| 162 | ForumEntry *pEntry; |
| 163 | ForumEntry *p; |
| 164 | Stmt q; |
| 165 | int sid = 1; |
| 166 | int firt, fprev; |
| 167 | pThread = fossil_malloc( sizeof(*pThread) ); |
| 168 | memset(pThread, 0, sizeof(*pThread)); |
| @@ -171,62 +171,62 @@ | |
| 171 | " FROM forumpost" |
| 172 | " WHERE froot=%d ORDER BY fmtime", |
| 173 | froot |
| 174 | ); |
| 175 | while( db_step(&q)==SQLITE_ROW ){ |
| 176 | pEntry = fossil_malloc( sizeof(*pEntry) ); |
| 177 | memset(pEntry, 0, sizeof(*pEntry)); |
| 178 | pEntry->fpid = db_column_int(&q, 0); |
| 179 | firt = db_column_int(&q, 1); |
| 180 | fprev = db_column_int(&q, 2); |
| 181 | pEntry->zUuid = fossil_strdup(db_column_text(&q,3)); |
| 182 | if( !fprev ) pEntry->sid = sid++; |
| 183 | pEntry->pPrev = pThread->pLast; |
| 184 | pEntry->pNext = 0; |
| 185 | if( pThread->pLast==0 ){ |
| 186 | pThread->pFirst = pEntry; |
| 187 | }else{ |
| 188 | pThread->pLast->pNext = pEntry; |
| 189 | } |
| 190 | pThread->pLast = pEntry; |
| 191 | |
| 192 | /* Find the in-reply-to post. Default to the topic post if the replied-to |
| 193 | ** post cannot be found. */ |
| 194 | if( firt ){ |
| 195 | pEntry->pIrt = pThread->pFirst; |
| 196 | for(p=pThread->pFirst; p; p=p->pNext){ |
| 197 | if( p->fpid==firt ){ |
| 198 | pEntry->pIrt = p; |
| 199 | break; |
| 200 | } |
| 201 | } |
| 202 | } |
| 203 | |
| 204 | /* Maintain the linked list of post edits. */ |
| 205 | if( fprev ){ |
| 206 | p = forumentry_backward(pEntry->pPrev, fprev); |
| 207 | p->pEditNext = pEntry; |
| 208 | pEntry->sid = p->sid; |
| 209 | pEntry->rev = p->rev+1; |
| 210 | pEntry->nEdit = p->nEdit+1; |
| 211 | pEntry->pEditPrev = p; |
| 212 | pEntry->pEditHead = p->pEditHead ? p->pEditHead : p; |
| 213 | for(; p; p=p->pEditPrev ){ |
| 214 | p->nEdit = pEntry->nEdit; |
| 215 | p->pEditTail = pEntry; |
| 216 | } |
| 217 | } |
| 218 | } |
| 219 | db_finalize(&q); |
| 220 | |
| 221 | if( computeHierarchy ){ |
| 222 | /* Compute the hierarchical display order */ |
| 223 | pEntry = pThread->pFirst; |
| 224 | pEntry->nIndent = 1; |
| 225 | pThread->mxIndent = 1; |
| 226 | forumentry_add_to_display(pThread, pEntry); |
| 227 | forumthread_display_order(pThread, pEntry); |
| 228 | } |
| 229 | |
| 230 | /* Return the result */ |
| 231 | return pThread; |
| 232 | } |
| @@ -270,11 +270,11 @@ | |
| 270 | void forumthread_cmd(void){ |
| 271 | int fpid; |
| 272 | int froot; |
| 273 | const char *zName; |
| 274 | ForumThread *pThread; |
| 275 | ForumEntry *p; |
| 276 | |
| 277 | db_find_and_open_repository(0,0); |
| 278 | verify_all_options(); |
| 279 | if( g.argc==2 ){ |
| 280 | forum_thread_list(); |
| @@ -413,11 +413,11 @@ | |
| 413 | /* |
| 414 | ** Display all posts in a forum thread in chronological order |
| 415 | */ |
| 416 | static void forum_display_chronological(int froot, int target, int bRawMode){ |
| 417 | ForumThread *pThread = forumthread_create(froot, 0); |
| 418 | ForumEntry *p; |
| 419 | int notAnon = login_is_individual(); |
| 420 | char cMode = bRawMode ? 'r' : 'c'; |
| 421 | for(p=pThread->pFirst; p; p=p->pNext){ |
| 422 | char *zDate; |
| 423 | Manifest *pPost; |
| @@ -548,14 +548,14 @@ | |
| 548 | /* |
| 549 | ** Display all the edit history of post "target". |
| 550 | */ |
| 551 | static void forum_display_history(int froot, int target, int bRawMode){ |
| 552 | ForumThread *pThread = forumthread_create(froot, 0); |
| 553 | ForumEntry *p; |
| 554 | int notAnon = login_is_individual(); |
| 555 | char cMode = bRawMode ? 'r' : 'c'; |
| 556 | ForumEntry *pEditTail = 0; |
| 557 | int cnt = 0; |
| 558 | for(p=pThread->pFirst; p; p=p->pNext){ |
| 559 | if( p->fpid==target ){ |
| 560 | pEditTail = p->pEditTail ? p->pEditTail : p; |
| 561 | break; |
| @@ -644,11 +644,11 @@ | |
| 644 | /* |
| 645 | ** Display all messages in a forumthread with indentation. |
| 646 | */ |
| 647 | static int forum_display_hierarchical(int froot, int target){ |
| 648 | ForumThread *pThread; |
| 649 | ForumEntry *p; |
| 650 | Manifest *pPost, *pOPost; |
| 651 | int fpid; |
| 652 | const char *zUuid; |
| 653 | char *zDate; |
| 654 | const char *zSel; |
| @@ -1031,11 +1031,11 @@ | |
| 1031 | } |
| 1032 | |
| 1033 | /* |
| 1034 | ** Paint the form elements for entering a Forum post |
| 1035 | */ |
| 1036 | static void forum_entry_widget( |
| 1037 | const char *zTitle, |
| 1038 | const char *zMimetype, |
| 1039 | const char *zContent |
| 1040 | ){ |
| 1041 | if( zTitle ){ |
| @@ -1140,11 +1140,11 @@ | |
| 1140 | } |
| 1141 | style_header("New Forum Thread"); |
| 1142 | @ <form action="%R/forume1" method="POST"> |
| 1143 | @ <h1>New Thread:</h1> |
| 1144 | forum_from_line(); |
| 1145 | forum_entry_widget(zTitle, zMimetype, zContent); |
| 1146 | @ <input type="submit" name="preview" value="Preview"> |
| 1147 | if( P("preview") && !whitespace_only(zContent) ){ |
| 1148 | @ <input type="submit" name="submit" value="Submit"> |
| 1149 | }else{ |
| 1150 | @ <input type="submit" name="submit" value="Submit" disabled> |
| @@ -1290,11 +1290,11 @@ | |
| 1290 | @ <h2>Revised Message:</h2> |
| 1291 | @ <form action="%R/forume2" method="POST"> |
| 1292 | @ <input type="hidden" name="fpid" value="%h(P("fpid"))"> |
| 1293 | @ <input type="hidden" name="edit" value="1"> |
| 1294 | forum_from_line(); |
| 1295 | forum_entry_widget(zTitle, zMimetype, zContent); |
| 1296 | }else{ |
| 1297 | /* Reply */ |
| 1298 | char *zDisplayName; |
| 1299 | zMimetype = PD("mimetype",DEFAULT_FORUM_MIMETYPE); |
| 1300 | zContent = PDT("content",""); |
| @@ -1316,11 +1316,11 @@ | |
| 1316 | @ <h2>Enter Reply:</h2> |
| 1317 | @ <form action="%R/forume2" method="POST"> |
| 1318 | @ <input type="hidden" name="fpid" value="%h(P("fpid"))"> |
| 1319 | @ <input type="hidden" name="reply" value="1"> |
| 1320 | forum_from_line(); |
| 1321 | forum_entry_widget(0, zMimetype, zContent); |
| 1322 | } |
| 1323 | if( !isDelete ){ |
| 1324 | @ <input type="submit" name="preview" value="Preview"> |
| 1325 | } |
| 1326 | @ <input type="submit" name="cancel" value="Cancel"> |
| 1327 |
| --- src/forum.c | |
| +++ src/forum.c | |
| @@ -30,41 +30,41 @@ | |
| 30 | /* |
| 31 | ** Each instance of the following object represents a single message - |
| 32 | ** either the initial post, an edit to a post, a reply, or an edit to |
| 33 | ** a reply. |
| 34 | */ |
| 35 | struct ForumPost { |
| 36 | int fpid; /* rid for this post */ |
| 37 | int sid; /* Serial ID number */ |
| 38 | int rev; /* Revision number */ |
| 39 | char *zUuid; /* Artifact hash */ |
| 40 | ForumPost *pIrt; /* This post replies to pIrt */ |
| 41 | ForumPost *pEditHead; /* Original, unedited post */ |
| 42 | ForumPost *pEditTail; /* Most recent edit for this post */ |
| 43 | ForumPost *pEditNext; /* This post is edited by pEditNext */ |
| 44 | ForumPost *pEditPrev; /* This post is an edit of pEditPrev */ |
| 45 | ForumPost *pNext; /* Next in chronological order */ |
| 46 | ForumPost *pPrev; /* Previous in chronological order */ |
| 47 | ForumPost *pDisplay; /* Next in display order */ |
| 48 | int nEdit; /* Number of edits to this post */ |
| 49 | int nIndent; /* Number of levels of indentation for this post */ |
| 50 | }; |
| 51 | |
| 52 | /* |
| 53 | ** A single instance of the following tracks all entries for a thread. |
| 54 | */ |
| 55 | struct ForumThread { |
| 56 | ForumPost *pFirst; /* First post in chronological order */ |
| 57 | ForumPost *pLast; /* Last post in chronological order */ |
| 58 | ForumPost *pDisplay; /* Entries in display order */ |
| 59 | ForumPost *pTail; /* Last on the display list */ |
| 60 | int mxIndent; /* Maximum indentation level */ |
| 61 | }; |
| 62 | #endif /* INTERFACE */ |
| 63 | |
| 64 | /* |
| 65 | ** Return true if the forum post with the given rid has been |
| 66 | ** subsequently edited. |
| 67 | */ |
| 68 | int forum_rid_has_been_edited(int rid){ |
| 69 | static Stmt q; |
| 70 | int res; |
| @@ -80,41 +80,41 @@ | |
| 80 | |
| 81 | /* |
| 82 | ** Delete a complete ForumThread and all its entries. |
| 83 | */ |
| 84 | static void forumthread_delete(ForumThread *pThread){ |
| 85 | ForumPost *pPost, *pNext; |
| 86 | for(pPost=pThread->pFirst; pPost; pPost = pNext){ |
| 87 | pNext = pPost->pNext; |
| 88 | fossil_free(pPost->zUuid); |
| 89 | fossil_free(pPost); |
| 90 | } |
| 91 | fossil_free(pThread); |
| 92 | } |
| 93 | |
| 94 | #if 0 /* not used */ |
| 95 | /* |
| 96 | ** Search a ForumPost list forwards looking for the post with fpid |
| 97 | */ |
| 98 | static ForumPost *forumpost_forward(ForumPost *p, int fpid){ |
| 99 | while( p && p->fpid!=fpid ) p = p->pNext; |
| 100 | return p; |
| 101 | } |
| 102 | #endif |
| 103 | |
| 104 | /* |
| 105 | ** Search backwards for a ForumPost |
| 106 | */ |
| 107 | static ForumPost *forumpost_backward(ForumPost *p, int fpid){ |
| 108 | while( p && p->fpid!=fpid ) p = p->pPrev; |
| 109 | return p; |
| 110 | } |
| 111 | |
| 112 | /* |
| 113 | ** Add a post to the display list |
| 114 | */ |
| 115 | static void forumpost_add_to_display(ForumThread *pThread, ForumPost *p){ |
| 116 | if( pThread->pDisplay==0 ){ |
| 117 | pThread->pDisplay = p; |
| 118 | }else{ |
| 119 | pThread->pTail->pDisplay = p; |
| 120 | } |
| @@ -121,48 +121,48 @@ | |
| 121 | pThread->pTail = p; |
| 122 | } |
| 123 | |
| 124 | /* |
| 125 | ** Extend the display list for pThread by adding all entries that |
| 126 | ** reference fpid. The first such post will be no earlier then |
| 127 | ** post "p". |
| 128 | */ |
| 129 | static void forumthread_display_order( |
| 130 | ForumThread *pThread, /* The complete thread */ |
| 131 | ForumPost *pBase /* Add replies to this post */ |
| 132 | ){ |
| 133 | ForumPost *p; |
| 134 | ForumPost *pPrev = 0; |
| 135 | ForumPost *pBaseIrt; |
| 136 | for(p=pBase->pNext; p; p=p->pNext){ |
| 137 | if( !p->pEditPrev && p->pIrt ){ |
| 138 | pBaseIrt = p->pIrt->pEditHead ? p->pIrt->pEditHead : p->pIrt; |
| 139 | if( pBaseIrt==pBase ){ |
| 140 | if( pPrev ){ |
| 141 | pPrev->nIndent = pBase->nIndent + 1; |
| 142 | forumpost_add_to_display(pThread, pPrev); |
| 143 | forumthread_display_order(pThread, pPrev); |
| 144 | } |
| 145 | pPrev = p; |
| 146 | } |
| 147 | } |
| 148 | } |
| 149 | if( pPrev ){ |
| 150 | pPrev->nIndent = pBase->nIndent + 1; |
| 151 | if( pPrev->nIndent>pThread->mxIndent ) pThread->mxIndent = pPrev->nIndent; |
| 152 | forumpost_add_to_display(pThread, pPrev); |
| 153 | forumthread_display_order(pThread, pPrev); |
| 154 | } |
| 155 | } |
| 156 | |
| 157 | /* |
| 158 | ** Construct a ForumThread object given the root record id. |
| 159 | */ |
| 160 | static ForumThread *forumthread_create(int froot, int computeHierarchy){ |
| 161 | ForumThread *pThread; |
| 162 | ForumPost *pPost; |
| 163 | ForumPost *p; |
| 164 | Stmt q; |
| 165 | int sid = 1; |
| 166 | int firt, fprev; |
| 167 | pThread = fossil_malloc( sizeof(*pThread) ); |
| 168 | memset(pThread, 0, sizeof(*pThread)); |
| @@ -171,62 +171,62 @@ | |
| 171 | " FROM forumpost" |
| 172 | " WHERE froot=%d ORDER BY fmtime", |
| 173 | froot |
| 174 | ); |
| 175 | while( db_step(&q)==SQLITE_ROW ){ |
| 176 | pPost = fossil_malloc( sizeof(*pPost) ); |
| 177 | memset(pPost, 0, sizeof(*pPost)); |
| 178 | pPost->fpid = db_column_int(&q, 0); |
| 179 | firt = db_column_int(&q, 1); |
| 180 | fprev = db_column_int(&q, 2); |
| 181 | pPost->zUuid = fossil_strdup(db_column_text(&q,3)); |
| 182 | if( !fprev ) pPost->sid = sid++; |
| 183 | pPost->pPrev = pThread->pLast; |
| 184 | pPost->pNext = 0; |
| 185 | if( pThread->pLast==0 ){ |
| 186 | pThread->pFirst = pPost; |
| 187 | }else{ |
| 188 | pThread->pLast->pNext = pPost; |
| 189 | } |
| 190 | pThread->pLast = pPost; |
| 191 | |
| 192 | /* Find the in-reply-to post. Default to the topic post if the replied-to |
| 193 | ** post cannot be found. */ |
| 194 | if( firt ){ |
| 195 | pPost->pIrt = pThread->pFirst; |
| 196 | for(p=pThread->pFirst; p; p=p->pNext){ |
| 197 | if( p->fpid==firt ){ |
| 198 | pPost->pIrt = p; |
| 199 | break; |
| 200 | } |
| 201 | } |
| 202 | } |
| 203 | |
| 204 | /* Maintain the linked list of post edits. */ |
| 205 | if( fprev ){ |
| 206 | p = forumpost_backward(pPost->pPrev, fprev); |
| 207 | p->pEditNext = pPost; |
| 208 | pPost->sid = p->sid; |
| 209 | pPost->rev = p->rev+1; |
| 210 | pPost->nEdit = p->nEdit+1; |
| 211 | pPost->pEditPrev = p; |
| 212 | pPost->pEditHead = p->pEditHead ? p->pEditHead : p; |
| 213 | for(; p; p=p->pEditPrev ){ |
| 214 | p->nEdit = pPost->nEdit; |
| 215 | p->pEditTail = pPost; |
| 216 | } |
| 217 | } |
| 218 | } |
| 219 | db_finalize(&q); |
| 220 | |
| 221 | if( computeHierarchy ){ |
| 222 | /* Compute the hierarchical display order */ |
| 223 | pPost = pThread->pFirst; |
| 224 | pPost->nIndent = 1; |
| 225 | pThread->mxIndent = 1; |
| 226 | forumpost_add_to_display(pThread, pPost); |
| 227 | forumthread_display_order(pThread, pPost); |
| 228 | } |
| 229 | |
| 230 | /* Return the result */ |
| 231 | return pThread; |
| 232 | } |
| @@ -270,11 +270,11 @@ | |
| 270 | void forumthread_cmd(void){ |
| 271 | int fpid; |
| 272 | int froot; |
| 273 | const char *zName; |
| 274 | ForumThread *pThread; |
| 275 | ForumPost *p; |
| 276 | |
| 277 | db_find_and_open_repository(0,0); |
| 278 | verify_all_options(); |
| 279 | if( g.argc==2 ){ |
| 280 | forum_thread_list(); |
| @@ -413,11 +413,11 @@ | |
| 413 | /* |
| 414 | ** Display all posts in a forum thread in chronological order |
| 415 | */ |
| 416 | static void forum_display_chronological(int froot, int target, int bRawMode){ |
| 417 | ForumThread *pThread = forumthread_create(froot, 0); |
| 418 | ForumPost *p; |
| 419 | int notAnon = login_is_individual(); |
| 420 | char cMode = bRawMode ? 'r' : 'c'; |
| 421 | for(p=pThread->pFirst; p; p=p->pNext){ |
| 422 | char *zDate; |
| 423 | Manifest *pPost; |
| @@ -548,14 +548,14 @@ | |
| 548 | /* |
| 549 | ** Display all the edit history of post "target". |
| 550 | */ |
| 551 | static void forum_display_history(int froot, int target, int bRawMode){ |
| 552 | ForumThread *pThread = forumthread_create(froot, 0); |
| 553 | ForumPost *p; |
| 554 | int notAnon = login_is_individual(); |
| 555 | char cMode = bRawMode ? 'r' : 'c'; |
| 556 | ForumPost *pEditTail = 0; |
| 557 | int cnt = 0; |
| 558 | for(p=pThread->pFirst; p; p=p->pNext){ |
| 559 | if( p->fpid==target ){ |
| 560 | pEditTail = p->pEditTail ? p->pEditTail : p; |
| 561 | break; |
| @@ -644,11 +644,11 @@ | |
| 644 | /* |
| 645 | ** Display all messages in a forumthread with indentation. |
| 646 | */ |
| 647 | static int forum_display_hierarchical(int froot, int target){ |
| 648 | ForumThread *pThread; |
| 649 | ForumPost *p; |
| 650 | Manifest *pPost, *pOPost; |
| 651 | int fpid; |
| 652 | const char *zUuid; |
| 653 | char *zDate; |
| 654 | const char *zSel; |
| @@ -1031,11 +1031,11 @@ | |
| 1031 | } |
| 1032 | |
| 1033 | /* |
| 1034 | ** Paint the form elements for entering a Forum post |
| 1035 | */ |
| 1036 | static void forum_post_widget( |
| 1037 | const char *zTitle, |
| 1038 | const char *zMimetype, |
| 1039 | const char *zContent |
| 1040 | ){ |
| 1041 | if( zTitle ){ |
| @@ -1140,11 +1140,11 @@ | |
| 1140 | } |
| 1141 | style_header("New Forum Thread"); |
| 1142 | @ <form action="%R/forume1" method="POST"> |
| 1143 | @ <h1>New Thread:</h1> |
| 1144 | forum_from_line(); |
| 1145 | forum_post_widget(zTitle, zMimetype, zContent); |
| 1146 | @ <input type="submit" name="preview" value="Preview"> |
| 1147 | if( P("preview") && !whitespace_only(zContent) ){ |
| 1148 | @ <input type="submit" name="submit" value="Submit"> |
| 1149 | }else{ |
| 1150 | @ <input type="submit" name="submit" value="Submit" disabled> |
| @@ -1290,11 +1290,11 @@ | |
| 1290 | @ <h2>Revised Message:</h2> |
| 1291 | @ <form action="%R/forume2" method="POST"> |
| 1292 | @ <input type="hidden" name="fpid" value="%h(P("fpid"))"> |
| 1293 | @ <input type="hidden" name="edit" value="1"> |
| 1294 | forum_from_line(); |
| 1295 | forum_post_widget(zTitle, zMimetype, zContent); |
| 1296 | }else{ |
| 1297 | /* Reply */ |
| 1298 | char *zDisplayName; |
| 1299 | zMimetype = PD("mimetype",DEFAULT_FORUM_MIMETYPE); |
| 1300 | zContent = PDT("content",""); |
| @@ -1316,11 +1316,11 @@ | |
| 1316 | @ <h2>Enter Reply:</h2> |
| 1317 | @ <form action="%R/forume2" method="POST"> |
| 1318 | @ <input type="hidden" name="fpid" value="%h(P("fpid"))"> |
| 1319 | @ <input type="hidden" name="reply" value="1"> |
| 1320 | forum_from_line(); |
| 1321 | forum_post_widget(0, zMimetype, zContent); |
| 1322 | } |
| 1323 | if( !isDelete ){ |
| 1324 | @ <input type="submit" name="preview" value="Preview"> |
| 1325 | } |
| 1326 | @ <input type="submit" name="cancel" value="Cancel"> |
| 1327 |