Fossil SCM

For the /forumthreadhashlist page, show more details, and especially tags that set status and "closed" for the thread.

drh 2026-10-24 18:44 UTC trunk
Commit 08ce190f39d8f9f1161ca837a3400f266be34cd62f1f6dd04d74295697a30259
1 file changed +117 -8
+117 -8
--- src/forum.c
+++ src/forum.c
@@ -833,19 +833,19 @@
833833
** WEBPAGE: forumthreadhashlist
834834
**
835835
** Usage: /forumthreadhashlist/HASH-OF-ROOT
836836
**
837837
** This page (accessibly only to admins) shows a list of all artifacts
838
-** associated with a single forum thread. An admin might copy/paste this
839
-** list into the /shun page in order to shun an entire thread.
838
+** associated with a single forum thread, including control artifacts
839
+** that close or reopen posts or change the status of the thread.
840
+** An admin might copy/paste the list of hashes into the /shun page in
841
+** order to shun an entire thread.
840842
*/
841843
void forumthreadhashlist(void){
842844
int fpid;
843845
int froot;
844846
const char *zName = P("name");
845
- ForumThread *pThread;
846
- ForumPost *p;
847847
char *fuuid;
848848
Stmt q;
849849
850850
login_check_credentials();
851851
if( !g.perm.Admin ){
@@ -868,19 +868,128 @@
868868
webpage_notfound_error("Not a forum post: \"%s\"", zName);
869869
}
870870
fuuid = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", froot);
871871
style_set_current_feature("forum");
872872
style_header("Artifacts Of Forum Thread");
873
+
874
+ /* The fthread table holds the RID of every artifact associated with
875
+ ** the thread. That is the forum posts themselves, plus any control
876
+ ** artifacts that tag those posts, such as to close or reopen a post
877
+ ** or to change the status of the thread. For control artifacts,
878
+ ** zDesc is an HTML description of the tags applied.
879
+ **
880
+ ** Candidate control artifacts come from tagxref.srcid, which only
881
+ ** remembers the most recent tag of each name on each post, and from
882
+ ** the event.comment that manifest_crosslink() generates for each
883
+ ** control artifact, which also finds tags that have since been
884
+ ** superseded. That comment includes a hash prefix of at least 12
885
+ ** characters for each tagged artifact. Each candidate is then
886
+ ** parsed to verify that it really does tag a post in this thread.
887
+ */
888
+ db_multi_exec(
889
+ "CREATE TEMP TABLE IF NOT EXISTS fthread("
890
+ " rid INTEGER PRIMARY KEY, isCtrl BOOLEAN, zDesc TEXT);"
891
+ "DELETE FROM fthread;"
892
+ "INSERT OR IGNORE INTO fthread(rid,isCtrl)"
893
+ " SELECT fpid, 0 FROM forumpost WHERE froot=%d;"
894
+ "INSERT OR IGNORE INTO fthread(rid,isCtrl)"
895
+ " SELECT srcid, 1 FROM tagxref"
896
+ " WHERE rid IN (SELECT fpid FROM forumpost WHERE froot=%d)"
897
+ " AND srcid>0 AND srcid!=rid;"
898
+ "INSERT OR IGNORE INTO fthread(rid,isCtrl)"
899
+ " SELECT event.objid, 1 FROM event, forumpost, blob"
900
+ " WHERE forumpost.froot=%d"
901
+ " AND blob.rid=forumpost.fpid"
902
+ " AND event.type='g'"
903
+ " AND instr(event.comment, '['||substr(blob.uuid,1,12))>0"
904
+ " AND event.mtime >= forumpost.fmtime-0.01"
905
+ " AND event.mtime <= (SELECT max(mtime) FROM tagxref"
906
+ " WHERE rid=%d);",
907
+ froot, froot, froot, froot
908
+ );
909
+ db_prepare(&q, "SELECT rid FROM fthread WHERE isCtrl");
910
+ while( db_step(&q)==SQLITE_ROW ){
911
+ int rid = db_column_int(&q, 0);
912
+ Manifest *pCtrl = manifest_get(rid, CFTYPE_CONTROL, 0);
913
+ Blob desc = BLOB_INITIALIZER;
914
+ int i;
915
+ for(i=0; pCtrl && i<pCtrl->nTag; i++){
916
+ const char *zTag = pCtrl->aTag[i].zName;
917
+ const char *zVal = pCtrl->aTag[i].zValue;
918
+ const char *zTarget = pCtrl->aTag[i].zUuid;
919
+ int isCancel = zTag[0]=='-';
920
+ if( zTarget==0
921
+ || !db_exists("SELECT 1 FROM forumpost, blob"
922
+ " WHERE forumpost.froot=%d AND blob.rid=forumpost.fpid"
923
+ " AND blob.uuid=%Q", froot, zTarget)
924
+ ){
925
+ continue;
926
+ }
927
+ if( blob_size(&desc) ) blob_append(&desc, "; ", 2);
928
+ if( fossil_strcmp(&zTag[1], "closed")==0 ){
929
+ blob_append(&desc, isCancel ? "reopen" : "close", -1);
930
+ }else if( fossil_strcmp(&zTag[1], "status")==0 ){
931
+ if( isCancel || zVal==0 || zVal[0]==0 ){
932
+ blob_append(&desc, "clear status of", -1);
933
+ }else{
934
+ blob_appendf(&desc, "set status \"%h\" on", zVal);
935
+ }
936
+ }else if( zVal && zVal[0] ){
937
+ blob_appendf(&desc, "tag %h=\"%h\" on", zTag, zVal);
938
+ }else{
939
+ blob_appendf(&desc, "tag %h on", zTag);
940
+ }
941
+ blob_appendf(&desc, " post %z%S</a>",
942
+ href("%R/forumpost/%!S", zTarget), zTarget);
943
+ }
944
+ manifest_destroy(pCtrl);
945
+ if( blob_size(&desc)==0 ){
946
+ db_multi_exec("DELETE FROM fthread WHERE rid=%d", rid);
947
+ }else{
948
+ db_multi_exec("UPDATE fthread SET zDesc=%Q WHERE rid=%d",
949
+ blob_str(&desc), rid);
950
+ }
951
+ blob_reset(&desc);
952
+ }
953
+ db_finalize(&q);
954
+ describe_artifacts("IN (SELECT rid FROM fthread)");
955
+
873956
@ <h2>
874957
@ Artifacts associated with the forum thread
875958
@ <a href="%R/forumthread/%S(fuuid)">%S(fuuid)</a>:</h2>
959
+ @ <table border="1" cellpadding="4" cellspacing="0">
960
+ @ <tr><th>Date<th>Hash<th>User<th>Description
961
+ db_prepare(&q,
962
+ "SELECT description.uuid,"
963
+ " datetime(coalesce(event.mtime,description.ctime)),"
964
+ " coalesce(event.euser,event.user),"
965
+ " description.summary, fthread.zDesc"
966
+ " FROM fthread JOIN description USING(rid)"
967
+ " LEFT JOIN event ON event.objid=fthread.rid"
968
+ " ORDER BY coalesce(event.mtime,description.ctime), fthread.rid"
969
+ );
970
+ while( db_step(&q)==SQLITE_ROW ){
971
+ const char *zUuid = db_column_text(&q, 0);
972
+ const char *zCtrlDesc = db_column_text(&q, 4);
973
+ @ <tr><td>%h(db_column_text(&q,1))\
974
+ @ <td>%z(href("%R/artifact/%!S",zUuid))%S(zUuid)</a>\
975
+ @ <td>%h(db_column_text(&q,2))\
976
+ if( zCtrlDesc ){
977
+ @ <td>forum-tag: %s(zCtrlDesc)</tr>
978
+ }else{
979
+ @ <td>%h(db_column_text(&q,3))</tr>
980
+ }
981
+ }
982
+ @ </table>
983
+ @ <h2>Artifact hashes, suitable for pasting into
984
+ @ %z(href("%R/shun"))/shun</a>:</h2>
876985
@ <pre>
877
- pThread = forumthread_create(froot, 1);
878
- for(p=pThread->pFirst; p; p=p->pNext){
879
- @ %h(p->zUuid)
986
+ db_reset(&q);
987
+ while( db_step(&q)==SQLITE_ROW ){
988
+ @ %h(db_column_text(&q,0))
880989
}
881
- forumthread_delete(pThread);
990
+ db_finalize(&q);
882991
@ </pre>
883992
@ <hr>
884993
@ <h2>Related FORUMPOST Table Content</h2>
885994
@ <table border="1" cellpadding="4" cellspacing="0">
886995
@ <tr><th>fpid<th>froot<th>fprev<th>firt<th>fmtime
887996
--- src/forum.c
+++ src/forum.c
@@ -833,19 +833,19 @@
833 ** WEBPAGE: forumthreadhashlist
834 **
835 ** Usage: /forumthreadhashlist/HASH-OF-ROOT
836 **
837 ** This page (accessibly only to admins) shows a list of all artifacts
838 ** associated with a single forum thread. An admin might copy/paste this
839 ** list into the /shun page in order to shun an entire thread.
 
 
840 */
841 void forumthreadhashlist(void){
842 int fpid;
843 int froot;
844 const char *zName = P("name");
845 ForumThread *pThread;
846 ForumPost *p;
847 char *fuuid;
848 Stmt q;
849
850 login_check_credentials();
851 if( !g.perm.Admin ){
@@ -868,19 +868,128 @@
868 webpage_notfound_error("Not a forum post: \"%s\"", zName);
869 }
870 fuuid = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", froot);
871 style_set_current_feature("forum");
872 style_header("Artifacts Of Forum Thread");
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
873 @ <h2>
874 @ Artifacts associated with the forum thread
875 @ <a href="%R/forumthread/%S(fuuid)">%S(fuuid)</a>:</h2>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
876 @ <pre>
877 pThread = forumthread_create(froot, 1);
878 for(p=pThread->pFirst; p; p=p->pNext){
879 @ %h(p->zUuid)
880 }
881 forumthread_delete(pThread);
882 @ </pre>
883 @ <hr>
884 @ <h2>Related FORUMPOST Table Content</h2>
885 @ <table border="1" cellpadding="4" cellspacing="0">
886 @ <tr><th>fpid<th>froot<th>fprev<th>firt<th>fmtime
887
--- src/forum.c
+++ src/forum.c
@@ -833,19 +833,19 @@
833 ** WEBPAGE: forumthreadhashlist
834 **
835 ** Usage: /forumthreadhashlist/HASH-OF-ROOT
836 **
837 ** This page (accessibly only to admins) shows a list of all artifacts
838 ** associated with a single forum thread, including control artifacts
839 ** that close or reopen posts or change the status of the thread.
840 ** An admin might copy/paste the list of hashes into the /shun page in
841 ** order to shun an entire thread.
842 */
843 void forumthreadhashlist(void){
844 int fpid;
845 int froot;
846 const char *zName = P("name");
 
 
847 char *fuuid;
848 Stmt q;
849
850 login_check_credentials();
851 if( !g.perm.Admin ){
@@ -868,19 +868,128 @@
868 webpage_notfound_error("Not a forum post: \"%s\"", zName);
869 }
870 fuuid = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", froot);
871 style_set_current_feature("forum");
872 style_header("Artifacts Of Forum Thread");
873
874 /* The fthread table holds the RID of every artifact associated with
875 ** the thread. That is the forum posts themselves, plus any control
876 ** artifacts that tag those posts, such as to close or reopen a post
877 ** or to change the status of the thread. For control artifacts,
878 ** zDesc is an HTML description of the tags applied.
879 **
880 ** Candidate control artifacts come from tagxref.srcid, which only
881 ** remembers the most recent tag of each name on each post, and from
882 ** the event.comment that manifest_crosslink() generates for each
883 ** control artifact, which also finds tags that have since been
884 ** superseded. That comment includes a hash prefix of at least 12
885 ** characters for each tagged artifact. Each candidate is then
886 ** parsed to verify that it really does tag a post in this thread.
887 */
888 db_multi_exec(
889 "CREATE TEMP TABLE IF NOT EXISTS fthread("
890 " rid INTEGER PRIMARY KEY, isCtrl BOOLEAN, zDesc TEXT);"
891 "DELETE FROM fthread;"
892 "INSERT OR IGNORE INTO fthread(rid,isCtrl)"
893 " SELECT fpid, 0 FROM forumpost WHERE froot=%d;"
894 "INSERT OR IGNORE INTO fthread(rid,isCtrl)"
895 " SELECT srcid, 1 FROM tagxref"
896 " WHERE rid IN (SELECT fpid FROM forumpost WHERE froot=%d)"
897 " AND srcid>0 AND srcid!=rid;"
898 "INSERT OR IGNORE INTO fthread(rid,isCtrl)"
899 " SELECT event.objid, 1 FROM event, forumpost, blob"
900 " WHERE forumpost.froot=%d"
901 " AND blob.rid=forumpost.fpid"
902 " AND event.type='g'"
903 " AND instr(event.comment, '['||substr(blob.uuid,1,12))>0"
904 " AND event.mtime >= forumpost.fmtime-0.01"
905 " AND event.mtime <= (SELECT max(mtime) FROM tagxref"
906 " WHERE rid=%d);",
907 froot, froot, froot, froot
908 );
909 db_prepare(&q, "SELECT rid FROM fthread WHERE isCtrl");
910 while( db_step(&q)==SQLITE_ROW ){
911 int rid = db_column_int(&q, 0);
912 Manifest *pCtrl = manifest_get(rid, CFTYPE_CONTROL, 0);
913 Blob desc = BLOB_INITIALIZER;
914 int i;
915 for(i=0; pCtrl && i<pCtrl->nTag; i++){
916 const char *zTag = pCtrl->aTag[i].zName;
917 const char *zVal = pCtrl->aTag[i].zValue;
918 const char *zTarget = pCtrl->aTag[i].zUuid;
919 int isCancel = zTag[0]=='-';
920 if( zTarget==0
921 || !db_exists("SELECT 1 FROM forumpost, blob"
922 " WHERE forumpost.froot=%d AND blob.rid=forumpost.fpid"
923 " AND blob.uuid=%Q", froot, zTarget)
924 ){
925 continue;
926 }
927 if( blob_size(&desc) ) blob_append(&desc, "; ", 2);
928 if( fossil_strcmp(&zTag[1], "closed")==0 ){
929 blob_append(&desc, isCancel ? "reopen" : "close", -1);
930 }else if( fossil_strcmp(&zTag[1], "status")==0 ){
931 if( isCancel || zVal==0 || zVal[0]==0 ){
932 blob_append(&desc, "clear status of", -1);
933 }else{
934 blob_appendf(&desc, "set status \"%h\" on", zVal);
935 }
936 }else if( zVal && zVal[0] ){
937 blob_appendf(&desc, "tag %h=\"%h\" on", zTag, zVal);
938 }else{
939 blob_appendf(&desc, "tag %h on", zTag);
940 }
941 blob_appendf(&desc, " post %z%S</a>",
942 href("%R/forumpost/%!S", zTarget), zTarget);
943 }
944 manifest_destroy(pCtrl);
945 if( blob_size(&desc)==0 ){
946 db_multi_exec("DELETE FROM fthread WHERE rid=%d", rid);
947 }else{
948 db_multi_exec("UPDATE fthread SET zDesc=%Q WHERE rid=%d",
949 blob_str(&desc), rid);
950 }
951 blob_reset(&desc);
952 }
953 db_finalize(&q);
954 describe_artifacts("IN (SELECT rid FROM fthread)");
955
956 @ <h2>
957 @ Artifacts associated with the forum thread
958 @ <a href="%R/forumthread/%S(fuuid)">%S(fuuid)</a>:</h2>
959 @ <table border="1" cellpadding="4" cellspacing="0">
960 @ <tr><th>Date<th>Hash<th>User<th>Description
961 db_prepare(&q,
962 "SELECT description.uuid,"
963 " datetime(coalesce(event.mtime,description.ctime)),"
964 " coalesce(event.euser,event.user),"
965 " description.summary, fthread.zDesc"
966 " FROM fthread JOIN description USING(rid)"
967 " LEFT JOIN event ON event.objid=fthread.rid"
968 " ORDER BY coalesce(event.mtime,description.ctime), fthread.rid"
969 );
970 while( db_step(&q)==SQLITE_ROW ){
971 const char *zUuid = db_column_text(&q, 0);
972 const char *zCtrlDesc = db_column_text(&q, 4);
973 @ <tr><td>%h(db_column_text(&q,1))\
974 @ <td>%z(href("%R/artifact/%!S",zUuid))%S(zUuid)</a>\
975 @ <td>%h(db_column_text(&q,2))\
976 if( zCtrlDesc ){
977 @ <td>forum-tag: %s(zCtrlDesc)</tr>
978 }else{
979 @ <td>%h(db_column_text(&q,3))</tr>
980 }
981 }
982 @ </table>
983 @ <h2>Artifact hashes, suitable for pasting into
984 @ %z(href("%R/shun"))/shun</a>:</h2>
985 @ <pre>
986 db_reset(&q);
987 while( db_step(&q)==SQLITE_ROW ){
988 @ %h(db_column_text(&q,0))
989 }
990 db_finalize(&q);
991 @ </pre>
992 @ <hr>
993 @ <h2>Related FORUMPOST Table Content</h2>
994 @ <table border="1" cellpadding="4" cellspacing="0">
995 @ <tr><th>fpid<th>froot<th>fprev<th>firt<th>fmtime
996

Keyboard Shortcuts

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