72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
+
-
+
-
+
-
-
+
+
+
+
|
*/
char *interwiki_url(const char *zTarget){
int nCode;
int i;
const char *zPage;
int nPage;
char *zUrl = 0;
char *zName;
Stmt q;
static Stmt q;
for(i=0; fossil_isalnum(zTarget[i]); i++){}
if( zTarget[i]!=':' ) return 0;
nCode = i;
if( nCode==4 && strncmp(zTarget,"wiki",4)==0 ) return 0;
zPage = zTarget + nCode + 1;
nPage = (int)strlen(zPage);
db_prepare(&q,
db_static_prepare(&q,
"SELECT json_extract(value,'$.base'),"
" json_extract(value,'$.hash'),"
" json_extract(value,'$.wiki')"
" FROM config WHERE name=lower('interwiki:%.*q')",
nCode, zTarget);
" FROM config WHERE name=lower($name)"
);
zName = mprintf("interwiki:%.*s", nCode, zTarget);
db_bind_text(&q, "$name", zName);
while( db_step(&q)==SQLITE_ROW ){
const char *zBase = db_column_text(&q,0);
if( zBase==0 || zBase[0]==0 ) break;
if( nPage==0 || zPage[0]=='/' ){
/* Path */
zUrl = mprintf("%s%s", zBase, zPage);
}else if( nPage>=4 && validate16(zPage,nPage) ){
|
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
|
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
|
-
+
+
|
const char *zWiki = db_column_text(&q,2);
if( zWiki && zWiki[0] ){
zUrl = mprintf("%s%s%s", zBase, zWiki, zPage);
}
}
break;
}
db_finalize(&q);
db_reset(&q);
free(zName);
return zUrl;
}
/*
** If hyperlink target zTarget begins with an interwiki tag that ought
** to be excluded from display, then return the number of characters in
** that tag.
|