Fossil

Check-in [ac3f1f2ba7]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Improvements to how ticket changes are displayed in the UI. The hyperlink is show with strick-through if the ticket is closed. The title is shown after the ticket hyperlink. SQL to determine the closed condition and the title can be set in the ticket setup screens.
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: ac3f1f2ba755061a7a205bc8a91c9adc757791ee
User & Date: drh 2008-10-18 02:27:13.000
Context
2008-10-18
12:55
Add defenses against [http://en.wikipedia.org/wiki/Cross-site_request_forgery | cross-site request forgery] attacks. check-in: 0be54823ba user: drh tags: trunk
02:27
Improvements to how ticket changes are displayed in the UI. The hyperlink is show with strick-through if the ticket is closed. The title is shown after the ticket hyperlink. SQL to determine the closed condition and the title can be set in the ticket setup screens. check-in: ac3f1f2ba7 user: drh tags: trunk
2008-10-17
13:30
Update the "info" command so that it can take the name of a repository as its argument and then report information about that repository. check-in: 974f025c6e user: drh tags: trunk
Changes
Unified Diff Ignore Whitespace Patch
Changes to src/configure.c.
84
85
86
87
88
89
90


91
92
93
94
95
96
97
  { "ticket-table",           CONFIGSET_TKT  },
  { "ticket-common",          CONFIGSET_TKT  },
  { "ticket-newpage",         CONFIGSET_TKT  },
  { "ticket-viewpage",        CONFIGSET_TKT  },
  { "ticket-editpage",        CONFIGSET_TKT  },
  { "ticket-report-template", CONFIGSET_TKT  },
  { "ticket-key-template",    CONFIGSET_TKT  },


  { "@reportfmt",             CONFIGSET_TKT  },
  { "@user",                  CONFIGSET_USER },
  { "@shun",                  CONFIGSET_SHUN },
};
static int iConfig = 0;

/*







>
>







84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
  { "ticket-table",           CONFIGSET_TKT  },
  { "ticket-common",          CONFIGSET_TKT  },
  { "ticket-newpage",         CONFIGSET_TKT  },
  { "ticket-viewpage",        CONFIGSET_TKT  },
  { "ticket-editpage",        CONFIGSET_TKT  },
  { "ticket-report-template", CONFIGSET_TKT  },
  { "ticket-key-template",    CONFIGSET_TKT  },
  { "ticket-title-expr",      CONFIGSET_TKT  },
  { "ticket-closed-expr",     CONFIGSET_TKT  },
  { "@reportfmt",             CONFIGSET_TKT  },
  { "@user",                  CONFIGSET_USER },
  { "@shun",                  CONFIGSET_SHUN },
};
static int iConfig = 0;

/*
Changes to src/manifest.c.
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
      TAG_COMMENT, rid
    );
    free(zComment);
  }
  if( m.type==CFTYPE_TICKET ){
    char *zTag;
    Blob comment;
    int i;

    ticket_insert(&m, 1, 1);
    zTag = mprintf("tkt-%s", m.zTicketUuid);
    tag_insert(zTag, 1, 0, rid, m.rDate, rid);
    free(zTag);
    blob_zero(&comment);
    if( m.nField==1 ){







<







892
893
894
895
896
897
898

899
900
901
902
903
904
905
      TAG_COMMENT, rid
    );
    free(zComment);
  }
  if( m.type==CFTYPE_TICKET ){
    char *zTag;
    Blob comment;


    ticket_insert(&m, 1, 1);
    zTag = mprintf("tkt-%s", m.zTicketUuid);
    tag_insert(zTag, 1, 0, rid, m.rDate, rid);
    free(zTag);
    blob_zero(&comment);
    if( m.nField==1 ){
917
918
919
920
921
922
923


924
925
926
927
928
929
930
931
932
933


934
935
936
937
938
939
940
941
942
943
944
945
      }else{
        blob_appendf(&comment,
          "Changed %h in ticket [%.10s]",
          m.aField[0].zName, m.zTicketUuid
        );
      }
    }else{


      const char *z;
      const char *zSep = " ";
      blob_appendf(&comment, "%d changes to ticket [%.10s]:",
                            m.nField, m.zTicketUuid);
      for(i=0; i<m.nField; i++){
        z = m.aField[i].zName;
        if( z[0]=='+' ) z++;
        blob_appendf(&comment, "%s%h", zSep, z);
        zSep = ", ";
      }


    }
    db_multi_exec(
      "REPLACE INTO event(type,mtime,objid,user,comment)"
      "VALUES('t',%.17g,%d,%Q,%Q)",
      m.rDate, rid, m.zUser, blob_str(&comment)
    );
    blob_reset(&comment);
  }
  db_end_transaction(0);
  manifest_clear(&m);
  return 1;
}







>
>










>
>












916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
      }else{
        blob_appendf(&comment,
          "Changed %h in ticket [%.10s]",
          m.aField[0].zName, m.zTicketUuid
        );
      }
    }else{
#if 0
      int i;
      const char *z;
      const char *zSep = " ";
      blob_appendf(&comment, "%d changes to ticket [%.10s]:",
                            m.nField, m.zTicketUuid);
      for(i=0; i<m.nField; i++){
        z = m.aField[i].zName;
        if( z[0]=='+' ) z++;
        blob_appendf(&comment, "%s%h", zSep, z);
        zSep = ", ";
      }
#endif
      blob_appendf(&comment, "Edits to ticket [%.10s]", m.zTicketUuid);
    }
    db_multi_exec(
      "REPLACE INTO event(type,mtime,objid,user,comment)"
      "VALUES('t',%.17g,%d,%Q,%Q)",
      m.rDate, rid, m.zUser, blob_str(&comment)
    );
    blob_reset(&comment);
  }
  db_end_transaction(0);
  manifest_clear(&m);
  return 1;
}
Changes to src/setup.c.
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
    @ <input type="checkbox" name="%s(zQParm)"><b>%s(zLabel)</b></input>
  }
}

/*
** Generate an entry box for an attribute.
*/
static void entry_attribute(
  const char *zLabel,   /* The text label on the entry box */
  int width,            /* Width of the entry box */
  const char *zVar,     /* The corresponding row in the VAR table */
  const char *zQParm,   /* The query parameter */
  char *zDflt     /* Default value if VAR table entry does not exist */
){
  const char *zVal = db_get(zVar, zDflt);







|







555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
    @ <input type="checkbox" name="%s(zQParm)"><b>%s(zLabel)</b></input>
  }
}

/*
** Generate an entry box for an attribute.
*/
void entry_attribute(
  const char *zLabel,   /* The text label on the entry box */
  int width,            /* Width of the entry box */
  const char *zVar,     /* The corresponding row in the VAR table */
  const char *zQParm,   /* The query parameter */
  char *zDflt     /* Default value if VAR table entry does not exist */
){
  const char *zVal = db_get(zVar, zDflt);
Changes to src/tktsetup.c.
38
39
40
41
42
43
44


45
46
47
48
49
50
51
    login_needed();
  }

  style_header("Ticket Setup");
  @ <table border="0" cellspacing="20">
  setup_menu_entry("Table", "tktsetup_tab",
    "Specify the schema of the  \"ticket\" table in the database.");


  setup_menu_entry("Common", "tktsetup_com",
    "Common TH1 code run before all ticket processing.");
  setup_menu_entry("New Ticket Page", "tktsetup_newpage",
    "HTML with embedded TH1 code for the \"new ticket\" webpage.");
  setup_menu_entry("View Ticket Page", "tktsetup_viewpage",
    "HTML with embedded TH1 code for the \"view ticket\" webpage.");
  setup_menu_entry("Edit Ticket Page", "tktsetup_editpage",







>
>







38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
    login_needed();
  }

  style_header("Ticket Setup");
  @ <table border="0" cellspacing="20">
  setup_menu_entry("Table", "tktsetup_tab",
    "Specify the schema of the  \"ticket\" table in the database.");
  setup_menu_entry("Timeline", "tktsetup_timeline",
    "How to display ticket status in the timeline");
  setup_menu_entry("Common", "tktsetup_com",
    "Common TH1 code run before all ticket processing.");
  setup_menu_entry("New Ticket Page", "tktsetup_newpage",
    "HTML with embedded TH1 code for the \"new ticket\" webpage.");
  setup_menu_entry("View Ticket Page", "tktsetup_viewpage",
    "HTML with embedded TH1 code for the \"view ticket\" webpage.");
  setup_menu_entry("Edit Ticket Page", "tktsetup_editpage",
614
615
616
617
618
619
620







































    zDefaultKey,
    zDesc,
    0,
    0,
    10
  );
}














































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
    zDefaultKey,
    zDesc,
    0,
    0,
    10
  );
}

/*
** WEBPAGE: tktsetup_timeline
*/
void tktsetup_timeline_page(void){
  login_check_credentials();
  if( !g.okSetup ){
    login_needed();
  }

  if( P("setup") ){
    cgi_redirect("tktsetup");
  }
  style_header("Ticket Display On Timelines");
  db_begin_transaction();
  @ <form action="%s(g.zBaseURL)/tktsetup_timeline" method="POST">

  @ <hr>
  entry_attribute("Ticket Title", 40, "ticket-title-expr", "t", "title");
  @ <p>An SQL expression in a query against the TICKET table that will
  @ return the title of the ticket for display purposes after hyperlinks to
  @ that ticket</p>

  @ <hr>
  entry_attribute("Ticket Closed", 40, "ticket-closed-expr", "c",
                  "status='Closed'");
  @ <p>An SQL expression that evaluates to true in a TICKET table query if
  @ the ticket is closed.</p>

  @ <hr>
  @ <p>
  @ <input type="submit"  name="submit" value="Apply Changes">
  @ <input type="submit" name="setup" value="Cancel">
  @ </p>
  @ </form>
  db_end_transaction(0);
  style_footer();
  
}
Changes to src/wikiformat.c.
865
866
867
868
869
870
871
872
873


874
875
876
877
878
879
880

881

882
883




884
885






886




887











888




889
890
891











892
893






894
895
896
897
898
899

900

901


902









903




















904
905

906
907

908

909
910
911
912
913
914
915
  int n = strlen(z);
  if( n<4 || n>UUID_SIZE ) return 0;
  if( !validate16(z, n) ) return 0;
  return 1;
}

/*
** Return true if the given hyperlink should be implemented for
** the current login.


*/
static int okToHyperlink(const char *zTarget){
  if( g.okHistory ) return 1;
  if( strncmp(zTarget, "http:", 5)==0 
   || strncmp(zTarget, "https:", 6)==0
   || strncmp(zTarget, "ftp:", 4)==0 
   || strncmp(zTarget, "mailto:", 7)==0

  ){

    return 1;
  }




  if( zTarget[0]=='/' || is_valid_uuid(zTarget) ) return 0;
  if( wiki_name_is_wellformed(zTarget) ) return 1;






  return 0;




}
















/*
** Resolve a hyperlink.  The argument is the content of the [...]
** in the wiki.  Append the URL to the output of the Renderer.











*/
static void resolveHyperlink(const char *zTarget, Renderer *p){






  if( strncmp(zTarget, "http:", 5)==0 
   || strncmp(zTarget, "https:", 6)==0
   || strncmp(zTarget, "ftp:", 4)==0 
   || strncmp(zTarget, "mailto:", 7)==0
  ){
    blob_appendf(p->pOut, zTarget);

  }else if( zTarget[0]=='/' ){

    blob_appendf(p->pOut, "%s%h", g.zBaseURL, zTarget);


  }else if( is_valid_uuid(zTarget) ){









    blob_appendf(p->pOut, "%s/info/%s", g.zBaseURL, zTarget);




















  }else if( wiki_name_is_wellformed(zTarget) ){
    blob_appendf(p->pOut, "%s/wiki?name=%T", g.zBaseURL, zTarget);

  }else{
    blob_appendf(p->pOut, "error");

  }

}

/*
** Check to see if the given parsed markup is the correct
** </verbatim> tag.
*/
static int endVerbatim(Renderer *p, ParsedMarkup *pMarkup){







|
|
>
>

|
<
|
<
|
|
>
|
>
|
<
>
>
>
>
|
|
>
>
>
>
>
>
|
>
>
>
>
|
>
>
>
>
>
>
>
>
>
>
>
|
>
>
>
>

|
|
>
>
>
>
>
>
>
>
>
>
>

|
>
>
>
>
>
>





|
>

>
|
>
>

>
>
>
>
>
>
>
>
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>

|
>

|
>

>







865
866
867
868
869
870
871
872
873
874
875
876
877

878

879
880
881
882
883
884

885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
  int n = strlen(z);
  if( n<4 || n>UUID_SIZE ) return 0;
  if( !validate16(z, n) ) return 0;
  return 1;
}

/*
** zTarget is guaranteed to be a UUID.  It might be the UUID of a ticket.
** If it is, fill zDisplay[0..nDisplay-1] with the title of the ticket
** (or a prefix if the title is too long) and return true.  If zTarget
** is not the UUID of a ticket, return false.
*/
static int is_ticket(

  const char *zTarget,    /* Ticket UUID */

  char *zDisplay,         /* Space in which to write ticket title */
  int nDisplay,           /* Bytes available in zDisplay[] */
  int *pClosed            /* True if the ticket is closed */
){
  static Stmt q;
  static int once = 1;

  int n;
  int rc;
  char zLower[UUID_SIZE+1];
  char zUpper[UUID_SIZE+1];
  n = strlen(zTarget);
  memcpy(zLower, zTarget, n+1);
  canonical16(zLower, n+1);
  memcpy(zUpper, zLower, n+1);
  zUpper[n-1]++;
  if( once ){
    const char *zTitleExpr = db_get("ticket-title-expr", "title");
    const char *zClosedExpr = db_get("ticket-closed-expr", "status='Closed'");
    db_static_prepare(&q, 
      "SELECT %s, %s FROM ticket "
      " WHERE tkt_uuid>=:lwr AND tkt_uuid<:upr",
      zTitleExpr, zClosedExpr
    );
  }
  db_bind_text(&q, ":lwr", zLower);
  db_bind_text(&q, ":upr", zUpper);
  if( db_step(&q)==SQLITE_ROW ){
    n = db_column_bytes(&q,0);
    if( n>nDisplay-1 ) n = nDisplay - 1;
    memcpy(zDisplay, db_column_text(&q, 0), n);
    zDisplay[n] = 0;
    rc = 1;
    *pClosed = db_column_int(&q, 1);
  }else{
    rc = 0;
  }
  db_reset(&q);
  return rc;
}

/*
** Resolve a hyperlink.  The zTarget argument is the content of the [...]
** in the wiki.  Append an <a> markup to the output of the Renderer.
**
** Actually, this routine might or might not append the hyperlink, depending
** on current rendering rules: specifically does the current user have
** "History" permission.  If this routine does append the <a> and thus needs
** a </a> to follow, it returns true.  If the <a> is suppressed, then return
** false.
**
** If nDisplay>0 then optionally write up to nDisplay bytes of 
** alternative display text into zDisplay.  The text must be zero
** terminated.  The final zero is included in the nDisplay byte count
** limit.
*/
static int resolveHyperlink(
  Renderer *p,            /* Rendering context */
  const char *zTarget,    /* Hyperlink traget; text within [...] */
  char *zDisplay,         /* Space in which to write alternative display */
  int nDisplay            /* Bytes available in zDisplay[] */
){
  int rc = 0;
  if( strncmp(zTarget, "http:", 5)==0 
   || strncmp(zTarget, "https:", 6)==0
   || strncmp(zTarget, "ftp:", 4)==0 
   || strncmp(zTarget, "mailto:", 7)==0
  ){
    blob_appendf(p->pOut, "<a href=\"%s\">", zTarget);
    rc = 1;
  }else if( zTarget[0]=='/' ){
    if( g.okHistory ){
      blob_appendf(p->pOut, "<a href=\"%s%h\">", g.zBaseURL, zTarget);
      rc = 1;
    }
  }else if( is_valid_uuid(zTarget) ){
    int isClosed;
    if( nDisplay && is_ticket(zTarget, zDisplay, nDisplay, &isClosed) ){
      /* Special display processing for tickets.  Display the hyperlink
      ** as crossed out if the ticket is closed.  Add the title after the
      ** hyperlink.
      */
      if( isClosed ){
        if( g.okHistory ){
          blob_appendf(p->pOut,"<a href=\"%s/info/%s\">[<s>%s</s>]</a>: %s",
              g.zBaseURL, zTarget, zTarget, zDisplay
          );
        }else{
          blob_appendf(p->pOut,"[<s>%s</s>]: %s", zTarget, zDisplay);
        }
      }else{
        if( g.okHistory ){
          blob_appendf(p->pOut,"<a href=\"%s/info/%s\">[%s]</a>: %s",
              g.zBaseURL, zTarget, zTarget, zDisplay
          );
        }else{
          blob_appendf(p->pOut,"[%s]: %s", zTarget, zDisplay);
        }
      }
      zDisplay[0] = ' ';
      zDisplay[1] = 0;
      rc = 0;
    }else if( g.okHistory ){
      blob_appendf(p->pOut, "<a href=\"%s/info/%s\">", g.zBaseURL, zTarget);
      rc = 1;
    }
  }else if( wiki_name_is_wellformed(zTarget) ){
    blob_appendf(p->pOut, "<a href=\"%s/wiki?name=%T\">", g.zBaseURL, zTarget);
    rc = 1;
  }else{
    blob_appendf(p->pOut, "[bad-link: %h]", zTarget);
    rc = 0;
  }
  return rc;
}

/*
** Check to see if the given parsed markup is the correct
** </verbatim> tag.
*/
static int endVerbatim(Renderer *p, ParsedMarkup *pMarkup){
1026
1027
1028
1029
1030
1031
1032

1033


1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045

1046
1047

1048
1049
1050
1051
1052
1053
1054
1055
1056
1057



1058

1059
1060
1061
1062
1063
1064
1065
1066
1067
        break;
      }
      case TOKEN_LINK: {
        char *zTarget;
        char *zDisplay = 0;
        int i, j;
        int savedState;

        int ok;


        startAutoParagraph(p);
        zTarget = &z[1];
        for(i=1; z[i] && z[i]!=']'; i++){
          if( z[i]=='|' && zDisplay==0 ){
            zDisplay = &z[i+1];
            z[i] = 0;
            for(j=i-1; j>0 && isspace(z[j]); j--){ z[j] = 0; }
          }
        }
        z[i] = 0;
        if( zDisplay==0 ){
          zDisplay = zTarget;

        }else{
          while( isspace(*zDisplay) ) zDisplay++;

        }
        ok = okToHyperlink(zTarget);
        if( ok ){
          blob_append(p->pOut, "<a href=\"", -1);
          resolveHyperlink(zTarget, p);
          blob_append(p->pOut, "\">", -1);
        }
        savedState = p->state;
        p->state &= ~ALLOW_WIKI;
        p->state |= FONT_MARKUP_ONLY;



        wiki_render(p, zDisplay);

        p->state = savedState;
        if( ok ) blob_append(p->pOut, "</a>", 4);
        break;
      }
      case TOKEN_TEXT: {
        startAutoParagraph(p);
        blob_append(p->pOut, z, n);
        break;
      }







>
|
>
>












>


>

|
<
<
|
<
<



>
>
>
|
>

|







1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137


1138


1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
        break;
      }
      case TOKEN_LINK: {
        char *zTarget;
        char *zDisplay = 0;
        int i, j;
        int savedState;
        int needCloseA;
        int altSize;
        char zAltDisplay[100];

        startAutoParagraph(p);
        zTarget = &z[1];
        for(i=1; z[i] && z[i]!=']'; i++){
          if( z[i]=='|' && zDisplay==0 ){
            zDisplay = &z[i+1];
            z[i] = 0;
            for(j=i-1; j>0 && isspace(z[j]); j--){ z[j] = 0; }
          }
        }
        z[i] = 0;
        if( zDisplay==0 ){
          zDisplay = zTarget;
          altSize = sizeof(zAltDisplay);
        }else{
          while( isspace(*zDisplay) ) zDisplay++;
          altSize = 0;
        }
        zAltDisplay[0] = 0;


        needCloseA = resolveHyperlink(p, zTarget, zAltDisplay, altSize);


        savedState = p->state;
        p->state &= ~ALLOW_WIKI;
        p->state |= FONT_MARKUP_ONLY;
        if( zAltDisplay[0] ){
          wiki_render(p, zAltDisplay);
        }else{
          wiki_render(p, zDisplay);
        }
        p->state = savedState;
        if( needCloseA ) blob_append(p->pOut, "</a>", 4);
        break;
      }
      case TOKEN_TEXT: {
        startAutoParagraph(p);
        blob_append(p->pOut, z, n);
        break;
      }