Fossil SCM

Internally rename "entry" to "post" for more consistent terminology

andygoth 2020-08-21 23:40 andygoth-forum-refactor
Commit adefa86c5e1fe13ae5dd0208425da7e5801830ef0dde458be867c8d7ce6cdeca
1 file changed +72 -72
+72 -72
--- src/forum.c
+++ src/forum.c
@@ -30,41 +30,41 @@
3030
/*
3131
** Each instance of the following object represents a single message -
3232
** either the initial post, an edit to a post, a reply, or an edit to
3333
** a reply.
3434
*/
35
-struct ForumEntry {
36
- int fpid; /* rid for this entry */
35
+struct ForumPost {
36
+ int fpid; /* rid for this post */
3737
int sid; /* Serial ID number */
3838
int rev; /* Revision number */
3939
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 */
5050
};
5151
5252
/*
5353
** A single instance of the following tracks all entries for a thread.
5454
*/
5555
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 */
6060
int mxIndent; /* Maximum indentation level */
6161
};
6262
#endif /* INTERFACE */
6363
6464
/*
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
6666
** subsequently edited.
6767
*/
6868
int forum_rid_has_been_edited(int rid){
6969
static Stmt q;
7070
int res;
@@ -80,41 +80,41 @@
8080
8181
/*
8282
** Delete a complete ForumThread and all its entries.
8383
*/
8484
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);
9090
}
9191
fossil_free(pThread);
9292
}
9393
9494
#if 0 /* not used */
9595
/*
96
-** Search a ForumEntry list forwards looking for the entry with fpid
96
+** Search a ForumPost list forwards looking for the post with fpid
9797
*/
98
-static ForumEntry *forumentry_forward(ForumEntry *p, int fpid){
98
+static ForumPost *forumpost_forward(ForumPost *p, int fpid){
9999
while( p && p->fpid!=fpid ) p = p->pNext;
100100
return p;
101101
}
102102
#endif
103103
104104
/*
105
-** Search backwards for a ForumEntry
105
+** Search backwards for a ForumPost
106106
*/
107
-static ForumEntry *forumentry_backward(ForumEntry *p, int fpid){
107
+static ForumPost *forumpost_backward(ForumPost *p, int fpid){
108108
while( p && p->fpid!=fpid ) p = p->pPrev;
109109
return p;
110110
}
111111
112112
/*
113
-** Add an entry to the display list
113
+** Add a post to the display list
114114
*/
115
-static void forumentry_add_to_display(ForumThread *pThread, ForumEntry *p){
115
+static void forumpost_add_to_display(ForumThread *pThread, ForumPost *p){
116116
if( pThread->pDisplay==0 ){
117117
pThread->pDisplay = p;
118118
}else{
119119
pThread->pTail->pDisplay = p;
120120
}
@@ -121,48 +121,48 @@
121121
pThread->pTail = p;
122122
}
123123
124124
/*
125125
** 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".
128128
*/
129129
static void forumthread_display_order(
130130
ForumThread *pThread, /* The complete thread */
131
- ForumEntry *pBase /* Add replies to this entry */
131
+ ForumPost *pBase /* Add replies to this post */
132132
){
133
- ForumEntry *p;
134
- ForumEntry *pPrev = 0;
135
- ForumEntry *pBaseIrt;
133
+ ForumPost *p;
134
+ ForumPost *pPrev = 0;
135
+ ForumPost *pBaseIrt;
136136
for(p=pBase->pNext; p; p=p->pNext){
137137
if( !p->pEditPrev && p->pIrt ){
138138
pBaseIrt = p->pIrt->pEditHead ? p->pIrt->pEditHead : p->pIrt;
139139
if( pBaseIrt==pBase ){
140140
if( pPrev ){
141141
pPrev->nIndent = pBase->nIndent + 1;
142
- forumentry_add_to_display(pThread, pPrev);
142
+ forumpost_add_to_display(pThread, pPrev);
143143
forumthread_display_order(pThread, pPrev);
144144
}
145145
pPrev = p;
146146
}
147147
}
148148
}
149149
if( pPrev ){
150150
pPrev->nIndent = pBase->nIndent + 1;
151151
if( pPrev->nIndent>pThread->mxIndent ) pThread->mxIndent = pPrev->nIndent;
152
- forumentry_add_to_display(pThread, pPrev);
152
+ forumpost_add_to_display(pThread, pPrev);
153153
forumthread_display_order(pThread, pPrev);
154154
}
155155
}
156156
157157
/*
158158
** Construct a ForumThread object given the root record id.
159159
*/
160160
static ForumThread *forumthread_create(int froot, int computeHierarchy){
161161
ForumThread *pThread;
162
- ForumEntry *pEntry;
163
- ForumEntry *p;
162
+ ForumPost *pPost;
163
+ ForumPost *p;
164164
Stmt q;
165165
int sid = 1;
166166
int firt, fprev;
167167
pThread = fossil_malloc( sizeof(*pThread) );
168168
memset(pThread, 0, sizeof(*pThread));
@@ -171,62 +171,62 @@
171171
" FROM forumpost"
172172
" WHERE froot=%d ORDER BY fmtime",
173173
froot
174174
);
175175
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);
179179
firt = db_column_int(&q, 1);
180180
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;
185185
if( pThread->pLast==0 ){
186
- pThread->pFirst = pEntry;
186
+ pThread->pFirst = pPost;
187187
}else{
188
- pThread->pLast->pNext = pEntry;
188
+ pThread->pLast->pNext = pPost;
189189
}
190
- pThread->pLast = pEntry;
190
+ pThread->pLast = pPost;
191191
192192
/* Find the in-reply-to post. Default to the topic post if the replied-to
193193
** post cannot be found. */
194194
if( firt ){
195
- pEntry->pIrt = pThread->pFirst;
195
+ pPost->pIrt = pThread->pFirst;
196196
for(p=pThread->pFirst; p; p=p->pNext){
197197
if( p->fpid==firt ){
198
- pEntry->pIrt = p;
198
+ pPost->pIrt = p;
199199
break;
200200
}
201201
}
202202
}
203203
204204
/* Maintain the linked list of post edits. */
205205
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;
213213
for(; p; p=p->pEditPrev ){
214
- p->nEdit = pEntry->nEdit;
215
- p->pEditTail = pEntry;
214
+ p->nEdit = pPost->nEdit;
215
+ p->pEditTail = pPost;
216216
}
217217
}
218218
}
219219
db_finalize(&q);
220220
221221
if( computeHierarchy ){
222222
/* Compute the hierarchical display order */
223
- pEntry = pThread->pFirst;
224
- pEntry->nIndent = 1;
223
+ pPost = pThread->pFirst;
224
+ pPost->nIndent = 1;
225225
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);
228228
}
229229
230230
/* Return the result */
231231
return pThread;
232232
}
@@ -270,11 +270,11 @@
270270
void forumthread_cmd(void){
271271
int fpid;
272272
int froot;
273273
const char *zName;
274274
ForumThread *pThread;
275
- ForumEntry *p;
275
+ ForumPost *p;
276276
277277
db_find_and_open_repository(0,0);
278278
verify_all_options();
279279
if( g.argc==2 ){
280280
forum_thread_list();
@@ -413,11 +413,11 @@
413413
/*
414414
** Display all posts in a forum thread in chronological order
415415
*/
416416
static void forum_display_chronological(int froot, int target, int bRawMode){
417417
ForumThread *pThread = forumthread_create(froot, 0);
418
- ForumEntry *p;
418
+ ForumPost *p;
419419
int notAnon = login_is_individual();
420420
char cMode = bRawMode ? 'r' : 'c';
421421
for(p=pThread->pFirst; p; p=p->pNext){
422422
char *zDate;
423423
Manifest *pPost;
@@ -548,14 +548,14 @@
548548
/*
549549
** Display all the edit history of post "target".
550550
*/
551551
static void forum_display_history(int froot, int target, int bRawMode){
552552
ForumThread *pThread = forumthread_create(froot, 0);
553
- ForumEntry *p;
553
+ ForumPost *p;
554554
int notAnon = login_is_individual();
555555
char cMode = bRawMode ? 'r' : 'c';
556
- ForumEntry *pEditTail = 0;
556
+ ForumPost *pEditTail = 0;
557557
int cnt = 0;
558558
for(p=pThread->pFirst; p; p=p->pNext){
559559
if( p->fpid==target ){
560560
pEditTail = p->pEditTail ? p->pEditTail : p;
561561
break;
@@ -644,11 +644,11 @@
644644
/*
645645
** Display all messages in a forumthread with indentation.
646646
*/
647647
static int forum_display_hierarchical(int froot, int target){
648648
ForumThread *pThread;
649
- ForumEntry *p;
649
+ ForumPost *p;
650650
Manifest *pPost, *pOPost;
651651
int fpid;
652652
const char *zUuid;
653653
char *zDate;
654654
const char *zSel;
@@ -1031,11 +1031,11 @@
10311031
}
10321032
10331033
/*
10341034
** Paint the form elements for entering a Forum post
10351035
*/
1036
-static void forum_entry_widget(
1036
+static void forum_post_widget(
10371037
const char *zTitle,
10381038
const char *zMimetype,
10391039
const char *zContent
10401040
){
10411041
if( zTitle ){
@@ -1140,11 +1140,11 @@
11401140
}
11411141
style_header("New Forum Thread");
11421142
@ <form action="%R/forume1" method="POST">
11431143
@ <h1>New Thread:</h1>
11441144
forum_from_line();
1145
- forum_entry_widget(zTitle, zMimetype, zContent);
1145
+ forum_post_widget(zTitle, zMimetype, zContent);
11461146
@ <input type="submit" name="preview" value="Preview">
11471147
if( P("preview") && !whitespace_only(zContent) ){
11481148
@ <input type="submit" name="submit" value="Submit">
11491149
}else{
11501150
@ <input type="submit" name="submit" value="Submit" disabled>
@@ -1290,11 +1290,11 @@
12901290
@ <h2>Revised Message:</h2>
12911291
@ <form action="%R/forume2" method="POST">
12921292
@ <input type="hidden" name="fpid" value="%h(P("fpid"))">
12931293
@ <input type="hidden" name="edit" value="1">
12941294
forum_from_line();
1295
- forum_entry_widget(zTitle, zMimetype, zContent);
1295
+ forum_post_widget(zTitle, zMimetype, zContent);
12961296
}else{
12971297
/* Reply */
12981298
char *zDisplayName;
12991299
zMimetype = PD("mimetype",DEFAULT_FORUM_MIMETYPE);
13001300
zContent = PDT("content","");
@@ -1316,11 +1316,11 @@
13161316
@ <h2>Enter Reply:</h2>
13171317
@ <form action="%R/forume2" method="POST">
13181318
@ <input type="hidden" name="fpid" value="%h(P("fpid"))">
13191319
@ <input type="hidden" name="reply" value="1">
13201320
forum_from_line();
1321
- forum_entry_widget(0, zMimetype, zContent);
1321
+ forum_post_widget(0, zMimetype, zContent);
13221322
}
13231323
if( !isDelete ){
13241324
@ <input type="submit" name="preview" value="Preview">
13251325
}
13261326
@ <input type="submit" name="cancel" value="Cancel">
13271327
--- 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

Keyboard Shortcuts

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