Fossil SCM

In the forum, omit unnecessary query parameters on generated URLs, so that it is easier to copy/paste URLs into commit messages or chat windows.

drh 2022-01-02 20:46 trunk
Commit 168eb71643a47549b901243a5061df5e1afcd683dd7731f05e7bcafa397ed37a
1 file changed +41 -12
+41 -12
--- src/forum.c
+++ src/forum.c
@@ -500,21 +500,21 @@
500500
}
501501
zDate = db_text(0, "SELECT datetime(%.17g,toLocal())", p->rDate);
502502
if( p->pEditPrev ){
503503
zPosterName = forum_post_display_name(p->pEditHead, 0);
504504
zEditorName = forum_post_display_name(p, pManifest);
505
- zHist = bHist ? "" : "&hist";
505
+ zHist = bHist ? "" : zQuery[0]==0 ? "?hist" : "&hist";
506506
@ <h3 class='forumPostHdr'>(%d(p->sid)\
507507
@ .%0*d(fossil_num_digits(p->nEdit))(p->rev)) \
508508
if( fossil_strcmp(zPosterName, zEditorName)==0 ){
509509
@ By %s(zPosterName) on %h(zDate) edited from \
510510
@ %z(href("%R/forumpost/%S?%s%s",p->pEditPrev->zUuid,zQuery,zHist))\
511511
@ %d(p->sid).%0*d(fossil_num_digits(p->nEdit))(p->pEditPrev->rev)</a>
512512
}else{
513513
@ Originally by %s(zPosterName) \
514514
@ with edits by %s(zEditorName) on %h(zDate) from \
515
- @ %z(href("%R/forumpost/%S?%s%s",p->pEditPrev->zUuid,zQuery,zHist))\
515
+ @ %z(href("%R/forumpost/%S%s%s",p->pEditPrev->zUuid,zQuery,zHist))\
516516
@ %d(p->sid).%0*d(fossil_num_digits(p->nEdit))(p->pEditPrev->rev)</a>
517517
}
518518
}else{
519519
zPosterName = forum_post_display_name(p, pManifest);
520520
@ <h3 class='forumPostHdr'>(%d(p->sid)) \
@@ -529,28 +529,28 @@
529529
@ <a href="%R/artifact/%h(p->zUuid)">(artifact-%d(p->fpid))</a></span>
530530
}
531531
532532
/* If this is a reply, refer back to the parent post. */
533533
if( p->pIrt ){
534
- @ in reply to %z(href("%R/forumpost/%S?%s",p->pIrt->zUuid,zQuery))\
534
+ @ in reply to %z(href("%R/forumpost/%S%s",p->pIrt->zUuid,zQuery))\
535535
@ %d(p->pIrt->sid)\
536536
if( p->pIrt->nEdit ){
537537
@ .%0*d(fossil_num_digits(p->pIrt->nEdit))(p->pIrt->rev)\
538538
}
539539
@ </a>
540540
}
541541
542542
/* If this post was later edited, refer forward to the next edit. */
543543
if( p->pEditNext ){
544
- @ updated by %z(href("%R/forumpost/%S?%s",p->pEditNext->zUuid,zQuery))\
544
+ @ updated by %z(href("%R/forumpost/%S%s",p->pEditNext->zUuid,zQuery))\
545545
@ %d(p->pEditNext->sid)\
546546
@ .%0*d(fossil_num_digits(p->nEdit))(p->pEditNext->rev)</a>
547547
}
548548
549549
/* Provide a link to select the individual post. */
550550
if( !bSelect ){
551
- @ %z(href("%R/forumpost/%!S?%s",p->zUuid,zQuery))[link]</a>
551
+ @ %z(href("%R/forumpost/%!S%s",p->zUuid,zQuery))[link]</a>
552552
}
553553
554554
/* Provide a link to the raw source code. */
555555
if( !bUnf ){
556556
@ %z(href("%R/forumpost/%!S?raw",p->zUuid))[source]</a>
@@ -632,19 +632,21 @@
632632
*/
633633
static void forum_display_thread(
634634
int froot, /* Forum thread root post ID */
635635
int fpid, /* Selected forum post ID, or 0 if none selected */
636636
int mode, /* Forum display mode, one of the FD_* enumerations */
637
+ int autoMode, /* mode was selected automatically */
637638
int bUnf, /* True if rendering unformatted */
638639
int bHist /* True if showing edit history, ignored for FD_RAW */
639640
){
640641
ForumThread *pThread; /* Thread structure */
641642
ForumPost *pSelect; /* Currently selected post, or NULL if none */
642643
ForumPost *p; /* Post iterator pointer */
643
- char *zQuery; /* Common query string */
644
+ char zQuery[30]; /* Common query string */
644645
int iIndentScale = 4; /* Indent scale factor, measured in "ex" units */
645646
int sid; /* Comparison serial ID */
647
+ int i;
646648
647649
/* In raw mode, force unformatted display and disable history. */
648650
if( mode == FD_RAW ){
649651
bUnf = 1;
650652
bHist = 0;
@@ -675,13 +677,39 @@
675677
if( !pSelect && (mode==FD_RAW || mode==FD_SINGLE) ){
676678
return;
677679
}
678680
679681
/* Create the common query string to append to nearly all post links. */
680
- zQuery = mode==FD_RAW ? 0 : mprintf("t=%c%s%s",
681
- mode==FD_SINGLE ? 's' : mode==FD_CHRONO ? 'c' : 'h',
682
- bUnf ? "&unf" : "", bHist ? "&hist" : "");
682
+ i = 0;
683
+ if( !autoMode ){
684
+ char m = 'a';
685
+ switch( mode ){
686
+ case FD_RAW: m = 'r'; break;
687
+ case FD_CHRONO: m = 'c'; break;
688
+ case FD_HIER: m = 'h'; break;
689
+ case FD_SINGLE: m = 's'; break;
690
+ }
691
+ zQuery[i++] = '?';
692
+ zQuery[i++] = 't';
693
+ zQuery[i++] = '=';
694
+ zQuery[i++] = m;
695
+ }
696
+ if( bUnf ){
697
+ zQuery[i] = i==0 ? '?' : '&'; i++;
698
+ zQuery[i++] = 'u';
699
+ zQuery[i++] = 'n';
700
+ zQuery[i++] = 'f';
701
+ }
702
+ if( bHist ){
703
+ zQuery[i] = i==0 ? '?' : '&'; i++;
704
+ zQuery[i++] = 'h';
705
+ zQuery[i++] = 'i';
706
+ zQuery[i++] = 's';
707
+ zQuery[i++] = 't';
708
+ }
709
+ assert( i<sizeof(zQuery) );
710
+ zQuery[i] = 0;
683711
684712
/* Identify which post to display first. If history is shown, start with the
685713
** original, unedited post. Otherwise advance to the post's latest edit. */
686714
if( mode==FD_RAW || mode==FD_SINGLE ){
687715
p = pSelect;
@@ -744,11 +772,10 @@
744772
@ </table>
745773
}
746774
747775
/* Clean up. */
748776
forumthread_delete(pThread);
749
- fossil_free(zQuery);
750777
}
751778
752779
/*
753780
** Emit Forum Javascript which applies (or optionally can apply)
754781
** to all forum-related pages. It does not include page-specific
@@ -813,10 +840,11 @@
813840
const char *zMode = PD("t","a");
814841
int bRaw = PB("raw");
815842
int bUnf = PB("unf");
816843
int bHist = PB("hist");
817844
int mode = 0;
845
+ int autoMode = 0;
818846
login_check_credentials();
819847
if( !g.perm.RdForum ){
820848
login_needed(g.anon.RdForum);
821849
return;
822850
}
@@ -846,11 +874,12 @@
846874
cgi_replace_query_parameter("unf", "on");
847875
cgi_delete_query_parameter("hist");
848876
cgi_delete_query_parameter("raw");
849877
}else{
850878
switch( *zMode ){
851
- case 'a': mode = cgi_from_mobile() ? FD_CHRONO : FD_HIER; break;
879
+ case 'a': mode = cgi_from_mobile() ? FD_CHRONO : FD_HIER;
880
+ autoMode=1; break;
852881
case 'c': mode = FD_CHRONO; break;
853882
case 'h': mode = FD_HIER; break;
854883
case 's': mode = FD_SINGLE; break;
855884
case 'r': mode = FD_CHRONO; break;
856885
case 'y': mode = FD_SINGLE; break;
@@ -887,11 +916,11 @@
887916
}
888917
style_submenu_checkbox("unf", "Unformatted", 0, 0);
889918
style_submenu_checkbox("hist", "History", 0, 0);
890919
891920
/* Display the thread. */
892
- forum_display_thread(froot, fpid, mode, bUnf, bHist);
921
+ forum_display_thread(froot, fpid, mode, autoMode, bUnf, bHist);
893922
894923
/* Emit Forum Javascript. */
895924
builtin_request_js("forum.js");
896925
forum_emit_js();
897926
898927
--- src/forum.c
+++ src/forum.c
@@ -500,21 +500,21 @@
500 }
501 zDate = db_text(0, "SELECT datetime(%.17g,toLocal())", p->rDate);
502 if( p->pEditPrev ){
503 zPosterName = forum_post_display_name(p->pEditHead, 0);
504 zEditorName = forum_post_display_name(p, pManifest);
505 zHist = bHist ? "" : "&hist";
506 @ <h3 class='forumPostHdr'>(%d(p->sid)\
507 @ .%0*d(fossil_num_digits(p->nEdit))(p->rev)) \
508 if( fossil_strcmp(zPosterName, zEditorName)==0 ){
509 @ By %s(zPosterName) on %h(zDate) edited from \
510 @ %z(href("%R/forumpost/%S?%s%s",p->pEditPrev->zUuid,zQuery,zHist))\
511 @ %d(p->sid).%0*d(fossil_num_digits(p->nEdit))(p->pEditPrev->rev)</a>
512 }else{
513 @ Originally by %s(zPosterName) \
514 @ with edits by %s(zEditorName) on %h(zDate) from \
515 @ %z(href("%R/forumpost/%S?%s%s",p->pEditPrev->zUuid,zQuery,zHist))\
516 @ %d(p->sid).%0*d(fossil_num_digits(p->nEdit))(p->pEditPrev->rev)</a>
517 }
518 }else{
519 zPosterName = forum_post_display_name(p, pManifest);
520 @ <h3 class='forumPostHdr'>(%d(p->sid)) \
@@ -529,28 +529,28 @@
529 @ <a href="%R/artifact/%h(p->zUuid)">(artifact-%d(p->fpid))</a></span>
530 }
531
532 /* If this is a reply, refer back to the parent post. */
533 if( p->pIrt ){
534 @ in reply to %z(href("%R/forumpost/%S?%s",p->pIrt->zUuid,zQuery))\
535 @ %d(p->pIrt->sid)\
536 if( p->pIrt->nEdit ){
537 @ .%0*d(fossil_num_digits(p->pIrt->nEdit))(p->pIrt->rev)\
538 }
539 @ </a>
540 }
541
542 /* If this post was later edited, refer forward to the next edit. */
543 if( p->pEditNext ){
544 @ updated by %z(href("%R/forumpost/%S?%s",p->pEditNext->zUuid,zQuery))\
545 @ %d(p->pEditNext->sid)\
546 @ .%0*d(fossil_num_digits(p->nEdit))(p->pEditNext->rev)</a>
547 }
548
549 /* Provide a link to select the individual post. */
550 if( !bSelect ){
551 @ %z(href("%R/forumpost/%!S?%s",p->zUuid,zQuery))[link]</a>
552 }
553
554 /* Provide a link to the raw source code. */
555 if( !bUnf ){
556 @ %z(href("%R/forumpost/%!S?raw",p->zUuid))[source]</a>
@@ -632,19 +632,21 @@
632 */
633 static void forum_display_thread(
634 int froot, /* Forum thread root post ID */
635 int fpid, /* Selected forum post ID, or 0 if none selected */
636 int mode, /* Forum display mode, one of the FD_* enumerations */
 
637 int bUnf, /* True if rendering unformatted */
638 int bHist /* True if showing edit history, ignored for FD_RAW */
639 ){
640 ForumThread *pThread; /* Thread structure */
641 ForumPost *pSelect; /* Currently selected post, or NULL if none */
642 ForumPost *p; /* Post iterator pointer */
643 char *zQuery; /* Common query string */
644 int iIndentScale = 4; /* Indent scale factor, measured in "ex" units */
645 int sid; /* Comparison serial ID */
 
646
647 /* In raw mode, force unformatted display and disable history. */
648 if( mode == FD_RAW ){
649 bUnf = 1;
650 bHist = 0;
@@ -675,13 +677,39 @@
675 if( !pSelect && (mode==FD_RAW || mode==FD_SINGLE) ){
676 return;
677 }
678
679 /* Create the common query string to append to nearly all post links. */
680 zQuery = mode==FD_RAW ? 0 : mprintf("t=%c%s%s",
681 mode==FD_SINGLE ? 's' : mode==FD_CHRONO ? 'c' : 'h',
682 bUnf ? "&unf" : "", bHist ? "&hist" : "");
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
683
684 /* Identify which post to display first. If history is shown, start with the
685 ** original, unedited post. Otherwise advance to the post's latest edit. */
686 if( mode==FD_RAW || mode==FD_SINGLE ){
687 p = pSelect;
@@ -744,11 +772,10 @@
744 @ </table>
745 }
746
747 /* Clean up. */
748 forumthread_delete(pThread);
749 fossil_free(zQuery);
750 }
751
752 /*
753 ** Emit Forum Javascript which applies (or optionally can apply)
754 ** to all forum-related pages. It does not include page-specific
@@ -813,10 +840,11 @@
813 const char *zMode = PD("t","a");
814 int bRaw = PB("raw");
815 int bUnf = PB("unf");
816 int bHist = PB("hist");
817 int mode = 0;
 
818 login_check_credentials();
819 if( !g.perm.RdForum ){
820 login_needed(g.anon.RdForum);
821 return;
822 }
@@ -846,11 +874,12 @@
846 cgi_replace_query_parameter("unf", "on");
847 cgi_delete_query_parameter("hist");
848 cgi_delete_query_parameter("raw");
849 }else{
850 switch( *zMode ){
851 case 'a': mode = cgi_from_mobile() ? FD_CHRONO : FD_HIER; break;
 
852 case 'c': mode = FD_CHRONO; break;
853 case 'h': mode = FD_HIER; break;
854 case 's': mode = FD_SINGLE; break;
855 case 'r': mode = FD_CHRONO; break;
856 case 'y': mode = FD_SINGLE; break;
@@ -887,11 +916,11 @@
887 }
888 style_submenu_checkbox("unf", "Unformatted", 0, 0);
889 style_submenu_checkbox("hist", "History", 0, 0);
890
891 /* Display the thread. */
892 forum_display_thread(froot, fpid, mode, bUnf, bHist);
893
894 /* Emit Forum Javascript. */
895 builtin_request_js("forum.js");
896 forum_emit_js();
897
898
--- src/forum.c
+++ src/forum.c
@@ -500,21 +500,21 @@
500 }
501 zDate = db_text(0, "SELECT datetime(%.17g,toLocal())", p->rDate);
502 if( p->pEditPrev ){
503 zPosterName = forum_post_display_name(p->pEditHead, 0);
504 zEditorName = forum_post_display_name(p, pManifest);
505 zHist = bHist ? "" : zQuery[0]==0 ? "?hist" : "&hist";
506 @ <h3 class='forumPostHdr'>(%d(p->sid)\
507 @ .%0*d(fossil_num_digits(p->nEdit))(p->rev)) \
508 if( fossil_strcmp(zPosterName, zEditorName)==0 ){
509 @ By %s(zPosterName) on %h(zDate) edited from \
510 @ %z(href("%R/forumpost/%S?%s%s",p->pEditPrev->zUuid,zQuery,zHist))\
511 @ %d(p->sid).%0*d(fossil_num_digits(p->nEdit))(p->pEditPrev->rev)</a>
512 }else{
513 @ Originally by %s(zPosterName) \
514 @ with edits by %s(zEditorName) on %h(zDate) from \
515 @ %z(href("%R/forumpost/%S%s%s",p->pEditPrev->zUuid,zQuery,zHist))\
516 @ %d(p->sid).%0*d(fossil_num_digits(p->nEdit))(p->pEditPrev->rev)</a>
517 }
518 }else{
519 zPosterName = forum_post_display_name(p, pManifest);
520 @ <h3 class='forumPostHdr'>(%d(p->sid)) \
@@ -529,28 +529,28 @@
529 @ <a href="%R/artifact/%h(p->zUuid)">(artifact-%d(p->fpid))</a></span>
530 }
531
532 /* If this is a reply, refer back to the parent post. */
533 if( p->pIrt ){
534 @ in reply to %z(href("%R/forumpost/%S%s",p->pIrt->zUuid,zQuery))\
535 @ %d(p->pIrt->sid)\
536 if( p->pIrt->nEdit ){
537 @ .%0*d(fossil_num_digits(p->pIrt->nEdit))(p->pIrt->rev)\
538 }
539 @ </a>
540 }
541
542 /* If this post was later edited, refer forward to the next edit. */
543 if( p->pEditNext ){
544 @ updated by %z(href("%R/forumpost/%S%s",p->pEditNext->zUuid,zQuery))\
545 @ %d(p->pEditNext->sid)\
546 @ .%0*d(fossil_num_digits(p->nEdit))(p->pEditNext->rev)</a>
547 }
548
549 /* Provide a link to select the individual post. */
550 if( !bSelect ){
551 @ %z(href("%R/forumpost/%!S%s",p->zUuid,zQuery))[link]</a>
552 }
553
554 /* Provide a link to the raw source code. */
555 if( !bUnf ){
556 @ %z(href("%R/forumpost/%!S?raw",p->zUuid))[source]</a>
@@ -632,19 +632,21 @@
632 */
633 static void forum_display_thread(
634 int froot, /* Forum thread root post ID */
635 int fpid, /* Selected forum post ID, or 0 if none selected */
636 int mode, /* Forum display mode, one of the FD_* enumerations */
637 int autoMode, /* mode was selected automatically */
638 int bUnf, /* True if rendering unformatted */
639 int bHist /* True if showing edit history, ignored for FD_RAW */
640 ){
641 ForumThread *pThread; /* Thread structure */
642 ForumPost *pSelect; /* Currently selected post, or NULL if none */
643 ForumPost *p; /* Post iterator pointer */
644 char zQuery[30]; /* Common query string */
645 int iIndentScale = 4; /* Indent scale factor, measured in "ex" units */
646 int sid; /* Comparison serial ID */
647 int i;
648
649 /* In raw mode, force unformatted display and disable history. */
650 if( mode == FD_RAW ){
651 bUnf = 1;
652 bHist = 0;
@@ -675,13 +677,39 @@
677 if( !pSelect && (mode==FD_RAW || mode==FD_SINGLE) ){
678 return;
679 }
680
681 /* Create the common query string to append to nearly all post links. */
682 i = 0;
683 if( !autoMode ){
684 char m = 'a';
685 switch( mode ){
686 case FD_RAW: m = 'r'; break;
687 case FD_CHRONO: m = 'c'; break;
688 case FD_HIER: m = 'h'; break;
689 case FD_SINGLE: m = 's'; break;
690 }
691 zQuery[i++] = '?';
692 zQuery[i++] = 't';
693 zQuery[i++] = '=';
694 zQuery[i++] = m;
695 }
696 if( bUnf ){
697 zQuery[i] = i==0 ? '?' : '&'; i++;
698 zQuery[i++] = 'u';
699 zQuery[i++] = 'n';
700 zQuery[i++] = 'f';
701 }
702 if( bHist ){
703 zQuery[i] = i==0 ? '?' : '&'; i++;
704 zQuery[i++] = 'h';
705 zQuery[i++] = 'i';
706 zQuery[i++] = 's';
707 zQuery[i++] = 't';
708 }
709 assert( i<sizeof(zQuery) );
710 zQuery[i] = 0;
711
712 /* Identify which post to display first. If history is shown, start with the
713 ** original, unedited post. Otherwise advance to the post's latest edit. */
714 if( mode==FD_RAW || mode==FD_SINGLE ){
715 p = pSelect;
@@ -744,11 +772,10 @@
772 @ </table>
773 }
774
775 /* Clean up. */
776 forumthread_delete(pThread);
 
777 }
778
779 /*
780 ** Emit Forum Javascript which applies (or optionally can apply)
781 ** to all forum-related pages. It does not include page-specific
@@ -813,10 +840,11 @@
840 const char *zMode = PD("t","a");
841 int bRaw = PB("raw");
842 int bUnf = PB("unf");
843 int bHist = PB("hist");
844 int mode = 0;
845 int autoMode = 0;
846 login_check_credentials();
847 if( !g.perm.RdForum ){
848 login_needed(g.anon.RdForum);
849 return;
850 }
@@ -846,11 +874,12 @@
874 cgi_replace_query_parameter("unf", "on");
875 cgi_delete_query_parameter("hist");
876 cgi_delete_query_parameter("raw");
877 }else{
878 switch( *zMode ){
879 case 'a': mode = cgi_from_mobile() ? FD_CHRONO : FD_HIER;
880 autoMode=1; break;
881 case 'c': mode = FD_CHRONO; break;
882 case 'h': mode = FD_HIER; break;
883 case 's': mode = FD_SINGLE; break;
884 case 'r': mode = FD_CHRONO; break;
885 case 'y': mode = FD_SINGLE; break;
@@ -887,11 +916,11 @@
916 }
917 style_submenu_checkbox("unf", "Unformatted", 0, 0);
918 style_submenu_checkbox("hist", "History", 0, 0);
919
920 /* Display the thread. */
921 forum_display_thread(froot, fpid, mode, autoMode, bUnf, bHist);
922
923 /* Emit Forum Javascript. */
924 builtin_request_js("forum.js");
925 forum_emit_js();
926
927

Keyboard Shortcuts

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