Fossil SCM

On the main /forum screen, provide the new n= and x= query parameters to enable access to older threads.

drh 2018-08-15 20:41 trunk
Commit aff20904fad05b078dfe5470686d106247fcffd3decf326bfb5a82e74e2c1c76
1 file changed +31 -6
+31 -6
--- src/forum.c
+++ src/forum.c
@@ -905,14 +905,19 @@
905905
** WEBPAGE: forum
906906
**
907907
** The main page for the forum feature. Show a list of recent forum
908908
** threads. Also show a search box at the top if search is enabled,
909909
** and a button for creating a new thread, if enabled.
910
+**
911
+** Query parameters:
912
+**
913
+** n=N The number of threads to show on each page
914
+** x=X Skip the first X threads
910915
*/
911916
void forum_main_page(void){
912917
Stmt q;
913
- int iLimit, iOfst;
918
+ int iLimit, iOfst, iCnt;
914919
login_check_credentials();
915920
if( !g.perm.RdForum ){
916921
login_needed(g.anon.RdForum);
917922
return;
918923
}
@@ -926,12 +931,12 @@
926931
if( search_screen(SRCH_FORUM, 0) ){
927932
style_submenu_element("Recent Threads","%R/forum");
928933
style_footer();
929934
return;
930935
}
931
- iLimit = 50;
932
- iOfst = 0;
936
+ iLimit = atoi(PD("n","25"));
937
+ iOfst = atoi(PD("x","0"));
933938
@ <h1>Recent Threads</h1>
934939
@ <div class='fileage'><table width="100%%">
935940
if( db_table_exists("repository","forumpost") ){
936941
db_prepare(&q,
937942
"SELECT"
@@ -943,23 +948,43 @@
943948
" FROM event WHERE objid=(SELECT fpid FROM forumpost AS y"
944949
" WHERE y.froot=x.froot"
945950
" ORDER BY fmtime DESC LIMIT 1))"
946951
" FROM forumpost AS x"
947952
" GROUP BY froot ORDER BY 1 LIMIT %d OFFSET %d;",
948
- iLimit, iOfst
953
+ iLimit+1, iOfst
949954
);
955
+ iCnt = 0;
950956
while( db_step(&q)==SQLITE_ROW ){
951
- char *zAge = human_readable_age(db_column_double(&q,0));
952
- char *zDuration = human_readable_age(db_column_double(&q,1));
957
+ char *zAge = 0;
958
+ char *zDuration = 0;
953959
int nMsg = db_column_int(&q, 2);
954960
const char *zUuid = db_column_text(&q, 3);
955961
const char *zTitle = db_column_text(&q, 4);
962
+ if( iCnt==0 && iOfst>0 ){
963
+ if( iOfst>iLimit ){
964
+ @ <tr><td colspan="3">\
965
+ @ %z(href("%R/forum?x=%d&n=%d",iOfst-iLimit,iLimit))\
966
+ @ &uarr; Newer...</a></td></tr>
967
+ }else{
968
+ @ <tr><td colspan="3">%z(href("%R/forum?n=%d",iLimit))\
969
+ @ &uarr; Newer...</a></td></tr>
970
+ }
971
+ }
972
+ iCnt++;
973
+ if( iCnt>iLimit ){
974
+ @ <tr><td colspan="3">\
975
+ @ %z(href("%R/forum?x=%d&n=%d",iOfst+iLimit,iLimit))\
976
+ @ &darr; Older...</a></td></tr>
977
+ break;
978
+ }
979
+ zAge = human_readable_age(db_column_double(&q,0));
956980
@ <tr><td>%h(zAge) ago</td>
957981
@ <td>%z(href("%R/forumpost/%S",zUuid))%h(zTitle)</a></td>
958982
if( nMsg<2 ){
959983
@ <td>no replies</td>
960984
}else{
985
+ zDuration = human_readable_age(db_column_double(&q,1));
961986
@ <td>%d(nMsg) posts spanning %h(zDuration)</td>
962987
}
963988
@ </tr>
964989
fossil_free(zAge);
965990
fossil_free(zDuration);
966991
--- src/forum.c
+++ src/forum.c
@@ -905,14 +905,19 @@
905 ** WEBPAGE: forum
906 **
907 ** The main page for the forum feature. Show a list of recent forum
908 ** threads. Also show a search box at the top if search is enabled,
909 ** and a button for creating a new thread, if enabled.
 
 
 
 
 
910 */
911 void forum_main_page(void){
912 Stmt q;
913 int iLimit, iOfst;
914 login_check_credentials();
915 if( !g.perm.RdForum ){
916 login_needed(g.anon.RdForum);
917 return;
918 }
@@ -926,12 +931,12 @@
926 if( search_screen(SRCH_FORUM, 0) ){
927 style_submenu_element("Recent Threads","%R/forum");
928 style_footer();
929 return;
930 }
931 iLimit = 50;
932 iOfst = 0;
933 @ <h1>Recent Threads</h1>
934 @ <div class='fileage'><table width="100%%">
935 if( db_table_exists("repository","forumpost") ){
936 db_prepare(&q,
937 "SELECT"
@@ -943,23 +948,43 @@
943 " FROM event WHERE objid=(SELECT fpid FROM forumpost AS y"
944 " WHERE y.froot=x.froot"
945 " ORDER BY fmtime DESC LIMIT 1))"
946 " FROM forumpost AS x"
947 " GROUP BY froot ORDER BY 1 LIMIT %d OFFSET %d;",
948 iLimit, iOfst
949 );
 
950 while( db_step(&q)==SQLITE_ROW ){
951 char *zAge = human_readable_age(db_column_double(&q,0));
952 char *zDuration = human_readable_age(db_column_double(&q,1));
953 int nMsg = db_column_int(&q, 2);
954 const char *zUuid = db_column_text(&q, 3);
955 const char *zTitle = db_column_text(&q, 4);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
956 @ <tr><td>%h(zAge) ago</td>
957 @ <td>%z(href("%R/forumpost/%S",zUuid))%h(zTitle)</a></td>
958 if( nMsg<2 ){
959 @ <td>no replies</td>
960 }else{
 
961 @ <td>%d(nMsg) posts spanning %h(zDuration)</td>
962 }
963 @ </tr>
964 fossil_free(zAge);
965 fossil_free(zDuration);
966
--- src/forum.c
+++ src/forum.c
@@ -905,14 +905,19 @@
905 ** WEBPAGE: forum
906 **
907 ** The main page for the forum feature. Show a list of recent forum
908 ** threads. Also show a search box at the top if search is enabled,
909 ** and a button for creating a new thread, if enabled.
910 **
911 ** Query parameters:
912 **
913 ** n=N The number of threads to show on each page
914 ** x=X Skip the first X threads
915 */
916 void forum_main_page(void){
917 Stmt q;
918 int iLimit, iOfst, iCnt;
919 login_check_credentials();
920 if( !g.perm.RdForum ){
921 login_needed(g.anon.RdForum);
922 return;
923 }
@@ -926,12 +931,12 @@
931 if( search_screen(SRCH_FORUM, 0) ){
932 style_submenu_element("Recent Threads","%R/forum");
933 style_footer();
934 return;
935 }
936 iLimit = atoi(PD("n","25"));
937 iOfst = atoi(PD("x","0"));
938 @ <h1>Recent Threads</h1>
939 @ <div class='fileage'><table width="100%%">
940 if( db_table_exists("repository","forumpost") ){
941 db_prepare(&q,
942 "SELECT"
@@ -943,23 +948,43 @@
948 " FROM event WHERE objid=(SELECT fpid FROM forumpost AS y"
949 " WHERE y.froot=x.froot"
950 " ORDER BY fmtime DESC LIMIT 1))"
951 " FROM forumpost AS x"
952 " GROUP BY froot ORDER BY 1 LIMIT %d OFFSET %d;",
953 iLimit+1, iOfst
954 );
955 iCnt = 0;
956 while( db_step(&q)==SQLITE_ROW ){
957 char *zAge = 0;
958 char *zDuration = 0;
959 int nMsg = db_column_int(&q, 2);
960 const char *zUuid = db_column_text(&q, 3);
961 const char *zTitle = db_column_text(&q, 4);
962 if( iCnt==0 && iOfst>0 ){
963 if( iOfst>iLimit ){
964 @ <tr><td colspan="3">\
965 @ %z(href("%R/forum?x=%d&n=%d",iOfst-iLimit,iLimit))\
966 @ &uarr; Newer...</a></td></tr>
967 }else{
968 @ <tr><td colspan="3">%z(href("%R/forum?n=%d",iLimit))\
969 @ &uarr; Newer...</a></td></tr>
970 }
971 }
972 iCnt++;
973 if( iCnt>iLimit ){
974 @ <tr><td colspan="3">\
975 @ %z(href("%R/forum?x=%d&n=%d",iOfst+iLimit,iLimit))\
976 @ &darr; Older...</a></td></tr>
977 break;
978 }
979 zAge = human_readable_age(db_column_double(&q,0));
980 @ <tr><td>%h(zAge) ago</td>
981 @ <td>%z(href("%R/forumpost/%S",zUuid))%h(zTitle)</a></td>
982 if( nMsg<2 ){
983 @ <td>no replies</td>
984 }else{
985 zDuration = human_readable_age(db_column_double(&q,1));
986 @ <td>%d(nMsg) posts spanning %h(zDuration)</td>
987 }
988 @ </tr>
989 fossil_free(zAge);
990 fossil_free(zDuration);
991

Keyboard Shortcuts

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