Fossil SCM

Add an Attach button to the currently-selected forum post if the user is an admin or the owner of the post. Make some use of ForumPost::pEditHead to save a query.

stephan 2026-05-22 22:04 UTC forum-attachments
Commit b3c9af20921ee19b41ad6136108573c28884d4a8d4e1da80d886094edc66a3f2
1 file changed +22 -13
+22 -13
--- src/forum.c
+++ src/forum.c
@@ -779,12 +779,12 @@
779779
if( p->zDisplayName==0 ) return "(unknown)";
780780
return p->zDisplayName;
781781
}
782782
783783
static void forum_render_attachment_list(ForumPost *p){
784
- while( p->pEditPrev ) p = p->pEditPrev;
785
- attachment_list(p->zUuid, "Attachments", 1);
784
+ if( p->pEditHead ) p = p->pEditHead;
785
+ attachment_list(p->zUuid, "Attachments:", 1);
786786
}
787787
788788
/*
789789
** Display a single post in a forum thread.
790790
*/
@@ -971,21 +971,30 @@
971971
/* Allow users to delete (reject) their own pending posts. */
972972
@ <input type="submit" name="reject" value="Delete">
973973
}
974974
login_insert_csrf_secret();
975975
@ </form>
976
- if( bSelect && forumpost_may_close() && iClosed>=0 ){
977
- int iHead = forumpost_head_rid(p->fpid);
978
- @ <form method="post" \
979
- @ action='%R/forumpost_%s(iClosed > 0 ? "reopen" : "close")'>
980
- login_insert_csrf_secret();
981
- @ <input type="hidden" name="fpid" value="%z(rid_to_uuid(iHead))" />
982
- if( moderation_pending(p->fpid)==0 ){
983
- @ <input type="button" value='%s(iClosed ? "Re-open" : "Close")' \
984
- @ class='%s(iClosed ? "action-reopen" : "action-close")'/>
985
- }
986
- @ </form>
976
+
977
+ if( bSelect ){
978
+ ForumPost *pHead = p->pEditHead ? p->pEditHead : p;
979
+ if( forumpost_may_close() && iClosed>=0 ){
980
+ @ <form method="post" \
981
+ @ action='%R/forumpost_%s(iClosed > 0 ? "reopen" : "close")'>
982
+ login_insert_csrf_secret();
983
+ @ <input type="hidden" name="fpid" value="%s(pHead->zUuid)" />
984
+ if( moderation_pending(p->fpid)==0 ){
985
+ @ <input type="button" value='%s(iClosed ? "Re-open" : "Close")' \
986
+ @ class='%s(iClosed ? "action-reopen" : "action-close")'/>
987
+ }
988
+ @ </form>
989
+ }
990
+ if( g.perm.Admin || forumpost_is_owner(p/*not pHead*/->fpid, 0) ){
991
+ @ <form method="post" action="%R/attachadd">\
992
+ @ <input type="hidden" name="forumpost" value="%T(pHead->zUuid)">
993
+ @ <input type="submit" value="Attach...">
994
+ @ </form>
995
+ }
987996
}
988997
@ </div>
989998
}
990999
@ </div>
9911000
}
9921001
--- src/forum.c
+++ src/forum.c
@@ -779,12 +779,12 @@
779 if( p->zDisplayName==0 ) return "(unknown)";
780 return p->zDisplayName;
781 }
782
783 static void forum_render_attachment_list(ForumPost *p){
784 while( p->pEditPrev ) p = p->pEditPrev;
785 attachment_list(p->zUuid, "Attachments", 1);
786 }
787
788 /*
789 ** Display a single post in a forum thread.
790 */
@@ -971,21 +971,30 @@
971 /* Allow users to delete (reject) their own pending posts. */
972 @ <input type="submit" name="reject" value="Delete">
973 }
974 login_insert_csrf_secret();
975 @ </form>
976 if( bSelect && forumpost_may_close() && iClosed>=0 ){
977 int iHead = forumpost_head_rid(p->fpid);
978 @ <form method="post" \
979 @ action='%R/forumpost_%s(iClosed > 0 ? "reopen" : "close")'>
980 login_insert_csrf_secret();
981 @ <input type="hidden" name="fpid" value="%z(rid_to_uuid(iHead))" />
982 if( moderation_pending(p->fpid)==0 ){
983 @ <input type="button" value='%s(iClosed ? "Re-open" : "Close")' \
984 @ class='%s(iClosed ? "action-reopen" : "action-close")'/>
985 }
986 @ </form>
 
 
 
 
 
 
 
 
 
987 }
988 @ </div>
989 }
990 @ </div>
991 }
992
--- src/forum.c
+++ src/forum.c
@@ -779,12 +779,12 @@
779 if( p->zDisplayName==0 ) return "(unknown)";
780 return p->zDisplayName;
781 }
782
783 static void forum_render_attachment_list(ForumPost *p){
784 if( p->pEditHead ) p = p->pEditHead;
785 attachment_list(p->zUuid, "Attachments:", 1);
786 }
787
788 /*
789 ** Display a single post in a forum thread.
790 */
@@ -971,21 +971,30 @@
971 /* Allow users to delete (reject) their own pending posts. */
972 @ <input type="submit" name="reject" value="Delete">
973 }
974 login_insert_csrf_secret();
975 @ </form>
976
977 if( bSelect ){
978 ForumPost *pHead = p->pEditHead ? p->pEditHead : p;
979 if( forumpost_may_close() && iClosed>=0 ){
980 @ <form method="post" \
981 @ action='%R/forumpost_%s(iClosed > 0 ? "reopen" : "close")'>
982 login_insert_csrf_secret();
983 @ <input type="hidden" name="fpid" value="%s(pHead->zUuid)" />
984 if( moderation_pending(p->fpid)==0 ){
985 @ <input type="button" value='%s(iClosed ? "Re-open" : "Close")' \
986 @ class='%s(iClosed ? "action-reopen" : "action-close")'/>
987 }
988 @ </form>
989 }
990 if( g.perm.Admin || forumpost_is_owner(p/*not pHead*/->fpid, 0) ){
991 @ <form method="post" action="%R/attachadd">\
992 @ <input type="hidden" name="forumpost" value="%T(pHead->zUuid)">
993 @ <input type="submit" value="Attach...">
994 @ </form>
995 }
996 }
997 @ </div>
998 }
999 @ </div>
1000 }
1001

Keyboard Shortcuts

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