@@ -869,16 +869,14 @@
}
/*
** 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
+** If it is, store in *pClosed a true or false depending on whether or not
+** the ticket is closed 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;
@@ -891,25 +889,21 @@
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 "
+ "SELECT %s FROM ticket "
" WHERE tkt_uuid>=:lwr AND tkt_uuid<:upr",
- zTitleExpr, zClosedExpr
+ zClosedExpr
);
+ once = 0;
}
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);
+ *pClosed = db_column_int(&q, 0);
}else{
rc = 0;
}
db_reset(&q);
@@ -917,79 +911,73 @@
}
/*
** Resolve a hyperlink. The zTarget argument is the content of the [...]
-** in the wiki. Append an <a> markup to the output of the Renderer.
+** in the wiki. Append to the output string whatever text is approprate
+** for opening the hyperlink. Write into zClose[0...nClose-1] text that will
+** close the markup.
**
** 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.
+** "History" permission.
*/
-static int resolveHyperlink(
+static void openHyperlink(
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[] */
+ char *zClose, /* Write hyperlink closing text here */
+ int nClose /* Bytes available in zClose[] */
){
- int rc = 0;
+ const char *zTerm = "</a>";
+ assert( nClose>10 );
+
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{
+ zTerm = "";
}
}else if( is_valid_uuid(zTarget) ){
int isClosed;
- if( nDisplay && is_ticket(zTarget, zDisplay, nDisplay, &isClosed) ){
+ if( is_ticket(zTarget, &isClosed) ){
/* Special display processing for tickets. Display the hyperlink
- ** as crossed out if the ticket is closed. Add the title after the
- ** hyperlink.
+ ** as crossed out if the ticket is closed.
*/
if( isClosed ){
if( g.okHistory ){
- blob_appendf(p->pOut,"<a href=\"%s/info/%s\">[<s>%s</s>]</a>: %s",
- g.zBaseURL, zTarget, zTarget, zDisplay
+ blob_appendf(p->pOut,"<a href=\"%s/info/%s\"><s>",
+ g.zBaseURL, zTarget
);
+ zTerm = "</s></a>";
}else{
- blob_appendf(p->pOut,"[<s>%s</s>]: %s", zTarget, zDisplay);
+ blob_appendf(p->pOut,"<s>");
+ zTerm = "</s>";
}
}else{
if( g.okHistory ){
- blob_appendf(p->pOut,"<a href=\"%s/info/%s\">[%s]</a>: %s",
- g.zBaseURL, zTarget, zTarget, zDisplay
+ blob_appendf(p->pOut,"<a href=\"%s/info/%s\">",
+ g.zBaseURL, zTarget
);
}else{
- blob_appendf(p->pOut,"[%s]: %s", zTarget, zDisplay);
+ zTerm = "";
}
}
- 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;
+ zTerm = "";
}
- return rc;
+ assert( strlen(zTerm)<nClose );
+ strcpy(zClose, zTerm);
}
/*
** Check to see if the given parsed markup is the correct
@@ -1112,11 +1100,9 @@
char *zTarget;
char *zDisplay = 0;
int i, j;
int savedState;
- int needCloseA;
- int altSize;
- char zAltDisplay[100];
+ char zClose[20];
startAutoParagraph(p);
zTarget = &z[1];
for(i=1; z[i] && z[i]!=']'; i++){
@@ -1128,25 +1114,18 @@
}
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);
+ openHyperlink(p, zTarget, zClose, sizeof(zClose));
savedState = p->state;
p->state &= ~ALLOW_WIKI;
p->state |= FONT_MARKUP_ONLY;
- if( zAltDisplay[0] ){
- wiki_render(p, zAltDisplay);
- }else{
- wiki_render(p, zDisplay);
- }
+ wiki_render(p, zDisplay);
p->state = savedState;
- if( needCloseA ) blob_append(p->pOut, "</a>", 4);
+ blob_append(p->pOut, zClose, -1);
break;
}
case TOKEN_TEXT: {
startAutoParagraph(p);