Fossil SCM

Adjust the /forum page so that it for users without forum moderator privilege, it pretends that unmoderated posts do not exist, and for user with moderator privilege it paints an "Awaiting Moderator Approval" message on posts that need moderation.

drh 2018-08-16 16:13 trunk
Commit ef7f85eecd9605921bd0aad9087022e87ab0936a92561a2dd19a737ed886dba7
2 files changed +34 -15 +1 -1
+34 -15
--- src/forum.c
+++ src/forum.c
@@ -935,24 +935,38 @@
935935
}
936936
iLimit = atoi(PD("n","25"));
937937
iOfst = atoi(PD("x","0"));
938938
iCnt = 0;
939939
if( db_table_exists("repository","forumpost") ){
940
- db_prepare(&q,
940
+ db_prepare(&q,
941
+ "WITH thread(age,duration,cnt,root,last) AS ("
942
+ " SELECT"
943
+ " julianday('now') - max(fmtime),"
944
+ " max(fmtime) - min(fmtime),"
945
+ " sum(fprev IS NULL),"
946
+ " froot,"
947
+ " (SELECT fpid FROM forumpost AS y"
948
+ " WHERE y.froot=x.froot %s"
949
+ " ORDER BY y.fmtime DESC LIMIT 1)"
950
+ " FROM forumpost AS x"
951
+ " WHERE %s"
952
+ " GROUP BY froot"
953
+ " ORDER BY 1 LIMIT %d OFFSET %d"
954
+ ")"
941955
"SELECT"
942
- " julianday('now') - max(fmtime) AS a," /* 0 */
943
- " max(fmtime) - min(fmtime) AS b," /* 1 */
944
- " sum(fprev IS NULL) AS c," /* 2 */
945
- " (SELECT substr(uuid,1,10) FROM blob, forumpost AS z" /* 3 */
946
- " WHERE rid=z.fpid AND z.froot=x.froot"
947
- " ORDER BY z.fmtime DESC LIMIT 1),"
948
- " (SELECT substr(comment,instr(comment,':')+2)" /* 4 */
949
- " FROM event WHERE objid=(SELECT fpid FROM forumpost AS y"
950
- " WHERE y.froot=x.froot"
951
- " ORDER BY fmtime DESC LIMIT 1))"
952
- " FROM forumpost AS x"
953
- " GROUP BY froot ORDER BY 1 LIMIT %d OFFSET %d;",
956
+ " thread.age," /* 0 */
957
+ " thread.duration," /* 1 */
958
+ " thread.cnt," /* 2 */
959
+ " blob.uuid," /* 3 */
960
+ " substr(event.comment,instr(event.comment,':')+1)," /* 4 */
961
+ " thread.last" /* 5 */
962
+ " FROM thread, blob, event"
963
+ " WHERE blob.rid=thread.last"
964
+ " AND event.objid=thread.last"
965
+ " ORDER BY 1;",
966
+ g.perm.ModForum ? "" : "AND y.fpid NOT IN private" /*safe-for-%s*/,
967
+ g.perm.ModForum ? "true" : "fpid NOT IN private" /*safe-for-%s*/,
954968
iLimit+1, iOfst
955969
);
956970
while( db_step(&q)==SQLITE_ROW ){
957971
char *zAge = human_readable_age(db_column_double(&q,0));
958972
int nMsg = db_column_int(&q, 2);
@@ -984,15 +998,20 @@
984998
fossil_free(zAge);
985999
break;
9861000
}
9871001
@ <tr><td>%h(zAge) ago</td>
9881002
@ <td>%z(href("%R/forumpost/%S",zUuid))%h(zTitle)</a></td>
1003
+ @ <td>\
1004
+ if( g.perm.ModForum && moderation_pending(db_column_int(&q,5)) ){
1005
+ @ <span class="modpending">\
1006
+ @ Awaiting Moderator Approval</span><br>
1007
+ }
9891008
if( nMsg<2 ){
990
- @ <td>no replies</td>
1009
+ @ no replies</td>
9911010
}else{
9921011
char *zDuration = human_readable_age(db_column_double(&q,1));
993
- @ <td>%d(nMsg) posts spanning %h(zDuration)</td>
1012
+ @ %d(nMsg) posts spanning %h(zDuration)</td>
9941013
fossil_free(zDuration);
9951014
}
9961015
@ </tr>
9971016
fossil_free(zAge);
9981017
}
9991018
--- src/forum.c
+++ src/forum.c
@@ -935,24 +935,38 @@
935 }
936 iLimit = atoi(PD("n","25"));
937 iOfst = atoi(PD("x","0"));
938 iCnt = 0;
939 if( db_table_exists("repository","forumpost") ){
940 db_prepare(&q,
 
 
 
 
 
 
 
 
 
 
 
 
 
 
941 "SELECT"
942 " julianday('now') - max(fmtime) AS a," /* 0 */
943 " max(fmtime) - min(fmtime) AS b," /* 1 */
944 " sum(fprev IS NULL) AS c," /* 2 */
945 " (SELECT substr(uuid,1,10) FROM blob, forumpost AS z" /* 3 */
946 " WHERE rid=z.fpid AND z.froot=x.froot"
947 " ORDER BY z.fmtime DESC LIMIT 1),"
948 " (SELECT substr(comment,instr(comment,':')+2)" /* 4 */
949 " FROM event WHERE objid=(SELECT fpid FROM forumpost AS y"
950 " WHERE y.froot=x.froot"
951 " ORDER BY fmtime DESC LIMIT 1))"
952 " FROM forumpost AS x"
953 " GROUP BY froot ORDER BY 1 LIMIT %d OFFSET %d;",
954 iLimit+1, iOfst
955 );
956 while( db_step(&q)==SQLITE_ROW ){
957 char *zAge = human_readable_age(db_column_double(&q,0));
958 int nMsg = db_column_int(&q, 2);
@@ -984,15 +998,20 @@
984 fossil_free(zAge);
985 break;
986 }
987 @ <tr><td>%h(zAge) ago</td>
988 @ <td>%z(href("%R/forumpost/%S",zUuid))%h(zTitle)</a></td>
 
 
 
 
 
989 if( nMsg<2 ){
990 @ <td>no replies</td>
991 }else{
992 char *zDuration = human_readable_age(db_column_double(&q,1));
993 @ <td>%d(nMsg) posts spanning %h(zDuration)</td>
994 fossil_free(zDuration);
995 }
996 @ </tr>
997 fossil_free(zAge);
998 }
999
--- src/forum.c
+++ src/forum.c
@@ -935,24 +935,38 @@
935 }
936 iLimit = atoi(PD("n","25"));
937 iOfst = atoi(PD("x","0"));
938 iCnt = 0;
939 if( db_table_exists("repository","forumpost") ){
940 db_prepare(&q,
941 "WITH thread(age,duration,cnt,root,last) AS ("
942 " SELECT"
943 " julianday('now') - max(fmtime),"
944 " max(fmtime) - min(fmtime),"
945 " sum(fprev IS NULL),"
946 " froot,"
947 " (SELECT fpid FROM forumpost AS y"
948 " WHERE y.froot=x.froot %s"
949 " ORDER BY y.fmtime DESC LIMIT 1)"
950 " FROM forumpost AS x"
951 " WHERE %s"
952 " GROUP BY froot"
953 " ORDER BY 1 LIMIT %d OFFSET %d"
954 ")"
955 "SELECT"
956 " thread.age," /* 0 */
957 " thread.duration," /* 1 */
958 " thread.cnt," /* 2 */
959 " blob.uuid," /* 3 */
960 " substr(event.comment,instr(event.comment,':')+1)," /* 4 */
961 " thread.last" /* 5 */
962 " FROM thread, blob, event"
963 " WHERE blob.rid=thread.last"
964 " AND event.objid=thread.last"
965 " ORDER BY 1;",
966 g.perm.ModForum ? "" : "AND y.fpid NOT IN private" /*safe-for-%s*/,
967 g.perm.ModForum ? "true" : "fpid NOT IN private" /*safe-for-%s*/,
968 iLimit+1, iOfst
969 );
970 while( db_step(&q)==SQLITE_ROW ){
971 char *zAge = human_readable_age(db_column_double(&q,0));
972 int nMsg = db_column_int(&q, 2);
@@ -984,15 +998,20 @@
998 fossil_free(zAge);
999 break;
1000 }
1001 @ <tr><td>%h(zAge) ago</td>
1002 @ <td>%z(href("%R/forumpost/%S",zUuid))%h(zTitle)</a></td>
1003 @ <td>\
1004 if( g.perm.ModForum && moderation_pending(db_column_int(&q,5)) ){
1005 @ <span class="modpending">\
1006 @ Awaiting Moderator Approval</span><br>
1007 }
1008 if( nMsg<2 ){
1009 @ no replies</td>
1010 }else{
1011 char *zDuration = human_readable_age(db_column_double(&q,1));
1012 @ %d(nMsg) posts spanning %h(zDuration)</td>
1013 fossil_free(zDuration);
1014 }
1015 @ </tr>
1016 fossil_free(zAge);
1017 }
1018
+1 -1
--- src/schema.c
+++ src/schema.c
@@ -562,11 +562,11 @@
562562
@ froot INT, -- fpid of the thread root
563563
@ fprev INT, -- Previous version of this same post
564564
@ firt INT, -- This post is in-reply-to
565565
@ fmtime REAL -- When posted. Julian day
566566
@ );
567
-@ CREATE INDEX repository.forumthread ON forumpost(froot);
567
+@ CREATE INDEX repository.forumthread ON forumpost(froot,fmtime);
568568
;
569569
570570
/* Create the forum-post schema if it does not already exist */
571571
void schema_forum(void){
572572
if( !db_table_exists("repository","forumpost") ){
573573
--- src/schema.c
+++ src/schema.c
@@ -562,11 +562,11 @@
562 @ froot INT, -- fpid of the thread root
563 @ fprev INT, -- Previous version of this same post
564 @ firt INT, -- This post is in-reply-to
565 @ fmtime REAL -- When posted. Julian day
566 @ );
567 @ CREATE INDEX repository.forumthread ON forumpost(froot);
568 ;
569
570 /* Create the forum-post schema if it does not already exist */
571 void schema_forum(void){
572 if( !db_table_exists("repository","forumpost") ){
573
--- src/schema.c
+++ src/schema.c
@@ -562,11 +562,11 @@
562 @ froot INT, -- fpid of the thread root
563 @ fprev INT, -- Previous version of this same post
564 @ firt INT, -- This post is in-reply-to
565 @ fmtime REAL -- When posted. Julian day
566 @ );
567 @ CREATE INDEX repository.forumthread ON forumpost(froot,fmtime);
568 ;
569
570 /* Create the forum-post schema if it does not already exist */
571 void schema_forum(void){
572 if( !db_table_exists("repository","forumpost") ){
573

Keyboard Shortcuts

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