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.
Commit
ef7f85eecd9605921bd0aad9087022e87ab0936a92561a2dd19a737ed886dba7
Parent
b0ae37c0391dc26…
2 files changed
+34
-15
+1
-1
+34
-15
| --- src/forum.c | ||
| +++ src/forum.c | ||
| @@ -935,24 +935,38 @@ | ||
| 935 | 935 | } |
| 936 | 936 | iLimit = atoi(PD("n","25")); |
| 937 | 937 | iOfst = atoi(PD("x","0")); |
| 938 | 938 | iCnt = 0; |
| 939 | 939 | 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 | + ")" | |
| 941 | 955 | "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*/, | |
| 954 | 968 | iLimit+1, iOfst |
| 955 | 969 | ); |
| 956 | 970 | while( db_step(&q)==SQLITE_ROW ){ |
| 957 | 971 | char *zAge = human_readable_age(db_column_double(&q,0)); |
| 958 | 972 | int nMsg = db_column_int(&q, 2); |
| @@ -984,15 +998,20 @@ | ||
| 984 | 998 | fossil_free(zAge); |
| 985 | 999 | break; |
| 986 | 1000 | } |
| 987 | 1001 | @ <tr><td>%h(zAge) ago</td> |
| 988 | 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 | + } | |
| 989 | 1008 | if( nMsg<2 ){ |
| 990 | - @ <td>no replies</td> | |
| 1009 | + @ no replies</td> | |
| 991 | 1010 | }else{ |
| 992 | 1011 | 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> | |
| 994 | 1013 | fossil_free(zDuration); |
| 995 | 1014 | } |
| 996 | 1015 | @ </tr> |
| 997 | 1016 | fossil_free(zAge); |
| 998 | 1017 | } |
| 999 | 1018 |
| --- 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 @@ | ||
| 562 | 562 | @ froot INT, -- fpid of the thread root |
| 563 | 563 | @ fprev INT, -- Previous version of this same post |
| 564 | 564 | @ firt INT, -- This post is in-reply-to |
| 565 | 565 | @ fmtime REAL -- When posted. Julian day |
| 566 | 566 | @ ); |
| 567 | -@ CREATE INDEX repository.forumthread ON forumpost(froot); | |
| 567 | +@ CREATE INDEX repository.forumthread ON forumpost(froot,fmtime); | |
| 568 | 568 | ; |
| 569 | 569 | |
| 570 | 570 | /* Create the forum-post schema if it does not already exist */ |
| 571 | 571 | void schema_forum(void){ |
| 572 | 572 | if( !db_table_exists("repository","forumpost") ){ |
| 573 | 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); |
| 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 |