Fossil SCM
Add status=VALUE filter to /forumpost. There's no UI for it yet, so requires manual URL editing.
Commit
52ac6bc1b2c720ff7d4533ecd1bc472467af7b940cbd8bd76abe41eeb696218e
Parent
32501ce53181ce7…
1 file changed
+33
-14
+33
-14
| --- src/forum.c | ||
| +++ src/forum.c | ||
| @@ -2437,11 +2437,11 @@ | ||
| 2437 | 2437 | void forum_main_page(void){ |
| 2438 | 2438 | Stmt q; |
| 2439 | 2439 | int iLimit = 0, iOfst, iCnt; |
| 2440 | 2440 | int srchFlags; |
| 2441 | 2441 | const int isSearch = P("s")!=0; |
| 2442 | - const char *zStatus = P("status"); | |
| 2442 | + const char *zStatusFilter = P("status"); | |
| 2443 | 2443 | char const *zLimit = 0; |
| 2444 | 2444 | |
| 2445 | 2445 | login_check_credentials(); |
| 2446 | 2446 | srchFlags = search_restrict(SRCH_FORUM); |
| 2447 | 2447 | if( !g.perm.RdForum ){ |
| @@ -2486,10 +2486,11 @@ | ||
| 2486 | 2486 | iLimit = 25; |
| 2487 | 2487 | } |
| 2488 | 2488 | style_submenu_entry("n","Max:",4,0); |
| 2489 | 2489 | iOfst = atoi(PD("x","0")); |
| 2490 | 2490 | iCnt = 0; |
| 2491 | + if( zStatusFilter && !*zStatusFilter ) zStatusFilter = 0; | |
| 2491 | 2492 | if( db_table_exists("repository","forumpost") ){ |
| 2492 | 2493 | const int bHasStatus = forum_statuses()->n>1; |
| 2493 | 2494 | db_prepare(&q, |
| 2494 | 2495 | "WITH " |
| 2495 | 2496 | "root(id,pinned,status,statlbl) AS (" |
| @@ -2519,11 +2520,11 @@ | ||
| 2519 | 2520 | " AND ref.value=fs.value" |
| 2520 | 2521 | " ORDER BY ref.mtime desc" |
| 2521 | 2522 | " )," |
| 2522 | 2523 | " (SELECT label FROM forumstatus WHERE ord=1)" |
| 2523 | 2524 | " ) ELSE NULL END statlbl" |
| 2524 | - " FROM forumpost x WHERE firt IS NULL" | |
| 2525 | + " FROM forumpost x WHERE firt IS NULL AND fprev IS NULL" | |
| 2525 | 2526 | ")," |
| 2526 | 2527 | " thread(age,duration,cnt,root,last,pinned,status,statlbl)" |
| 2527 | 2528 | " AS (" |
| 2528 | 2529 | " SELECT" |
| 2529 | 2530 | " julianday('now') - max(fmtime)," |
| @@ -2533,11 +2534,12 @@ | ||
| 2533 | 2534 | " (SELECT fpid FROM forumpost AS y" |
| 2534 | 2535 | " WHERE y.froot=root.id %s" |
| 2535 | 2536 | " ORDER BY y.fmtime DESC LIMIT 1)," |
| 2536 | 2537 | " root.pinned, root.status, root.statlbl" |
| 2537 | 2538 | " FROM forumpost, root" |
| 2538 | - " WHERE root.id=froot AND %s" | |
| 2539 | + " WHERE root.id=froot AND %s/*ModForum*/" | |
| 2540 | + " AND CASE WHEN %d/*status filter*/ THEN root.status=%Q ELSE 1 END" | |
| 2539 | 2541 | " GROUP BY froot" |
| 2540 | 2542 | " ORDER BY 6 DESC, 1 LIMIT %d OFFSET %d" |
| 2541 | 2543 | ")" |
| 2542 | 2544 | "SELECT" |
| 2543 | 2545 | " thread.age," /* 0 */ |
| @@ -2554,10 +2556,11 @@ | ||
| 2554 | 2556 | " AND event.objid=thread.last" |
| 2555 | 2557 | " ORDER BY 7 DESC, 1;", |
| 2556 | 2558 | bHasStatus, bHasStatus, |
| 2557 | 2559 | g.perm.ModForum ? "" : "AND y.fpid NOT IN private" /*safe-for-%s*/, |
| 2558 | 2560 | g.perm.ModForum ? "true" : "fpid NOT IN private" /*safe-for-%s*/, |
| 2561 | + !!zStatusFilter, zStatusFilter, | |
| 2559 | 2562 | iLimit+1, iOfst |
| 2560 | 2563 | ); |
| 2561 | 2564 | while( db_step(&q)==SQLITE_ROW ){ |
| 2562 | 2565 | char *zAge = human_readable_age(db_column_double(&q,0)); |
| 2563 | 2566 | int nMsg = db_column_int(&q, 2); |
| @@ -2564,33 +2567,49 @@ | ||
| 2564 | 2567 | int bPinned = db_column_int(&q, 6); |
| 2565 | 2568 | const char *zUuid = db_column_text(&q, 3); |
| 2566 | 2569 | const char *zTitle = db_column_text(&q, 4); |
| 2567 | 2570 | const char *zStatus = bHasStatus ? db_column_text(&q, 7) : NULL; |
| 2568 | 2571 | const char *zStatusLbl = bHasStatus ? db_column_text(&q, 8) : NULL; |
| 2572 | + const int bShowStatus = bHasStatus && !zStatusFilter; | |
| 2573 | + const int nCols = bShowStatus ? 4 : 3; | |
| 2569 | 2574 | if( iCnt==0 ){ |
| 2575 | + char * zTail = zStatusFilter | |
| 2576 | + ? mprintf(" with status=%Q", zStatusFilter) | |
| 2577 | + : 0; | |
| 2570 | 2578 | if( iOfst>0 ){ |
| 2571 | - @ <h1>Threads at least %s(zAge) old</h1> | |
| 2579 | + @ <h1>Threads at least %s(zAge) old%h(zTail ? zTail : "")</h1> | |
| 2572 | 2580 | }else{ |
| 2573 | - @ <h1>Most recent threads</h1> | |
| 2581 | + @ <h1>Most recent threads%h(zTail ? zTail : "")</h1> | |
| 2574 | 2582 | } |
| 2583 | + fossil_free(zTail); | |
| 2575 | 2584 | @ <div class='forumPosts fileage'><table width="100%%"> |
| 2576 | 2585 | if( iOfst>0 ){ |
| 2577 | 2586 | if( iOfst>iLimit ){ |
| 2578 | - @ <tr><td colspan="3">\ | |
| 2579 | - @ %z(href("%R/forum?x=%d&n=%d",iOfst-iLimit,iLimit))\ | |
| 2580 | - @ ↑ Newer...</a></td></tr> | |
| 2587 | + @ <tr><td colspan="%d(nCols)">\ | |
| 2588 | + @ <a href='%R/forum?x=%d(iOfst-iLimit)&n=%d(iLimit) \ | |
| 2589 | + if( zStatusFilter ){ | |
| 2590 | + @ &status=%T(zStatusFilter)\ | |
| 2591 | + } | |
| 2592 | + @ '>↑ Newer...</a></td></tr> | |
| 2581 | 2593 | }else{ |
| 2582 | - @ <tr><td colspan="3">%z(href("%R/forum?n=%d",iLimit))\ | |
| 2583 | - @ ↑ Newer...</a></td></tr> | |
| 2594 | + @ <tr><td colspan="%d(nCols)">\ | |
| 2595 | + @ <a href='%R/forum?n=%d(iLimit)\ | |
| 2596 | + if( zStatusFilter ){ | |
| 2597 | + @ &status=%T(zStatusFilter) \ | |
| 2598 | + } | |
| 2599 | + @ '>↑ Newer...</a></td></tr> | |
| 2584 | 2600 | } |
| 2585 | 2601 | } |
| 2586 | 2602 | } |
| 2587 | 2603 | iCnt++; |
| 2588 | 2604 | if( iCnt>iLimit ){ |
| 2589 | - @ <tr><td colspan="3">\ | |
| 2590 | - @ %z(href("%R/forum?x=%d&n=%d",iOfst+iLimit,iLimit))\ | |
| 2591 | - @ ↓ Older...</a></td></tr> | |
| 2605 | + @ <tr><td colspan="%d(nCols)">\ | |
| 2606 | + @ <a href='%R/forum?x=%d(iOfst+iLimit)&n=%d(iLimit) \ | |
| 2607 | + if( zStatusFilter ){ | |
| 2608 | + @ &status=%T(zStatusFilter)\ | |
| 2609 | + } | |
| 2610 | + @ '>↓ Older...</a></td></tr> | |
| 2592 | 2611 | fossil_free(zAge); |
| 2593 | 2612 | break; |
| 2594 | 2613 | } |
| 2595 | 2614 | @ <tr%s(bPinned ? " class='pinned'" : "") |
| 2596 | 2615 | if( bHasStatus ){ |
| @@ -2609,11 +2628,11 @@ | ||
| 2609 | 2628 | char *zDuration = human_readable_age(db_column_double(&q,1)); |
| 2610 | 2629 | @ %d(nMsg) posts spanning %h(zDuration)\ |
| 2611 | 2630 | fossil_free(zDuration); |
| 2612 | 2631 | } |
| 2613 | 2632 | @ </td>\ |
| 2614 | - if( bHasStatus ){ | |
| 2633 | + if( bShowStatus ){ | |
| 2615 | 2634 | @ <td class='status'>%h(zStatusLbl)</td>\ |
| 2616 | 2635 | } |
| 2617 | 2636 | @</tr> |
| 2618 | 2637 | fossil_free(zAge); |
| 2619 | 2638 | } |
| 2620 | 2639 |
| --- src/forum.c | |
| +++ src/forum.c | |
| @@ -2437,11 +2437,11 @@ | |
| 2437 | void forum_main_page(void){ |
| 2438 | Stmt q; |
| 2439 | int iLimit = 0, iOfst, iCnt; |
| 2440 | int srchFlags; |
| 2441 | const int isSearch = P("s")!=0; |
| 2442 | const char *zStatus = P("status"); |
| 2443 | char const *zLimit = 0; |
| 2444 | |
| 2445 | login_check_credentials(); |
| 2446 | srchFlags = search_restrict(SRCH_FORUM); |
| 2447 | if( !g.perm.RdForum ){ |
| @@ -2486,10 +2486,11 @@ | |
| 2486 | iLimit = 25; |
| 2487 | } |
| 2488 | style_submenu_entry("n","Max:",4,0); |
| 2489 | iOfst = atoi(PD("x","0")); |
| 2490 | iCnt = 0; |
| 2491 | if( db_table_exists("repository","forumpost") ){ |
| 2492 | const int bHasStatus = forum_statuses()->n>1; |
| 2493 | db_prepare(&q, |
| 2494 | "WITH " |
| 2495 | "root(id,pinned,status,statlbl) AS (" |
| @@ -2519,11 +2520,11 @@ | |
| 2519 | " AND ref.value=fs.value" |
| 2520 | " ORDER BY ref.mtime desc" |
| 2521 | " )," |
| 2522 | " (SELECT label FROM forumstatus WHERE ord=1)" |
| 2523 | " ) ELSE NULL END statlbl" |
| 2524 | " FROM forumpost x WHERE firt IS NULL" |
| 2525 | ")," |
| 2526 | " thread(age,duration,cnt,root,last,pinned,status,statlbl)" |
| 2527 | " AS (" |
| 2528 | " SELECT" |
| 2529 | " julianday('now') - max(fmtime)," |
| @@ -2533,11 +2534,12 @@ | |
| 2533 | " (SELECT fpid FROM forumpost AS y" |
| 2534 | " WHERE y.froot=root.id %s" |
| 2535 | " ORDER BY y.fmtime DESC LIMIT 1)," |
| 2536 | " root.pinned, root.status, root.statlbl" |
| 2537 | " FROM forumpost, root" |
| 2538 | " WHERE root.id=froot AND %s" |
| 2539 | " GROUP BY froot" |
| 2540 | " ORDER BY 6 DESC, 1 LIMIT %d OFFSET %d" |
| 2541 | ")" |
| 2542 | "SELECT" |
| 2543 | " thread.age," /* 0 */ |
| @@ -2554,10 +2556,11 @@ | |
| 2554 | " AND event.objid=thread.last" |
| 2555 | " ORDER BY 7 DESC, 1;", |
| 2556 | bHasStatus, bHasStatus, |
| 2557 | g.perm.ModForum ? "" : "AND y.fpid NOT IN private" /*safe-for-%s*/, |
| 2558 | g.perm.ModForum ? "true" : "fpid NOT IN private" /*safe-for-%s*/, |
| 2559 | iLimit+1, iOfst |
| 2560 | ); |
| 2561 | while( db_step(&q)==SQLITE_ROW ){ |
| 2562 | char *zAge = human_readable_age(db_column_double(&q,0)); |
| 2563 | int nMsg = db_column_int(&q, 2); |
| @@ -2564,33 +2567,49 @@ | |
| 2564 | int bPinned = db_column_int(&q, 6); |
| 2565 | const char *zUuid = db_column_text(&q, 3); |
| 2566 | const char *zTitle = db_column_text(&q, 4); |
| 2567 | const char *zStatus = bHasStatus ? db_column_text(&q, 7) : NULL; |
| 2568 | const char *zStatusLbl = bHasStatus ? db_column_text(&q, 8) : NULL; |
| 2569 | if( iCnt==0 ){ |
| 2570 | if( iOfst>0 ){ |
| 2571 | @ <h1>Threads at least %s(zAge) old</h1> |
| 2572 | }else{ |
| 2573 | @ <h1>Most recent threads</h1> |
| 2574 | } |
| 2575 | @ <div class='forumPosts fileage'><table width="100%%"> |
| 2576 | if( iOfst>0 ){ |
| 2577 | if( iOfst>iLimit ){ |
| 2578 | @ <tr><td colspan="3">\ |
| 2579 | @ %z(href("%R/forum?x=%d&n=%d",iOfst-iLimit,iLimit))\ |
| 2580 | @ ↑ Newer...</a></td></tr> |
| 2581 | }else{ |
| 2582 | @ <tr><td colspan="3">%z(href("%R/forum?n=%d",iLimit))\ |
| 2583 | @ ↑ Newer...</a></td></tr> |
| 2584 | } |
| 2585 | } |
| 2586 | } |
| 2587 | iCnt++; |
| 2588 | if( iCnt>iLimit ){ |
| 2589 | @ <tr><td colspan="3">\ |
| 2590 | @ %z(href("%R/forum?x=%d&n=%d",iOfst+iLimit,iLimit))\ |
| 2591 | @ ↓ Older...</a></td></tr> |
| 2592 | fossil_free(zAge); |
| 2593 | break; |
| 2594 | } |
| 2595 | @ <tr%s(bPinned ? " class='pinned'" : "") |
| 2596 | if( bHasStatus ){ |
| @@ -2609,11 +2628,11 @@ | |
| 2609 | char *zDuration = human_readable_age(db_column_double(&q,1)); |
| 2610 | @ %d(nMsg) posts spanning %h(zDuration)\ |
| 2611 | fossil_free(zDuration); |
| 2612 | } |
| 2613 | @ </td>\ |
| 2614 | if( bHasStatus ){ |
| 2615 | @ <td class='status'>%h(zStatusLbl)</td>\ |
| 2616 | } |
| 2617 | @</tr> |
| 2618 | fossil_free(zAge); |
| 2619 | } |
| 2620 |
| --- src/forum.c | |
| +++ src/forum.c | |
| @@ -2437,11 +2437,11 @@ | |
| 2437 | void forum_main_page(void){ |
| 2438 | Stmt q; |
| 2439 | int iLimit = 0, iOfst, iCnt; |
| 2440 | int srchFlags; |
| 2441 | const int isSearch = P("s")!=0; |
| 2442 | const char *zStatusFilter = P("status"); |
| 2443 | char const *zLimit = 0; |
| 2444 | |
| 2445 | login_check_credentials(); |
| 2446 | srchFlags = search_restrict(SRCH_FORUM); |
| 2447 | if( !g.perm.RdForum ){ |
| @@ -2486,10 +2486,11 @@ | |
| 2486 | iLimit = 25; |
| 2487 | } |
| 2488 | style_submenu_entry("n","Max:",4,0); |
| 2489 | iOfst = atoi(PD("x","0")); |
| 2490 | iCnt = 0; |
| 2491 | if( zStatusFilter && !*zStatusFilter ) zStatusFilter = 0; |
| 2492 | if( db_table_exists("repository","forumpost") ){ |
| 2493 | const int bHasStatus = forum_statuses()->n>1; |
| 2494 | db_prepare(&q, |
| 2495 | "WITH " |
| 2496 | "root(id,pinned,status,statlbl) AS (" |
| @@ -2519,11 +2520,11 @@ | |
| 2520 | " AND ref.value=fs.value" |
| 2521 | " ORDER BY ref.mtime desc" |
| 2522 | " )," |
| 2523 | " (SELECT label FROM forumstatus WHERE ord=1)" |
| 2524 | " ) ELSE NULL END statlbl" |
| 2525 | " FROM forumpost x WHERE firt IS NULL AND fprev IS NULL" |
| 2526 | ")," |
| 2527 | " thread(age,duration,cnt,root,last,pinned,status,statlbl)" |
| 2528 | " AS (" |
| 2529 | " SELECT" |
| 2530 | " julianday('now') - max(fmtime)," |
| @@ -2533,11 +2534,12 @@ | |
| 2534 | " (SELECT fpid FROM forumpost AS y" |
| 2535 | " WHERE y.froot=root.id %s" |
| 2536 | " ORDER BY y.fmtime DESC LIMIT 1)," |
| 2537 | " root.pinned, root.status, root.statlbl" |
| 2538 | " FROM forumpost, root" |
| 2539 | " WHERE root.id=froot AND %s/*ModForum*/" |
| 2540 | " AND CASE WHEN %d/*status filter*/ THEN root.status=%Q ELSE 1 END" |
| 2541 | " GROUP BY froot" |
| 2542 | " ORDER BY 6 DESC, 1 LIMIT %d OFFSET %d" |
| 2543 | ")" |
| 2544 | "SELECT" |
| 2545 | " thread.age," /* 0 */ |
| @@ -2554,10 +2556,11 @@ | |
| 2556 | " AND event.objid=thread.last" |
| 2557 | " ORDER BY 7 DESC, 1;", |
| 2558 | bHasStatus, bHasStatus, |
| 2559 | g.perm.ModForum ? "" : "AND y.fpid NOT IN private" /*safe-for-%s*/, |
| 2560 | g.perm.ModForum ? "true" : "fpid NOT IN private" /*safe-for-%s*/, |
| 2561 | !!zStatusFilter, zStatusFilter, |
| 2562 | iLimit+1, iOfst |
| 2563 | ); |
| 2564 | while( db_step(&q)==SQLITE_ROW ){ |
| 2565 | char *zAge = human_readable_age(db_column_double(&q,0)); |
| 2566 | int nMsg = db_column_int(&q, 2); |
| @@ -2564,33 +2567,49 @@ | |
| 2567 | int bPinned = db_column_int(&q, 6); |
| 2568 | const char *zUuid = db_column_text(&q, 3); |
| 2569 | const char *zTitle = db_column_text(&q, 4); |
| 2570 | const char *zStatus = bHasStatus ? db_column_text(&q, 7) : NULL; |
| 2571 | const char *zStatusLbl = bHasStatus ? db_column_text(&q, 8) : NULL; |
| 2572 | const int bShowStatus = bHasStatus && !zStatusFilter; |
| 2573 | const int nCols = bShowStatus ? 4 : 3; |
| 2574 | if( iCnt==0 ){ |
| 2575 | char * zTail = zStatusFilter |
| 2576 | ? mprintf(" with status=%Q", zStatusFilter) |
| 2577 | : 0; |
| 2578 | if( iOfst>0 ){ |
| 2579 | @ <h1>Threads at least %s(zAge) old%h(zTail ? zTail : "")</h1> |
| 2580 | }else{ |
| 2581 | @ <h1>Most recent threads%h(zTail ? zTail : "")</h1> |
| 2582 | } |
| 2583 | fossil_free(zTail); |
| 2584 | @ <div class='forumPosts fileage'><table width="100%%"> |
| 2585 | if( iOfst>0 ){ |
| 2586 | if( iOfst>iLimit ){ |
| 2587 | @ <tr><td colspan="%d(nCols)">\ |
| 2588 | @ <a href='%R/forum?x=%d(iOfst-iLimit)&n=%d(iLimit) \ |
| 2589 | if( zStatusFilter ){ |
| 2590 | @ &status=%T(zStatusFilter)\ |
| 2591 | } |
| 2592 | @ '>↑ Newer...</a></td></tr> |
| 2593 | }else{ |
| 2594 | @ <tr><td colspan="%d(nCols)">\ |
| 2595 | @ <a href='%R/forum?n=%d(iLimit)\ |
| 2596 | if( zStatusFilter ){ |
| 2597 | @ &status=%T(zStatusFilter) \ |
| 2598 | } |
| 2599 | @ '>↑ Newer...</a></td></tr> |
| 2600 | } |
| 2601 | } |
| 2602 | } |
| 2603 | iCnt++; |
| 2604 | if( iCnt>iLimit ){ |
| 2605 | @ <tr><td colspan="%d(nCols)">\ |
| 2606 | @ <a href='%R/forum?x=%d(iOfst+iLimit)&n=%d(iLimit) \ |
| 2607 | if( zStatusFilter ){ |
| 2608 | @ &status=%T(zStatusFilter)\ |
| 2609 | } |
| 2610 | @ '>↓ Older...</a></td></tr> |
| 2611 | fossil_free(zAge); |
| 2612 | break; |
| 2613 | } |
| 2614 | @ <tr%s(bPinned ? " class='pinned'" : "") |
| 2615 | if( bHasStatus ){ |
| @@ -2609,11 +2628,11 @@ | |
| 2628 | char *zDuration = human_readable_age(db_column_double(&q,1)); |
| 2629 | @ %d(nMsg) posts spanning %h(zDuration)\ |
| 2630 | fossil_free(zDuration); |
| 2631 | } |
| 2632 | @ </td>\ |
| 2633 | if( bShowStatus ){ |
| 2634 | @ <td class='status'>%h(zStatusLbl)</td>\ |
| 2635 | } |
| 2636 | @</tr> |
| 2637 | fossil_free(zAge); |
| 2638 | } |
| 2639 |