| ︙ | | | ︙ | |
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
*******************************************************************************
**
** Implementation of the Tag View page
*/
#include <assert.h>
#include "config.h"
#include "tagview.h"
/**
tagview_strxform_f is a typedef for funcs with the following policy:
They accept a const string which they then transform into some other
form. They return a transformed copy, which the caller is responsible
for freeing.
|
>
>
>
>
>
>
>
>
|
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
*******************************************************************************
**
** Implementation of the Tag View page
*/
#include <assert.h>
#include "config.h"
#include "tagview.h"
#if 1
# define TAGVIEW_DEFAULT_FILTER "AND t.tagname NOT GLOB 'wiki-*' "
#else
# define TAGVIEW_DEFAULT_FILTER
#endif
/**
tagview_strxform_f is a typedef for funcs with the following policy:
They accept a const string which they then transform into some other
form. They return a transformed copy, which the caller is responsible
for freeing.
|
| ︙ | | | ︙ | |
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
/** Returns a hyperlink to uuid. */
static char * tagview_xf_link_to_uuid( char const * uuid )
{
const int offset = 10;
char shortname[offset+1];
shortname[offset] = '\0';
memcpy( shortname, uuid, offset );
return mprintf( "<tt><a href='%s/vinfo/%s'><strong>%s</strong>%s</a></tt>",
g.zBaseURL, uuid, shortname, uuid+offset );
}
/** Returns a hyperlink to the given tag. */
static char * tagview_xf_link_to_tagid( char const * tagid )
{
return mprintf( "<a href='%s/tagview?tagid=%s'>%s</a>",
|
|
|
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
/** Returns a hyperlink to uuid. */
static char * tagview_xf_link_to_uuid( char const * uuid )
{
const int offset = 10;
char shortname[offset+1];
shortname[offset] = '\0';
memcpy( shortname, uuid, offset );
return mprintf( "<tt><a href='%s/vinfo/%s'><span style='font-size:1.5em'>%s</span>%s</a></tt>",
g.zBaseURL, uuid, shortname, uuid+offset );
}
/** Returns a hyperlink to the given tag. */
static char * tagview_xf_link_to_tagid( char const * tagid )
{
return mprintf( "<a href='%s/tagview?tagid=%s'>%s</a>",
|
| ︙ | | | ︙ | |
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
|
{
likeclause = mprintf( "AND t.tagname LIKE '%%%%%q%%%%'", like );
@ <h2>Tags matching [%s(likeclause)]:</h2>
}
else
{
limitstr = mprintf( "LIMIT %d", limit );
@ <h2>%d(limit) most recent non-wiki tags:</h2>
}
char * sql = mprintf(
"SELECT t.tagid, t.tagname, DATETIME(tx.mtime), b.uuid "
"FROM tag t, tagxref tx, blob b "
"WHERE (t.tagid=tx.tagid) and (tx.srcid=b.rid) "
"AND (tx.tagtype != 0) %s "
"AND t.tagname NOT GLOB 'wiki-*' "
"ORDER BY tx.mtime DESC %s",
likeclause ? likeclause : " ",
limitstr ? limitstr : " "
);
/* " AND t.tagname NOT GLOB 'wiki-*'" // Do we want this?? */
char const * const colnames[] = {
"Tag ID", "Name", "Timestamp", "Version"
};
tagview_strxform_f xf[] = {
tagview_xf_link_to_tagid,
tagview_xf_link_to_tagname,
0,
|
|
|
|
|
|
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
|
{
likeclause = mprintf( "AND t.tagname LIKE '%%%%%q%%%%'", like );
@ <h2>Tags matching [%s(likeclause)]:</h2>
}
else
{
limitstr = mprintf( "LIMIT %d", limit );
@ <h2>%d(limit) most recent tags:</h2>
}
char * sql = mprintf(
"SELECT t.tagid, t.tagname, DATETIME(tx.mtime), b.uuid "
"FROM tag t, tagxref tx, blob b "
"WHERE (t.tagid=tx.tagid) and (tx.srcid=b.rid) "
"AND (tx.tagtype != 0) %s "
TAGVIEW_DEFAULT_FILTER
"ORDER BY tx.mtime DESC %s",
likeclause ? likeclause : " ",
limitstr ? limitstr : " "
);
if( limitstr ) free(limitstr);
if( likeclause ) free(likeclause);
char const * const colnames[] = {
"Tag ID", "Name", "Timestamp", "Version"
};
tagview_strxform_f xf[] = {
tagview_xf_link_to_tagid,
tagview_xf_link_to_tagname,
0,
|
| ︙ | | | ︙ | |
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
|
static void tagview_page_tag_by_id( int tagid )
{
@ <h2>Tag #%d(tagid):</h2>
char * sql = mprintf(
"SELECT DISTINCT (t.tagname), DATETIME(tx.mtime), b.uuid "
"FROM tag t, tagxref tx, blob b "
"WHERE (t.tagid=%d) AND (t.tagid=tx.tagid) AND (tx.srcid=b.rid) "
"AND t.tagname NOT GLOB 'wiki-*' "
"ORDER BY tx.mtime DESC",
tagid);
char const * const colnames[] = {
"Tag Name", "Timestamp", "Version"
};
tagview_strxform_f xf[] = {
tagview_xf_link_to_tagname,
|
|
|
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
|
static void tagview_page_tag_by_id( int tagid )
{
@ <h2>Tag #%d(tagid):</h2>
char * sql = mprintf(
"SELECT DISTINCT (t.tagname), DATETIME(tx.mtime), b.uuid "
"FROM tag t, tagxref tx, blob b "
"WHERE (t.tagid=%d) AND (t.tagid=tx.tagid) AND (tx.srcid=b.rid) "
TAGVIEW_DEFAULT_FILTER
"ORDER BY tx.mtime DESC",
tagid);
char const * const colnames[] = {
"Tag Name", "Timestamp", "Version"
};
tagview_strxform_f xf[] = {
tagview_xf_link_to_tagname,
|
| ︙ | | | ︙ | |
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
|
static void tagview_page_tag_by_name( char const * tagname )
{
@ <h2>Tag '%s(tagname)':</h2>
char * sql = mprintf(
"SELECT DISTINCT t.tagid, DATETIME(tx.mtime), b.uuid "
"FROM tag t, tagxref tx, blob b "
"WHERE (t.tagname='%q') AND (t.tagid=tx.tagid) AND (tx.srcid=b.rid) "
"AND t.tagname NOT GLOB 'wiki-*' "
"ORDER BY tx.mtime DESC",
tagname);
char const * const colnames[] = {
"Tag ID", "Timestamp", "Version"
};
tagview_strxform_f xf[] = {
tagview_xf_link_to_tagid,
0,
tagview_xf_link_to_uuid
};
tagview_run_query( sql, colnames, xf );
free( sql );
}
/*
** WEBPAGE: /tagview
*/
void tagview_page(void){
login_check_credentials();
if( !g.okRdWiki ){
login_needed();
}
style_header("Tags");
tagview_page_search_miniform();
@ <hr/>
|
|
<
|
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
|
static void tagview_page_tag_by_name( char const * tagname )
{
@ <h2>Tag '%s(tagname)':</h2>
char * sql = mprintf(
"SELECT DISTINCT t.tagid, DATETIME(tx.mtime), b.uuid "
"FROM tag t, tagxref tx, blob b "
"WHERE (t.tagname='%q') AND (t.tagid=tx.tagid) AND (tx.srcid=b.rid) "
TAGVIEW_DEFAULT_FILTER
"ORDER BY tx.mtime DESC",
tagname);
char const * const colnames[] = {
"Tag ID", "Timestamp", "Version"
};
tagview_strxform_f xf[] = {
tagview_xf_link_to_tagid,
0,
tagview_xf_link_to_uuid
};
tagview_run_query( sql, colnames, xf );
free( sql );
}
/*
** WEBPAGE: /tagview
*/
void tagview_page(void){
login_check_credentials();
if( !g.okRdWiki ){
login_needed();
}
style_header("Tags");
tagview_page_search_miniform();
@ <hr/>
|
| ︙ | | | ︙ | |
314
315
316
317
318
319
320
|
}
else
{
tagview_page_default();
}
style_footer();
}
|
>
>
|
321
322
323
324
325
326
327
328
329
|
}
else
{
tagview_page_default();
}
style_footer();
}
#undef TAGVIEW_DEFAULT_FILTER
|